JSPM

@yjsync/core

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q64718F
  • License MIT

Runtime-agnostic Yjs room session: y-websocket-compatible sync, awareness, persistence hooks, and export helpers.

Package Exports

  • @yjsync/core

Readme

@yjsync/core

Runtime-agnostic Yjs room session: y-websocket-compatible binary protocol (MESSAGE_SYNC, MESSAGE_AWARENESS), optional persistence, compaction, and JSON export helpers.

Use this when you are building your own transport (custom Worker glue, tests) and want shared room logic without importing Cloudflare SDKs.

Install

bun add @yjsync/core yjs

Minimal in-memory room

import { MemoryPersistenceAdapter, RoomSession } from '@yjsync/core'

const room = new RoomSession('my-room-id', {
  persistence: new MemoryPersistenceAdapter(),
  compactAfterTailSize: 256,
})

await room.whenReady

await room.addConnection(myConnHandle, {
  send: (data) => ws.send(data),
  readyState: ws.readyState,
  close: () => ws.close(),
})

room.handleMessage(myConnHandle, incomingUint8Array)

RoomSession extends Y.Doc. Use room.awareness for collaboration cursors when your client supports it.

TipTap / JSON export

import {
  exportJsonToApi,
  serializeCollabOrRootForExport,
  TIPTAP_COLLAB_FIELD,
} from '@yjsync/core'

await exportJsonToApi({
  roomId: 'demo/doc-1',
  doc: roomSession,
  url: 'https://api.example.com/snapshots',
  revision: roomSession.revision,
  serialize: serializeCollabOrRootForExport,
})

TIPTAP_COLLAB_FIELD is 'default' (the fragment name TipTap collaboration uses).

Optional auth hook

const room = new RoomSession('private-room', {
  persistence: adapter,
  auth: async ({ roomId, conn }) => {
    // return false to reject addConnection
    return true
  },
})

Example apps

Develop

bun run build
bun run typecheck