@solana/rpc-spec
Advanced tools
Comparing version
import { Callable, RpcRequestTransformer, RpcResponse, RpcResponseTransformer } from '@solana/rpc-spec-types'; | ||
import type { RpcTransport } from './rpc-transport'; | ||
export type RpcApiConfig = Readonly<{ | ||
@@ -7,4 +8,6 @@ requestTransformer?: RpcRequestTransformer; | ||
export type RpcPlan<TResponse> = { | ||
payload: unknown; | ||
responseTransformer?: (response: RpcResponse) => RpcResponse<TResponse>; | ||
execute: (config: Readonly<{ | ||
signal?: AbortSignal; | ||
transport: RpcTransport; | ||
}>) => Promise<RpcResponse<TResponse>>; | ||
}; | ||
@@ -11,0 +14,0 @@ export type RpcApi<TRpcMethods> = { |
{ | ||
"name": "@solana/rpc-spec", | ||
"version": "2.0.0-canary-20241023215849", | ||
"version": "2.0.0-canary-20241023220505", | ||
"description": "A generic implementation of JSON RPCs using proxies", | ||
@@ -57,4 +57,4 @@ "exports": { | ||
"dependencies": { | ||
"@solana/errors": "2.0.0-canary-20241023215849", | ||
"@solana/rpc-spec-types": "2.0.0-canary-20241023215849" | ||
"@solana/errors": "2.0.0-canary-20241023220505", | ||
"@solana/rpc-spec-types": "2.0.0-canary-20241023220505" | ||
}, | ||
@@ -61,0 +61,0 @@ "peerDependencies": { |
@@ -54,7 +54,10 @@ [![npm][npm-image]][npm-url] | ||
This type allows an `RpcApi` to describe 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: | ||
This type allows an `RpcApi` to describe how a particular request should be issued to the JSON RPC server. Given a function that was called on a `Rpc`, this object returns an `execute` function that dictates which request will be sent, how the underlying transport will be used and how the responses will be transformed. | ||
- provide a `payload` from the requested method name and parameters. | ||
- provide a function to transform the JSON RPC server's response, in case it does not match the `TResponse` specified by the `PendingRpcRequest<TResponse>` returned from that function. | ||
This function accepts an `RpcTransport` and an `AbortSignal` and asynchronously returns an `RpcResponse`. This gives us the opportunity to: | ||
- define the `payload` from the requested method name and parameters before passing it to the transport. | ||
- call the underlying transport zero, one or multiple times depending on the use-case (e.g. caching or aggregating multiple responses). | ||
- transform the response from the JSON RPC server, in case it does not match the `TResponse` specified by the `PendingRpcRequest<TResponse>` returned from that function. | ||
### `RpcSendOptions` | ||
@@ -88,6 +91,6 @@ | ||
Creates a JavaScript proxy that converts _any_ function call called on it to a `RpcPlan` by: | ||
Creates a JavaScript proxy that converts _any_ function call called on it to a `RpcPlan` by creating an `execute` function that: | ||
- setting `payload` to a JSON RPC v2 payload object with the requested `methodName` and `params` properties, optionally transformed by `config.requestTransformer`. | ||
- setting `responseTransformer` to `config.responseTransformer`, if provided. | ||
- sets the transport payload to a JSON RPC v2 payload object with the requested `methodName` and `params` properties, optionally transformed by `config.requestTransformer`. | ||
- transforms the transport's response using the `config.responseTransformer` function, if provided. | ||
@@ -104,8 +107,5 @@ ```ts | ||
// ...will produce the following `RpcPlan` object: | ||
// | ||
// { | ||
// payload: { id: 1, jsonrpc: '2.0', method: 'foo', params: ['bar', { baz: 'bat' }] }, | ||
// responseTransformer: (response) => response.result, | ||
// } | ||
// ...will produce an `RpcPlan` that: | ||
// - Uses the following payload: { id: 1, jsonrpc: '2.0', method: 'foo', params: ['bar', { baz: 'bat' }] }. | ||
// - Returns the "result" attribute of the RPC response. | ||
``` | ||
@@ -112,0 +112,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
72659
-1.35%437
-0.46%+ Added
+ Added
- Removed
- Removed