Skip to content

add jsonrpc serialization to rpc #4623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

add jsonrpc serialization to rpc #4623

wants to merge 2 commits into from

Conversation

tim-smart
Copy link
Contributor

No description provided.

@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Mar 21, 2025
Copy link

changeset-bot bot commented Mar 21, 2025

⚠️ No Changeset found

Latest commit: 5825d3d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

jsonRpcMessage = {
jsonrpc: "2.0",
method: response.tag,
params: response.payload,
Copy link
Member

Choose a reason for hiding this comment

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

Generally for the RPC module, payload should be:

a) optional
b) not just Schema.Struct

E.g. JSON RPC commonly uses positional tuples for payloads and for some methods, the payload can also be optional entirely. In these cases, the params key should not be set (but most implementations will accept an empty array or empty object anyways).

export const jsonrpc: Effect.Effect<RpcSerialization["Type"]> = Effect.sync(() => {
const decoder = new TextDecoder()
return RpcSerialization.of({
contentType: "application/json-rpc",
Copy link
Member

Choose a reason for hiding this comment

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

Some JSON RPC server will NOT accept application/json-rpc (as ridiculous as that sounds).

In these cases, we could either require the user to override the header in their client or alternatively we'd have to change how the muxing currently behaves when e.g. application/json is set and instead make that more explicitly configurable here (I think I'd prefer that).

@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog May 8, 2025
supportsBigInt: false,
unsafeMake: () => ({
decode: (bytes) => {
const decoded: JsonRpcMessage = JSON.parse(typeof bytes === "string" ? bytes : decoder.decode(bytes))
Copy link
Member

Choose a reason for hiding this comment

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

Some JSON RPC server support batch requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

2 participants