{"_id":"@efesto-cloud/mongodb-unit-of-work","name":"@efesto-cloud/mongodb-unit-of-work","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@efesto-cloud/mongodb-unit-of-work","version":"1.0.0","description":"MongoDB-backed IUnitOfWork for efesto-cloud","repository":{"type":"git","url":"git+https://github.com/efesto-cloud/lib.git","directory":"packages/mongodb-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"},"peerDependencies":{"mongodb":"^6 || ^7"},"keywords":[],"license":"MIT","publishConfig":{"access":"public"},"scripts":{"build":"tsc --project tsconfig.json","typecheck":"tsc --noEmit","clean":"rm -rf dist"},"_id":"@efesto-cloud/mongodb-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-K0Y/1qvOWBiPEeUZ2zuQ4ROBNvqko06Iqr4vduK5O3YJXrnEduWkZzKo4fdqzz3w8uF4jPfFzPYI9Q6zN9+TRA==","_resolved":"/tmp/2f44f33494bf906aacc895b748752272/efesto-cloud-mongodb-unit-of-work-1.0.0.tgz","_from":"file:efesto-cloud-mongodb-unit-of-work-1.0.0.tgz","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-K0Y/1qvOWBiPEeUZ2zuQ4ROBNvqko06Iqr4vduK5O3YJXrnEduWkZzKo4fdqzz3w8uF4jPfFzPYI9Q6zN9+TRA==","shasum":"b38194db677cef60c334102c1dcfb2ea923bc7c8","tarball":"https://registry.npmjs.org/@efesto-cloud/mongodb-unit-of-work/-/mongodb-unit-of-work-1.0.0.tgz","fileCount":15,"unpackedSize":8347,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@efesto-cloud%2fmongodb-unit-of-work@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCCvOSrDbIZStkXPFg2thcdEUjk05RHYUp5NPrHVvY6CAIgHr33iGW5Pt8sxpbugZDsSyfcFfapVdgXNlbpIqIoMNc="}]},"_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/mongodb-unit-of-work_1.0.0_1780908805005_0.9454124987119177"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-08T08:53:24.807Z","1.0.0":"2026-06-08T08:53:25.133Z","modified":"2026-06-08T08:53:25.554Z"},"maintainers":[{"name":"dariofurlan","email":"dario@dariofurlan.com"}],"description":"MongoDB-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/mongodb-unit-of-work"},"bugs":{"url":"https://github.com/efesto-cloud/lib/issues"},"license":"MIT","readme":"# @efesto-cloud/mongodb-unit-of-work\n\nMongoDB implementation of [`IUnitOfWork`](../unit-of-work). Wraps a `MongoClient` and exposes a `ClientSession` that repositories can use for session-scoped reads/writes inside `runWithTransaction`.\n\n## Installation\n\n```bash\npnpm add @efesto-cloud/mongodb-unit-of-work @efesto-cloud/unit-of-work mongodb\n```\n\n## Quick Start\n\n```ts\nimport { MongoClient } from \"mongodb\";\nimport MongoDBUnitOfWork from \"@efesto-cloud/mongodb-unit-of-work/MongoDBUnitOfWork\";\n\nconst client = new MongoClient(process.env.MONGO_URL!);\nawait client.connect();\n\nconst uow = new MongoDBUnitOfWork(client);\n\nawait uow.runWithTransaction(async () => {\n    await coll.updateOne(\n        { _id: id },\n        { $set: { … } },\n        { session: uow.session },   // pass the session to every op\n    );\n});\n```\n\n## API\n\n```ts\ninterface IMongoDBUnitOfWork extends IUnitOfWork {\n    readonly session: ClientSession | undefined; // active session, if any\n    readonly sessionOrNull: ClientSession | null;\n\n    runWithTransaction<T>(fn: () => Promise<T>): Promise<T>;\n}\n```\n\n- `session` / `sessionOrNull` — the currently active `ClientSession`. Pass it as `{ session }` to every MongoDB operation so reads/writes participate in the transaction.\n- `runWithTransaction(fn)` — starts a session and wraps `fn` in `session.withTransaction`. If a transaction is already running (nested call), it reuses the outer one and just invokes `fn`.\n\n## Notes\n\n- The session is started lazily on the first `runWithTransaction` call and ended when the outermost call returns.\n- Nesting is safe: inner `runWithTransaction` calls run within the outer transaction without starting a new one.\n- Repositories should always thread `uow.session` into their MongoDB calls — forgetting to do so opts that operation out of the transaction.\n","readmeFilename":"README.md","_rev":"1-4d8e20c773ff3beb11e4ac861c18d248"}