From 9188fa6e13ea7facfab5fb6f55bf26444ec2c01e Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 03:15:05 +0000 Subject: document: values read and written through a view any kind of document gives document::view: Read (the value at a path, plain, typed, a map's keys) and Write (a value written, one deleted), which Automerge's documents, writes in progress and documents as they were all are. The member registry, the users, access control's reads and rules, the topology, forgetting and bootstrap read and write through them, and name neither Automerge's ReadDoc and Transactable nor document::store, which is what an Automerge document can do beyond. How a swarm holding a store judges what a change writes is handed to the rules (rules::judge_seen), being its kind of document's to say. --- src/api/login.rs | 6 +++--- src/api/peers.rs | 4 ++-- src/api/users.rs | 36 ++++++++++++++++++------------------ 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/api') diff --git a/src/api/login.rs b/src/api/login.rs index ffcf9b8..02c54a3 100644 --- a/src/api/login.rs +++ b/src/api/login.rs @@ -678,7 +678,7 @@ async fn end(state: &AppState, claims: &Claims, by: &str) -> Result<(), ApiError if !registry::exists(&*doc) { return Ok::<_, ApiError>(false); } - crate::document::store::write_path(doc, &path, &json!(until))?; + crate::document::view::write_path(doc, &path, &json!(until))?; Ok(true) }) .await? @@ -783,10 +783,10 @@ pub(crate) async fn revoke_tokens(state: &AppState, name: &str, by: &str) -> Res ), )); } - if crate::document::store::read_path(&*doc, &entry)?.is_none() { + if crate::document::view::read_path(&*doc, &entry)?.is_none() { return Err(ApiError(StatusCode::NOT_FOUND, None)); } - crate::document::store::write_path(doc, &logouts, &json!(after))?; + crate::document::view::write_path(doc, &logouts, &json!(after))?; Ok(()) }) .await?; diff --git a/src/api/peers.rs b/src/api/peers.rs index 30d1204..fc203f5 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -13,7 +13,7 @@ use tracing::warn; use super::store_status; use crate::document::replica::EpochRecord; -use crate::document::store; +use crate::document::view; use crate::locks::MutexExt; use crate::state::{AppState, HelloState, Incidents, Liveness}; use crate::swarm::peer::forgotten_path; @@ -326,7 +326,7 @@ pub(crate) async fn delete_peer( user, crate::document::signatures::Sign::Protocol, move |doc| { - store::write_path(doc, &forgotten_path(&peer_clone), &record)?; + view::write_path(doc, &forgotten_path(&peer_clone), &record)?; crate::swarm::members::unregister(doc, &peer_clone) }, ) diff --git a/src/api/users.rs b/src/api/users.rs index f27eff1..cf28ed1 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -49,7 +49,7 @@ use super::ApiError; use super::access::{Access, Before, registry_kept}; use super::auth::AuthenticatedUser; use crate::access::{Right, envelope, registry}; -use crate::document::store; +use crate::document::view; use crate::state::AppState; /// A capability as a request gives it. @@ -133,7 +133,7 @@ fn may_manage(state: &AppState, user: &str, access: &Access) -> Result<(), ApiEr /// A user's entry as the API shows it: as recorded, with its name. fn shown(doc: &impl crate::document::ReadDoc, name: &str) -> Option { - let mut entry = store::read_plain(doc, ®istry::user_path(name)).ok()??; + let mut entry = view::read_plain(doc, ®istry::user_path(name)).ok()??; if let Some(object) = entry.as_object_mut() { object.insert("name".to_owned(), json!(name)); } @@ -148,11 +148,11 @@ pub(crate) async fn own_keys( ) -> Result, ApiError> { let replica = state.doc.read().await; let path = registry::user_path(&user.0); - let entry = store::read_plain(&replica.doc, &path) + let entry = view::read_plain(&replica.doc, &path) .ok() .flatten() .ok_or_else(|| ApiError(StatusCode::NOT_FOUND, Some("no entry of yours".to_owned())))?; - let signed = match store::read_path(&replica.doc, &path) { + let signed = match view::read_path(&replica.doc, &path) { Ok(Some(JsonValue::String(text))) if envelope::read(&text).is_ok() => Some(text), _ => None, }; @@ -218,7 +218,7 @@ async fn own_key( ), )); } - if store::read_path(&*doc, &entry)?.is_none() { + if view::read_path(&*doc, &entry)?.is_none() { return Err(ApiError( StatusCode::NOT_FOUND, Some("no entry of yours".to_owned()), @@ -227,7 +227,7 @@ async fn own_key( if line.is_none() && !password { let mut keys = entry.clone(); keys.push("keys".to_owned()); - let others = store::keys_at(&*doc, &keys)? + let others = view::keys_at(&*doc, &keys)? .unwrap_or_default() .into_iter() .filter(|other| *other != id_kept) @@ -244,8 +244,8 @@ async fn own_key( } } match line { - Some(line) => store::write_path(doc, &path, &json!(line))?, - None => match store::delete_path(doc, &path, false) { + Some(line) => view::write_path(doc, &path, &json!(line))?, + None => match view::delete_path(doc, &path, false) { Ok(()) => {} Err(crate::document::store::StoreError::NotFound) => { return Err(ApiError(StatusCode::NOT_FOUND, None)); @@ -340,7 +340,7 @@ pub(crate) async fn add( &user.0, format!("Added user {name}"), move |doc, by, since| { - if store::read_path(&*doc, &path)?.is_some() { + if view::read_path(&*doc, &path)?.is_some() { return Err(ApiError( StatusCode::CONFLICT, Some("the user exists".to_owned()), @@ -350,7 +350,7 @@ pub(crate) async fn add( .iter() .map(|(path, rights)| (path.clone(), rights.as_slice())) .collect(); - store::write_path(doc, &path, ®istry::entry(by, since, &caps))?; + view::write_path(doc, &path, ®istry::entry(by, since, &caps))?; Ok(()) }, ) @@ -372,7 +372,7 @@ pub(crate) async fn remove( &user.0, format!("Removed user {name}"), move |doc, _, _| { - store::delete_path(doc, &path, false)?; + view::delete_path(doc, &path, false)?; Ok(()) }, ) @@ -395,12 +395,12 @@ pub(crate) async fn set_disabled( if disabled { "Disabled" } else { "Enabled" } ); change(&state, &user.0, what, move |doc, _, _| { - if store::read_path(&*doc, &entry)?.is_none() { + if view::read_path(&*doc, &entry)?.is_none() { return Err(ApiError(StatusCode::NOT_FOUND, None)); } let mut path = entry; path.push("disabled".to_owned()); - store::write_path(doc, &path, &json!(disabled))?; + view::write_path(doc, &path, &json!(disabled))?; Ok(()) }) .await?; @@ -423,10 +423,10 @@ pub(crate) async fn grant( path.extend(["caps".to_owned(), id.clone()]); let what = format!("Granted user {name} {:?} on {:?}", cap.rights, cap.path); change(&state, &user.0, what, move |doc, by, since| { - if store::read_path(&*doc, &entry)?.is_none() { + if view::read_path(&*doc, &entry)?.is_none() { return Err(ApiError(StatusCode::NOT_FOUND, None)); } - store::write_path( + view::write_path( doc, &path, ®istry::capability(by, since, &cap.path, &rights), @@ -452,7 +452,7 @@ pub(crate) async fn revoke( &user.0, format!("Revoked capability {id} of user {name}"), move |doc, _, _| { - store::delete_path(doc, &path, false)?; + view::delete_path(doc, &path, false)?; Ok(()) }, ) @@ -498,7 +498,7 @@ pub(crate) async fn add_several( change(&state, &user.0, what, move |doc, by, since| { for (name, caps) in &users { let path = registry::user_path(name); - if store::read_path(&*doc, &path)?.is_some() { + if view::read_path(&*doc, &path)?.is_some() { return Err(ApiError( StatusCode::CONFLICT, Some(format!("user {name} exists")), @@ -508,7 +508,7 @@ pub(crate) async fn add_several( .iter() .map(|(path, rights)| (path.clone(), rights.as_slice())) .collect(); - store::write_path(doc, &path, ®istry::entry(by, since, &caps))?; + view::write_path(doc, &path, ®istry::entry(by, since, &caps))?; } Ok(()) }) -- cgit v1.3.1