feat(server,contract): narrow TMeta through .meta() chains#1550
Conversation
.meta() now returns a builder whose TMeta reflects the values actually passed in: Omit<TMeta, keyof U> & U. .meta() takes Partial<TMetaDef> and constraint is in a new TMetaDef generic - only changed fields must be passed.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughThe PR introduces a metadata definition type parameter ChangesMetadata Definition Type Propagation Across Builders
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
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 unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
Code Review
This pull request introduces a TMetaDef generic parameter across the contract and server builders to support metadata narrowing while preserving the original metadata definition, alongside a new MergedMeta utility type. Feedback focuses on ensuring that this generic is explicitly propagated through class constructors in methods like .meta(), $route(), and errors() to prevent incorrect type inference and maintain consistent type information across the builder chain.
|
Gemini is wrong but if helpful I can add a test like |
|
Thanks for the contribution! A few concerns:
Let me know your thoughts! |
Motivation
~orpc.metawas typed as the wide declared schema rather than the values actually set, so there was no way to read the concrete meta a procedure carries.Summary
.meta()now narrowsTMetatoOmit<TMeta, keyof U> & Uon each call. The declared schema lives on a newTMetaDefgeneric that.meta()constrains against viaPartial<TMetaDef>, so unknown keys and wrong types are still rejected.TMetaDefdefaults toTMeta, so positional generics and downstream consumers (Procedure, Middleware, Router, plugins) are unchanged.mergeMetareturnsMergedMeta<T, U>.Summary by CodeRabbit