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

@shapeshift-labs/frontier-realtime-server

v0.1.0

Published

Authoritative room, tick, command validation, rate-limit, and snapshot-history runtime for Frontier realtime.

Readme

Frontier Realtime Server

Authoritative room, tick, command validation, rate-limit, and snapshot-history runtime for Frontier realtime.

This package sits above @shapeshift-labs/frontier-realtime. It owns server-side room state, queued command processing, authoritative ticks, command validation boundaries, bounded snapshot history, and rate-limit helpers. It does not own WebSocket transport, CRDT collaboration sync, physics, rendering, persistence, or game/entity framework APIs.

Related Packages

The published Frontier package family is generated from one shared package catalog so READMEs stay in sync across packages:

Package source repositories:

Install

npm install @shapeshift-labs/frontier-realtime @shapeshift-labs/frontier-realtime-server

Usage

import { createCommandSource } from '@shapeshift-labs/frontier-realtime';
import { createRealtimeRoom } from '@shapeshift-labs/frontier-realtime-server';

const room = createRealtimeRoom({
  roomId: 'arena-1',
  initialState: { players: { a: { x: 0 } } },
  tickRate: 20,
  applyCommand(state, command) {
    if (command.type !== 'move') return state;
    const player = state.players[command.clientId];
    return {
      players: {
        ...state.players,
        [command.clientId]: { x: player.x + command.payload.dx }
      }
    };
  },
  validateCommand(_state, command) {
    return Math.abs(command.payload.dx) <= 1 || 'move too large';
  }
});

room.join('a');

const commands = createCommandSource({ clientId: 'a' });
room.enqueue(commands.create('move', { dx: 1 }, { roomId: 'arena-1' }));

const result = room.step();
console.log(result.snapshot);

API

import {
  createRateLimiter,
  createRealtimeRoom,
  createRealtimeSessionStore,
  createSnapshotHistory,
  type RealtimeServerRoom
} from '@shapeshift-labs/frontier-realtime-server';

Realtime Rooms

createRealtimeRoom(options) creates an authoritative room that accepts client command envelopes, validates sequence/rate/room boundaries, processes queued commands in deterministic order, advances server ticks, and publishes authoritative snapshots.

const room = createRealtimeRoom({
  roomId: 'room-1',
  initialState,
  applyCommand(state, command, context) {
    return reduce(state, command, context.tick);
  },
  validateCommand(state, command) {
    return canApply(state, command) || 'invalid command';
  }
});

room.join('client-a');
room.enqueue(command);
const step = room.step();

Room steps return accepted command acknowledgements, rejected command records, the authoritative state, an authoritative snapshot, and server messages that can be passed to a transport layer.

Session Resume

Rooms issue sessionId and resumeToken values in welcome messages by default. Passing them back to join(clientId, { sessionId, resumeToken, lastSeenTick }) resumes the client session, preserves the last accepted command sequence, and lets transports reconnect without treating the client as a brand-new participant.

createRealtimeSessionStore() is also exported behind ./session for custom room/session orchestration.

Snapshot History

createSnapshotHistory(options) keeps a bounded tick-sorted snapshot history for replay, debug inspection, and lag-compensation queries.

const history = createSnapshotHistory({ capacity: 128 });
history.push(snapshot);
const rewind = history.atOrBefore(targetTick);

Rate Limits

createRateLimiter(options) provides a small token-bucket limiter for per-client command admission. Realtime rooms also include a per-tick command cap; this helper is for broader session or transport policy.

const limiter = createRateLimiter({ capacity: 20, refillPerSecond: 10 });
if (!limiter.allow(clientId).allowed) {
  // Reject or delay the command at the server edge.
}

Subpath Imports

import { createSnapshotHistory } from '@shapeshift-labs/frontier-realtime-server/history';
import { appendRealtimeStepToEventLog } from '@shapeshift-labs/frontier-realtime-server/event-log';
import { createRateLimiter } from '@shapeshift-labs/frontier-realtime-server/rate-limit';
import { createRealtimeRoom } from '@shapeshift-labs/frontier-realtime-server/room';
import { createRealtimeSessionStore } from '@shapeshift-labs/frontier-realtime-server/session';

Package Scope

This package intentionally owns only server-side realtime primitives:

  • Authoritative room state and tick stepping.
  • Command queueing, sequence checks, validation hooks, and rejection records.
  • Per-tick command caps and standalone token-bucket rate limits.
  • Bounded authoritative snapshot history.
  • Session records for reconnect/resume.
  • Optional frontier-event-log replay helpers behind ./event-log.
  • Server message records for future transports.

It does not own WebSocket transport, browser clients, CRDT collaboration sync, rendering, physics, durable persistence, entity/component gameplay APIs, or anti-cheat policy beyond command validation hooks. Those belong in higher packages or application code.

TypeScript

The package ships ESM JavaScript plus .d.ts declarations for the root export and public subpaths.

Validation

npm test
npm run fuzz
npm run bench
npm run pack:dry

The package test suite covers root and subpath imports, room join/leave, command queueing, duplicate/unknown/rate-limit/validation rejections, authoritative snapshots, snapshot history lookup, token-bucket limits, TypeScript declarations, randomized room replay, and package export boundaries.

Benchmarks

Run the package-local benchmark:

npm run bench

Latest local package benchmark on Node v26.1.0, darwin arm64, 9 rounds:

| Fixture | Median | p95 | | --- | ---: | ---: | | Room enqueue/process 128 commands | 97.73 us | 98.39 us | | Room idle step | 3.84 us | 4.34 us | | Snapshot history push/query | 8.95 us | 9.42 us | | Token bucket allow 128 commands | 1.87 us | 2.04 us |

These are Frontier-only package measurements, not competitor comparisons.

License

MIT. See LICENSE.