refactor(orm): make ZenStackPromise compatible with standard Promise signature#2650
refactor(orm): make ZenStackPromise compatible with standard Promise signature#2650
Conversation
…signature Drop the `Schema` type parameter from `ZenStackPromise` and remove the public `cb` property from its type, so the type is structurally assignable to a standard `Promise<T>`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR refactors the ZenStackPromise type system to remove the Schema generic parameter and introduces lazy, on-demand execution with callback extraction. The changes propagate through contract signatures and implementation to support the new promise model and add extended-result-field support utilities. ChangesPromise Type Simplification and Lazy Execution
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
Claude finished @ymc9's task —— View job Code Review CompleteI've thoroughly reviewed the ZenStackPromise refactor. This is a well-structured change that improves Promise compatibility while maintaining functionality. Here's my analysis: ✅ Strengths
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/orm/src/client/contract.ts`:
- Around line 208-211: The array overload of $transaction declares it accepts
ZenStackPromise<any>[] but ClientImpl still expects the internal branded
transaction promise with the hidden callback carrier (p.cb), causing a
type/runtime mismatch; update the declaration so the array overload uses the
internal/branded transaction-promise type (the same shape produced by the
factory) instead of public ZenStackPromise, or alternatively move the hidden
callback off the magic string property and introduce/export a single internal
interface used by both the factory that creates promises and
ClientImpl::$transaction so both the compile-time signature and runtime check
reference the same branded type (refer to $transaction, ClientImpl,
ZenStackPromise and the hidden p.cb callback carrier when making the change).
In `@packages/orm/src/client/promise.ts`:
- Around line 14-16: The exported createZenStackPromise lost its generic result
type (T) and now returns ZenStackPromise<unknown>; restore a generic type
parameter (e.g., <T>) so the function signature remains
createZenStackPromise<T>(callback: (txClient?: ClientContract<any>) =>
Promise<T>): ZenStackPromise<T>, and update any internal uses/returns to
propagate that T while keeping the Schema parameter removal intact so callers
preserve their fulfilled type instead of being forced to unknown.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 48a454ed-891b-467c-b87d-27708b820b46
📒 Files selected for processing (3)
packages/orm/src/client/client-impl.tspackages/orm/src/client/contract.tspackages/orm/src/client/promise.ts
Summary
Schematype parameter fromZenStackPromiseand remove the publiccbproperty from its type, so it is structurally assignable to a standardPromise<T>.ClientContractandClientImplto the new single-parameter form.cbcallback is still attached to the runtime object;ClientImpl.sequentialTransactionnow reaches it via a typedgetPromiseCallbackhelper that asserts its presence.Test plan
pnpm buildpnpm testfor the orm packageFixes #2356
Summary by CodeRabbit
Release Notes
New Features
Improvements