diff options
Diffstat (limited to 'src/document')
| -rw-r--r-- | src/document/events.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/document/events.rs b/src/document/events.rs index ee16de7..687079e 100644 --- a/src/document/events.rs +++ b/src/document/events.rs @@ -8,7 +8,7 @@ //! (`store::write_path`). Its writer is the first 16 bytes of the root's ID, its time 0, //! and it has no message. -use automerge::legacy::OpType; +use automerge::legacy::{Key, OpType}; use automerge::transaction::CommitOptions; use automerge::{ObjId, ObjType, ScalarValue, Value}; use serde_json::Value as JsonValue; @@ -51,6 +51,22 @@ pub(crate) fn bytes(doc: &impl ReadDoc, id: &Id) -> Option<Vec<u8>> { } } +/// The events `change` puts: bytes, each at a key that is its ID. +pub(crate) fn carried(change: &Change) -> Vec<Vec<u8>> { + super::changes::decode(change) + .operations + .into_iter() + .filter_map(|op| match (op.key, op.action) { + (Key::Map(key), OpType::Put(ScalarValue::Bytes(bytes))) + if Id::of(&bytes).to_string() == key.as_str() => + { + Some(bytes) + } + _ => None, + }) + .collect() +} + /// The policy of a swarm holding a store of the fold `fold`. pub(crate) fn policy(fold: &str) -> JsonValue { serde_json::json!({"version": 2, "store": fold}) @@ -159,6 +175,7 @@ mod tests { ); assert_eq!(ids(&doc), vec![id]); assert_eq!(bytes(&doc, &id).as_deref(), Some(ROOT)); + assert_eq!(carried(&genesis("federation", ROOT)), vec![ROOT.to_vec()]); } #[test] |
