Socket
Socket
Sign inDemoInstall

@solana/rpc-spec

Package Overview
Dependencies
Maintainers
0
Versions
723
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/rpc-spec - npm Package Compare versions

Comparing version 2.0.0-canary-20240901181915 to 2.0.0-canary-20240901182608

dist/types/rpc-shared.d.ts

1

dist/types/index.d.ts
export * from './rpc';
export * from './rpc-api';
export * from './rpc-request';
export * from './rpc-shared';
export * from './rpc-transport';
//# sourceMappingURL=index.d.ts.map

4

dist/types/rpc-api.d.ts
import { Callable } from '@solana/rpc-spec-types';
import { RpcRequest } from './rpc-request';
import { RpcApiRequestPlan } from './rpc-request';
export type RpcApiConfig = Readonly<{

@@ -10,3 +10,3 @@ parametersTransformer?: <T extends unknown[]>(params: T, methodName: string) => unknown;

};
type RpcReturnTypeMapper<TRpcMethod> = TRpcMethod extends Callable ? (...rawParams: unknown[]) => RpcRequest<ReturnType<TRpcMethod>> : never;
type RpcReturnTypeMapper<TRpcMethod> = TRpcMethod extends Callable ? (...rawParams: unknown[]) => RpcApiRequestPlan<ReturnType<TRpcMethod>> : never;
type RpcApiMethod = (...args: any) => any;

@@ -13,0 +13,0 @@ export interface RpcApiMethods {

@@ -1,2 +0,2 @@

export type RpcRequest<TResponse> = {
export type RpcApiRequestPlan<TResponse> = {
methodName: string;

@@ -3,0 +3,0 @@ params: unknown;

{
"name": "@solana/rpc-spec",
"version": "2.0.0-canary-20240901181915",
"version": "2.0.0-canary-20240901182608",
"description": "A generic implementation of JSON RPCs using proxies",

@@ -57,3 +57,3 @@ "exports": {

"dependencies": {
"@solana/rpc-spec-types": "2.0.0-canary-20240901181915"
"@solana/rpc-spec-types": "2.0.0-canary-20240901182608"
},

@@ -60,0 +60,0 @@ "peerDependencies": {

@@ -44,5 +44,31 @@ [![npm][npm-image]][npm-url]

### `RpcRequest`
An object that describes the elements of a JSON RPC request. It consists of the following properties:
- `methodName`: The name of the JSON RPC method to be called.
- `params`: The parameters to be passed to the JSON RPC method.
### `RpcRequestTransformer`
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.
### `RpcResponse`
An object that represents the response from a JSON RPC server. It contains two asynchronous methods that can be used to access the response data:
- `await response.json()`: Returns the data as a JSON object.
- `await response.text()`: Returns the data, unparsed, as a JSON string.
This allows the `RpcApi` to decide whether they want the parsed JSON object or the raw JSON string. Ultimately, the `json` method will be used by the `Rpc` to provide the final response to the caller.
### `RpcResponseTransformer`
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.
Note that a `RpcResponseTransformerFor<T>` generic function type is also available to ensure the response data returned by the transformer matches the expected type `T`.
### `RpcApi<TRpcMethods>`
For each of `TRpcMethods` this object exposes a method with the same name that maps between its input arguments and a `RpcRequest<TResponse>` 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<TResponse>` that describes how to prepare a JSON RPC request to fetch `TResponse`.

@@ -53,5 +79,5 @@ ### `RpcApiMethods`

### `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:
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:

@@ -90,3 +116,3 @@ - customize the JSON RPC method name in the case that it's different than the name of that function

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:

@@ -107,3 +133,3 @@ - setting `methodName` to the name of the function called

// ...will produce the following `RpcRequest` object:
// ...will produce the following `RpcApiRequestPlan` object:
//

@@ -123,1 +149,15 @@ // {

- `responseTransformer<T>(response, methodName): T`: An optional function that maps between the shape of the JSON RPC server response for a given method and the shape of the response expected by the `RpcApi`.
### `createJsonRpcResponseTransformer<T>(jsonTransformer)`
Creates an `RpcResponseTransformerFor<T>` function from a function that transforms any JSON value to a value of type `T` by wrapping it in a `json` async function.
```ts
const getResultTransformer = createJsonRpcResponseTransformer((json: unknown) => {
return (json as { result: TResponse }).result;
});
```
#### Arguments
- `jsonTransformer: (json: unknown, request: RpcRequest) => T`: A function that transforms an unknown JSON value to a value of type `T`.

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc