@groundstate/resolve
v1.0.0-beta
Published
Conflict detection and resolution
Maintainers
Readme
@groundstate/resolve
Conflict detection and resolution toolkit with built-in strategies, custom policies, and visual debugging.
Installation
# npm
npm install @groundstate/resolve
# yarn
yarn add @groundstate/resolve
# pnpm
pnpm add @groundstate/resolveQuick Start
import { ConflictDetector, lww, custom, PolicyEngine } from '@groundstate/resolve';
import { Doc, Field } from '@groundstate/crdt';
const doc = Doc({ title: Field(''), priority: Field(0) });
const detector = new ConflictDetector(doc);
// Detect conflicts after merge
const conflicts = detector.detect();
// Resolve with built-in strategies
for (const conflict of conflicts) {
resolveConflict(conflict, lww());
}
// Or define field-level policies
const policy = new PolicyEngine({
'title': lww(),
'priority': custom((a, b) => ({ value: Math.max(a.value, b.value) })),
});
policy.resolveAll(conflicts);API Highlights
Detection
ConflictDetector-- Detect concurrent edits across merged documentsConflict/ConflictType/ConflictValue-- Conflict metadata types
Strategies
lww()-- Last-writer-wins (by timestamp)pick()-- Always pick a specific side (local or remote)longest()-- Keep the longest string valuesum()-- Sum numeric values from both sidesunion()-- Union of set/list valuescustom()-- Provide your own resolution functionresolveConflict()-- Apply a strategy to a single conflict
Policies
PolicyEngine-- Map field paths to resolution strategies for automatic bulk resolution
Visualization & Audit
ConflictVisualizer-- Generate timeline visualizations of divergent editsConflictAuditLog-- Record all resolution decisions for compliance or debuggingresolve.visualize()-- Convenience helper for quick conflict visualization
Documentation
See the full documentation for complete API reference.
License
MIT
