Skip to content

Feat/implemented by#871

Open
BelfordZ wants to merge 5 commits intomasterfrom
feat/implemented-by
Open

Feat/implemented by#871
BelfordZ wants to merge 5 commits intomasterfrom
feat/implemented-by

Conversation

@BelfordZ
Copy link
Copy Markdown
Member

@BelfordZ BelfordZ commented Feb 27, 2026

Summary

Add support for the OpenRPC x-implemented-by extension to server-js, enabling basic bidirectional APIs.

The server will no longer require handlers for methods declared as client-implemented and can optionally call those methods over WebSocket connections.

This introduces a minimal ownership model:

  • server implements server methods
  • connected peers implement client methods

No transport semantics or lifecycle rules are introduced — this strictly enables ownership-aware routing and outbound calls.


What this changes

Routing behavior

  • Methods marked x-implemented-by: ["client"] are excluded from server handler registration
  • Inbound calls to those methods are rejected (Method not found)
  • Existing OpenRPC documents continue to work (default = server)

WebSocket outbound support

When using the WebSocket transport:

  • Each connection is treated as a callable peer
  • The server can call client-implemented methods on connected peers
  • Handler context now exposes a client interface for calling peer methods

New usage patterns enabled

Inside a handler:

async sendMessage(params, { client }) {
  await client.chatMessage({ text: "hello back" });
}

Server-level outbound usage:

setInterval(() => {
  for (const client of server.clients()) {
    client.foo({ time: Date.now() });
  }
}, 1000);

Examples added

  • Bidirectional WebSocket example
  • Outbound server → client example

These demonstrate callback-style JSON-RPC usage without introducing pubsub semantics.


Motivation

OpenRPC historically models a server-handled API surface, but real JSON-RPC systems are commonly bidirectional:

  • callbacks
  • notifications in both directions
  • peer-style APIs

Without an ownership signal, tooling cannot deterministically:

  • decide which handlers to require
  • expose callable peer methods
  • implement realistic mocks

x-implemented-by enables this while remaining transport-agnostic and minimal.


Scope

This PR intentionally does not introduce:

  • subscription semantics
  • routing policies
  • lifecycle modeling
  • transport negotiation

It only adds ownership-aware dispatch and optional outbound peer calls for WebSocket connections.


Backwards compatibility

Existing APIs continue to behave exactly the same:

  • Missing x-implemented-by ⇒ treated as server-implemented
  • No changes required for current users

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 90.24390% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.32%. Comparing base (8531407) to head (cb82590).

Files with missing lines Patch % Lines
src/router.ts 83.33% 10 Missing ⚠️
src/plugins.ts 83.33% 4 Missing ⚠️
src/transports/websocket.ts 97.26% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #871      +/-   ##
==========================================
- Coverage   98.96%   95.32%   -3.64%     
==========================================
  Files           9       10       +1     
  Lines         289      428     +139     
  Branches       43       79      +36     
==========================================
+ Hits          286      408     +122     
- Misses          3       20      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@BelfordZ BelfordZ force-pushed the feat/implemented-by branch from bd58428 to a498ceb Compare February 27, 2026 21:41
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.

1 participant