nodedb_types/sync/wire/delta.rs
1//! Delta push / ack / reject / collection-purged messages.
2
3use serde::{Deserialize, Serialize};
4
5use crate::sync::compensation::CompensationHint;
6
7/// Delta push message (client → server, 0x10).
8#[derive(
9 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
10)]
11pub struct DeltaPushMsg {
12 /// Collection the delta applies to.
13 pub collection: String,
14 /// Document ID.
15 pub document_id: String,
16 /// Loro CRDT delta bytes.
17 pub delta: Vec<u8>,
18 /// Client's peer ID (for CRDT identity).
19 pub peer_id: u64,
20 /// Per-mutation unique ID for dedup.
21 pub mutation_id: u64,
22 /// CRC32C checksum of `delta` bytes for integrity verification.
23 /// Computed by sender, validated by receiver. 0 for legacy clients.
24 #[serde(default)]
25 pub checksum: u32,
26}
27
28/// Delta acknowledgment (server → client, 0x11).
29#[derive(
30 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
31)]
32pub struct DeltaAckMsg {
33 /// Mutation ID being acknowledged.
34 pub mutation_id: u64,
35 /// Server-assigned LSN for this mutation.
36 pub lsn: u64,
37}
38
39/// Delta rejection (server → client, 0x12).
40#[derive(
41 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
42)]
43pub struct DeltaRejectMsg {
44 /// Mutation ID being rejected.
45 pub mutation_id: u64,
46 /// Reason for rejection.
47 pub reason: String,
48 /// Compensation hints for the client.
49 pub compensation: Option<CompensationHint>,
50}
51
52/// Collection purged notification (server → client, 0x14).
53///
54/// Emitted when Origin hard-deletes a collection (retention window
55/// expired after `DROP COLLECTION` or explicit `DROP COLLECTION ... PURGE`).
56/// The receiving Lite client must:
57///
58/// 1. Drop all local Loro CRDT state for the collection.
59/// 2. Remove the collection's redb record.
60/// 3. Terminate any active shape subscriptions or streaming consumers
61/// sourced from the collection.
62/// 4. Fire the `on_collection_purged` client-trait callback.
63///
64/// `purge_lsn` is the Origin WAL LSN at which the hard-delete committed.
65/// Clients persist it so that on reconnect they can replay any purge
66/// events that landed while they were offline by querying
67/// `_system.dropped_collections` / purge event log at LSN > last_seen.
68#[derive(
69 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
70)]
71pub struct CollectionPurgedMsg {
72 /// Numeric tenant ID the collection belonged to.
73 pub tenant_id: u32,
74 /// Collection name.
75 pub name: String,
76 /// Origin WAL LSN at which the hard-delete was committed.
77 pub purge_lsn: u64,
78}