npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@unrdf/collab

v26.4.8

Published

Real-time collaborative RDF editing using CRDTs (Yjs) with offline-first architecture

Readme

@unrdf/collab

Real-time collaborative RDF editing using CRDTs (Conflict-free Replicated Data Types)

Enables multiple users to edit RDF graphs simultaneously with automatic conflict resolution, real-time synchronization, and offline-first architecture.

Features

  • Conflict-Free Editing: CRDT-based (Yjs) automatic conflict resolution using Last-Write-Wins semantics
  • Real-Time Sync: WebSocket synchronization for instant updates across clients
  • Offline-First: IndexedDB persistence with automatic merge when reconnecting
  • Presence Awareness: Track who's editing, cursor positions, and custom user state
  • Vue Integration: Reactive composables for seamless Vue 3 integration
  • Pure RDF: Works with standard RDF/JS data model and SPARQL

Installation

pnpm add @unrdf/collab

Quick Start

1. Start WebSocket Server

node node_modules/@unrdf/collab/examples/collab-server.mjs

Or create your own:

import { WebSocketServer } from 'ws';
// See examples/collab-server.mjs for full implementation

2. Create Collaborative Graph

import { CollaborativeRDFGraph, WebSocketSync } from '@unrdf/collab';

// Create CRDT-based RDF graph
const graph = new CollaborativeRDFGraph();

// Setup real-time sync
const sync = new WebSocketSync(graph, {
  url: 'ws://localhost:1234',
  roomName: 'my-graph',
  awareness: {
    user: { name: 'Alice', color: '#ff0000' }
  }
});

// Add triples (syncs automatically)
graph.addTriple({
  subject: 'http://example.org/alice',
  predicate: 'http://xmlns.com/foaf/0.1/name',
  object: 'Alice',
  objectType: 'literal'
});

// Query triples
const triples = graph.queryTriples({
  subject: 'http://example.org/alice'
});

3. Vue Composable (Recommended)

<script setup>
import { useCollaboration } from '@unrdf/collab/composables';

const {
  triples,
  addTriple,
  removeTriple,
  isConnected,
  isSynced
} = useCollaboration({
  wsUrl: 'ws://localhost:1234',
  roomName: 'my-graph',
  dbName: 'my-graph-db', // IndexedDB persistence
  awareness: {
    user: { name: 'Alice', color: '#ff0000' }
  }
});

// Add triple
function addPerson() {
  addTriple({
    subject: 'http://example.org/alice',
    predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
    object: 'http://xmlns.com/foaf/0.1/Person',
    objectType: 'uri'
  });
}
</script>

<template>
  <div>
    <p>Connected: {{ isConnected }}</p>
    <p>Synced: {{ isSynced }}</p>
    <p>Triples: {{ triples.length }}</p>
    <button @click="addPerson">Add Person</button>
  </div>
</template>

CRDT Algorithm

Uses Last-Write-Wins (LWW) CRDT for RDF triples:

  • Each triple has (timestamp, clientID) metadata
  • Conflicts resolved by taking triple with highest timestamp
  • Deletions use tombstones to preserve causality
  • Guarantees: Commutativity, Associativity, Idempotency

Conflict Resolution Example

// Client 1 adds triple at t=100
graph1.addTriple({
  subject: 'http://example.org/alice',
  predicate: 'http://xmlns.com/foaf/0.1/name',
  object: 'Alice v1'
});

// Client 2 adds same triple at t=101 (concurrent)
graph2.addTriple({
  subject: 'http://example.org/alice',
  predicate: 'http://xmlns.com/foaf/0.1/name',
  object: 'Alice v2'
});

// After sync: Both converge to 'Alice v2' (higher timestamp wins)

API Reference

CollaborativeRDFGraph

const graph = new CollaborativeRDFGraph(ydoc?);

// Operations
graph.addTriple(triple);              // Add with LWW
graph.removeTriple(triple);           // Remove with tombstone
graph.getTriples();                   // Get all active triples
graph.queryTriples(pattern);          // Query by pattern
graph.toStore();                      // Convert to @unrdf/core Store

