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

@nestjs/outbox

v0.1.4

Published

Nest - modern, fast, powerful node.js web framework (@outbox)

Readme

Description

Transactional outbox module for Nest: messages written in the same database transaction as your business data, a relay that publishes them after commit with leases, retries and a dead-letter table, and an inbox that deduplicates redeliveries, with no third-party dependencies.

Installation

$ npm i --save @nestjs/outbox

Quick Start

Overview & Tutorial

PostgreSQL store

@nestjs/outbox/postgres ships PostgresOutboxStore, which keeps the messages, the dead letters and the consumers' inbox in a schema of its own (nest_outbox) and writes through the client your application already uses: fromPg(pool), fromDrizzle(db), fromTypeOrm(dataSource), fromPrisma(prisma) or fromKysely(db). Register it with a factory provider:

import { OutboxStorage } from '@nestjs/outbox';
import { fromDrizzle, PostgresOutboxStore } from '@nestjs/outbox/postgres';

@Module({
  imports: [DrizzleModule.forRoot({ drizzle, connection: process.env.DATABASE_URL! }), OutboxModule.forRoot()],
  providers: [
    {
      provide: PostgresOutboxStore,
      inject: [getDrizzleToken(), OutboxStorage],
      useFactory: (db: Database, storage: OutboxStorage) => new PostgresOutboxStore({ executor: fromDrizzle(db) }, storage),
    },
  ],
})
export class AppModule {}

outbox.add(tx, message) then takes your ORM's own transaction object (Drizzle's tx, a TypeORM EntityManager, a Prisma transaction client, a Kysely Transaction, a pg client after BEGIN). The store applies its migrations at startup, except when NODE_ENV is production; there, apply them on deploy with npx @nestjs/outbox migrate --url <database url> (status checks, sql prints them for your own migration tool).

MySQL store

@nestjs/outbox/mysql ships MySqlOutboxStore (MySQL 8.4 LTS and 9.x), registered the same way: import it and the executor from @nestjs/outbox/mysql instead (fromMysql2(pool), fromDrizzle(db), fromTypeOrm(dataSource), fromPrisma(prisma) with @prisma/adapter-mariadb, or fromKysely(db)). Its tables live in your connection's database, named after the schema option (nest_outbox_messages, nest_outbox_dead_letters, nest_outbox_inbox); ids, topics, keys and consumer names are compared byte for byte and hold at most 255 characters. npx @nestjs/outbox migrate --url mysql://... applies its migrations, and sql --dialect mysql prints them (MySqlOutboxStore.migrationStatements() lists them one per string, for TypeORM's queryRunner.query()).

MySqlOutboxStore also runs on MariaDB 11.4.7 and later, and 11.8.2 and later, where utf8mb4_0900_bin compares byte for byte as on MySQL; it refuses an earlier MariaDB at startup. fromTypeOrm() takes a DataSource of type 'mariadb', and the command line reaches it through a mysql:// URL. On MariaDB 11.6.2 and later, whose innodb_snapshot_isolation is on by default, add() in a REPEATABLE READ transaction can fail with 1020 (ER_CHECKREAD) when it locks a key another transaction wrote since the transaction's snapshot: retry that transaction as you would one that fails with 1213, or run it at READ COMMITTED. MariaDB nests JSON at most 32 levels deep, so a payload can nest at most 30 levels there; a deeper one fails add() with 4040.

Retention

The consumers' inbox records (one per consumer per message) and the dead letters are kept until your application deletes them: nothing in the module does it for you. On the PostgreSQL and MySQL stores the tables grow without limit; on the default in-memory store they grow on the heap (about 470 bytes per inbox record, so 200k records take roughly 94 MB, and each dead letter keeps its full payload and attempt history), which adds up in a long-running dev server or with allowInMemoryStorage: true. Schedule OutboxInbox.prune(olderThan), and purge the dead letters you've handled (requeued or given up on) with OutboxDeadLetters.purge(target), e.g. with @nestjs/schedule:

import { Cron, CronExpression } from '@nestjs/schedule';
import { OutboxDeadLetters, OutboxInbox } from '@nestjs/outbox';

@Injectable()
export class OutboxRetention {
  constructor(private readonly inbox: OutboxInbox, private readonly deadLetters: OutboxDeadLetters) {}

  @Cron(CronExpression.EVERY_DAY_AT_3AM)
  async prune() {
    await this.deadLetters.purge({ failedBefore: new Date(Date.now() - 14 * 86_400_000) });
    await this.inbox.prune('30d');
  }
}

The inbox record is what recognizes a redelivery, so keep it longer than a message can take to come back: the whole retry schedule, your broker's redelivery window for remote consumers, and, above all, the longest a dead letter may wait before someone requeues it, since a requeued message keeps its id. Purging dead letters after 14 days bounds that wait, and 30 days of inbox covers it. Without @nestjs/schedule, a setInterval() started in onModuleInit() and cleared in onModuleDestroy() does the same.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.