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

@haikit/postgres

v0.9.1

Published

Postgres store adapter for haikit: durable conversations, fenced turn leases, write-once payloads. Bring your own driver.

Readme

@haikit/postgres

A durable StoreAdapter for haikit. Swap it in for memoryStore() before you ship: a parked elicit turn is durable state, and a conversation that loses it can never be sent again.

import pg from "pg";
import { createHai } from "@haikit/server";
import { pgStore, migrate } from "@haikit/postgres";

const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
await migrate(pool);

const hai = createHai({ store: pgStore(pool), model, tools, surfaces, system });

Bring your own driver

pgStore takes anything with query(text, params) → Promise<{ rows }>. A pg.Pool, a pg.Client and PGlite all fit as they are, so this package depends on @haikit/core and nothing else — pooling, TLS and connection lifecycle stay yours.

Why it is safe to run on several instances

  • One statement per operation. Every fenced write checks the turn's lease token inside the same UPDATE or INSERT … SELECT that performs it. There is no read-then-write anywhere, so there is nothing to race and no transaction to forget.
  • The database's clock. Lease expiry is computed with now(), never Date.now(), so clock skew between app servers cannot hand one conversation to two of them.
  • Write-once payloads. Everything about a surface that changes over a conversation lives on the fenced conversation row, so no payload write can disagree with the history that references it.

The test suite runs twenty real connections at one released lease and requires exactly one to win.

Schema

Two tables, haikit_conversations and haikit_payloads. migrate() creates them if they do not exist and brings existing ones up to date; if you use your own migration tool, the statements are exported as schema.

Upgrading to 0.4: migrate() adds stale_after_ms to haikit_payloads: the freshness window each payload was rendered under, so a later deploy that renames a surface or relaxes its window cannot make data already shown last longer. If you call migrate() at startup as above, there is nothing to do. With your own migration tool, apply the new ALTER TABLE from schema before deploying. Rows written before the column existed are held to the window your code declares.

Handles are numbered per conversation, so every conversation's digests start at ui_01.

Cleaning up

A turn that is overtaken mid-flight can leave payload rows that the surviving history never references. They are inert — an interaction on one is refused — but they are still rows:

import { sweepOrphans } from "@haikit/postgres";

await sweepOrphans(pool, { olderThanMs: 24 * 60 * 60 * 1000 });

A row is swept only when no history references it and the turn that wrote it can never save again — which is proven by the conversation's lease having been issued to someone else since. An expired lease is not enough: a turn slower than its TTL keeps running, and if nobody took over, its save still succeeds. So olderThanMs is a grace period, not a safety bound; no value of it can delete a payload a turn is still going to reference.

A turn that crashed leaves its rows until the conversation is next used, since only then is a new token issued. Deleting whole conversations is retention policy, not garbage collection, and is left to you.