1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: BUSL-1.1
//! # nodedb-crdt
//!
//! CRDT engine with SQL constraint validation for NodeDB.
//!
//! ## The CRDT / SQL Paradox
//!
//! CRDTs are AP (Available + Partition-tolerant): agents compute optimistic
//! deltas offline and sync later. SQL constraints are CP (Consistent +
//! Partition-tolerant): UNIQUE indexes, foreign keys, etc. must hold globally.
//!
//! This crate bridges the gap:
//!
//! 1. **Optimistic local writes** — agents apply deltas to their local `LoroDoc`
//! without constraint checks (AP behavior for availability).
//! 2. **Constraint validation at commit** — when deltas sync to the leader,
//! constraints are validated against the committed state.
//! 3. **Dead-letter queue** — rejected deltas are routed to a DLQ with
//! compensation hints so the application can recover gracefully.
//! 4. **Pre-validation** — optional fast-reject against the leader's state
//! before the full Raft round-trip, reducing wasted consensus bandwidth.
/// Authentication context threaded through CRDT validation.
///
/// Carries the identity of who submitted the delta so the DLQ and deferred
/// queue can attribute entries to the correct user/tenant.
///
/// ## Replay protection
///
/// `device_id` and `seq_no` close the replay vulnerability: a captured
/// delta cannot be resubmitted because `seq_no` must be strictly greater
/// than `last_seen[(user_id, device_id)]` on the server. The HMAC input
/// binds the seq_no and device_id so they cannot be altered after signing.
///
/// ## Required fields
///
/// All fields, including `device_id` and `seq_no`, must be present in the
/// serialized form. Missing fields are a hard decode error.
pub use ;
pub use ;
pub use DeferredQueue;
pub use ;
pub use ;
pub use ;
pub use CrdtState;
pub use ;