summaryrefslogtreecommitdiffstats
path: root/src/document
diff options
context:
space:
mode:
Diffstat (limited to 'src/document')
-rw-r--r--src/document/mod.rs4
-rw-r--r--src/document/replica.rs38
-rw-r--r--src/document/store.rs41
3 files changed, 45 insertions, 38 deletions
diff --git a/src/document/mod.rs b/src/document/mod.rs
index 1024859..3f489aa 100644
--- a/src/document/mod.rs
+++ b/src/document/mod.rs
@@ -3,5 +3,5 @@
pub(crate) mod file;
pub(crate) mod meta;
-pub mod replica;
-pub mod store;
+pub(crate) mod replica;
+pub(crate) mod store;
diff --git a/src/document/replica.rs b/src/document/replica.rs
index 0cab0be..fe76c12 100644
--- a/src/document/replica.rs
+++ b/src/document/replica.rs
@@ -20,14 +20,14 @@ use tokio::sync::watch;
/// * `id` is the hash of the epoch's snapshot change. It tells two epochs of the same
/// generation apart, which only happens if two remakes committed concurrently.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
-pub struct Epoch {
- pub generation: u64,
- pub id: [u8; 32],
+pub(crate) struct Epoch {
+ pub(crate) generation: u64,
+ pub(crate) id: [u8; 32],
}
/// How a peer's epoch relates to ours.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum EpochRelation {
+pub(crate) enum EpochRelation {
Same,
/// The peer is on an older generation and has to migrate.
PeerBehind,
@@ -39,12 +39,12 @@ pub enum EpochRelation {
impl Epoch {
/// Swarms that have never been compacted.
- pub const GENESIS: Epoch = Epoch {
+ pub(crate) const GENESIS: Epoch = Epoch {
generation: 0,
id: [0; 32],
};
- pub fn relation_to(&self, peer: &Epoch) -> EpochRelation {
+ pub(crate) fn relation_to(&self, peer: &Epoch) -> EpochRelation {
use std::cmp::Ordering;
match peer.generation.cmp(&self.generation) {
Ordering::Less => EpochRelation::PeerBehind,
@@ -54,7 +54,7 @@ impl Epoch {
}
}
- pub fn id_hex(&self) -> String {
+ pub(crate) fn id_hex(&self) -> String {
self.id.iter().map(|byte| format!("{byte:02x}")).collect()
}
}
@@ -90,12 +90,12 @@ impl fmt::Debug for Epoch {
/// The refresh also publishes a [`Stamp`], for what must not wait for the lock: a
/// tokio read lock waits behind a writer, and applying a large sync message holds the
/// write lock for seconds.
-pub struct Replica {
- pub epoch: Epoch,
+pub(crate) struct Replica {
+ pub(crate) epoch: Epoch,
/// How many times this node changed epoch (switch, rejoin, abandoned rejoin) in this
/// run: messages carry it, so a late one can't flip a peer's view of our epoch back.
- pub epoch_seq: u32,
- pub doc: AutoCommit,
+ pub(crate) epoch_seq: u32,
+ pub(crate) doc: AutoCommit,
heads: Vec<ChangeHash>,
stamp: watch::Sender<Stamp>,
}
@@ -103,15 +103,15 @@ pub struct Replica {
/// The epoch label and the heads of the replica, as of its last refresh, published
/// together: keepalives and HELLOs read them without the document's lock.
#[derive(Clone, Debug)]
-pub struct Stamp {
- pub epoch: Epoch,
- pub epoch_seq: u32,
+pub(crate) struct Stamp {
+ pub(crate) epoch: Epoch,
+ pub(crate) epoch_seq: u32,
/// Sorted.
- pub heads: Arc<[ChangeHash]>,
+ pub(crate) heads: Arc<[ChangeHash]>,
}
impl Replica {
- pub fn new(epoch: Epoch, doc: AutoCommit) -> Self {
+ pub(crate) fn new(epoch: Epoch, doc: AutoCommit) -> Self {
let (stamp, _) = watch::channel(Stamp {
epoch,
epoch_seq: 0,
@@ -129,13 +129,13 @@ impl Replica {
}
/// The document's heads as of the last refresh, sorted.
- pub fn heads(&self) -> &[ChangeHash] {
+ pub(crate) fn heads(&self) -> &[ChangeHash] {
&self.heads
}
/// Call after changing the document or its epoch (under the write lock). Publishes
/// the new [`Stamp`].
- pub fn refresh_heads(&mut self) {
+ pub(crate) fn refresh_heads(&mut self) {
self.heads = self.doc.get_heads();
self.heads.sort_unstable();
self.stamp.send_replace(Stamp {
@@ -146,7 +146,7 @@ impl Replica {
}
/// The published stamps, from the last refresh on.
- pub fn stamps(&self) -> watch::Receiver<Stamp> {
+ pub(crate) fn stamps(&self) -> watch::Receiver<Stamp> {
self.stamp.subscribe()
}
}
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)]