refactor(json-rpc-engine): Genericize JsonRpcServer middleware / engine
#6990
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.
Explanation
As it turns out, the
JsonRpcServerneeds its middleware / engine to be generic in order to support certain use cases. Without generics, its middleware type needs to beJsonRpcMiddleware<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
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.
JsonRpcServer)OptionsoverJsonRpcMiddleware; type underlyingJsonRpcEngineV2viaRequestOf/MergedContextOf.RequestOfandMergedContextOffromv2/JsonRpcEngineV2.v2/index.tswith named exports and type re-exports (JsonRpcMiddleware,MiddlewareParams,Next,ResultConstraint).JsonRpcServer.test.ts.JsonRpcRequest/JsonRpcNotificationmiddleware; add warning about servers that only accept one kind.JsonRpcEngineV2item.Written by Cursor Bugbot for commit e68ff03. This will update automatically on new commits. Configure here.