Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SuperSonicHub1/y-git
Git persistence layer for Y.js
https://github.com/SuperSonicHub1/y-git
Last synced: 3 months ago
JSON representation
Git persistence layer for Y.js
- Host: GitHub
- URL: https://github.com/SuperSonicHub1/y-git
- Owner: SuperSonicHub1
- License: unlicense
- Created: 2023-01-22T18:16:16.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-22T18:31:50.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T03:13:34.420Z (7 months ago)
- Language: TypeScript
- Size: 42 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# y-git
Git persistence layer for Y.js
## Install
```
npm i git+https://github.com/SuperSonicHub1/y-git
```
This project relies on NodeGit, which can be a bit of a pain to install
since you'll likely need to compile it from source: https://www.nodegit.org/guides/install/from-source/## Usage
```ts
import GitPersistence from "y-git"
import * as Y from "yjs"
import Git from "nodegit"const doc = new Y.Doc(),
repo = await Git.Repository.open('repo-name'),
provider = new GitPersistence(repo, doc)provider.on('synced', () => {
// Do stuff with doc here...// Calls provider.destroy()
doc.destroy()
})
```## Semantics
This library directly maps Y's update log to a Git repository's commit history.
Therefore, you get a lot of the power that Git gives you for free (although much of it is
already given by Y because CRDTs)!
```
$ git show
commit 9127dcaa3502eaacaaf23f437c536fc7e19db750 (HEAD -> master)
Author: y-git
Date: Sun Jan 22 13:13:59 2023 -0500Update at Sun Jan 22 2023 13:13:59 GMT-0500 (Eastern Standard Time)
diff --git a/updates b/updates
index 8acd12c..8c6fe4a 100644
Binary files a/updates and b/updates differ
```
(If anyone knows how to derive the name of a user from a document update,
that would be very much appreciated.)Syncing your local repo to a remote is likely best handled by a background
task which pushes every few minutes; this is an exersice left to the reader.In order for this library to function as expected, you must have at least
one existing commit with a file `updates` on the `master` branch. See
`generate-test-repo` for more details.