aboutsummaryrefslogtreecommitdiffstats
path: root/src/access/policy.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/access/policy.rs')
-rw-r--r--src/access/policy.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/access/policy.rs b/src/access/policy.rs
index 1e28731..e4027b8 100644
--- a/src/access/policy.rs
+++ b/src/access/policy.rs
@@ -20,7 +20,8 @@
use serde_json::Value as JsonValue;
-use crate::document::{ReadDoc, meta, store};
+use crate::document::meta;
+use crate::document::view::{self, Read};
/// The policy versions this node knows: rules by path, and a swarm holding a store.
pub(crate) const VERSION: u64 = 1;
@@ -108,7 +109,7 @@ pub(crate) fn first(
pub(crate) fn as_written(value: &JsonValue) -> Result<Policy, String> {
let mut doc = crate::document::Document::new();
let mut write = doc.transaction();
- store::write_path(&mut write, &path(), value).map_err(|error| error.to_string())?;
+ view::write_path(&mut write, &path(), value).map_err(|error| error.to_string())?;
let policy = of(&write);
write.rollback();
Ok(policy)
@@ -118,8 +119,8 @@ pub(crate) fn as_written(value: &JsonValue) -> Result<Policy, String> {
/// where its `store` is, as continuum writes them: an Automerge text there, or one holding
/// the policy, reads as a string in plain JSON, so a policy that would read so only
/// through a text is one nobody knows, never what its characters spell.
-pub(crate) fn of(doc: &impl ReadDoc) -> Policy {
- match store::read_plain(doc, &path()) {
+pub(crate) fn of(doc: &impl Read) -> Policy {
+ match view::read_plain(doc, &path()) {
Ok(Some(value)) => match read(&value) {
policy if policy.strict() && !a_string(doc, "values") => {
Policy::Unknown("values not a string".to_owned())
@@ -137,13 +138,9 @@ pub(crate) fn of(doc: &impl ReadDoc) -> Policy {
/// Whether the policy `doc` holds, read in typed JSON (where a text is tagged, and an
/// envelope reads as its payload), has a string for its `key`.
-fn a_string(doc: &impl ReadDoc, key: &str) -> bool {
- let typed = crate::document::typed::JsonForm {
- typed: true,
- ..Default::default()
- };
+fn a_string(doc: &impl Read, key: &str) -> bool {
matches!(
- store::read_plain_as(doc, &path(), typed),
+ doc.read_typed(&path()),
Ok(Some(value)) if value.get(key).is_some_and(JsonValue::is_string)
)
}
@@ -211,13 +208,14 @@ fn store_of(value: &JsonValue) -> Policy {
mod tests {
use super::*;
use crate::document::Document;
+ use crate::document::store;
use crate::document::testing::change;
use serde_json::json;
fn with(policy: JsonValue) -> Policy {
let mut doc = Document::new();
change(&mut doc, |doc| {
- store::write_path(doc, &path(), &policy).unwrap();
+ view::write_path(doc, &path(), &policy).unwrap();
});
of(&doc)
}