MDCS SDK
A high-level SDK for building collaborative applications with the Merkle-Delta CRDT Store.
Overview
The MDCS SDK provides easy-to-use abstractions for:
- Client Management: Create and manage database clients
- Sessions: Organize collaborative editing sessions
- Documents: Work with text, rich text, and JSON documents
- Presence: Track user cursors, selections, and status
- Network: Pluggable network transport for peer-to-peer communication
- Sync: Automatic delta synchronization between peers
Quick Start
use ;
async
Architecture
Modules
mdcs-sdk/
├── client.rs # Client entry point and factory
├── session.rs # Session management
├── document.rs # Document type wrappers (Text, RichText, JSON)
├── presence.rs # User awareness and presence
├── network.rs # Network transport abstraction
├── sync.rs # Synchronization configuration
└── error.rs # SDK error types
Document Types
TextDoc
Simple collaborative text editing:
let doc = session.open_text_doc?;
doc.insert?;
doc.delete?;
let content = doc.get_text;
RichTextDoc
Text with formatting support:
use MarkType;
let doc = session.open_rich_text_doc?;
doc.insert?;
doc.add_mark?; // "Hello" is bold
doc.add_mark?; // "World" is italic
JsonDoc
Structured JSON data:
use JsonValue;
let doc = session.open_json_doc?;
doc.set?;
doc.set?;
doc.set?;
if let Some = doc.get
Presence System
Track user awareness across sessions:
// Set user info
session.awareness.set_user_name;
session.awareness.set_status;
// Set cursor position
session.awareness.set_cursor;
// Set selection
session.awareness.set_selection;
// Get all connected users
for user in session.awareness.get_users
Network Transport
The SDK uses a pluggable network transport:
use ;
// Create in-memory transport (for testing/local simulation)
let transport = new;
// Connect to another peer
transport.connect_to;
// Send messages
transport.send.await?;
// Receive messages
let mut rx = transport.subscribe;
while let Some = rx.recv.await
Examples
Run examples with:
# Multi-user text collaboration
# Rich text with formatting
# JSON document editing
# Presence and awareness
# Network layer simulation
# Offline-first sync demo
Configuration
Sync Configuration
use SyncConfig;
let config = builder
.sync_interval
.batch_size
.retry_count
.build;
Error Handling
use SdkError;
match result
Integration with mdcs-db
The SDK builds on top of the lower-level mdcs-db crate:
// Direct database access when needed
use MdcsDb;
let db = new;
// Use db directly for low-level operations
Re-exported types from mdcs-db:
JsonValue- JSON value typeMarkType- Text formatting marksUserStatus- Presence statusCursor- Cursor position
Testing
# Run SDK tests
# Run with output
License
MIT