aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/access.md5
-rw-r--r--src/document/changes.rs63
2 files changed, 64 insertions, 4 deletions
diff --git a/docs/access.md b/docs/access.md
index 2b5f54c..ce1e55a 100644
--- a/docs/access.md
+++ b/docs/access.md
@@ -321,8 +321,9 @@ list's element, never its head, without inserting, replacing what is at that ele
(the element itself, or what was written at it); write at a map's key, never inserting,
a deletion or an increment replacing something; and mark only in a text, the end
inserted right after the begin, at the begin or at an element after the one the begin
-follows. Automerge applies some others, and then panics, saves a document that doesn't
-load, or holds another change than the one it was given. All of it is asked of the
+follows. A table is refused too, which transactions make but can't write into, and the
+store makes none. Automerge applies some others, and then panics, saves a document that
+doesn't load, or holds another change than the one it was given. All of it is asked of the
change and its history alone, so two nodes that hold a change's history come to the
same, whatever else they hold: a change of the same batch refused after it passed
(forged, or against the rules) stands in for nothing.
diff --git a/src/document/changes.rs b/src/document/changes.rs
index a40f4e4..575b83e 100644
--- a/src/document/changes.rs
+++ b/src/document/changes.rs
@@ -493,8 +493,11 @@ impl Written {
}
// The object written into: one, of the kind the key is for.
let in_list = matches!(op.key, Key::Seq(_));
- let fits = |kind: automerge::ObjType| {
- in_list == matches!(kind, automerge::ObjType::List | automerge::ObjType::Text)
+ // No table: `unwritten` refuses making one.
+ let fits = |kind: automerge::ObjType| match kind {
+ automerge::ObjType::Map => !in_list,
+ automerge::ObjType::List | automerge::ObjType::Text => in_list,
+ automerge::ObjType::Table => false,
};
// Whether the object is one the document held at `doc_heads`, for what
// can then be read there, and its kind.
@@ -732,6 +735,9 @@ impl Written {
/// * At a map's key, never inserted: a value put, an object made, or a deletion or an
/// increment replacing something; no mark.
/// * A mark: its begin, and its end as the operation right after, both inserted.
+///
+/// And no table made: transactions make one but can't write into it, and Automerge
+/// panics applying a change that does; continuum's store makes none.
fn unwritten(operations: &[automerge::legacy::Op], index: usize) -> Option<&'static str> {
use automerge::legacy::{ElementId, Key, OpType};
let op = &operations[index];
@@ -743,6 +749,7 @@ fn unwritten(operations: &[automerge::legacy::Op], index: usize) -> Option<&'sta
let mark = matches!(op.action, OpType::MarkBegin(_) | OpType::MarkEnd(_));
let replaces = !op.pred.is_empty();
match (&op.key, op.insert, &op.action) {
+ (_, _, OpType::Make(automerge::ObjType::Table)) => Some("it makes a table"),
(Key::Map(_), true, _) => Some("it inserts at a map's key"),
(Key::Seq(_), true, OpType::Delete | OpType::Increment(_)) => {
Some("it inserts a deletion or an increment")
@@ -1554,6 +1561,58 @@ mod tests {
}
}
+ /// No table: made, by itself or with what is written into it, or written into
+ /// where the document holds one. Automerge panics applying a change that writes
+ /// into one; transactions can't, and continuum's store makes none.
+ #[test]
+ fn no_table() {
+ use crate::document::Transaction;
+ use automerge::ObjType;
+ use automerge::legacy::{ObjectId, OpId, OpType};
+ let mut theirs = Document::new();
+ let map = change(&mut theirs, |doc| {
+ let map = doc.put_object(ROOT, "map", ObjType::Map).unwrap();
+ doc.put_object(ROOT, "table", ObjType::Table).unwrap();
+ map
+ });
+ let first = theirs.get_last_local_change().unwrap();
+ assert!(
+ Written::default()
+ .check(&Document::new(), &first, &first.decode())
+ .is_some()
+ );
+ // As if it was taken without screening.
+ let table = ObjectId::Id(OpId(first.start_op().get() + 1, first.actor_id().clone()));
+ let mut ours = Document::new();
+ ours.apply_changes([first]).unwrap();
+ fn on(doc: &Document, write: impl FnOnce(&mut Transaction<'_>)) -> Change {
+ let mut fork = doc.fork();
+ change(&mut fork, write);
+ fork.get_last_local_change().unwrap()
+ }
+ let put = on(&ours, |doc| doc.put(&map, "k", 1).unwrap());
+ let made = on(&ours, |doc| {
+ let made = doc.put_object(ROOT, "made", ObjType::Map).unwrap();
+ doc.put(&made, "k", 1).unwrap();
+ });
+ for honest in [&put, &made] {
+ assert_eq!(
+ Written::default().check(&ours, honest, &honest.decode()),
+ None
+ );
+ }
+ let crafted = [
+ crafted(&put, |change| change.operations[0].obj = table.clone()),
+ crafted(&made, |change| {
+ change.operations[0].action = OpType::Make(ObjType::Table)
+ }),
+ ];
+ for crafted in crafted {
+ let why = Written::default().check(&ours, &crafted, &crafted.decode());
+ assert!(why.is_some(), "{:?}", crafted.decode().operations);
+ }
+ }
+
/// What an operation replaces put a value or made an object, as a transaction names
/// it: a counter incremented and put over names its put alone, a key put again
/// after its deletion names nothing. One naming a deletion Automerge takes, and