{"id":13553419,"url":"https://github.com/yjs/y-dat","last_synced_at":"2025-04-14T15:13:20.268Z","repository":{"id":57402646,"uuid":"259016567","full_name":"yjs/y-dat","owner":"yjs","description":"Dat provider for Yjs","archived":false,"fork":false,"pushed_at":"2020-08-01T22:40:09.000Z","size":622,"stargazers_count":46,"open_issues_count":5,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-14T15:13:06.105Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://demos.yjs.dev/prosemirror-dat/prosemirror-dat.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-26T11:45:25.000Z","updated_at":"2025-02-12T19:51:35.000Z","dependencies_parsed_at":"2022-09-26T17:01:08.264Z","dependency_job_id":null,"html_url":"https://github.com/yjs/y-dat","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-dat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-dat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-dat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-dat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yjs","download_url":"https://codeload.github.com/yjs/y-dat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248904637,"owners_count":21180835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:02:24.296Z","updated_at":"2025-04-14T15:13:20.222Z","avatar_url":"https://github.com/yjs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"# Dat connector for [Yjs](https://github.com/yjs/yjs)\n\n\u003e Propagates document updates using the Dat protocol. WIP - not all details have been worked out yet. [Demo](https://demos.yjs.dev/prosemirror-dat/prosemirror-dat.html)\n\n* Uses hypercore data channels to exchange document updates and awareness information\n* Supports multiple users manipulating same date\n* Access is granted if the client knows about the public key (\"dat key\")\n* Currently, does *not* sign document updates using the private key.\n* Supports dat-storage to persist data\n* Works in node and the browser (uses [dat-sdk](https://github.com/datproject/sdk) internally)\n\n## Approach\n\nThe initial idea was to implement [Dat Multiwriter](https://www.datprotocol.com/deps/0008-multiwriter/). Internally, Yjs already maintains data in several append-only logs. But compared to Dat Hypercores, Yjs does optimizations on the append-only logs and even supports truncating the logs if \"garbage collection\" is enabled. Since history doesn't work anymore in a Dat Multiwriter (without keeping track of even more information), y-dat implements a custom storage and syncing mechanism. History management can still be implemented using [Yjs state vectors](https://github.com/yjs/yjs#State-Vector). y-dat does not use the Hypercore concept, but it uses many other concepts from the Dat ecosystem, including swarms, the noise protocol, dat storage, and will support signing of data in the future.\n\nYjs awareness information and document updates are shared using Hypercores data-channel functionality (a method to communicate to available peers). Connected peers perform a [two-way handshake](https://github.com/yjs/yjs#example-sync-two-clients-by-computing-the-differences) in order to sync and propagate all document updates to all connected peers. This is the same approach that is implemented by [y-webrtc](https://github.com/yjs/y-webrtc), but using technologies from the Dat ecosystem. The document updates can be persisted using Dat storage providers.\n\nThis allows multiple users to manipulate the same data if they have the same public key. In the future, we also want to sign document updates using the private key.\n\n## Setup\n\n### Install\n\n```sh\nnpm i y-dat\n```\n\n### Client code\n\n```js\nimport * as Y from 'yjs'\n// @ts-ignore\nimport { DatProvider } from 'y-dat'\n\nconst ydoc = new Y.Doc()\nconst givenDatKey = null // '7b0d584fcdaf1de2e8c473393a31f52327793931e03b330f7393025146dc02fb'\n\nconst provider = new DatProvider(givenDatKey, ydoc)\n\nconst yarray = ydoc.getArray('my-shared-array')\n\nprovider.on('loaded', () =\u003e {\n  console.log('Loaded document from dat-storage!')\n})\n\nprovider.on('synced', () =\u003e {\n  console.log('Synced document with all available peers!')\n})\n```\n\nAlternatively use an existing Hypercore constructor:\n\n```js\nimport SDK from 'dat-sdk'\n\nconst { Hypercore } = SDK()\n\nconst provider = new DatProvider(givenDatKey, ydoc, { Hypercore })\n```\n\n### Demos\n\nYou can find a working demos in `y-dat/demo/`. Clone this repository and run `npm install \u0026\u0026 npm start`. Another example can be found in [`yjs-demos/prosemirror-dat`](https://github.com/yjs/yjs-demos/tree/master/prosemirror-dat).\n\nThe demo also works in nodejs. Run `node y-dat/demo/node-server.cjs --key 7b0d584fcdaf1de2e8c473393a31f52327793931e03b330f7393025146dc02fb` to listen to updates for a given key. Run `node y-dat/demo/node-server.cjs` to generate a new key.\n\n## API\n\n```js\nnew DatProvider(roomName, ydoc[, opts])\n```\n\nThe following default values of `opts` can be overwritten:\n\n```js\n{\n  // Specify an existing Awareness instance - see https://github.com/yjs/y-protocols\n  awareness: new awarenessProtocol.Awareness(doc),\n  // Hypercore constructor, created by dat-sdk\n  Hypercore: SDK().Hypercore\n  // Custom hypercore options. See https://github.com/mafintosh/hypercore#api\n  hypercoreOpts: {},\n  // Dat storage provider\n  storage: require('random-access-memory'),\n  // whether to persist data in the storage provider\n  persist: true\n}\n```\n\n## Logging\n\n`y-dat` uses the `lib0/logging.js` logging library. By default this library disables logging. You can enable it by specifying the `log` environment / localStorage variable:\n\n```js\n// enable logging for all modules\nlocalStorage.log = 'true'\n// enable logging only for y-dat\nlocalStorage.log = 'y-dat'\n// by specifying a regex variables\nlocalStorage.log = '^y.*'\n```\n\n```sh\n# enable y-dat logging in nodejs\nLOG='y-dat' node index.js\n```\n\n## License\ny-dat is licensed under the [MIT License](./LICENSE).\n\n\u003ckevin.jahns@pm.me\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjs%2Fy-dat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyjs%2Fy-dat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjs%2Fy-dat/lists"}