This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
Split RpcResponse
into RpcResponse
and RpcTransportResponse
#3170
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.
This PR renames the current
RpcResponse
type toRpcTransportResponse
and adds a new type definition forRpcResponse
which is more consistent with the newRpcRequest
definition (from the previous PR).The benefit of this is that, when defining
RpcResponseTransformers
, we no longer need to worry about transformer both thejson
andtext
paths. Now, only thejson
path matter. However, if your transformer needs to affect how that JSON is initially parsed from a string, then thefromText
function may be added to theRpcResponse
object.The slight annoyance is that, in order to achieve this, we need some weird deferred logic which may confuse people looking at the internals of the RPC proxy.
solana-web3.js/packages/rpc-spec/src/rpc.ts
Lines 87 to 98 in f7a09e2
As you can see we need the final
response
object in order to define therawResponse
object which is then transformed into aresponse
object. It works because thejson
function is called after all this is resolved but it's a bit weird to read.Here are some diagrams illustrating the RPC changes made by this PR.
Current state
Proposed state