Skip to content

Commit bceb7ff

Browse files
committed
Add support for setting up Bemi context in tRPC apps via middleware
1 parent a0d18d0 commit bceb7ff

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
#### [v1.1.0](https://github.com/BemiHQ/bemi-prisma/compare/v1.0.0...v1.1.0) - 2025-05-27
4+
5+
- Add `bemiTRPCMiddleware` for setting up Bemi context in tRPC apps
6+
37
#### [v1.0.0](https://github.com/BemiHQ/bemi-prisma/compare/v0.9.0...v1.0.0) - 2025-05-26
48

59
- **Breaking change**: Use `new PrismaPg()` & `withBemiExtension()` explicitly instead of `withPgAdapter()`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bemi-db/prisma",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Automatic data change tracking for Prisma",
55
"main": "dist/index.js",
66
"module": "./dist/index.mjs",

src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,13 @@ export const BemiApolloServerPlugin = (callback: (requestContext: any) => any) =
101101
},
102102
}
103103
}
104+
105+
// T3 Stack
106+
export const bemiTRPCMiddleware = (t: any, callback: (opts: any) => any) => {
107+
return t.middleware((opts: any) => {
108+
const context = callback(opts);
109+
return ASYNC_LOCAL_STORAGE.run(context, () => {
110+
return opts.next();
111+
});
112+
})
113+
}

0 commit comments

Comments
 (0)