diff options
Diffstat (limited to 'src/document/store.rs')
| -rw-r--r-- | src/document/store.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/document/store.rs b/src/document/store.rs index cd455b6..7de7373 100644 --- a/src/document/store.rs +++ b/src/document/store.rs @@ -654,6 +654,29 @@ pub(crate) fn read_path_with_conflicts_as( Ok(value.map(|value| (value, log.reports))) } +/// Whether anything is at `path` (map keys only) in any of the values written at once on +/// the way to it, not only those a read shows: of every key, every map among its values, +/// then the key itself (as `by_seq` walks them). A read shows the newest value of a key, +/// merging maps only where that one is a map, so a value beside a map hides what is in it. +pub(crate) fn held_anywhere(doc: &impl ReadDoc, path: &[String]) -> bool { + let Some((last, way)) = path.split_last() else { + return true; + }; + let mut maps = vec![automerge::ROOT]; + for step in way { + maps = maps + .iter() + .flat_map(|map| doc.get_all(map, step.as_str()).unwrap_or_default()) + .filter_map(|(value, id)| matches!(value, Value::Object(ObjType::Map)).then_some(id)) + .collect(); + } + maps.iter().any(|map| { + !doc.get_all(map, last.as_str()) + .unwrap_or_default() + .is_empty() + }) +} + /// What is stored at `path` (the empty path: the root map), and, where it is a scalar /// or a text, the value itself, to show natively (`typed::native`); None if nothing is /// there. |
