Skip to content

Commit b965d83

Browse files
committed
Move RpcRequest and RpcResponse types to rpc-spec-types
1 parent ba88104 commit b965d83

29 files changed

+86
-51
lines changed

.changeset/giant-seals-mix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@solana/rpc-spec-types': patch
3+
'@solana/rpc-spec': patch
4+
---
5+
6+
Move RpcRequest and RpcResponse types to rpc-spec-types

packages/library/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"@solana/rpc-parsed-types": "workspace:*",
8787
"@solana/rpc-subscriptions": "workspace:*",
8888
"@solana/rpc-types": "workspace:*",
89+
"@solana/rpc-spec-types": "workspace:*",
8990
"@solana/signers": "workspace:*",
9091
"@solana/sysvars": "workspace:*",
9192
"@solana/transaction-confirmation": "workspace:*",

packages/library/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from '@solana/rpc';
1010
export * from '@solana/rpc-parsed-types';
1111
export * from '@solana/rpc-subscriptions';
1212
export * from '@solana/rpc-types';
13+
export * from '@solana/rpc-spec-types';
1314
export * from '@solana/signers';
1415
export * from '@solana/transaction-messages';
1516
export * from '@solana/transactions';

packages/rpc-spec-types/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,25 @@
1414

1515
# @solana/rpc-spec-types
1616

17-
TODO
17+
This package contains core types that can be used on both RPC and RPC Subscriptions specifications. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@rc`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
18+
19+
## Types
20+
21+
### `RpcRequest`
22+
23+
An object that describes the elements of an RPC or RPC Subscriptions request. It consists of the following properties:
24+
25+
- `methodName`: The name of the RPC method or subscription requested.
26+
- `params`: The parameters to be passed to the RPC server.
27+
28+
### `RpcRequestTransformer`
29+
30+
A function that accepts an `RpcRequest` and returns another `RpcRequest`. This allows the `RpcApi` to transform the request before it is sent to the RPC server.
31+
32+
### `RpcResponse`
33+
34+
A type that represents the response from an RPC server. This could be any sort of data which is why `RpcResponse` defaults to `unknown`. You may use a type parameter to specify the shape of the response — e.g. `RpcResponse<{ result: number }>`.
35+
36+
### `RpcResponseTransformer`
37+
38+
A function that accepts an `RpcResponse` and returns another `RpcResponse`. This allows the `RpcApi` to transform the response before it is returned to the caller.

packages/rpc-spec-types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './overloads';
22
export * from './rpc-message';
3+
export * from './rpc-request';
34
export * from './rpc-response';
45
export * from './type-helpers';

packages/rpc-spec/src/rpc-shared.ts renamed to packages/rpc-spec-types/src/rpc-request.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ export type RpcRequest<TParams = unknown> = {
33
readonly params: TParams;
44
};
55

6-
export type RpcResponse<TResponse = unknown> = TResponse;
7-
86
export type RpcRequestTransformer = {
97
<TParams>(request: RpcRequest<TParams>): RpcRequest;
108
};
11-
12-
export type RpcResponseTransformer<TResponse = unknown> = {
13-
(response: RpcResponse, request: RpcRequest): RpcResponse<TResponse>;
14-
};

packages/rpc-spec-types/src/rpc-response.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import type { RpcRequest } from './rpc-request';
2+
3+
export type RpcResponse<TResponse = unknown> = TResponse;
4+
5+
export type RpcResponseTransformer<TResponse = unknown> = {
6+
(response: RpcResponse, request: RpcRequest): RpcResponse<TResponse>;
7+
};
8+
19
interface IHasIdentifier {
210
readonly id: number;
311
}

packages/rpc-spec/README.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,6 @@ Calling the `send(options)` method on a `PendingRpcRequest` will trigger the req
4141

4242
An object that exposes all of the functions described by `TRpcMethods`, and fulfils them using `TRpcTransport`. Calling each method returns a `PendingRpcRequest<TResponse>` where `TResponse` is that method's response type.
4343

44-
### `RpcRequest`
45-
46-
An object that describes the elements of a JSON RPC request. It consists of the following properties:
47-
48-
- `methodName`: The name of the JSON RPC method to be called.
49-
- `params`: The parameters to be passed to the JSON RPC method.
50-
51-
### `RpcRequestTransformer`
52-
53-
A function that accepts an `RpcRequest` and returns another `RpcRequest`. This allows the `RpcApi` to transform the request before it is sent to the JSON RPC server.
54-
55-
### `RpcResponse`
56-
57-
A type that represents the response from a JSON RPC server. This could be any sort of data which is why `RpcResponse` defaults to `unknown`. You may use a type parameter to specify the shape of the response — e.g. `RpcResponse<{ result: number }>`.
58-
59-
### `RpcResponseTransformer`
60-
61-
A function that accepts an `RpcResponse` and returns another `RpcResponse`. This allows the `RpcApi` to transform the response before it is returned to the caller.
62-
6344
### `RpcApi<TRpcMethods>`
6445

6546
For each of `TRpcMethods` this object exposes a method with the same name that maps between its input arguments and a `RpcApiRequestPlan<TResponse>` that describes how to prepare a JSON RPC request to fetch `TResponse`.

packages/rpc-spec/src/__tests__/rpc-api-test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import '@solana/test-matchers/toBeFrozenObject';
22

3+
import type { RpcRequest, RpcResponse } from '@solana/rpc-spec-types';
4+
35
import { createJsonRpcApi } from '../rpc-api';
4-
import { RpcRequest, RpcResponse } from '../rpc-shared';
56

67
type DummyApi = {
78
someMethod(...args: unknown[]): unknown;

packages/rpc-spec/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './rpc';
22
export * from './rpc-api';
3-
export * from './rpc-shared';
43
export * from './rpc-transport';

0 commit comments

Comments
 (0)