@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.
- package/README.md +66 -89
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# @auditstream/prisma
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)
|
|
69
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
- [
|
|
127
|
-
- [
|
|
128
|
-
- [
|
|
129
|
-
- [
|
|
130
|
-
|
|
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.
|
|
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.
|
|
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",
|