y-leveldb is a persistence adapter for Yjs, the CRDT framework for real-time collaboration. It enables storing Yjs document updates persistently using LevelDB and its compatible implementations (like RocksDB, LMDB, or `level-mem`). The current stable version is `0.2.0`. Releases are infrequent but address compatibility, dependency updates, and bug fixes. Key differentiators include its flexibility to use various LevelUP-compatible storage backends, its direct integration into Yjs ecosystems (e.g., `y-websocket`), and its ability to manage multiple Yjs documents within a single database instance. The library provides a granular API for storing and retrieving document updates, state vectors, and custom metadata without necessarily hydrating a full Y.Doc object, which is crucial for efficient server-side synchronization and data management.
npm install y-leveldbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `y-leveldb`, store a Yjs document's state, and then retrieve it from the persistent storage, including setting and getting metadata. It shows basic CRUD operations for Yjs documents.
Review the changelog for the `level` package between v6 and v8 and update your custom `level` client code or configurations accordingly. Ensure your direct `level` dependencies are compatible with the version `y-leveldb` now expects.
For highly critical synchronization or to ensure the most up-to-date state, retrieve the full `Y.Doc` using `getYDoc` and then encode its state, or ensure `flushDocument` has been called if you manually manage flushes (though `flushDocument` is generally not needed in production).
Avoid using `flushDocument` in production code unless you have a specific, well-understood need for it and have thoroughly tested its implications on your application's data integrity and performance.
Always ensure that `yjs` is installed in your project and matches the peer dependency version range specified (e.g., `npm install yjs@^13.0.0`). Check `npm ls yjs` to verify your installed version.
Ensure you are using the correct ESM import: `import { LeveldbPersistence } from 'y-leveldb'`. If running in a pure CommonJS environment, ensure Node.js can resolve ESM modules or consider transpilation.Install the correct version of `yjs`: `npm install yjs@^13.0.0`. Verify with `npm ls yjs`.
Change the `storageLocation` to a path where the Node.js process has full read/write permissions (e.g., a subdirectory within your application's data folder) or adjust the file system permissions for the target directory.
Install the missing `level` adapter package: `npm install level-mem` (or the specific adapter you intend to use).