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

@ahmetskilinc/sync-server

v0.4.0

Published

Server for sync-engine: source-of-truth apply loop, global sync-ID log, WebSocket fan-out

Readme

@ahmetskilinc/sync-server

The server half of sync-engine: applies client transactions to your database, stamps each confirmed mutation with a global sync ID, and fans it out to every connected client.

npm install @ahmetskilinc/sync-server @ahmetskilinc/sync-core
import { WebSocketServer } from "ws";
import {
  SyncServer,
  attachWebSocketGuarded,
  createConnectionGuard,
  getCookie,
} from "@ahmetskilinc/sync-server";
import { schema } from "./schema.js";

const server = new SyncServer({
  schema,
  database: new MyPostgresAdapter(),   // MemoryDatabase by default
  requireContext: true,
  validateTransaction: (txn, context) => null,          // write rules
  authorizeRead: (record, model, context) =>            // read rules
    record.tenantId === context.tenantId,
  onError: (error, where) => logger.error({ error, where }),
});

const guard = createConnectionGuard({
  origin: ["https://app.example.com"],
  authenticate: async (request) => {
    const token = getCookie(request, "session");
    return token ? await lookupUser(token) : null;      // null ⇒ refuse
  },
});

const wss = new WebSocketServer({ port: 8080, maxPayload: 256 * 1024 });
wss.on("connection", (socket, request) => {
  void attachWebSocketGuarded(server, socket, request, guard);
});

Security defaults worth understanding

Browsers do not apply the same-origin policy to WebSockets. Any page on any origin can open a socket to your server, and the browser attaches the user's cookies. Authenticating from a cookie without checking Origin means every logged-in user is one visited page away from a full session (cross-site WebSocket hijacking). createConnectionGuard checks Origin by default and refuses requests carrying none.

authorizeRead governs what a connection may see — applied to the bootstrap snapshot, catch-up, and live fan-out. Without it, every client receives every record, even with perfect authentication.

Pair both with requireContext: true, so a connection that somehow skipped the guard cannot write.

Persistence

Implement DatabaseAdapter: get, put, delete, getAll, plus an optional but strongly recommended applyBatch that commits one transaction's writes atomically. Without applyBatch, a failure partway through leaves earlier writes committed while the client rolls everything back — the database and sync log then disagree permanently.

Deployment

Single long-lived process by default. For serverless or multi-instance, pass distributed (shared sync-ID sequence + action table) and a stable epoch, and feed ingestActions from that table.

server.stats reports connections, queue depth, log size and pending acks for monitoring; maxConnections bounds fan-out cost.

Zero runtime dependencies beyond @ahmetskilinc/sync-core — the WebSocket type is structural, so ws is not required.


Full documentation: github.com/ahmetskilinc/sync-engine · Upgrading? See MIGRATION.md

MIT