summaryrefslogtreecommitdiffstats
path: root/src/remake/kind.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/remake/kind.rs')
-rw-r--r--src/remake/kind.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/remake/kind.rs b/src/remake/kind.rs
index 42bdd88..aa9e978 100644
--- a/src/remake/kind.rs
+++ b/src/remake/kind.rs
@@ -25,7 +25,8 @@ use base64::engine::{Engine, general_purpose::STANDARD as BASE64};
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
-use super::snapshot::{META_ROOT, canonical};
+use super::snapshot::canonical;
+use crate::document::meta;
use crate::document::store::{self, StoreError};
use crate::files::{FileKind, Files};
@@ -141,7 +142,7 @@ pub(crate) fn remake_genesis(
/// Paths owned by the protocol rather than by any kind.
pub(crate) fn is_reserved(path: &[String]) -> bool {
- path.first().is_some_and(|root| root == META_ROOT)
+ meta::is_protocol(path)
}
/// Compaction: the new document has the old one's content at the base, without its
@@ -254,9 +255,10 @@ impl RemakeKind for Replace {
let JsonValue::Object(document) = &spec.document else {
return Err("document must be a JSON object (the store root)".to_owned());
};
- if document.contains_key(META_ROOT) {
+ if document.contains_key(meta::ROOT) {
return Err(format!(
- "document must not contain the reserved key {META_ROOT:?}"
+ "document must not contain the reserved key {:?}",
+ meta::ROOT
));
}
@@ -283,7 +285,7 @@ impl RemakeKind for Replace {
return Ok(()); // propose only accepts objects
};
for (key, value) in document {
- if key != META_ROOT {
+ if key != meta::ROOT {
store::write_path(target, &[key], &value)?;
}
}
@@ -311,7 +313,8 @@ fn prepare_rules(specs: Vec<RuleSpec>) -> Result<JsonValue, String> {
};
if is_reserved(&from) || to.as_deref().is_some_and(is_reserved) {
return Err(format!(
- "rules must not touch the reserved key {META_ROOT:?}"
+ "rules must not touch the reserved key {:?}",
+ meta::ROOT
));
}
if rules.iter().any(|existing: &Rule| existing.from == from) {
@@ -528,7 +531,7 @@ mod tests {
));
// Protocol data is never translated.
assert_eq!(
- translator.translate(&path(&[META_ROOT, "forgotten", "pk"])),
+ translator.translate(&path(&[meta::ROOT, meta::FORGOTTEN, "pk"])),
Translation::Same
);
}
@@ -541,7 +544,7 @@ mod tests {
fn replace_validates_the_spec() {
use serde_json::json;
assert!(replace(json!({ "document": [] })).is_err());
- assert!(replace(json!({ "document": { META_ROOT: {} } })).is_err());
+ assert!(replace(json!({ "document": { (meta::ROOT): {} } })).is_err());
assert!(replace(json!({ "document": {}, "rules": [{ "from": "a" }] })).is_err());
assert!(
replace(json!({ "document": {}, "rules": [{ "from": "a", "to": "b", "drop": true }] }))
@@ -551,7 +554,7 @@ mod tests {
replace(json!({ "document": {}, "rules": [{ "from": "a//b", "to": "c" }] })).is_err()
);
assert!(
- replace(json!({ "document": {}, "rules": [{ "from": "a", "to": META_ROOT }] }))
+ replace(json!({ "document": {}, "rules": [{ "from": "a", "to": (meta::ROOT) }] }))
.is_err()
);
assert!(replace(json!({ "document": {}, "rules": [{ "from": "a", "drop": true }, { "from": ["a"], "to": "b" }] })).is_err());
@@ -602,7 +605,7 @@ mod tests {
source
.put(ROOT, "hits", automerge::ScalarValue::counter(3))
.unwrap();
- let meta = source.put_object(ROOT, META_ROOT, ObjType::Map).unwrap();
+ let meta = source.put_object(ROOT, meta::ROOT, ObjType::Map).unwrap();
source.put(&meta, "members", "elsewhere").unwrap();
let encoded = BASE64.encode(source.save());
@@ -632,7 +635,7 @@ mod tests {
let mut b = build();
assert_eq!(a.get_heads(), b.get_heads());
- assert!(a.get(ROOT, META_ROOT).unwrap().is_none());
+ assert!(a.get(ROOT, meta::ROOT).unwrap().is_none());
let (notes, notes_id) = a.get(ROOT, "notes").unwrap().unwrap();
assert!(matches!(notes, automerge::Value::Object(ObjType::Text)));
assert_eq!(a.text(&notes_id).unwrap(), "hello");