auditstream.dev · TypeScript Docs · Rust Engine & CLI · Benchmarks
TypeScript adapters and query helpers for Auditstream, an open-source database audit trail engine.
Application code never writes audit rows directly. These packages propagate the active actor through AsyncLocalStorage and attach it to outgoing SQL queries so database capture triggers record who acted — including delegated AI agents (onBehalfOf).
Status: v0.7.1 (pre-1.0), targeting Auditstream Specification 0.2.1 (spec-v0.2.1).
All three packages are ESM-only, zero-dependency on the runtime path, and released together as a single Changesets fixed group:
| Package | npm | Purpose | Docs |
|---|---|---|---|
@auditstream/node |
AsyncLocalStorage actor scope (audit.as(), audit.current()), ORM-agnostic driver wrappers (/pg, /postgres-js, /neon-http), application events (audit.log()), record lookups (audit.history()), keyset-paginated queries (audit.query()), export record parser (parseExportRecord()), and Express, Hono, and Next.js integrations |
README | |
@auditstream/prisma |
Prisma 7 SQL comments plugin (auditstream()) and transaction-local set_config fallback (auditTransaction()) for paths where comments do not reach PostgreSQL |
README | |
@auditstream/drizzle |
Drizzle 1.x .comment() helper (auditComment()) and backwards-compatible re-exports of the pg / Neon WebSocket (wrapPgPool), postgres.js (wrapPostgresJs), and Neon HTTP (wrapNeonHttp) driver wrappers |
README |
Database migrations, capture triggers, auditstream verify, and auditstream export live in the Auditstream Rust engine repository.
First install the auditstream CLI (npm i -g auditstream or brew install auditstream/tap/auditstream), then generate the capture migration with auditstream init and apply it on a direct (non-pooled) PostgreSQL connection with your migration tool (Prisma Migrate, Drizzle Kit, or psql). auditstream init only writes migration files; the audit schema and capture triggers exist once the migration is applied.
Then install @auditstream/node alongside the ORM adapter you use:
# Plain pg / postgres.js / Neon / Kysely / TypeORM / Knex
pnpm add @auditstream/node
# Prisma 7.1+ (without a version, npm installs a pre-release of the Prisma 8 CLI)
pnpm add @auditstream/node @auditstream/prisma @prisma/client@7
pnpm add -D prisma@7
# Drizzle 0.45 or 1.x
pnpm add @auditstream/node @auditstream/drizzle drizzle-ormWrap request or job work in audit.as() — the adapter attaches the actor to every SQL statement automatically:
import { audit } from "@auditstream/node";
import { auditstream, wrapPrisma } from "@auditstream/prisma";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "./generated/prisma/client.js";
const prisma = wrapPrisma(
new PrismaClient({
adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }),
comments: [auditstream()],
}),
);
await audit.as({ type: "user", id: "usr_42" }, () =>
prisma.invoice.update({ where: { id: 1 }, data: { status: "paid" } }),
);The active scope wins: inside audit.as(), the driver wrappers replace an auditstream tag written for another actor (for example by a reused Drizzle query) with the active scope's tag, so exactly one valid auditstream key ends the statement and explicit attribution inside a scope must use a nested audit.as(). The scope is read when the driver call is made (a Drizzle query calls the driver when it is awaited). A trailing SQL comment is an assertion by the application, not authentication. See Actor precedence.
See each package's README or the TypeScript SDK docs for Prisma, Drizzle, Next.js, Express & Hono, audit.log(), and audit.query() guides.
Runnable end-to-end apps with real engine-generated migrations and live PostgreSQL smoke tests:
- Next.js 16 + Prisma 7 (
examples/next-prisma) —withAuditRoute Handlers,auditActionServer Actions,auditTransaction(set_configfallback),audit.log()application events, and a copy-paste BFF-safe Activity Feed (/activity+GET /api/activity) powered byaudit.query()with allowlist DTO projection, server-side actor ID resolution, and keyset pagination (zerocount(*)). Auditstream intentionally does not publish a styled@auditstream/reactnpm package; see ADR-0009. - Hono + Drizzle 0.45 (
examples/hono-drizzle) —@auditstream/node/honomiddleware, pool-safewrapPgPooltagging, transactions with nested savepoints, and unscoped writes.
| Dependency | Supported versions |
|---|---|
| Node.js | 22.12 or newer (CI tests 22.12.0 and the newest 22, 24, and 26) |
Engine (auditstream CLI) |
0.2.0 or newer within 0.2.x (tested with 0.2.4) |
| PostgreSQL | 15 to 19 (only supported engine; MySQL is demand-gated) |
| Prisma | @prisma/client 7.1 or newer within 7.x (CI tests 7.1.0 and 7.10.1; Prisma 6 is unsupported; Prisma 8 follows its stable release; the prisma CLI is never a peer dependency) |
| Drizzle | 0.45 from 0.45.2 and 1.x from 1.0.0-rc.1 (CI tests 0.45.2, 0.45.4, 1.0.0-rc.1 and 1.0.0-rc.6) |
| Kysely, TypeORM, Knex | With a wrapped pg.Pool (@auditstream/node/pg); CI tests Kysely 0.28.20 and 0.29.9, TypeORM 0.3.31 and 1.1.3, and Knex 3.3.0 (the oldest that works) |
| Frameworks | Express 4.21 or newer within 4.x and 5.x, Hono 4.x, Next.js 16.x (CI tests Express 4.21.0, 5.0.0 and the newest, Hono 4.0.0 and 4.13.20, Next.js 16.0.0 and 16.4.6) |
| Runtimes | Node.js (reference), Bun and Deno (CI imports every entry point and writes to PostgreSQL through pg, postgres.js, Drizzle and Prisma), Cloudflare Workers (tested in CI with workerd, except @auditstream/node/express; the Prisma and Drizzle adapters on the Neon HTTP driver; needs the nodejs_als flag or compatibility date 2026-08-04 or later) |
@auditstream/node pins the spec-v0.2.1 conformance fixtures in conformance.json (verified by SHA-256). CI runs every case:
- Encode and decode in
@auditstream/node, also withoutglobalThis.Buffer, with the error code of each rejected case (packages/node/test/conformance.test.ts). - Active scope through every driver wrapper (
packages/node/test/active-scope.test.ts) and the Prisma comments plugin (packages/prisma/test/active-scope.test.ts). - Decode, precedence and capture in PostgreSQL 15 to 19, against the SQL of the engine release in
engine.json(packages/node/test/integration/conformance-engine.test.ts).
Requires Node.js 26 (for workspace tooling) and pnpm 12 (corepack enable):
pnpm install --frozen-lockfile
pnpm check # Biome lint/format, typecheck, build, unit tests, API check, publint/attw, README snippets
pnpm test:workers # Cloudflare Workers smoke suite in workerd (both documented compatibility configs)
pnpm -r --if-present test:integration # Live PostgreSQL + PgBouncer integration suite (requires Docker)Read CONTRIBUTING.md before opening a pull request. Ask questions in GitHub Discussions or chat on the Auditstream Discord. Report vulnerabilities privately as described in SECURITY.md. Participation is governed by CODE_OF_CONDUCT.md.
Auditstream is licensed under the MIT License.