Repository navigation
refactor(rpc): make defineMethod preserve the method name and handler result - #20016
Conversation
… result `defineMethod` erased both halves of the contract it was given: the literal method name became `string` and the handler's return type became `unknown`, so nothing downstream could name a method or its result in a type. It is now generic over the literal name, the params schema, and the handler's inferred result, and the ~611 registered declarations keep those types because the per-module `RpcMethod[]` annotations — which were the erasure — are gone. Erasure now happens at one named site, `eraseRpcMethods`, which `buildRegistry` calls; the registry, the dispatcher, and the wire are unchanged, and the adapter returns the same array it was handed. Compile-time only: no handler body, return value, or dispatch path changed. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
Too many files changed for review (124 files, 100 file limit). Bypass the limit by tagging |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Typed
defineMethod/defineStreamingMethod— both are now generic over the literal method name and the handler's inferred result, returningRpcTypedMethod<TName, TSchema, TResult>/RpcTypedStreamingMethod<TName, TSchema>, so downstream code can see thatstatus.getis the literal"status.get"and what its handler returns. - Single erasure site —
eraseRpcMethods(three overloads that preserve the one-shot/streaming split) is the one named, commented place the parsed-params type is dropped;buildRegistry,DispatcherOptions.methods,OrcaRuntimeRpcServerOptions.methods, andparseRpcRequestParamsnow accept theRpcMethodDeclarationview. Thenever-param contravariance trick makes typed handlers assignable to declarations with no cast. - Annotation removal — ~88 method modules drop their
: RpcMethod[]/: RpcAnyMethod[]array annotations so literal names survive; no handler bodies changed. - Contract test —
core-typed-method-contract.test.tspins name/result/params inference withexpectTypeOf, and the author's mutation testing confirms it is a real gate (name→string= 19 errors, result→unknown= 4 errors underpnpm tc, whileviteststays green sinceexpectTypeOferases at runtime).
The variance reasoning is sound, the runtime path is untouched (eraseRpcMethods is an identity cast, and the dispatcher still invokes the erased handler with unknown), and the dispatcher/streaming split survives erasure correctly.
One observation for awareness, not a change request: the exported method arrays lost their readonly modifier as a side effect of dropping the annotations — immutability of those module constants is no longer type-enforced. No consumer relies on it, and restoring it cleanly would re-add the very annotations this PR removes, so this is an acceptable tradeoff.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (124)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe RPC core now preserves typed method names, parameter schemas, handler results, and streaming distinctions. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The typed RPC declaration changes preserve the existing runtime registry and wire behavior, with no unresolved merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the implementation, rationale, runtime impact, evidence, tests, and known limits. However, it omits required template sections, including the linked issue, visual proof or N/A, testing checklist, AI disclosure, review, agent skill boundary, notes, and final checklist. Resolution Add the missing template sections. Include a linked issue using “Fixes #…”, provide visual proof or write “N/A” with a reason, complete the testing checklist and platform coverage, complete the AI Disclosure section, address Review and Agent skill upstream boundary, add Notes, and complete the final Checklist. Full details: Docstring CoverageExplanation Docstring coverage is 17.39% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 50 files. (74 skipped: 74 over the file limit.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |

What
defineMethoderased the two things later migration steps need.RpcMethod.namewasstringandRpcMethod.handlerreturnedunknown, so nothing downstream could see thatstatus.getis the literal"status.get"or that its handler returns a 22-field object.defineMethodis now generic over the literal name and the handler's inferred result, returningRpcTypedMethod<TName, TSchema, TResult>. The registry stays erased —RpcMethod,RpcAnyMethod,RpcRegistryand the dispatcher are unchanged — but erasure now happens at one named, commented site (eraseRpcMethods) instead of implicitly by assignment.Why the diff touches 124 files
The 94
: RpcMethod[]/: RpcAnyMethod[]array annotations were the erasure. With them in place, contextual inference collapsedTNameback tostringand the change would have been decoration. Deleting them (one line each, 88 files) is what makes the types survive. No handler was annotated or otherwise touched.DispatcherOptions.methods,PairingOptions.methodsandparseRpcRequestParamsnow accept declarations, which resolved ~607 call-site errors with three signature edits.Runtime impact: none
eraseRpcMethodsreturns its argument (return methods as readonly RpcAnyMethod[]). Outsidecore.ts, the only files gaining a call to it are test files and two test-support harnesses. No production runtime path changed, no handler return value changed, and nothing on the wire changed.Evidence
Types actually survive, verified by resolving them rather than by inspection:
Mutation results against
config/tsconfig.node.json:stringunknownBoth are type-level failures.
viteststays green under either mutation becauseexpectTypeOferases at runtime, sopnpm tcis the gate that holds this contract — the new test file is confirmed present in the node project's file list.Gates
pnpm tc·typecheck:tsc(node + cli + web) ·vitest run src/main/runtime/rpc295 files / 2,503 passed ·verify:rpc-params-catalog·check:code-quality:changed0/0/0 across 124 files ·oxfmt --checkclean · max-lines ratchet OK (core.ts199/300).Known limits
emitis an input with no return position to infer from. That needs a separateTEmittedon the spec — a later unit.src/sharedwhere mobile can reach them, so identity mapping stays. What this newly enables is a type-level parity gate assertingRpcParams<M>matches the host's parsed params for everyM.