From cae74a1abc23aa0e72eca1b5668d9bba87ea4c1e Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 21 Oct 2026 04:08:26 +0200 Subject: turn compaction into a kind of remake --- src/remake/records.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/remake/records.rs') diff --git a/src/remake/records.rs b/src/remake/records.rs index 219fc9b..5e7841f 100644 --- a/src/remake/records.rs +++ b/src/remake/records.rs @@ -17,8 +17,10 @@ use automerge::{AutoCommit, ChangeHash}; use serde::{Deserialize, Serialize}; +use serde_json::Value as JsonValue; use tracing::warn; +use super::kind::DEFAULT_KIND; use super::snapshot::{SnapshotRequest, META_ROOT, REMAKES}; use crate::document::replica::Epoch; use crate::document::store::{self, StoreError}; @@ -123,6 +125,19 @@ pub(crate) struct Proposal { pub(crate) settle_until: u64, /// Peers that must stay active during the settle period. pub(crate) peers_considered: Vec, + /// The remake kind (`compact` for records written before kinds existed). + #[serde(default = "default_kind")] + pub(crate) kind: String, + /// The kind's build input. + #[serde(default, skip_serializing_if = "JsonValue::is_null")] + pub(crate) content: JsonValue, + /// The kind's translation input. + #[serde(default, skip_serializing_if = "JsonValue::is_null")] + pub(crate) translation: JsonValue, +} + +fn default_kind() -> String { + DEFAULT_KIND.to_owned() } impl Proposal { @@ -204,6 +219,9 @@ impl Record { base_heads: self.proposal.base_change_hashes()?, policy: serde_json::to_value(&self.proposal.policy).ok()?, proposed_at: self.proposal.proposed_at, + kind: self.proposal.kind.clone(), + content: self.proposal.content.clone(), + translation: self.proposal.translation.clone(), }) } @@ -338,6 +356,9 @@ mod tests { proposed_at: settle_until.saturating_sub(1_000), settle_until, peers_considered: vec!["node-b".into()], + kind: DEFAULT_KIND.to_owned(), + content: JsonValue::Null, + translation: JsonValue::Null, } } -- cgit v1.3.1