// Change tracking
graph.onChange((changes) => {
  console.log(changes.added, changes.removed);
});

// Stats
graph.getStats(); // { active, tombstones, total, clientID }

WebSocketSync

const sync = new WebSocketSync(graph, {
  url: 'ws://localhost:1234',
  roomName: 'my-graph',
  awareness: { user: { name: 'Alice' } }
});

// Connection
sync.connect();
sync.disconnect();
sync.getStatus(); // 'connected' | 'disconnected' | 'connecting'
sync.isSynced();  // boolean

// Events
sync.on('status', (event) => { ... });
sync.on('synced', (event) => { ... });
sync.on('awareness', (state) => { ... });

// Presence
sync.setAwareness({ cursor: 'http://example.org/alice' });
sync.getAllAwareness(); // Array of all clients

IndexedDBPersist

const persist = new IndexedDBPersist(graph, {
  dbName: 'my-graph-db'
});

await persist.whenSynced(); // Wait for initial load
await persist.forceSave();   // Manual save (auto by default)
await persist.clearDatabase(); // Clear all data

Multi-User Demo

See /home/user/unrdf/packages/collab/examples/collab-demo.mjs

# Terminal 1: Server
node examples/collab-server.mjs

# Terminal 2: Client Alice
node examples/collab-demo.mjs alice

# Terminal 3: Client Bob
node examples/collab-demo.mjs bob

Conflict Scenarios Tested

  1. Concurrent Additions: Different clients add same triple → LWW wins
  2. Add-Remove Conflicts: One adds, one removes → Newest operation wins
  3. Commutativity: Order of operations doesn't matter → Same result
  4. Offline Editing: Edit offline, sync when online → Automatic merge

Architecture

┌─────────────────────────────────────────────────────────┐
│                   Client 1 (Alice)                      │
│  ┌──────────────────────────────────────────────────┐   │
│  │  CollaborativeRDFGraph (Yjs CRDT)                │   │
│  │  ├─ YMap<triples>  (LWW + tombstones)            │   │
│  │  └─ YMap<metadata>                               │   │
│  └──────────────────────────────────────────────────┘   │
│           │                              │               │
│           │ (real-time)                  │ (offline)     │
│           ▼                              ▼               │
│  ┌────────────────┐            ┌─────────────────┐      │
│  │ WebSocketSync  │            │ IndexedDBPersist│      │
│  └────────────────┘            └─────────────────┘      │
│           │                                              │
└───────────┼──────────────────────────────────────────────┘
            │
            │ WebSocket
            ▼
┌───────────────────────┐
│  y-websocket Server   │
│  (Coordination Only)  │
└───────────────────────┘
            │
            │ WebSocket
            ▼
┌─────────────────────────────────────────────────────────┐
│                   Client 2 (Bob)                        │
│  ┌──────────────────────────────────────────────────┐   │
│  │  CollaborativeRDFGraph (Yjs CRDT)                │   │
│  │  ├─ YMap<triples>  (LWW + tombstones)            │   │
│  │  └─ YMap<metadata>                               │   │
│  └──────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────┘

Integration with @unrdf/core

import { CollaborativeRDFGraph } from '@unrdf/collab';
import { createEngine } from '@unrdf/core';

const graph = new CollaborativeRDFGraph();

// Add triples via CRDT
graph.addTriple({ ... });

// Convert to Store for SPARQL
const store = await graph.toStore();
const engine = createEngine();

const results = await engine.query(store, `
  SELECT ?s ?p ?o WHERE {
    ?s ?p ?o
  }
`);

Performance

  • Latency: <50ms for typical WebSocket sync
  • Throughput: 1000+ triples/sec local operations
  • Memory: ~100 bytes per triple (includes CRDT metadata)
  • Storage: IndexedDB handles 10K+ triples efficiently

License

MIT