{"_id":"@efesto-cloud/prisma-unit-of-work","name":"@efesto-cloud/prisma-unit-of-work","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@efesto-cloud/prisma-unit-of-work","version":"1.0.0","description":"Prisma-backed IUnitOfWork for efesto-cloud","repository":{"type":"git","url":"git+https://github.com/efesto-cloud/lib.git","directory":"packages/prisma-unit-of-work"},"type":"module","module":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"},"./*":{"import":"./dist/*.js","types":"./dist/*.d.ts"}},"dependencies":{"@efesto-cloud/unit-of-work":"1.0.0"},"keywords":[],"license":"MIT","publishConfig":{"access":"public"},"scripts":{"build":"tsc --project tsconfig.json","typecheck":"tsc --noEmit","clean":"rm -rf dist"},"_id":"@efesto-cloud/prisma-unit-of-work@1.0.0","bugs":{"url":"https://github.com/efesto-cloud/lib/issues"},"homepage":"https://github.com/efesto-cloud/lib#readme","_integrity":"sha512-YCC4cG4ypQDCheoeAtBvUrxftKx3fXnZvWdlDEZpO+Kxl9ygpmJG6N3UBRcaHdGd7hHej0ySfsrvs2qsmNfn+w==","_resolved":"/tmp/e8e62b714eee0b4b2dd04166c5668f78/efesto-cloud-prisma-unit-of-work-1.0.0.tgz","_from":"file:efesto-cloud-prisma-unit-of-work-1.0.0.tgz","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-YCC4cG4ypQDCheoeAtBvUrxftKx3fXnZvWdlDEZpO+Kxl9ygpmJG6N3UBRcaHdGd7hHej0ySfsrvs2qsmNfn+w==","shasum":"25a0918ddf94f1c4a9db8cc8c963e59c0328398c","tarball":"https://registry.npmjs.org/@efesto-cloud/prisma-unit-of-work/-/prisma-unit-of-work-1.0.0.tgz","fileCount":15,"unpackedSize":8789,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@efesto-cloud%2fprisma-unit-of-work@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD4u2lxLbhDjYORVnzmpvTui635BZr7YEeI5fPhW4DyFAIgA/xZja6SBoH8m4fb9EHfp3jRTX/WTt1dSKM9w3Lit1A="}]},"_npmUser":{"name":"dariofurlan","email":"dario@dariofurlan.com"},"directories":{},"maintainers":[{"name":"dariofurlan","email":"dario@dariofurlan.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prisma-unit-of-work_1.0.0_1780908804797_0.14724079501338605"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-08T08:53:24.658Z","1.0.0":"2026-06-08T08:53:24.964Z","modified":"2026-06-08T08:53:25.411Z"},"maintainers":[{"name":"dariofurlan","email":"dario@dariofurlan.com"}],"description":"Prisma-backed IUnitOfWork for efesto-cloud","homepage":"https://github.com/efesto-cloud/lib#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/efesto-cloud/lib.git","directory":"packages/prisma-unit-of-work"},"bugs":{"url":"https://github.com/efesto-cloud/lib/issues"},"license":"MIT","readme":"# @efesto-cloud/prisma-unit-of-work\n\nPrisma implementation of [`IUnitOfWork`](../unit-of-work). Wraps a Prisma-like client and exposes the current client (root or transactional `tx`) for repositories to use inside `runWithTransaction`.\n\nThe client is typed structurally via `PrismaLikeClient` — the package has no direct dependency on `@prisma/client`, so any object with a compatible `$transaction` method works (the real `PrismaClient` being the usual case).\n\n## Installation\n\n```bash\npnpm add @efesto-cloud/prisma-unit-of-work @efesto-cloud/unit-of-work\n# plus your Prisma client, typically:\npnpm add @prisma/client\n```\n\n## Quick Start\n\n```ts\nimport { PrismaClient } from \"@prisma/client\";\nimport PrismaUnitOfWork from \"@efesto-cloud/prisma-unit-of-work/PrismaUnitOfWork\";\n\nconst prisma = new PrismaClient();\nconst uow = new PrismaUnitOfWork(prisma);\n\nawait uow.runWithTransaction(async () => {\n    await uow.client.user.update({ where: { id }, data: { … } });\n});\n```\n\n## API\n\n```ts\ninterface PrismaLikeClient<TTx = object> {\n    $transaction<T>(fn: (tx: TTx) => Promise<T>): Promise<T>;\n}\n\ntype PrismaTxOf<TClient> = Omit<TClient, \"$connect\" | \"$disconnect\" | \"$on\" | \"$transaction\" | \"$use\" | \"$extends\">;\n\ninterface IPrismaUnitOfWork<\n    TClient extends PrismaLikeClient<PrismaTxOf<TClient>> = PrismaLikeClient,\n> extends IUnitOfWork {\n    readonly client: TClient | PrismaTxOf<TClient>; // transactional tx inside runWithTransaction, else root\n}\n```\n\n- `client` — always use this from repositories. Outside a transaction it's the root client; inside `runWithTransaction` it's the Prisma `tx` passed to `$transaction`'s callback (typed as `PrismaTxOf<TClient>`, i.e. the client minus the management methods).\n- `runWithTransaction(fn)` — inherited from `IUnitOfWork`. Wraps `fn` in `prisma.$transaction`. If a transaction is already running (nested call), it reuses the outer one and just invokes `fn`.\n- `PrismaLikeClient` / `PrismaTxOf` are re-exported so you can type custom clients (e.g. extended Prisma clients) precisely.\n\n## Notes\n\n- Prisma manages the transaction lifecycle; no explicit session open/close is needed.\n- Nesting is safe: inner `runWithTransaction` calls run within the outer transaction without opening a new one, so they commit/rollback atomically with the outermost call.\n- Repositories should always go through `uow.client` — using the root `PrismaClient` directly opts that operation out of the transaction.\n","readmeFilename":"README.md","_rev":"1-702092ae48bd1dd3c8427ffcdb182729"}