ubiquisync_core/log_entry.rs
1//! Wire-level log entry: a single op with timestamp and optional
2//! server-attested user attribution. This is the unit of encoding/decoding in a
3//! segment file.
4
5use crate::hlc::Timestamp;
6use crate::uuid::Uuid;
7
8/// A single log entry: one operation plus metadata. This is the unit
9/// written to and read from segment files — each entry has its own
10/// blake3 hash and can be independently expunged.
11///
12/// The entry is generic over its op vocabulary `E`: each data domain defines
13/// its own op type and carries it in this envelope — for example the table
14/// op vocabulary in `ubiquisync-tables`. Any domains in use share one HLC
15/// clock domain, so timestamps are causally comparable across them.
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct LogEntry<E> {
18 /// The **server-attested** user id for this entry. Every entry originates
19 /// from *some* user, but this field specifically carries the identity a
20 /// server vouched for — it is populated only in server-mode segments, where
21 /// the server asserts attribution. `None` in device mode, where attribution
22 /// is implicit from the peer directory and no server assertion exists.
23 ///
24 /// Do not read this as "the author"; read it as "who the server said this
25 /// was." It is distinct from a stream's `peer_id` (which stream the entry
26 /// came from).
27 pub server_user_id: Option<Uuid>,
28 /// HLC timestamp — monotonically non-decreasing within a peer's stream.
29 /// Entries written in one atomic transaction share a tick, so they are
30 /// treated as one logical write by LWW comparisons.
31 pub timestamp: Timestamp,
32 /// The state mutation.
33 pub op: E,
34}