@groundstate/compat
v1.0.0-beta
Published
yjs and automerge compatibility
Maintainers
Readme
@groundstate/compat
Yjs and Automerge compatibility layer for migrating existing CRDT documents to @groundstate.
Installation
# npm
npm install @groundstate/compat
# yarn
yarn add @groundstate/compat
# pnpm
pnpm add @groundstate/compatQuick Start
import { fromYjsJSON, toYjsJSON } from '@groundstate/compat';
import { Doc, Field, List } from '@groundstate/crdt';
// Import from a Yjs JSON export
const yjsData = { title: 'My Doc', items: ['a', 'b', 'c'] };
const doc = fromYjsJSON(yjsData, {
schema: { title: Field(''), items: List<string>() },
});
// Edit with Groundstate
doc.title = 'Updated Doc';
doc.items.push('d');
// Export back to Yjs-compatible JSON
const exported = toYjsJSON(doc);import { fromAutomergeJSON, toAutomergeJSON } from '@groundstate/compat';
// Import from an Automerge JSON export
const amDoc = fromAutomergeJSON(automergeData, { schema });
// Export back to Automerge-compatible JSON
const amExported = toAutomergeJSON(amDoc);API Highlights
Yjs Compatibility
fromYjsJSON(data, options?)-- Import a Yjs JSON snapshot into a Groundstate documenttoYjsJSON(doc)-- Export a Groundstate document as Yjs-compatible JSONImportOptions/ImportResult-- Configuration and result types for import
Automerge Compatibility
fromAutomergeJSON(data, options?)-- Import an Automerge JSON snapshot into a Groundstate documenttoAutomergeJSON(doc)-- Export a Groundstate document as Automerge-compatible JSONAutomergeImportOptions/AutomergeImportResult-- Configuration and result types for import
Use Cases
- Gradually migrate a Yjs or Automerge codebase to Groundstate
- Interoperate with existing collaborative tools that use Yjs or Automerge
- Import historical data from other CRDT libraries
Documentation
See the full documentation for complete API reference.
License
MIT
