Registry / database / k-sync

k-sync

JSON →
library0.13.3jsnpmunverified

ShareDB is a realtime database backend based on Operational Transformation (OT) for JSON documents. Version 0.13.3 is current, with active development and releases on npm. It features synchronous editing API with asynchronous eventual consistency, realtime query subscriptions, and horizontal scalability via pub/sub. Differentiators include OT-based conflict resolution, middleware for access control, and built-in reconnection and offline sync. It integrates with MongoDB and Redis for persistence and pub/sub.

npm install k-sync
INSTALL
IMPORT
SIG · K-SYNC
K
k-sync
databasejavascriptv0.13.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ShareDB
import ShareDB from 'sharedb'
const ShareDB = require('sharedb')
Default import. CommonJS require works in Node.js.
ShareDB
const ShareDB = require('sharedb')
CommonJS require is also valid for Node.js.
Query
import { Query } from 'sharedb'
const Query = require('sharedb').Query
Named export; use destructuring for ESM.
Doc
import { Doc } from 'sharedb'
Doc class is exported as a named export. Use for type annotations in TypeScript.
Backend and Connection
const { Backend, Connection } = require('sharedb')
const Backend = require('sharedb').Backend
CommonJS destructuring works in Node. Both are classes.

Shows basic setup with Mongo, query subscription, document create/op, and subscribe.

const ShareDB = require('sharedb'); const db = require('sharedb-mongo')('localhost:27017/test'); const backend = new ShareDB({db: db}); const connection = backend.connect(); // Subscribe to a query const query = connection.createSubscribeQuery('users', {accountId: 'acme'}); query.once('ready', () => { console.log('Initial results:', query.results); }); // Create and modify a document const doc = connection.get('users', 'jane'); doc.create({accountId: 'acme', name: 'Jane'}); doc.submitOp({p: ['email'], oi: 'jane@example.com'}); // Subscribe to document updates doc.subscribe((err) => { if (err) throw err; console.log('Doc data:', doc.data); });
Debug
Known issues
breakingShareDB v2 removed the `backend.connect()` returning a connection object; use `backend.connect()` directly.
fix
Use `const connection = backend.connect()` (returns a Connection instance).
affects: >=2.0.0
breakingShareDB v2 changed `createSubscribeQuery` to return a Query, not emit 'ready' on the connection.
fix
Attach event listeners directly on the query object.
affects: >=2.0.0
deprecated`doc.submitOp` without callback is deprecated; always provide a callback to catch errors.
fix
doc.submitOp(op, (err) => { if(err) handleError(err); });
affects: >=1.0.0
gotchaDo not call `doc.create` on an already created document; it will throw.
fix
Check `doc.type === null` before calling create.
affects: all
gotchaThe `sharedb-mongo` adapter requires MongoDB >=3.6.
fix
Ensure your MongoDB server version is compatible.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sharedb-mongo'
Missing database adapter dependency
fix
npm install sharedb-mongo
TypeError: backend.connect is not a function
Calling connect on a ShareDB instance instead of the returned object
fix
Use new ShareDB(options) then call connect() on the instance.
Error: Document already exists
Calling create on a document that already exists
fix
Check doc.type === null before calling create.
Unhandled rejection: Error: Op already submitted
Submitting an op after the document has been modified by another client and version mismatch
fix
Always subscribe to the document before submitting ops, or use a retry mechanism.
Upgrade
Version history
0.13.3latest on npm
Audit
Dependencies
sharedb-mongorequiredDefault database adapter for MongoDB persistence
Agent activity
7 hits · last 30 days
node
6
Resources
packagek-sync
k-sync — npm install k-sync · libregistry