Skip to main content

blockworx/doc_ng/
commit.rs

1//! The commit — the sealed unit of edit, undo, and review: a labeled
2//! batch of ops. The `Rev` and wall time are server-assigned at
3//! acceptance and live outside the payload.
4//! Rationale: `docs/doc-ng-design-notes.md`.
5
6use serde::{Deserialize, Serialize};
7
8use crate::doc_ng::opcode::OpCodes;
9
10#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
11pub struct Commit {
12    /// Semantic label for review/undo grouping: "Moved 15 elements".
13    label: String,
14    /// One gesture. An op's index is its `Seq` in the total write order;
15    /// the `Rev` half is assigned by the server at acceptance and lives
16    /// outside the payload.
17    ops: Vec<OpCodes>,
18}
19
20impl Commit {
21    pub fn new(label: String, ops: Vec<OpCodes>) -> Self {
22        Self { label, ops }
23    }
24
25    pub fn label(&self) -> &str {
26        &self.label
27    }
28
29    pub fn ops(&self) -> &[OpCodes] {
30        &self.ops
31    }
32}
33
34#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
35pub enum CommitEnvelope {
36    CommitV1(Commit),
37}