{"_id":"@apisandbox/y-leveldb","name":"@apisandbox/y-leveldb","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.3":{"name":"@apisandbox/y-leveldb","version":"0.1.3","description":"LevelDb database adapter for Yjs","type":"module","main":"./dist/y-leveldb.cjs","module":"./src/y-leveldb.js","types":"./dist/src/y-leveldb.d.ts","private":false,"sideEffects":false,"funding":{"type":"GitHub Sponsors ❤","url":"https://github.com/sponsors/dmonad"},"scripts":{"clean":"rm -rf dist","test":"rollup -c && nyc --check-coverage --lines 100 --branches 100 --functions 100 --statements 100 node ./dist/test.cjs","dist":"rollup -c","lint":"markdownlint README.md && standard && tsc","preversion":"npm run lint && npm run test && npm run clean && npm run dist && tsc && test -e dist/src/y-leveldb.d.ts && test -e dist/y-leveldb.cjs","debug":"concurrently 'rollup -wc' 'http-server -o .'"},"standard":{"ignore":["/dist","/node_modules","/docs"]},"exports":{"./package.json":"./package.json",".":{"import":"./src/y-leveldb.js","require":"./dist/y-leveldb.cjs"}},"repository":{"type":"git","url":"git+https://github.com/yjs/y-leveldb.git"},"keywords":["Yjs","CRDT","offline","shared editing","collaboration","concurrency"],"author":{"name":"Kevin Jahns","email":"kevin.jahns@protonmail.com"},"license":"MIT","bugs":{"url":"https://github.com/yjs/y-leveldb/issues"},"homepage":"https://yjs.dev","dependencies":{"level":"^8.0.1","level-read-stream":"^2.0.0","lib0":"^0.2.31"},"devDependencies":{"@rollup/plugin-commonjs":"^13.0.0","@rollup/plugin-node-resolve":"^8.1.0","@types/readable-stream":"^4.0.18","concurrently":"^3.6.1","http-server":"^0.12.3","jsdoc":"^3.6.3","level-mem":"^5.0.1","markdownlint-cli":"^0.23.2","nyc":"^15.1.0","rollup":"^2.20.0","rollup-plugin-node-polyfills":"^0.2.1","standard":"^14.3.4","typescript":"^3.9.6","y-protocols":"^1.0.0","yjs":"^13.2.0"},"peerDependencies":{"yjs":"^13.0.0"},"_id":"@apisandbox/y-leveldb@0.1.3","gitHead":"f469a7d1a78bbff792ab4d840aca4480049a5053","_nodeVersion":"21.6.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-r9WWHl/ca//OTvHElK1HNvR7ZyhAAow0yp3MOjCvVP1NEeAsKu+7JlbuNqm+AhynfKt5+9PZHCHL95OSmwpkKg==","shasum":"be0ccd75ce157765f5ec382f261ffde4b6509149","tarball":"https://registry.npmjs.org/@apisandbox/y-leveldb/-/y-leveldb-0.1.3.tgz","fileCount":10,"unpackedSize":3098287,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHEw43hl89Ib9cQz822vuV48m0wGpLicvoyDxw2Ks5O2AiAywzVnU0dHE6yoK4igrFrCpcxEcw/5/TWhj6TjG7ivLw=="}]},"_npmUser":{"name":"benlorantfy","email":"ben@lorantfy.com"},"directories":{},"maintainers":[{"name":"benlorantfy","email":"ben@lorantfy.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/y-leveldb_0.1.3_1745162557166_0.05701439833756328"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-20T15:22:37.060Z","0.1.3":"2025-04-20T15:22:37.445Z","modified":"2025-04-20T15:22:37.745Z"},"maintainers":[{"name":"benlorantfy","email":"ben@lorantfy.com"}],"description":"LevelDb database adapter for Yjs","homepage":"https://yjs.dev","keywords":["Yjs","CRDT","offline","shared editing","collaboration","concurrency"],"repository":{"type":"git","url":"git+https://github.com/yjs/y-leveldb.git"},"author":{"name":"Kevin Jahns","email":"kevin.jahns@protonmail.com"},"bugs":{"url":"https://github.com/yjs/y-leveldb/issues"},"license":"MIT","readme":"# LevelDB database adapter for [Yjs](https://github.com/yjs/yjs)\n\nLevelDB is a fast embedded database. It is the underlying technology of IndexedDB.\n\nInternally, y-leveldb uses [`level`](https://github.com/Level/level) which\nallows to exchange the storage medium for a different supported database.\nHence this adapter also supports rocksdb, lmdb, and many more..\n\n* Persistent storage for the server\n* Exchangeable storage medium\n* Can be used in [y-websocket](https://github.com/yjs/y-websocket)\n* A single y-leveldb instance can handle many documents.\n\n## Use it\n\n```sh\nnpm install y-leveldb --save\n```\n\n```js\nimport * as Y from 'yjs'\nimport { LeveldbPersistence } from 'y-leveldb'\n\nconst persistence = new LeveldbPersistence('./storage-location')\n\nconst ydoc = new Y.Doc()\nydoc.getArray('arr').insert(0, [1, 2, 3])\nydoc.getArray('arr').toArray() // => [1, 2, 3]\n\n// store document updates retrieved from other clients\npersistence.storeUpdate('my-doc', Y.encodeStateAsUpdate(ydoc))\n\n// when you want to sync, or store data to a database,\n// retrieve the temporary Y.Doc to consume data\nconst ydocPersisted = await persistence.getYDoc('my-doc')\nydocPersisted.getArray('arr') // [1, 2, 3]\n```\n\n## API\n\n### `persistence = LeveldbPersistence(storageLocation, [{ [level] }])`\n\nCreate a y-leveldb persistence instance.\n\nYou can use any levelup-compatible adapter.\n\n```js\nimport { LeveldbPersistence } from 'y-leveldb'\nimport level from 'level-mem'\n\nconst persistence = new LeveldbPersistence('./storage-location', { level })\n```\n\n#### `persistence.getYDoc(docName: string): Promise<Y.Doc>`\n\nCreate a Y.Doc instance with the data persisted in leveldb. Use this to\ntemporarily create a Yjs document to sync changes or extract data.\n\n#### `persistence.storeUpdate(docName: string, update: Uint8Array): Promise`\n\nStore a single document update to the database.\n\n#### `persistence.getStateVector(docName: string): Promise<Uint8Array>`\n\nThe state vector (describing the state of the persisted document - see\n[Yjs docs](https://github.com/yjs/yjs#Document-Updates)) is maintained in a separate\nfield and constantly updated.\n\nThis allows you to sync changes without actually creating a Yjs document.\n\n#### `persistence.getDiff(docName: string, stateVector: Uint8Array): Promise<Uint8Array>`\n\nGet the differences directly from the database. The same as\n`Y.encodeStateAsUpdate(ydoc, stateVector)`.\n\n#### `persistence.clearDocument(docName: string): Promise`\n\nDelete a document, and all associated data from the database.\n\n#### `persistence.setMeta(docName: string, metaKey: string, value: any): Promise`\n\nPersist some meta information in the database and associate it with a document.\nIt is up to you what you store here. You could, for example, store credentials\nhere.\n\n#### `persistence.getMeta(docName: string, metaKey: string): Promise<any|undefined>`\n\nRetrieve a store meta value from the database. Returns undefined if the\n`metaKey` doesn't exist.\n\n#### `persistence.delMeta(docName: string, metaKey: string): Promise`\n\nDelete a store meta value.\n\n#### `persistence.getAllDocNames(docName: string): Promise<Array<string>>`\n\nRetrieve the names of all stored documents.\n\n#### `persistence.getAllDocStateVectors(docName: string): Promise<Array<{ name:string,clock:number,sv:Uint8Array}`\n\nRetrieve the state vectors of all stored documents. You can use this to sync\ntwo y-leveldb instances.\n\nNote: The state vectors might be outdated if the associated document is not\nyet flushed. So use with caution.\n\n#### `persistence.flushDocument(docName: string): Promise` (dev only)\n\nInternally y-leveldb stores incremental updates. You can merge all document\nupdates to a single entry. You probably never have to use this.\n\n## License\n\ny-leveldb is licensed under the [MIT License](./LICENSE).\n\n<kevin.jahns@protonmail.com>\n","readmeFilename":"README.md","_rev":"1-66d12d02e26dcb88513732c087b92e35"}