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

@demystify/platform-state

v0.3.0

Published

Redis-backed shared-state seam with an in-memory reference (keyless/offline default): KV+TTL, atomic reserve/reconcile counter, priority queue, leased registry, and pub/sub. Backs gateway multi-instance correctness and the voice session registry. Leaf pac

Readme

platform-state — shared-state seam (memory reference + Redis)

@demystify/platform-state (TS) · demystify-platform-state (Py) · v0.2.0 · MIT

What it is / when to use it

The cross-instance shared-state seam for the platform. Five ports, each with a semantically faithful in-memory reference adapter (the keyless/offline default) and a Redis adapter (opt-in, integration-marked). Backs gateway multi-instance correctness (KV, atomic budget counters, priority queue) and the voice session registry across instances (leased registry), plus event/health fan-out (pub/sub).

Leaf package: no module dependency; ioredis (TS) / redis (Py) are optional integration-only deps, imported lazily.

Ports

| port | methods | backs | |---|---|---| | KvStore | get · set(key,val,ttlMs?) · del/delete · ttl | caches, flags | | AtomicCounter | get · incrby · reserve(key,amount,limit) · reconcile(res,actual) · release(res) | budgets / rate limits | | PriorityQueueStore | enqueue(q,item,priority,ts?) · drain(q,max) · peek · depth | gateway request queue | | LeasedRegistry | register(id,val,ttlMs) · renew · list · get · evict | voice session registry | | PubSub | publish(ch,msg) · subscribe(ch,handler) → unsubscribe | events + provider-health |

reserve → reconcile (the budget protocol gateway needs)

res = counter.reserve("budget:tenant", estimatedMicroUsd, ceilingMicroUsd)
if (res === null)  → over budget, reject the request
... make the provider call ...
counter.reconcile(res, actualMicroUsd)   // adjusts by (actual - estimate)
// or counter.release(res)               // cancel (actual = 0)

reserve atomically books the estimate only if current + amount <= limit; reconcile/release are idempotent per reservation. The Redis adapter does the check-and-add in a Lua script so it is atomic across instances.

PriorityQueueStore ordering

drain returns items priority desc, then ts asc, then insertion order. The Redis adapter encodes score = -priority*1e13 + ts and uses ZPOPMIN.

LeasedRegistry (voice sessions across instances)

Entries self-expire; list returns only unexpired leases. An instance registers a session lease and renews it on a heartbeat; a crashed instance's sessions disappear after the TTL. Memory expiry is driven by an injectable clock (ManualClock) so tests are deterministic.

SDK usage

import { createMemoryState, ManualClock } from "@demystify/platform-state";
const state = createMemoryState();                       // keyless, offline default
await state.queue.enqueue("gateway", { id, payload }, priority);
// opt-in Redis (integration): const state = await createRedisState(process.env.REDIS_URL!);
from demystify_platform_state import create_memory_state
state = create_memory_state()
await state.queue.enqueue("gateway", QueueItemInput(id=id, payload=payload), priority)
# opt-in Redis: state = await create_redis_state(os.environ["REDIS_URL"])

Note: the KV delete method is del in TS and delete in Python (del is a Python keyword); every other method name is identical across the two ports.

Architecture & ports/adapters

| port | memory adapter (default) | redis adapter (integration) | selection | |---|---|---|---| | all five | Memory* / create_memory_state | Redis* / create_redis_state(url) | memory unless a REDIS_URL is wired |

Testing

make -C packages/platform-state setup lint test build. Unit tests exercise every memory port (TTL expiry, reserve/reconcile, priority order, lease expiry/eviction, pubsub delivery). Redis adapter tests are integration-marked and skip without REDIS_URL (TS: INTEGRATION=1 + REDIS_URL; Py: pytest -m integration) — never in CI. Parity: TS and Py replay fixtures/priority-order.json and fixtures/counter-reserve.json and must produce identical results.

v1 scope

Five ports, memory reference + Redis. No cluster/streams/consumer-groups (events owns durable queues via pgmq); this is the lightweight coordination seam. Redis adapter is opt-in and never the default.