From ac5e7f8e1eeef06378498e12dc2195106baaa233 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Fri, 23 Aug 2024 11:37:02 +0100 Subject: [PATCH] Rename `RpcRequest` to `PendingRpcApiRequest` --- .changeset/fair-brooms-build.md | 5 +++++ packages/rpc-spec/README.md | 8 ++++---- packages/rpc-spec/src/__tests__/rpc-test.ts | 6 +++--- packages/rpc-spec/src/rpc-api.ts | 6 +++--- packages/rpc-spec/src/rpc-request.ts | 2 +- packages/rpc-spec/src/rpc.ts | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 .changeset/fair-brooms-build.md diff --git a/.changeset/fair-brooms-build.md b/.changeset/fair-brooms-build.md new file mode 100644 index 000000000000..234d377194ad --- /dev/null +++ b/.changeset/fair-brooms-build.md @@ -0,0 +1,5 @@ +--- +'@solana/rpc-spec': patch +--- + +Rename `RpcRequest` type to `RpcApiRequestPlan` to make room for new `RpcRequest` type diff --git a/packages/rpc-spec/README.md b/packages/rpc-spec/README.md index 3773ed9f6c1b..9599aad5309e 100644 --- a/packages/rpc-spec/README.md +++ b/packages/rpc-spec/README.md @@ -43,13 +43,13 @@ An object that exposes all of the functions described by `TRpcMethods`, and fulf ### `RpcApi` -For each of `TRpcMethods` this object exposes a method with the same name that maps between its input arguments and a `RpcRequest` that describes how to prepare a JSON RPC request to fetch `TResponse`. +For each of `TRpcMethods` this object exposes a method with the same name that maps between its input arguments and a `RpcApiRequestPlan` that describes how to prepare a JSON RPC request to fetch `TResponse`. ### `RpcApiMethods` This is a marker interface that all RPC method definitions must extend to be accepted for use with the `RpcApi` creator. -### `RpcRequest` +### `RpcApiRequestPlan` This type describes how a particular request should be issued to the JSON RPC server. Given a function that was called on a `Rpc`, this object gives you the opportunity to: @@ -85,7 +85,7 @@ A config object with the following properties: ### `createRpcApi(config)` -Creates a JavaScript proxy that converts _any_ function call called on it to a `RpcRequest` by: +Creates a JavaScript proxy that converts _any_ function call called on it to a `RpcApiRequestPlan` by: - setting `methodName` to the name of the function called - setting `params` to the arguments supplied to that function, optionally transformed by `config.parametersTransformer` @@ -101,7 +101,7 @@ const rpcApi = createRpcApi({ // ...the following function call: rpcApi.foo('bar', { baz: 'bat' }); -// ...will produce the following `RpcRequest` object: +// ...will produce the following `RpcApiRequestPlan` object: // // { // methodName: 'foo', diff --git a/packages/rpc-spec/src/__tests__/rpc-test.ts b/packages/rpc-spec/src/__tests__/rpc-test.ts index c37b09e5be52..4724285598cc 100644 --- a/packages/rpc-spec/src/__tests__/rpc-test.ts +++ b/packages/rpc-spec/src/__tests__/rpc-test.ts @@ -2,7 +2,7 @@ import { createRpcMessage } from '@solana/rpc-spec-types'; import { createRpc, Rpc } from '../rpc'; import { RpcApi } from '../rpc-api'; -import { RpcRequest } from '../rpc-request'; +import { RpcApiRequestPlan } from '../rpc-request'; import { RpcTransport } from '../rpc-transport'; interface TestRpcMethods { @@ -50,7 +50,7 @@ describe('JSON-RPC 2.0', () => { beforeEach(() => { rpc = createRpc({ api: { - someMethod(...params: unknown[]): RpcRequest { + someMethod(...params: unknown[]): RpcApiRequestPlan { return { methodName: 'someMethodAugmented', params: [...params, 'augmented', 'params'], @@ -77,7 +77,7 @@ describe('JSON-RPC 2.0', () => { responseTransformer = jest.fn(response => `${response} processed response`); rpc = createRpc({ api: { - someMethod(...params: unknown[]): RpcRequest { + someMethod(...params: unknown[]): RpcApiRequestPlan { return { methodName: 'someMethod', params, diff --git a/packages/rpc-spec/src/rpc-api.ts b/packages/rpc-spec/src/rpc-api.ts index f0ed256a00cb..5972bcfc2be6 100644 --- a/packages/rpc-spec/src/rpc-api.ts +++ b/packages/rpc-spec/src/rpc-api.ts @@ -1,6 +1,6 @@ import { Callable } from '@solana/rpc-spec-types'; -import { RpcRequest } from './rpc-request'; +import { RpcApiRequestPlan } from './rpc-request'; export type RpcApiConfig = Readonly<{ parametersTransformer?: (params: T, methodName: string) => unknown; @@ -12,7 +12,7 @@ export type RpcApi = { }; type RpcReturnTypeMapper = TRpcMethod extends Callable - ? (...rawParams: unknown[]) => RpcRequest> + ? (...rawParams: unknown[]) => RpcApiRequestPlan> : never; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -38,7 +38,7 @@ export function createRpcApi(config?: RpcApiC ...rawParams: Parameters< TRpcMethods[TMethodName] extends CallableFunction ? TRpcMethods[TMethodName] : never > - ): RpcRequest> { + ): RpcApiRequestPlan> { const params = config?.parametersTransformer ? config?.parametersTransformer(rawParams, methodName) : rawParams; diff --git a/packages/rpc-spec/src/rpc-request.ts b/packages/rpc-spec/src/rpc-request.ts index d3ade2828d5d..412795fa24b7 100644 --- a/packages/rpc-spec/src/rpc-request.ts +++ b/packages/rpc-spec/src/rpc-request.ts @@ -1,4 +1,4 @@ -export type RpcRequest = { +export type RpcApiRequestPlan = { methodName: string; params: unknown; responseTransformer?: (response: unknown, methodName: string) => TResponse; diff --git a/packages/rpc-spec/src/rpc.ts b/packages/rpc-spec/src/rpc.ts index c94667009b1b..b428b08bc49e 100644 --- a/packages/rpc-spec/src/rpc.ts +++ b/packages/rpc-spec/src/rpc.ts @@ -8,7 +8,7 @@ import { } from '@solana/rpc-spec-types'; import { RpcApi } from './rpc-api'; -import { PendingRpcRequest, RpcRequest, RpcSendOptions } from './rpc-request'; +import { PendingRpcRequest, RpcApiRequestPlan, RpcSendOptions } from './rpc-request'; import { RpcTransport } from './rpc-transport'; export type RpcConfig = Readonly<{ @@ -63,7 +63,7 @@ function makeProxy( function createPendingRpcRequest( rpcConfig: RpcConfig, - pendingRequest: RpcRequest, + pendingRequest: RpcApiRequestPlan, ): PendingRpcRequest { return { async send(options?: RpcSendOptions): Promise {