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

@nebutra/collab

v0.2.1

Published

Multi-tenant, transport-agnostic real-time collaborative sync layer: tenant-partitioned CRDT rooms (Yjs) with pluggable snapshot store + transport seams

Readme

@nebutra/collab

Multi-tenant, transport-agnostic real-time collaborative sync layer for Nebutra-Sailor. Sailor already had Pusher pub/sub (fire-and-forget broadcast) but no conflict-free concurrent editing. This package fills that gap with tenant-partitioned CRDT rooms built on Yjs (MIT).

It is generic: a node-graph canvas, a rich-text document, or any shared structure binds to a CollabRoom and gets convergence for free.

Zero-config quickstart

No env, no credentials — real (non-mock) CRDT behaviour out of the box:

import { getCollab } from "@nebutra/collab";

const hub = await getCollab();
const room = hub.room("org_123", "doc-1"); // tenantId is mandatory

room.doc.getText("body").insert(0, "Hello");
room.onUpdate((update) => relayToPeers(update));
await room.snapshot();

Public API

| Export | Purpose | | --- | --- | | getCollab(config?) / createCollab(config?) | Build a CollabHub (async / sync). | | CollabHub.room(tenantId, roomId) | Get/create a tenant-scoped CRDT room. Hard-partitioned by tenant. | | CollabHub.roomRestored(tenantId, roomId) | Like room, but hydrates from the snapshot store first. | | CollabHub.doctor() | Structured health report (Yjs + store + transport), < 3s. | | CollabHub.destroy() | Destroy every live room. | | CollabRoom | doc: Y.Doc, applyUpdate, encodeState, onUpdate (returns unsubscribe), snapshot, destroy. | | SnapshotStore | Pluggable persistence interface. In-memory default. | | CollabTransport | Pluggable fan-out interface. In-process loopback default. | | CollabError | Every thrown error — carries mandatory .code and .suggestion. |

Tenant isolation (security-critical)

Rooms are stored in a Map keyed by a composite tenantId<NUL>roomId string. The separator is a real NUL () which cannot occur in a normal id, so ("a","bc") and ("ab","c") can never collide into the same room key. There is no API that takes only a roomId — a room handle is only ever produced by passing an explicit tenantId, and the snapshot store and transport are likewise addressed by (tenantId, roomId). The default in-memory store composes @nebutra/tenant-store's InMemoryTenantStore, which adds a defense-in-depth tenantId equality check on top of its own composite key. The isolation property a Prisma adapter would get from RLS is here provided structurally by the composite key — not trusted from payload.

Snapshot persistence

room.snapshot() encodes the doc and persists it via the injected SnapshotStore, serialized through withTenantLock(tenantId, roomId, …) borrowed from @nebutra/tenant-store (same primitive used by canvas/reel — a future swap to a distributed lock changes one place).

Prisma adapter shape (interface-only — no migration run here)

import type { SnapshotStore } from "@nebutra/collab";

// Suggested table: collab_snapshot(tenant_id, room_id, state Bytes,
//   PRIMARY KEY (tenant_id, room_id)) — RLS scoped by tenant_id.
class PrismaSnapshotStore implements SnapshotStore {
  constructor(private prisma: PrismaClient) {}
  async load(tenantId: string, roomId: string) {
    const row = await this.prisma.collabSnapshot.findUnique({
      where: { tenantId_roomId: { tenantId, roomId } },
    });
    return row ? new Uint8Array(row.state) : null;
  }
  async save(tenantId: string, roomId: string, state: Uint8Array) {
    await this.prisma.collabSnapshot.upsert({
      where: { tenantId_roomId: { tenantId, roomId } },
      create: { tenantId, roomId, state: Buffer.from(state) },
      update: { state: Buffer.from(state) },
    });
  }
}

Redis adapter shape

class RedisSnapshotStore implements SnapshotStore {
  constructor(private redis: Redis) {}
  private k(t: string, r: string) { return `collab:${t}:${r}`; }
  async load(t: string, r: string) {
    const buf = await this.redis.getBuffer(this.k(t, r));
    return buf ? new Uint8Array(buf) : null;
  }
  async save(t: string, r: string, s: Uint8Array) {
    await this.redis.set(this.k(t, r), Buffer.from(s));
  }
}

Transport seam

CollabTransport is a transport-agnostic fan-out interface (broadcast(tenantId, roomId, update) + subscribe(tenantId, roomId, cb)). The default is an in-process loopback so zero-config single-process usage converges immediately. A Pusher or WebSocket adapter implements the same two methods and is injected via createCollab({ transport }) — channel name MUST be derived from (tenantId, roomId), e.g. collab-${tenantId}-${roomId}, so a subscriber for tenant A's room is never reached by tenant B's broadcast. This package intentionally ships no network code (interface + loopback only).

Examples

Runnable under examples/:

  • zero-config-convergence.ts — real CRDT convergence, no config (also the in-package caller keeping this module in the active tier).
  • tenant-isolation.ts — proves the tenant partition holds.
  • snapshot-restore.ts — persist then reload across hub lifetimes.

Scripts

pnpm --filter @nebutra/collab test           # vitest run
pnpm --filter @nebutra/collab test:coverage  # with coverage
pnpm --filter @nebutra/collab typecheck      # tsc --noEmit