This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The purpose of this PR stack is to refactor both the RPC and RPC Subscriptions packages such that they have better interfaces with their respective transports. In this first batch of PRs, we will start by focusing on the RPC packages whilst ensuring minimum changes on the RPC Subscriptions packages. The end goal of this first part is to have the following interfaces for the RPC packages: ### RPC Shared Layer ```ts type RpcRequest<TParams = unknown> = { readonly methodName: string; readonly params: TParams; } type RpcResponse<TResponse = unknown> = { readonly json: () => Promise<TResponse>; readonly text: () => Promise<string>; } type RpcRequestTransformer = { <TParams>(request: RpcRequest<unknown>): RpcRequest<TParams>; }; type RpcResponseTransformer = { <TResponse>(response: RpcResponse<unknown>, request: RpcRequest<unknown>): RpcResponse<TResponse>; }; type RpcResponseTransformerFor<TResponse> = { (response: RpcResponse<unknown>, request: RpcRequest<unknown>): RpcResponse<TResponse>; }; ``` ### RPC Transport Layer ```ts type RpcTransportRequest = { readonly payload: unknown; readonly signal?: AbortSignal; } type RpcTransport = { <TResponse>( request: RpcTransportRequest ): Promise<RpcResponse<TResponse>>; } ``` ### RPC API Layer ```ts type RpcApi<TRpcMethods> = { ... } type RpcApiConfig = { readonly requestTransformer?: RpcRequestTransformer; readonly responseTransformer?: RpcResponseTransformer; } type PendingRpcApiRequest<TResponse> = RpcRequest & { responseTransformer?: RpcResponseTransformerFor<TResponse>; }; ``` ### RPC Layer ```ts type PendingRpcRequest<TResponse> = { // Nothing changes here but the final send function returns the result of `response.json()`. send(options?: RpcSendOptions): Promise<TResponse>; }; ``` --- In the first two PRs of the stack, we start by cleaning up the type namespace to allow these new types to exist. First, we rename `RpcResponse` to `RpcResponseData`, since `RpcResponse` will be used to define a proper response interface that aligns all the RPC layers.
- Loading branch information
1 parent
1193f5f
commit 1c25dd4
Showing
6 changed files
with
18 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@solana/rpc-subscriptions-spec': patch | ||
'@solana/rpc-spec-types': patch | ||
'@solana/rpc-spec': patch | ||
'@solana/rpc-api': patch | ||
--- | ||
|
||
Rename `RpcResponse` type to `RpcResponseData` to make room for a new `RpcResponse` type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters