-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
RpcResponse
provide the resopnse payload directly (#3185)
This PR reverts some of the changes in the previous stack by making the following key change: ```ts // Before. type RpcResponse<TResponse = unknown> = { readonly json: () => Promise<TResponse>; readonly text: () => Promise<string>; }; // After. type RpcResponse<TResponse = unknown> = TResponse; ``` This is because we no longer believe that it is the responsibility of the RPC API to affect the response as text or JSON. This aspect should be encapsulated by the RPC Transport layer, meaning any custom JSON parsing/stringifying will need to be done at the RPC Transport layer. Note that, we could simply delete the `RpcResponse` type since it returns its type parameter directly but keeping it makes the code clearer as we will use `RpcResponse` instead of `unknown` everywhere in the codebase.
- Loading branch information
1 parent
28ca5d1
commit e1dfb2c
Showing
14 changed files
with
41 additions
and
184 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
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { createJsonRpcResponseTransformer } from '@solana/rpc-spec'; | ||
import { RpcResponseTransformer } from '@solana/rpc-spec'; | ||
|
||
type JsonRpcResponse = { result: unknown }; | ||
|
||
export function getResultResponseTransformer() { | ||
return createJsonRpcResponseTransformer(json => (json as JsonRpcResponse).result); | ||
export function getResultResponseTransformer(): RpcResponseTransformer { | ||
return json => (json as JsonRpcResponse).result; | ||
} |
8 changes: 4 additions & 4 deletions
8
packages/rpc-transformers/src/response-transformer-throw-solana-error.ts
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { getSolanaErrorFromJsonRpcError } from '@solana/errors'; | ||
import { createJsonRpcResponseTransformer } from '@solana/rpc-spec'; | ||
import { RpcResponseTransformer } from '@solana/rpc-spec'; | ||
|
||
type JsonRpcResponse = { error: Parameters<typeof getSolanaErrorFromJsonRpcError>[0] } | { result: unknown }; | ||
|
||
export function getThrowSolanaErrorResponseTransformer() { | ||
return createJsonRpcResponseTransformer(json => { | ||
export function getThrowSolanaErrorResponseTransformer(): RpcResponseTransformer { | ||
return json => { | ||
const jsonRpcResponse = json as JsonRpcResponse; | ||
if ('error' in jsonRpcResponse) { | ||
throw getSolanaErrorFromJsonRpcError(jsonRpcResponse.error); | ||
} | ||
return jsonRpcResponse; | ||
}); | ||
}; | ||
} |
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
Oops, something went wrong.