Implementation of the eg-walker CRDT algorithm with FugueMax sequence CRDT
moon add dowdiness/event-graph-walkerimport {
"dowdiness/event-graph-walker@0.10.0",
}import {
"dowdiness/event-graph-walker/text",
"dowdiness/event-graph-walker/tree",
}import "dowdiness/event-graph-walker/text"
fn main() -> Unit raise {
let doc = @text.TextState::new("alice-laptop-001")
// Insert and delete text
doc.insert(@text.Pos::at(0), "Hello")
doc.insert(@text.Pos::at(5), " World")
println(doc.text()) // "Hello World"
doc.delete(@text.Pos::at(5))
println(doc.text()) // "HelloWorld"
}fn sync_peers() -> Unit raise {
let alice = @text.TextState::new("alice-laptop-001")
alice.insert(@text.Pos::at(0), "Hello")
let bob = @text.TextState::new("bob-laptop-001")
// Full initial synchronization
let alice_sync = alice.sync()
bob.sync().apply(alice_sync.export_all())
println(bob.text()) // "Hello"
// Incremental delta synchronization
let bob_version = bob.version()
alice.insert(@text.Pos::at(5), "!")
bob.sync().apply(alice_sync.export_since(bob_version))
println(bob.text()) // "Hello!"
}import "dowdiness/event-graph-walker/tree"
fn main() -> Unit raise {
let doc = @tree.TreeState::new("alice-laptop-001")
let project = doc.create_node(parent=@tree.root_id)
let src = doc.create_node(parent=project)
let test = doc.create_node(parent=project)
doc.set_property(project, "name", "my-project")
doc.set_property(src, "name", "src")
doc.set_property(test, "name", "test")
let peer = @tree.TreeState::new("bob-laptop-001")
peer.sync().apply(doc.sync().export_all())
println(peer.get_property(project, "name")) // Some("my-project")
println(peer.children(project).length()) // 2
doc.delete_node(test)
println(doc.is_alive(test)) // false
}[!TIP] For advanced scenarios including undo/redo, container documents, historical checkout, and detailed error handling, see Worked Examples.
| Package | Description | API Contract |
|---|---|---|
| text | Concurrent text editing facade (insert, delete, range replace, delta sync, checkout) | text/pkg.generated.mbti |
| tree | Movable-tree CRDT facade (nodes, hierarchy moves, sorted properties) | tree/pkg.generated.mbti |
| undo | Local undo/redo manager preserving concurrent remote mutations | undo/pkg.generated.mbti |
| container | Advanced document API combining tree nodes, per-block text, sync, and undo | container/pkg.generated.mbti |
| history | Read-only CausalSnapshot for DAG visualization and history inspection | history/pkg.generated.mbti |
| sync | Shared sync limits, wire envelopes, and structured failure classifications | sync/pkg.generated.mbti |
| peer_sync | Transport-free synchronization decision engine and façade adapters (peer_sync/text, peer_sync/container) | peer_sync/pkg.generated.mbti |
event-graph-walker/
├── text/ # Public text CRDT facade
├── tree/ # Public movable-tree facade
├── undo/ # Public undo/redo package
├── container/ # Advanced document API: tree + block text + sync + undo
├── history/ # Read-only causal history snapshots
├── sync/ # Shared sync limits and error definitions
├── peer_sync/ # Peer-free synchronization policy and adapters
├── internal/ # Core algorithms and data structures (internal only)
├── docs/ # Documentation, guides, benchmarks, and architecture notes
├── scripts/ # Nushell verification implementations
├── justfile # Project recipe entry points
└── moon.modInstall
Download zipImplementation of the eg-walker CRDT algorithm with FugueMax sequence CRDT