Skip to content

capnweb shim: doRpc overload for call-result stubs + byRef - #90

Merged
ryanrasti merged 1 commit into
mainfrom
ryan_1_capnweb_shim
Jul 23, 2026
Merged

capnweb shim: doRpc overload for call-result stubs + byRef#90
ryanrasti merged 1 commit into
mainfrom
ryan_1_capnweb_shim

Conversation

@ryanrasti

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a doRpc overload 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 byRef behavior and the new doRpc overload.

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.

Comment thread src/capnweb/shim.ts
// 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 thread src/capnweb/shim.ts Outdated
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
ryanrasti force-pushed the ryan_1_capnweb_shim branch from 3940059 to 8515194 Compare July 23, 2026 00:12
@ryanrasti
ryanrasti merged commit 1d00391 into main Jul 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants