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

@table-games-engine/persistence

v0.1.3

Published

Snapshot, event and replay persistence (in-memory and SQLite) for table-games-engine matches.

Readme

@table-games-engine/persistence

Persistence for table-games-engine matches: event and snapshot storage (in-memory or SQLite), snapshot policies, state checksums, replay, and ownership leases.

Most game authors don't install this directly: it comes with @table-games-engine/game-kit and is used by @table-games-engine/nakama-adapter. Install it to keep matches alive across restarts on your own host.

Install

npm install @table-games-engine/persistence

SqliteAdapter uses better-sqlite3 (a native module, installed as a dependency).

What is in it

  • InMemoryAdapter - no I/O, for tests and ephemeral runs.
  • SqliteAdapter(path, opts?) - SQLite via better-sqlite3; takes a file path or ':memory:'; WAL mode, migrations applied on open.
  • createPersistedEngine(args) - wraps a core Engine so every transition appends events and snapshots per policy.
  • checksumState(state) - deterministic checksum of a MatchState (FNV-1a 32-bit over canonical JSON).
  • replayMatch(adapter, matchId, toVersion?) and loadEventsBetween(adapter, matchId, from, to).
  • Snapshot policies: everyNTransitions, everyTTicks, always, never, combine.

Quick start

import { SqliteAdapter, createPersistedEngine, everyNTransitions, replayMatch, checksumState } from '@table-games-engine/persistence';

const adapter = new SqliteAdapter('./match.db');

const engine = await createPersistedEngine({
  manifest, initialState, handlers,
  adapter,
  matchId: 'match-42',
  policy: everyNTransitions(50),   // default
  ownerNode: 'node-A',             // optional ownership lease
  leaseSeconds: 60,                // optional, default 60
});

const r = await engine.applyAction(myInput);   // same shape as the core Engine, but async
if (r.ok) await engine.resolveTopFrame();

await engine.forceSnapshot();                  // e.g. on match end
const recovered = await replayMatch(adapter, 'match-42');
checksumState(recovered!) === checksumState(engine.getState());
await engine.close();                          // releases the lease and closes the DB handle

Snapshot policies

| Policy | Fires | |---|---| | everyNTransitions(n) | after every n transitions | | everyTTicks(t) | after every t logical ticks | | always() | every transition (best for async games and deterministic tests) | | never() | never | | combine(...policies) | when any sub-policy fires |

Replay

replayMatch returns the latest snapshot at or before toVersion (or the latest overall), or null if nothing was stored. It does not re-apply events, so to recover an exact version use a policy that snapshots there (for example always()). Use loadEventsBetween for the audit log.

Failure behaviour

Adapter errors reject the returned promise and do not roll back in-memory state. If you need all-or-nothing, close the engine and recover from the last good snapshot. With ownerNode set, construction throws if another node holds an unexpired lease.

Licence

FSL-1.1-ALv2 (Functional Source License, converts to Apache-2.0 after two years). See LICENSE.md in the package.