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

@yjsync/snapshot-server

v0.1.0

Published

Runtime-agnostic Web Request/Response handler that mirrors yjsync JSON snapshots into a pluggable SnapshotStore.

Readme

@yjsync/snapshot-server

Runtime-agnostic Web Request/Response handler that mirrors yjsync JSON snapshots into a pluggable SnapshotStore. Serves authenticated reads with an optional fallback to a live source (e.g. the Cloudflare DO /__snapshot endpoint).

Built on Web standards (Request/Response/fetch) — works on Cloudflare Workers, Bun, Deno, and Node 20+.

Install

bun add @yjsync/snapshot-server

Usage

import {
  createSnapshotHandler,
  MemorySnapshotStore,
} from '@yjsync/snapshot-server'

const store = new MemorySnapshotStore()
const handle = createSnapshotHandler({
  store,
  internalSecret: env.INTERNAL_SNAPSHOT_SECRET,
  authorize: async (request, roomId) => {
    return await myAuthCheck(request, roomId)
  },
})

export default {
  async fetch(request: Request): Promise<Response> {
    const handled = await handle(request)
    if (handled) return handled
    // …your other routes…
    return new Response('Not Found', { status: 404 })
  },
}

Routes (defaults; both overrideable via routes)

  • POST /api/internal/snapshot — internal upsert. Header X-Internal-Secret required (constant-time compare). Body: { roomId, revision, exportedAt?, data }. Stale revisions return 200 { accepted: false, reason: 'stale' }.
  • GET /api/rooms/:roomId/snapshot — read; runs authorize(request, roomId). Returns the stored snapshot, falls back to liveFetcher.fetch(roomId) if provided, otherwise { data: null, source: 'none' }.

For paths it does not own, the handler returns null so it composes with your existing router.

SnapshotStore contract

interface SnapshotStore {
  get(roomId: string): Promise<Snapshot | null>
  put(roomId: string, snap: Snapshot): Promise<PutResult>
}

Implementations MUST guarantee monotonicity: put for a given room never regresses the stored revision. Older revisions return { accepted: false, reason: 'stale' }; equal revisions return 'duplicate'. This is what fixes the latent bug where a late retry of an old export overwrote newer state.

Available stores

  • MemorySnapshotStore — in this package. For tests / local dev.
  • @yjsync/snapshot-store-d1 — Cloudflare D1.
  • Bring your own — implement SnapshotStore for Postgres, KV, R2, etc.

With Cloudflare Durable Objects

import { createSnapshotHandler } from '@yjsync/snapshot-server'
import { D1SnapshotStore } from '@yjsync/snapshot-store-d1'
import { createDoLiveFetcher } from '@yjsync/cloudflare'

const handle = createSnapshotHandler({
  store: new D1SnapshotStore(env.DB),
  liveFetcher: createDoLiveFetcher({
    binding: env.YJS_ROOM,
    secret: env.INTERNAL_SNAPSHOT_SECRET,
  }),
  internalSecret: env.INTERNAL_SNAPSHOT_SECRET,
  authorize: async (req, roomId) => isAllowed(req, roomId),
})