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

@onlineapps/conn-base-state

v1.0.3

Published

Redis persistent state connector (no TTL) with atomic rebuild for OA Drive microservices

Readme

Status: current Owns: the Redis persistent state a business service keeps — state: keys with no TTL and an atomic rebuild from the database

Uniform: library/connector

Duty sections that apply:

  • all: L-MAIN, L-ENGINES, L-TESTS, L-TEST-SCRIPT, L-PACK-TESTS, L-PINS, L-NO-FILE-RANGE, L-CHANGELOG, L-README, L-README-REGION, L-CONSUMER
  • connector: L-CONNECTOR-ENV

@onlineapps/conn-base-state

Redis persistent state connector for OA Drive microservices. Unlike conn-base-cache, state keys have no TTL — they persist until explicitly deleted or rebuilt from DB.

Key differences from conn-base-cache

| Feature | conn-base-cache | conn-base-state | |---------|----------------|-----------------| | Key prefix | cache:<service>: | state:<service>: | | TTL | Required (default 3600s) | Never — keys persist | | Purpose | Temporary caching | Operational state (entitlements, credits) | | Rebuild | No rebuild concept | rebuildFromDB() — atomic SCAN+DEL+repopulate | | Retry | Hard cutoff after N attempts | Exponential backoff, never gives up |

Quick Start

const StateConnector = require('@onlineapps/conn-base-state');

const state = new StateConnector({
  host: '127.0.0.1',
  port: 6379,
  serviceName: 'meta',
  logger                       // required: info/warn/error/debug
});

await state.connect();

// Set/get state (no TTL)
await state.set('entitlement:100:1', '1');
const val = await state.get('entitlement:100:1');

// Rebuild from DB — buildVersion is required, the connector cannot know it
const { flushed, written, epoch } = await state.rebuildFromDB(async (pipeline) => {
  pipeline.set('entitlement:100:1', '1');
  pipeline.sadd('entitlement:100:bundles', '1');
}, { buildVersion: process.env.BUILD_ID });

The projection epoch marker

rebuildFromDB() flushes the whole state:<service>: prefix before it repopulates it. Between those two halves — and after a crash that interrupts them — the prefix is empty, and an empty prefix is indistinguishable from a tenant that genuinely has no entitlements: the gateway answered 402 to everyone until meta was restarted by hand.

The marker makes the two states tellable apart.

| | | |---|---| | Key | state:<service>:__epoch (logical __epoch, exported as StateConnector.PROJECTION_EPOCH_KEY) | | Value | JSON { "at": "<ISO-8601 UTC instant>", "build": "<buildVersion the caller passed>" } | | Written | as the last command of the same pipeline the projection is written with, by rebuildFromDB() — never separately | | Exists | exactly when a rebuild completed | | Absent | before the first rebuild, during one (the flush removes the previous marker), and after one whose populate callback threw | | Writer | the connector, i.e. the service that owns the prefix. Readers (gateway, monitoring) read only — docs/standards/redis-key-contract.md rule 3 |

await state.hasProjection();       // → true | false   (EXISTS __epoch)
await state.getProjectionEpoch();  // → { at, build } | null

getProjectionEpoch() returns null only when the key is absent. Content that cannot be parsed, or that does not carry both fields, throws — null means "no projection", and answering that for damaged content would hide the damage behind the one value callers act on.

An ioredis pipeline is a batch, not a MULTI transaction. What the ordering buys is that the marker can never be visible before the records it vouches for, and that a populate callback which throws produces no marker at all; a marker command Redis rejects makes rebuildFromDB() throw rather than report a rebuild that did not complete.

Return value

{ flushed: 12, written: 340, epoch: { at: '2026-09-07T09:31:04.882Z', build: '1.4.2' } }

written counts the records the populate callback wrote. The marker is the connector's own bookkeeping, so it is reported as epoch and not counted in written.

API

See JSDoc in src/index.js for full documentation.

Testing

npm run test:unit                                                  # mocked ioredis, no stack
REDIS_HOST=127.0.0.1 REDIS_PORT=33030 npm run test:integration     # live Redis
npm test                                                           # both tiers

The integration tier isolates itself by prefix, not by database: every suite uses a service name carrying its own pid, so it can never see or delete another run's keys, and a raw prefix-less observer client makes the assertions on absolute key names.

Mock connector available for tests — it mirrors the epoch contract, including the required buildVersion:

const { MockStateConnector } = require('@onlineapps/conn-base-state');
const state = new MockStateConnector({ serviceName: 'test' });