@auditstream/prisma 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +66 -89
  2. package/package.json +3 -2
package/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # @auditstream/prisma
2
2
 
3
- Prisma 7 SQL comments plugin and transaction-local `set_config` fallback for [Auditstream](https://github.com/auditstream/auditstream).
3
+ [![npm version][npm-badge]][npm-url]
4
+ [![CI][ci-badge]][ci-url]
5
+ [![SonarCloud Quality Gate][sonar-badge]][sonar-url]
6
+ [![OpenSSF Scorecard][scorecard-badge]][scorecard-url]
4
7
 
5
- `@auditstream/prisma` reads the active actor from `@auditstream/node` and sends it to PostgreSQL triggers without altering your Prisma schema.
8
+ Prisma 7 SQL comments plugin and transaction-local `set_config` fallback for [Auditstream](https://auditstream.dev).
9
+
10
+ `@auditstream/prisma` reads the active actor from `@auditstream/node` and sends it to database capture triggers without altering your Prisma schema. Full guides and API reference live at **[auditstream.dev/docs/typescript/prisma](https://auditstream.dev/docs/typescript/prisma/)**.
6
11
 
7
12
  ## Install
8
13
 
@@ -12,110 +17,74 @@ pnpm add @auditstream/prisma @auditstream/node @prisma/client
12
17
 
13
18
  Install the `prisma` CLI as a dev dependency if needed. The `prisma` CLI is never a peer dependency.
14
19
 
15
- ## Supported versions
16
-
17
- | Dependency | Supported in v0.1 |
18
- | --- | --- |
19
- | Node.js | `22.12` or newer (CI tests `22`, `24`, and `26`) |
20
- | PostgreSQL | `15` to `19` |
21
- | Prisma | `@prisma/client` `7.1` or newer within `7.x` (tested on `7.10.1`) |
22
- | Drizzle | `0.45` and `1.x` (via `@auditstream/drizzle`) |
23
- | Runtimes | Node.js (reference), Bun and Deno (tested in CI), Cloudflare Workers (`nodejs_als` flag or compatibility date `2026-08-04` or later) |
24
-
25
- Prisma 6 is not supported. Prisma 8 support follows its stable release. The `prisma` CLI is never a peer dependency.
20
+ > **Prerequisite:** Run `auditstream init` from the [`auditstream` CLI](https://auditstream.dev/docs/getting-started/) to create the audit schema and database capture triggers.
26
21
 
27
22
  ## Quick start
28
23
 
29
24
  ### SQL comments plugin (`auditstream`)
30
25
 
31
- Register `auditstream()` in your Prisma 7 client `comments` array. Every write inside `audit.as()` receives one trailing `auditstream` tag.
32
-
33
- ```ts
34
- import { audit } from "@auditstream/node";
35
- import {
36
- auditstream,
37
- PACKAGE_NAME,
38
- type SqlCommenterContext,
39
- type SqlCommenterPlugin,
40
- type SqlCommenterTags,
41
- } from "@auditstream/prisma";
42
-
43
- const plugin: SqlCommenterPlugin = auditstream();
44
- const ctx: SqlCommenterContext = { sql: "UPDATE invoice SET status = $1 WHERE id = $2" };
45
-
46
- const tags: SqlCommenterTags = await audit.as({ type: "user", id: "usr_42" }, () => plugin(ctx));
47
- void [tags, PACKAGE_NAME];
48
- ```
49
-
50
- Pass the plugin when constructing `PrismaClient`:
26
+ Register `auditstream()` in your Prisma 7 client `comments` array. Every write inside `audit.as()` receives one trailing `auditstream` tag:
51
27
 
52
28
  ```ts
53
29
  import { audit } from "@auditstream/node";
54
30
  import { auditstream } from "@auditstream/prisma";
55
31
  import { PrismaPg } from "@prisma/adapter-pg";
56
- import pg from "pg";
57
-
58
- interface AppPrismaClient {
59
- invoice: { update(args: { where: { id: number }; data: { status: string } }): Promise<unknown> };
60
- }
61
-
62
- function createClient(
63
- PrismaClientCtor: new (options: {
64
- adapter: PrismaPg;
65
- comments: ReturnType<typeof auditstream>[];
66
- }) => AppPrismaClient,
67
- connectionString: string,
68
- ): AppPrismaClient {
69
- const pool = new pg.Pool({ connectionString });
70
- const adapter = new PrismaPg(pool);
71
- return new PrismaClientCtor({ adapter, comments: [auditstream()] });
72
- }
73
-
74
- async function markPaid(prisma: AppPrismaClient): Promise<void> {
75
- await audit.as({ type: "user", id: "usr_42" }, () =>
76
- prisma.invoice.update({ where: { id: 1 }, data: { status: "paid" } }),
77
- );
78
- }
79
-
80
- void [createClient, markPaid];
32
+ import { PrismaClient } from "./generated/prisma/client.js";
33
+
34
+ const adapter = new PrismaPg({ connectionString: "postgres://localhost/app" });
35
+ const prisma = new PrismaClient({
36
+ adapter,
37
+ comments: [auditstream()],
38
+ });
39
+
40
+ await audit.as({ type: "user", id: "usr_42" }, () =>
41
+ prisma.invoice.update({
42
+ where: { id: 1 },
43
+ data: { status: "paid" },
44
+ }),
45
+ );
81
46
  ```
82
47
 
83
48
  ### Transaction fallback (`auditTransaction`)
84
49
 
85
- Use `auditTransaction()` when SQL comments are unavailable, such as under Prisma Accelerate. It sets `auditstream.actor` with `set_config(..., true)` inside the transaction.
50
+ Use `auditTransaction()` when SQL comments are unavailable, such as under Prisma Accelerate or proxies that strip comments. It sets `auditstream.actor` with `set_config(..., true)` inside the transaction:
86
51
 
87
52
  ```ts
88
53
  import { audit } from "@auditstream/node";
89
- import {
90
- auditTransaction,
91
- type PrismaRawExecutor,
92
- type PrismaTransactionRunner,
93
- } from "@auditstream/prisma";
94
-
95
- interface TxClient extends PrismaRawExecutor {
96
- markPaid(id: number): Promise<void>;
97
- }
98
-
99
- async function updateWithFallback(
100
- prisma: PrismaTransactionRunner<TxClient, { timeout?: number }>,
101
- ): Promise<void> {
102
- await audit.as({ type: "user", id: "usr_42" }, () =>
103
- auditTransaction(
104
- prisma,
105
- async (tx) => {
106
- await tx.markPaid(1);
107
- },
108
- { timeout: 5000 },
109
- ),
110
- );
111
- }
112
-
113
- void updateWithFallback;
54
+ import { auditTransaction } from "@auditstream/prisma";
55
+ import { PrismaClient } from "./generated/prisma/client.js";
56
+
57
+ const prisma = new PrismaClient();
58
+
59
+ await audit.as({ type: "user", id: "usr_42" }, () =>
60
+ auditTransaction(
61
+ prisma,
62
+ async (tx) => {
63
+ await tx.invoice.update({
64
+ where: { id: 1 },
65
+ data: { status: "paid" },
66
+ });
67
+ },
68
+ { timeout: 5000 },
69
+ ),
70
+ );
114
71
  ```
115
72
 
73
+ ## Supported versions
74
+
75
+ | Dependency | Supported versions |
76
+ | --- | --- |
77
+ | Node.js | `22.12` or newer (CI tests `22`, `24`, and `26`) |
78
+ | PostgreSQL | `15` to `19` |
79
+ | Prisma | `@prisma/client` `7.1` or newer within `7.x` (tested on `7.10.1`) |
80
+ | Runtimes | Node.js (reference), Bun and Deno (tested in CI), Cloudflare Workers (`nodejs_als` flag or compatibility date `2026-08-04` or later) |
81
+
82
+ Prisma 6 is not supported. Prisma 8 support follows its stable release. The `prisma` CLI is never a peer dependency.
83
+
116
84
  ## Context and limits
117
85
 
118
86
  - **Unawaited lazy queries:** Prisma queries execute only when awaited. Always await them inside `audit.as()`, which awaits your callback before closing the scope.
87
+ - **No `statementNameGenerator`:** Never configure `PrismaPg`'s optional `statementNameGenerator` alongside SQL comments; per-actor comments with named prepared statements grow caches unboundedly.
119
88
  - **Next.js `proxy`:** `AsyncLocalStorage` does not cross Next.js `proxy`. Pass actor data through headers, cookies, rewrites, redirects, or URLs, and wrap handlers with `@auditstream/node/next`.
120
89
  - **Background jobs:** Code running outside a request has no active actor. Open a scope with a `service` or `system` actor.
121
90
  - **Prisma Accelerate:** Comment plugins do not receive the SQL under Accelerate. Use `auditTransaction()` there instead.
@@ -123,8 +92,16 @@ void updateWithFallback;
123
92
 
124
93
  ## Links
125
94
 
126
- - [Auditstream engine repository](https://github.com/auditstream/auditstream)
127
- - [Engineering handbook](https://github.com/auditstream/auditstream/tree/main/docs/handbook)
128
- - [Adapters design](https://github.com/auditstream/auditstream/blob/main/docs/handbook/adapters.md)
129
- - [Transport specification](https://github.com/auditstream/auditstream/blob/main/spec/transport.md)
130
- - [Supported versions](https://github.com/auditstream/auditstream/blob/main/docs/handbook/releases.md#supported-versions)
95
+ - [Prisma guide (auditstream.dev)](https://auditstream.dev/docs/typescript/prisma/)
96
+ - [Monorepo (auditstream-js)](https://github.com/auditstream/auditstream-js)
97
+ - [Rust Engine & CLI](https://github.com/auditstream/auditstream)
98
+ - [Security policy](https://github.com/auditstream/auditstream-js/security/policy)
99
+
100
+ [npm-badge]: https://img.shields.io/npm/v/%40auditstream%2Fprisma?style=flat&label=%40auditstream%2Fprisma
101
+ [npm-url]: https://www.npmjs.com/package/@auditstream/prisma
102
+ [ci-badge]: https://img.shields.io/github/actions/workflow/status/auditstream/auditstream-js/ci.yml?branch=main&style=flat&label=CI
103
+ [ci-url]: https://github.com/auditstream/auditstream-js/actions/workflows/ci.yml
104
+ [sonar-badge]: https://img.shields.io/sonar/quality_gate/auditstream_auditstream-js?server=https%3A%2F%2Fsonarcloud.io&style=flat&label=SonarCloud
105
+ [sonar-url]: https://sonarcloud.io/project/overview?id=auditstream_auditstream-js
106
+ [scorecard-badge]: https://img.shields.io/ossf-scorecard/github.com/auditstream/auditstream-js?style=flat&label=OpenSSF%20Scorecard
107
+ [scorecard-url]: https://scorecard.dev/viewer/?uri=github.com/auditstream/auditstream-js
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@auditstream/prisma",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Prisma 7 SQL comments plugin and set_config fallback for Auditstream",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
+ "homepage": "https://auditstream.dev/docs/typescript/prisma/",
7
8
  "repository": {
8
9
  "type": "git",
9
10
  "url": "https://github.com/auditstream/auditstream-js.git",
@@ -30,7 +31,7 @@
30
31
  "@prisma/client": ">=7.1.0 <8"
31
32
  },
32
33
  "devDependencies": {
33
- "@auditstream/node": "0.2.0",
34
+ "@auditstream/node": "0.2.1",
34
35
  "@auditstream/test-utils": "0.1.0",
35
36
  "@neondatabase/serverless": "1.2.1",
36
37
  "@prisma/adapter-neon": "7.10.1",