https://github.com/substrate-system/__old_mergeparty
Automerge + Partykit
https://github.com/substrate-system/__old_mergeparty
Last synced: 9 months ago
JSON representation
Automerge + Partykit
- Host: GitHub
- URL: https://github.com/substrate-system/__old_mergeparty
- Owner: substrate-system
- License: other
- Created: 2025-08-15T00:22:41.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-24T02:50:10.000Z (10 months ago)
- Last Synced: 2025-09-09T08:15:41.762Z (9 months ago)
- Language: TypeScript
- Size: 112 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Merge Party
[](https://github.com/substrate-system/mergeparty/actions/workflows/nodejs.yml)
[](README.md)
[](README.md)
[](https://semver.org/)
[](./CHANGELOG.md)
[](https://packagephobia.com/result?p=@substrate-system/mergeparty)
[](LICENSE)
Automerge + Partykit.
Based on [automerge-repo-sync-server](https://github.com/automerge/automerge-repo-sync-server).
This creates 1 partykit room per document, using the automerge document ID as
the room name.
Contents
- [Install](#install)
- [Use](#use)
* [Backend](#backend)
* [Browser Client](#browser-client)
- [Modules](#modules)
* [ESM](#esm)
* [Common JS](#common-js)
- [Develop](#develop)
* [start a localhost server](#start-a-localhost-server)
* [start partykit](#start-partykit)
## Install
```sh
npm i -S @substrate-system/mergeparty
```
## Use
Create a backend (the websocket/partykit server) and a browser client.
### Backend
Just need to export a class that extends the `MergeParty` class from this
module.
See [./example_backend](./example_backend/).
```js
import { MergeParty, CORS } from '@substrate-system/mergeparty/server'
export default class ExampleServer extends MergeParty {
static async onBeforeConnect (request:Party.Request, _lobby:Party.Lobby) {
// auth goes here
}
}
```
#### HTTP
Also you can make HTTP calls to the server:
```
http://localhost:1999/parties/main/
```
You should see a response
```
👍 All good
```
##### `/health`
```
http://localhost:1999/parties/main//health
```
Response:
```js
{
"status": "ok",
"room": "my-document-id",
"connectedPeers": 0
}
```
### Browser Client
See [./example/](./example/) for the browser version.
This is a small wrapper around [@automerge/automerge-repo-network-websocket](https://github.com/automerge/automerge-repo/tree/main/packages/automerge-repo-network-websocket),
just adding some parameters for partykit.
```ts
export class PartykitNetworkAdapter extends WebSocketClientAdapter {
constructor (options:{
host?:string
room:string
party?:string
})
```
#### Browser Example
Create a new in-browser automerge node.
```ts
import {
IndexedDBStorageAdapter
} from '@automerge/automerge-repo-storage-indexeddb'
import { PartykitNetworkAdapter } from '@substrate-system/merge-party/client'
const repo = new Repo({
storage: new IndexedDBStorageAdapter(),
})
const doc = repo.create({ text: '' })
documentId = doc.documentId
// use the document ID as the room name
const networkAdapter = new PartykitNetworkAdapter({
host: PARTYKIT_HOST,
room: documentId
})
repo.networkSubsystem.addNetworkAdapter(networkAdapter)
await networkAdapter.whenReady()
// ... use the repo ...
```
## Modules
This exposes ESM and common JS via
[package.json `exports` field](https://nodejs.org/api/packages.html#exports).
### ESM
```js
import { MergeParty } from '@substrate-system/mergeparty'
```
### Common JS
```js
require('@substrate-system/mergeparty')
```
-----------------
## Develop
### start a localhost server
Use vite + local partykit server.
```sh
npm start
```
### start partykit
```sh
npx partykit dev
```