npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@durable-streams/y-durable-streams

v0.2.1

Published

Yjs provider for Durable Streams - sync Yjs documents over append-only streams

Downloads

268

Readme

@durable-streams/y-durable-streams

Yjs provider for Durable Streams - sync Yjs documents over append-only streams with optional awareness (presence) support.

Overview

This package provides a Yjs provider that syncs documents using the Durable Streams protocol. Unlike WebSocket-based providers, it uses HTTP long-polling over append-only streams, making it simpler to deploy and scale.

Key benefits:

  • No WebSocket infrastructure - Works with standard HTTP load balancers and CDNs
  • Built-in persistence - Document history is stored in the stream itself
  • Scalable - Clients connect directly to streams, no central sync server needed
  • Presence support - Optional awareness stream for cursors, selections, and user status

Installation

npm install @durable-streams/y-durable-streams yjs y-protocols lib0

Quick Start

import { DurableStreamsProvider } from "@durable-streams/y-durable-streams"
import * as Y from "yjs"
import { Awareness } from "y-protocols/awareness"

const doc = new Y.Doc()
const awareness = new Awareness(doc)

const provider = new DurableStreamsProvider({
  doc,
  documentStream: {
    url: "https://your-server.com/v1/stream/rooms/my-room",
    transport: "sse",
  },
  awarenessStream: {
    url: "https://your-server.com/v1/stream/presence/my-room",
    protocol: awareness,
    transport: "sse",
  },
})

provider.on("synced", (synced) => {
  console.log("Synced:", synced)
})

Usage

Document Only (No Presence)

const provider = new DurableStreamsProvider({
  doc,
  documentStream: {
    url: "https://your-server.com/v1/stream/rooms/my-room",
    transport: "sse",
  },
})

With Authentication

const provider = new DurableStreamsProvider({
  doc,
  documentStream: {
    url: "https://your-server.com/v1/stream/rooms/my-room",
    transport: "sse",
    headers: {
      Authorization: "Bearer your-token",
    },
  },
  awarenessStream: {
    url: "https://your-server.com/v1/stream/presence/my-room",
    protocol: awareness,
    transport: "sse",
    headers: {
      Authorization: "Bearer your-token",
    },
  },
})

Transport Mode

By default, the provider uses Server-Sent Events (SSE) for real-time updates. You can switch to long-polling if needed:

const provider = new DurableStreamsProvider({
  doc,
  documentStream: {
    url: "https://your-server.com/v1/stream/rooms/my-room",
    transport: "long-poll", // Use long-poll instead of SSE
  },
  awarenessStream: {
    url: "https://your-server.com/v1/stream/presence/my-room",
    protocol: awareness,
    transport: "long-poll", // Can configure each stream independently
  },
})

Note: When using SSE with binary streams, base64 encoding is automatically applied.

Manual Connection

const provider = new DurableStreamsProvider({
  doc,
  documentStream: { url, transport: "sse" },
  connect: false, // Don't connect automatically
})

// Set up listeners first
provider.on("synced", handleSync)
provider.on("error", handleError)

// Then connect
provider.connect()

Event Handling

// Sync state changes
provider.on("synced", (synced: boolean) => {
  if (synced) {
    console.log("Document is synced with server")
  }
})

// Connection status changes
provider.on("status", (status: ProviderStatus) => {
  console.log("Status:", status) // "disconnected" | "connecting" | "connected"
})

// Error handling
provider.on("error", (error: Error) => {
  console.error("Provider error:", error)
})

Cleanup

// Disconnect temporarily
provider.disconnect()

// Reconnect
provider.connect()

// Destroy permanently
provider.destroy()

API

DurableStreamsProvider

class DurableStreamsProvider {
  constructor(options: DurableStreamsProviderOptions)

  // Properties
  readonly doc: Y.Doc
  readonly synced: boolean
  readonly connected: boolean
  readonly connecting: boolean
  readonly status: ProviderStatus

  // Methods
  connect(): void
  disconnect(): void
  destroy(): void

  // Events
  on(event: "synced", handler: (synced: boolean) => void): void
  on(event: "status", handler: (status: ProviderStatus) => void): void
  on(event: "error", handler: (error: Error) => void): void
}

Options

interface DurableStreamsProviderOptions {
  doc: Y.Doc
  documentStream: StreamConfig
  awarenessStream?: AwarenessConfig
  connect?: boolean // default: true
  debug?: boolean // default: false
}

type TransportMode = "long-poll" | "sse"

interface StreamConfig {
  url: string | URL
  headers?: Record<string, string | (() => string)>
  transport: TransportMode // required
}

interface AwarenessConfig extends StreamConfig {
  protocol: Awareness
}

How It Works

The provider uses two separate durable streams:

  1. Document Stream - Stores Yjs document updates. Reads from the beginning to replay full document history on connect.

  2. Awareness Stream - Syncs presence data (cursors, selections, user info). Reads from current position since historical presence is not needed.

Both streams support two transport modes for real-time updates:

  • SSE (default) - Lower latency, uses Server-Sent Events with automatic base64 encoding for binary data
  • Long-polling - Compatible with all HTTP infrastructure, useful as fallback

Updates are encoded using lib0's VarUint8Array framing.

License

Apache-2.0