blockworx/doc_ng/change.rs
1//! The change — DAG node / envelope.
2//! Rationale — content addressing, bytes-immutable-after-mint, batching:
3//! `docs/doc-ng-design-notes.md`.
4
5use std::collections::BTreeSet;
6
7use chrono::{DateTime, Local};
8use serde::{Deserialize, Serialize};
9
10use crate::doc_ng::{command::Command, stamp::Stamp};
11
12/// blake3 over the canonically-encoded change (payload + parents): the
13/// storage key, and the value other changes' `parents` hold.
14#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
15pub struct ChangeHash(pub [u8; 32]);
16
17#[derive(Serialize, Deserialize, Debug, Clone)]
18pub struct Change {
19 /// Envelope format version.
20 pub version: u16,
21 /// Heads of the log as the author saw them: 1 = linear, 2+ = merge.
22 /// Never empty except the document-creation change.
23 pub parents: BTreeSet<ChangeHash>,
24 pub stamp: Stamp,
25 /// Display only — never load-bearing.
26 pub wall_time: DateTime<Local>,
27 /// Semantic label for review/undo grouping: "Moved 15 elements".
28 pub label: String,
29 /// One gesture, as a canonical net diff: at most one write per
30 /// register, commands sorted at seal. All share the change's stamp.
31 pub commands: Vec<Command>,
32}