capnweb shim: doRpc overload for call-result stubs + byRef - #90
Merged
Conversation
ryanrasti
commented
Jul 22, 2026
Owner
- doRpc gains an overload accepting a raw-capability-typed stub (a call result typed Stubbed = T & Disposable), not just ShimStub — the mapped type can't reverse-infer T from those. Stubbed is now exported.
- byRef(fn) wraps a function as a pass-by-reference capability (an RpcStub) instead of the default record-replay closure, so a callback survives to be called back per invocation (e.g. a push/subscription API) rather than recorded once at serialization.
There was a problem hiding this comment.
Pull request overview
This PR updates the capnweb shim layer to better support composing RPC calls when capabilities are returned from other RPC calls, and adds an explicit way to send callbacks across the wire by reference (as capabilities) instead of as record/replay closures.
Changes:
- Export
Stubbed<T>and add adoRpcoverload intended to accept call-result (raw capability) stubs. - Add
byRef(fn)to wrap a function as a pass-by-reference capability (RpcStub) so it can be invoked remotely per-call. - Extend tests to cover
byRefbehavior and the newdoRpcoverload.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/capnweb/shim.ts | Exports Stubbed, adds doRpc overloads, and introduces byRef for pass-by-reference function capabilities. |
| src/capnweb/shim.test.ts | Adds coverage for byRef passthrough behavior and doRpc accepting call-result stubs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // overload can't reverse-infer T through its mapped type from those, so | ||
| // match them as-is — the callback experiences the unmangled type either | ||
| // way. | ||
| export function doRpc<T extends object, R>(stub: T, fn: (api: T) => R): Promise<Stubbed<Awaited<R>>>; |
Comment on lines
+82
to
+83
| export const byRef = <F extends (...args: never[]) => unknown>(fn: F): F => | ||
| new (RpcStub as unknown as new (target: unknown) => unknown)(fn) as F; |
- doRpc gains an overload accepting a raw-capability-typed stub (a call result typed Stubbed<T> = T & Disposable), not just ShimStub<T> — the mapped type can't reverse-infer T from those. Stubbed is now exported. - byRef(fn) wraps a function as a pass-by-reference capability (an RpcStub) instead of the default record-replay closure, so a callback survives to be called back per invocation (e.g. a push/subscription API) rather than recorded once at serialization. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ryanrasti
force-pushed
the
ryan_1_capnweb_shim
branch
from
July 23, 2026 00:12
3940059 to
8515194
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.