Prisma Monorepo Support
I raised this on Discord, where I was asked to create this issue, so I am x-posting the feature request to GitHub.
Background
When using a NodeJS monorepo such as Turborepo, Lerna, Yarn, NX, etc, it is currently not possible to use DBOS with Prisma. You receive an error that the @prisma/client node module cannot be found.
This is due to the following lines of code: https://github.com/dbos-inc/dbos-transact-ts/blob/8f0652bc8fe921025ceda99fa57a22fef132b1f3/src/dbos-executor.ts#L250-L252
In various monorepos it is considered best practice to keep the Prisma schema and client in a separate workspace package, and the @prisma/client module itself is often located in the root projects node modules folder.
Expectation
DBOS on Prisma works as normal in monorepos without throwing an error.
What have I tried?
I went ahead and applied a small patch to the aforementioned lines in a Turborepo, and confirmed that it works fine if you let it know where the root of the monorepo is located, as then it is able to locate the @prisma/client correctly. This works for my needs, but I imagine an official solution would be preferred by the community.
If I run into any other issues with monorepos I will let DBOS know, as I am integrating with DBOS for the first time in a Typescript based Turborepo project.
Thanks @vinnymac we'll take a look!
I will likely run into this too. I was hoping to start implementing this in my project, but it sounds like it wouldn't work since in the monorepo setup I'm using the prisma client in its entirety is exported from a workspace package, and should not be accessed in the root node_modules either. Have there been any other workarounds documented, or is patching the package the best way forward currently?
You may have to do this workaround in the short term, but we have a much better design for handling these clients coming soon.
In TS v3, we redid the way DB clients work, which should fix this. Instead of DBOS making a single PrismaClient and holding onto it for you, you make the PrismaClient (which you can configure the way you want) and then register via a PrismaDataSource from @dbos-inc/prisma-datasource; that will allow DBOS to manage transactions for transactional methods, but your app can use your PrismaClient directly too.
This approach fixes several long-standing issues surrounding the monorepo-type setup, the type checking for PrismaClient, and the availability of DB operations outside of DBOS transactions.
See https://docs.dbos.dev/typescript/tutorials/transaction-tutorial for docs, and https://github.com/dbos-inc/dbos-transact-ts/tree/main/packages/create/templates/dbos-prisma for a template.
This stuff is quite new, so please reach out on discord or file GH issues if you see anything wrong or have suggestions to improve the code / docs.