@bhoomash/syncraft-core
v0.1.0
Published
Deterministic CRDT state engine with Lamport clocks for Syncraft
Downloads
111
Maintainers
Readme
@bhoomash/syncraft-core
Deterministic, conflict-free replicated data type (CRDT) state engine with Lamport logical clocks for local-first collaborative applications.
Installation
npm install @bhoomash/syncraft-coreFeatures
- 🕒 Monotonic Lamport Clocks: Logical scalar timestamps with causal tick/update semantics.
- 🌳 Safe Deep Path Engine: Dot-path traversal (
doc.tags.0), immutable copy-on-write, and prototype-pollution immune (__proto__,constructor,prototype). - ⚡ Deterministic Total Ordering: Resolves concurrent conflicts deterministically via $\text{logicalClock} \to \text{nodeId} \to \text{operationId}$.
- 🛡️ Tombstone & Container Pruning: Prunes empty intermediate objects on key deletion to guarantee structural tree equivalence across arbitrary replay permutations.
- 📦 Snapshotting & Deduplication: Fast state serialization, snapshot hydration, and duplicate operation filtering.
Quick Start
import { createSyncStore } from '@bhoomash/syncraft-core';
// 1. Initialize local replica store
const store = createSyncStore({ nodeId: 'replica-A' });
// 2. Subscribe to reactive state updates
const unsubscribe = store.subscribe((state) => {
console.log('Current document state:', state);
});
// 3. Mutate local state
const op1 = store.set('user.name', 'Alice');
const op2 = store.set('user.preferences.theme', 'dark');
console.log(store.get('user.name')); // "Alice"
// 4. Hydrate remote operations from other replicas
store.applyRemoteOperation({
operationId: 'replica-B-1-xyz',
nodeId: 'replica-B',
logicalClock: 2,
operationType: 'SET',
path: 'user.role',
value: 'admin'
});
console.log(store.getState());
// { user: { name: 'Alice', preferences: { theme: 'dark' }, role: 'admin' } }
unsubscribe();License
MIT © Bhoomash
