diff options
Diffstat (limited to 'src/document/store.rs')
| -rw-r--r-- | src/document/store.rs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/document/store.rs b/src/document/store.rs index 573b811..132a2ef 100644 --- a/src/document/store.rs +++ b/src/document/store.rs @@ -10,7 +10,7 @@ use serde_json::Value as JsonValue; use std::collections::BTreeSet; #[derive(Debug, thiserror::Error)] -pub enum StoreError { +pub(crate) enum StoreError { #[error("path crosses a non-map value")] Conflict, #[error("value does not exist")] @@ -204,11 +204,14 @@ fn read_path_inner( } /// Reads a path; the empty path is the whole store. -pub fn read_path(doc: &AutoCommit, path: &[String]) -> Result<Option<JsonValue>, StoreError> { +pub(crate) fn read_path( + doc: &AutoCommit, + path: &[String], +) -> Result<Option<JsonValue>, StoreError> { read_path_inner(doc, path, None) } -pub fn read_path_with_conflicts( +pub(crate) fn read_path_with_conflicts( doc: &AutoCommit, path: &[String], ) -> Result<Option<(JsonValue, Vec<ConflictReport>)>, StoreError> { @@ -222,7 +225,7 @@ pub fn read_path_with_conflicts( /// For streams: the value, plus whether the path or subtree involves any conflict. /// Reports are collected without values, so this costs little more than read_path. -pub fn read_path_traced( +pub(crate) fn read_path_traced( doc: &AutoCommit, path: &[String], ) -> Result<(Option<JsonValue>, bool), StoreError> { @@ -232,7 +235,7 @@ pub fn read_path_traced( } /// Keys of the merged map at `path`; empty if it doesn't exist or isn't a map. -pub fn keys_at(doc: &AutoCommit, path: &[String]) -> Result<Vec<String>, StoreError> { +pub(crate) fn keys_at(doc: &AutoCommit, path: &[String]) -> Result<Vec<String>, StoreError> { let mut maps = vec![automerge::ROOT]; for segment in path { maps = match resolve(doc, &maps, segment, None)? { @@ -267,7 +270,7 @@ pub(crate) fn read_candidates( } /// Writes (replaces) the value at `path`, creating intermediate maps. -pub fn write_path( +pub(crate) fn write_path( doc: &mut AutoCommit, path: &[String], value: &JsonValue, @@ -353,7 +356,11 @@ pub(crate) fn copy_path_to( } /// Deletes the value at `path`, optionally pruning ancestors that become empty. -pub fn delete_path(doc: &mut AutoCommit, path: &[String], prune: bool) -> Result<(), StoreError> { +pub(crate) fn delete_path( + doc: &mut AutoCommit, + path: &[String], + prune: bool, +) -> Result<(), StoreError> { let (leaf, parents) = path.split_last().ok_or(StoreError::NotFound)?; // levels[d] = merged maps at path[..d] @@ -615,29 +622,29 @@ fn scalar_to_json(scalar: ScalarValue) -> Result<JsonValue, StoreError> { #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] -pub enum Resolution { +pub(crate) enum Resolution { MergedMaps, NewestWins, } #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] -pub struct CandidateReport { - pub op_id: String, - pub selected: bool, +pub(crate) struct CandidateReport { + pub(crate) op_id: String, + pub(crate) selected: bool, #[serde(skip_serializing_if = "Option::is_none")] - pub value: Option<JsonValue>, + pub(crate) value: Option<JsonValue>, } #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] -pub struct ConflictReport { - pub path: Vec<String>, +pub(crate) struct ConflictReport { + pub(crate) path: Vec<String>, /// On the way to the requested path; reported without candidate values. #[serde(skip_serializing_if = "std::ops::Not::not")] - pub ancestor: bool, - pub resolution: Resolution, - pub candidates: Vec<CandidateReport>, + pub(crate) ancestor: bool, + pub(crate) resolution: Resolution, + pub(crate) candidates: Vec<CandidateReport>, } #[derive(Default)] |
