Automerge + Partykit.
Based on automerge-repo-sync-server.
This creates 1 partykit room per document, using the automerge document ID as the room name.
npm i -S @substrate-system/mergeparty
Create a backend (the websocket/partykit server) and a browser client.
Just need to export a class that extends the MergeParty
class from this
module.
See ./example_backend.
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
}
}
Also you can make HTTP calls to the server:
http://localhost:1999/parties/main/<document-id-here>
You should see a response
👍 All good
http://localhost:1999/parties/main/<document-id-here>/health
Response:
{
"status": "ok",
"room": "my-document-id",
"connectedPeers": 0
}
See ./example/ for the browser version.
This is a small wrapper around @automerge/automerge-repo-network-websocket, just adding some parameters for partykit.
export class PartykitNetworkAdapter extends WebSocketClientAdapter {
constructor (options:{
host?:string
room:string
party?:string
})
Create a new in-browser automerge node.
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 ...
This exposes ESM and common JS via
package.json exports
field.
import { MergeParty } from '@substrate-system/mergeparty'
require('@substrate-system/mergeparty')
Use vite + local partykit server.
npm start
npx partykit dev