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

@multitenant/database

v0.5.6

Published

Node-only ALS + shared-DB + Postgres helpers + per-tenant DSN + bounded pool cache — Phase 8.1–8.6

Readme

@multitenant/database

Node-only async context for tenant scope using AsyncLocalStorage. Use after you have resolved a tenant (e.g. from ResolvedTenant) to make tenantKey (and optional resolved) available inside the request’s async tree — without a global singleton.

Phase 8.2 — shared DB: requireTenantKey(), assignTenantIdForWrite(row, column?), assertRowTenantColumn(row, column?) help enforce tenant_id (or a custom column name) on writes and reads. Still no SQL generation or drivers — see shared-db-tenant-id.md.

Phase 8.5 — per-tenant URL: resolveTenantDatabaseUrl(resolved, registry.tenants, options?) reads tenant.database.envVar from validated config (see per-tenant-database-url.md).

Phase 8.6 — bounded pool cache: BoundedTenantDbResourceCache, getOrCreateTenantDatabaseResource, makeTenantDatabaseCacheKey — LRU-capped cache for distinct pools/clients per tenant+DSN (see bounded-tenant-db-pools.md).

Phase 8.3 — Postgres RLS: buildSetLocalTenantGucSql, buildSetLocalTenantGucSqlFromScope, escapePostgresStringLiteral, POSTGRES_RLS_TENANT_GUC_DEFAULT — safe SET LOCAL … TO … strings for current_setting policies. See postgres-rls-tenant.md.

Phase 8.4 — schema-per-tenant Postgres: schemaNameForTenant(tenantKey, options?), requireSchemaNameForCurrentTenant(options?) map registry keys to PostgreSQL-safe schema names (63-byte cap, normalization rules). See schema-per-tenant-postgres.md.

Install

npm install @multitenant/database @multitenant/core

Usage

import { runWithTenantScopeAsync, requireTenantScope } from '@multitenant/database';

await runWithTenantScopeAsync({ tenantKey: 'acme', resolved }, async () => {
  const scope = requireTenantScope();
  // use scope.tenantKey in repositories; scope.resolved when you passed it
  // or: requireResolvedTenantFromScope() when you always attach full ResolvedTenant
});

Write / read invariants (same scope):

import { assignTenantIdForWrite, assertRowTenantColumn, schemaNameForTenant } from '@multitenant/database';

const payload = assignTenantIdForWrite({ title: 'Hello' }); // adds tenant_id
// … INSERT with parameterized SQL …

const row = { id: '1', tenant_id: 'acme', title: 'Hello' }; // from SELECT
assertRowTenantColumn(row);

const schema = schemaNameForTenant('us-main', { prefix: 'tnt' }); // "tnt_us_main"

Docs: database-scope.md · shared-db-tenant-id.md · schema-per-tenant-postgres.md.


Open source

MIT licensed — github.com/klypalskyi/multitenant · Issues · npm