feat: add transaction and write batch support - #55
Conversation
|
Warning Review limit reached
Next review available in: 14 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughFirestore transaction and batch support was added to the public API, client and admin services, mock service, tests, and documentation. Operations now use fiber-local routing, preserve typed failures, support nesting, and enforce transaction and batch restrictions. ChangesFirestore transactions and batches
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Application
participant FirestoreService
participant FirestoreSDK
Application->>FirestoreService: withTransaction(effect) or withBatch(effect)
FirestoreService->>FirestoreSDK: runTransaction(callback) or writeBatch()
Application->>FirestoreService: repository reads and writes
FirestoreService->>FirestoreSDK: route reads or stage writes
FirestoreSDK-->>FirestoreService: transaction result or batch commit
FirestoreService-->>Application: effect result or typed failure
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Adds withTransaction and withBatch to FirestoreService, routed through fiber-local Context.References (CurrentTransaction/CurrentBatch) so all reads and writes — including those made through repositories — are transparently redirected to the active transaction or batch. - effect-firebase: extend FirestoreServiceShape, add Firestore.withTransaction / Firestore.withBatch helpers, noop layer - @effect-firebase/admin: transactions via db.runTransaction (typed failures roll back and propagate), batches via db.batch; queries run through transaction.get; streams and deleteRecursive die inside a transaction - @effect-firebase/client: same via runTransaction/writeBatch; queries also die inside a transaction (client SDK supports document reads only) - @effect-firebase/mock: pass-through defaults - Nested withTransaction/withBatch join the ambient one; withBatch inside a transaction routes writes to the transaction Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LJB3ye9tLX17ar4rFSSLYi
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/effect-firebase/src/lib/firestore/transaction.ts`:
- Around line 27-38: Update the JSDoc transaction example to derive the new
balances from the defined source and target objects, replacing the undefined
sourceBalance and targetBalance references while preserving the existing
repository update calls.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1cf531f2-788b-4da6-adc1-46948da8f7bb
📒 Files selected for processing (13)
README.mdpackages/admin/src/lib/firestore/firestore-service.spec.tspackages/admin/src/lib/firestore/firestore-service.tspackages/client/src/lib/firestore/firestore-service.spec.tspackages/client/src/lib/firestore/firestore-service.tspackages/effect-firebase/README.mdpackages/effect-firebase/src/lib/firestore/firestore-service.tspackages/effect-firebase/src/lib/firestore/firestore.tspackages/effect-firebase/src/lib/firestore/noop-layer.tspackages/effect-firebase/src/lib/firestore/transaction.spec.tspackages/effect-firebase/src/lib/firestore/transaction.tspackages/mock/README.mdpackages/mock/src/lib/firestore/firestore-service.ts
e7d3f31 to
c6934e1
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LJB3ye9tLX17ar4rFSSLYi
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Adds Firestore transaction and write batch support across all packages via two new
FirestoreServicecombinators:Design
Reads and writes are routed through fiber-local
Context.References (CurrentTransaction/CurrentBatch) that each SDK layer consults at call time. Since repositories capture theFirestoreServiceinstance at construction, this is the only routing strategy that lets existing repositories participate in transactions with zero changes — the same pattern@effect/sqluses forwithTransaction.withTransaction/withBatchonFirestoreServiceShape, user-facingFirestore.withTransaction/Firestore.withBatchhelpers, noop layer supportdb.runTransaction, batches viadb.batch();addpre-allocates a ref and usestx.create; queries run throughtx.get(query)runTransaction/writeBatch;addusestx.set(client SDK has nocreate);querydies inside a transaction (client SDK only supports document reads)Semantics
Exitinside therunTransactioncallback, failures are thrown as an internal wrapper to abort the SDK transaction, and the originalExitis resumed outside the promise boundary. Interruption of the outer fiber is wired through the abort signal.withTransaction/withBatchjoin the ambient one;withBatchinside a transaction routes writes to the transaction.withBatchexecute immediately and do not see staged writes.streamDoc,streamQuery, anddeleteRecursivedie inside a transaction (deleteRecursivealso inside a batch) instead of silently bypassing it.Caveats (documented on the API)
FirestoreErrorat runtime).Testing
Firestorecovering routing, commit/rollback, typed-failure propagation, join semantics, and defect guardsvi.mock('firebase/firestore')covering the same plus client-specific restrictions4.0.0-beta.99🤖 Generated with Claude Code
https://claude.ai/code/session_01LJB3ye9tLX17ar4rFSSLYi
Generated by Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests