Skip to content

Conversation

@rekmarks
Copy link
Member

@rekmarks rekmarks commented Oct 29, 2025

Explanation

As it turns out, the JsonRpcServer needs its middleware / engine to be generic in order to support certain use cases. Without generics, its middleware type needs to be JsonRpcMiddleware<JsonRpcCall>, which prevents constructing engines that only support either requests or notifications.

Enabling this comes at the cost of some type safety, but the server will still handle any errors thrown by its engine due to the latter's lack of support of requests or notifications. The alternative would be to make the server aware of which type of requests it supports at runtime, which seems overkill.

References

N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Note

Genericizes JsonRpcServer over middleware/engine types, exports RequestOf/MergedContextOf, updates v2 index exports, adds tests for request/notification-only servers, and clarifies docs with warnings.

  • Server (v2/JsonRpcServer)
    • Genericize class and Options over JsonRpcMiddleware; type underlying JsonRpcEngineV2 via RequestOf/MergedContextOf.
    • Accept middleware directly with preserved types; add warnings in JSDoc about request vs. notification handling.
  • Types/Exports
    • Export RequestOf and MergedContextOf from v2/JsonRpcEngineV2.
    • Replace wildcard re-export in v2/index.ts with named exports and type re-exports (JsonRpcMiddleware, MiddlewareParams, Next, ResultConstraint).
  • Tests
    • Add tests ensuring errors when a server supports only requests or only notifications and receives the wrong kind.
    • Minor wording/import adjustments in JsonRpcServer.test.ts.
  • Docs
    • README: refine warning about mixing JsonRpcRequest/JsonRpcNotification middleware; add warning about servers that only accept one kind.
    • Changelog: add PR reference for JsonRpcEngineV2 item.

Written by Cursor Bugbot for commit e68ff03. This will update automatically on new commits. Configure here.

@rekmarks rekmarks marked this pull request as ready for review October 29, 2025 07:19
@rekmarks rekmarks requested review from a team as code owners October 29, 2025 07:19
@rekmarks rekmarks force-pushed the rekm/jrpce-server-generic branch from 5c06d3c to e68ff03 Compare October 29, 2025 17:14
@rekmarks rekmarks enabled auto-merge (squash) October 29, 2025 22:34
@rekmarks rekmarks merged commit caa214e into main Oct 30, 2025
256 checks passed
@rekmarks rekmarks deleted the rekm/jrpce-server-generic branch October 30, 2025 07:58
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.

3 participants