Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana/rpc-transport

Package Overview
Dependencies
Maintainers
13
Versions
602
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/rpc-transport - npm Package Compare versions

Comparing version 2.0.0-experimental.982fafd to 2.0.0-experimental.a1e77c4

dist/types/index.d.ts.map

38

dist/index.browser.js

@@ -36,4 +36,4 @@ // ../build-scripts/env-shim.ts

// src/json-rpc.ts
function createArmedJsonRpc(rpcConfig, pendingRequest) {
const overrides = {
function createPendingRpcRequest(rpcConfig, pendingRequest) {
return {
async send(options) {

@@ -53,26 +53,4 @@ const { methodName, params, responseProcessor } = pendingRequest;

};
return makeProxy(rpcConfig, overrides, pendingRequest);
}
function createArmedBatchJsonRpc(rpcConfig, pendingRequests) {
const overrides = {
async sendBatch(options) {
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params));
const responses = await rpcConfig.transport({
payload,
signal: options?.abortSignal
});
const requestOrder = payload.map((p) => p.id);
return responses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => {
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
const { responseProcessor } = pendingRequests[ii];
return responseProcessor ? responseProcessor(response.result) : response.result;
}
});
}
};
return makeProxy(rpcConfig, overrides, pendingRequests);
}
function makeProxy(rpcConfig, overrides, pendingRequestOrRequests) {
function makeProxy(rpcConfig) {
return new Proxy(rpcConfig.api, {

@@ -86,5 +64,2 @@ defineProperty() {

get(target, p, receiver) {
if (overrides && Reflect.has(overrides, p)) {
return Reflect.get(overrides, p, receiver);
}
return function(...rawParams) {

@@ -94,8 +69,3 @@ const methodName = p.toString();

const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams };
if (pendingRequestOrRequests == null) {
return createArmedJsonRpc(rpcConfig, newRequest);
} else {
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest];
return createArmedBatchJsonRpc(rpcConfig, nextPendingRequests);
}
return createPendingRpcRequest(rpcConfig, newRequest);
};

@@ -102,0 +72,0 @@ }

@@ -36,4 +36,4 @@ // ../build-scripts/env-shim.ts

// src/json-rpc.ts
function createArmedJsonRpc(rpcConfig, pendingRequest) {
const overrides = {
function createPendingRpcRequest(rpcConfig, pendingRequest) {
return {
async send(options) {

@@ -53,26 +53,4 @@ const { methodName, params, responseProcessor } = pendingRequest;

};
return makeProxy(rpcConfig, overrides, pendingRequest);
}
function createArmedBatchJsonRpc(rpcConfig, pendingRequests) {
const overrides = {
async sendBatch(options) {
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params));
const responses = await rpcConfig.transport({
payload,
signal: options?.abortSignal
});
const requestOrder = payload.map((p) => p.id);
return responses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => {
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
const { responseProcessor } = pendingRequests[ii];
return responseProcessor ? responseProcessor(response.result) : response.result;
}
});
}
};
return makeProxy(rpcConfig, overrides, pendingRequests);
}
function makeProxy(rpcConfig, overrides, pendingRequestOrRequests) {
function makeProxy(rpcConfig) {
return new Proxy(rpcConfig.api, {

@@ -86,5 +64,2 @@ defineProperty() {

get(target, p, receiver) {
if (overrides && Reflect.has(overrides, p)) {
return Reflect.get(overrides, p, receiver);
}
return function(...rawParams) {

@@ -94,8 +69,3 @@ const methodName = p.toString();

const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams };
if (pendingRequestOrRequests == null) {
return createArmedJsonRpc(rpcConfig, newRequest);
} else {
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest];
return createArmedBatchJsonRpc(rpcConfig, nextPendingRequests);
}
return createPendingRpcRequest(rpcConfig, newRequest);
};

@@ -102,0 +72,0 @@ }

@@ -38,4 +38,4 @@ import t from 'node-fetch';

// src/json-rpc.ts
function createArmedJsonRpc(rpcConfig, pendingRequest) {
const overrides = {
function createPendingRpcRequest(rpcConfig, pendingRequest) {
return {
async send(options) {

@@ -55,26 +55,4 @@ const { methodName, params, responseProcessor } = pendingRequest;

};
return makeProxy(rpcConfig, overrides, pendingRequest);
}
function createArmedBatchJsonRpc(rpcConfig, pendingRequests) {
const overrides = {
async sendBatch(options) {
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params));
const responses = await rpcConfig.transport({
payload,
signal: options?.abortSignal
});
const requestOrder = payload.map((p) => p.id);
return responses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => {
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
const { responseProcessor } = pendingRequests[ii];
return responseProcessor ? responseProcessor(response.result) : response.result;
}
});
}
};
return makeProxy(rpcConfig, overrides, pendingRequests);
}
function makeProxy(rpcConfig, overrides, pendingRequestOrRequests) {
function makeProxy(rpcConfig) {
return new Proxy(rpcConfig.api, {

@@ -88,5 +66,2 @@ defineProperty() {

get(target, p, receiver) {
if (overrides && Reflect.has(overrides, p)) {
return Reflect.get(overrides, p, receiver);
}
return function(...rawParams) {

@@ -96,8 +71,3 @@ const methodName = p.toString();

const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams };
if (pendingRequestOrRequests == null) {
return createArmedJsonRpc(rpcConfig, newRequest);
} else {
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest];
return createArmedBatchJsonRpc(rpcConfig, nextPendingRequests);
}
return createPendingRpcRequest(rpcConfig, newRequest);
};

@@ -104,0 +74,0 @@ }

import { IRpcTransport } from './transports/transport-types';
/**
* Public API.
* Public RPC API.
*/

@@ -8,5 +8,2 @@ export type IRpcApi<TRpcMethods> = {

};
export type SendOptions = Readonly<{
abortSignal?: AbortSignal;
}>;
export type Rpc<TRpcMethods> = RpcMethods<TRpcMethods>;

@@ -17,2 +14,5 @@ export type RpcConfig<TRpcMethods> = Readonly<{

}>;
/**
* Public pending RPC request API.
*/
export type RpcRequest<TResponse> = {

@@ -23,10 +23,8 @@ methodName: string;

};
export interface ArmedRpcOwnMethods<TResponse> {
export type PendingRpcRequest<TResponse> = {
send(options?: SendOptions): Promise<TResponse>;
}
export type ArmedRpc<TRpcMethods, TResponse> = ArmedRpcMethods<TRpcMethods, TResponse> & ArmedRpcOwnMethods<TResponse>;
export interface ArmedBatchRpcOwnMethods<TResponses> {
sendBatch(options?: SendOptions): Promise<TResponses>;
}
export type ArmedBatchRpc<TRpcMethods, TResponses extends unknown[]> = ArmedBatchRpcMethods<TRpcMethods, TResponses> & ArmedBatchRpcOwnMethods<TResponses>;
};
export type SendOptions = Readonly<{
abortSignal?: AbortSignal;
}>;
/**

@@ -36,15 +34,8 @@ * Private RPC-building types.

type RpcMethods<TRpcMethods> = {
[TMethodName in keyof TRpcMethods]: ArmedRpcReturner<TRpcMethods, ApiMethodImplementations<TRpcMethods, TMethodName>>;
[TMethodName in keyof TRpcMethods]: PendingRpcRequestBuilder<ApiMethodImplementations<TRpcMethods, TMethodName>>;
};
type ArmedRpcMethods<TRpcMethods, TResponse> = ArmedBatchRpcMethods<TRpcMethods, [TResponse]>;
type ArmedBatchRpcMethods<TRpcMethods, TResponses extends unknown[]> = {
[TMethodName in keyof TRpcMethods]: ArmedBatchRpcReturner<TRpcMethods, ApiMethodImplementations<TRpcMethods, TMethodName>, TResponses>;
};
type ApiMethodImplementations<TRpcMethods, TMethod extends keyof TRpcMethods> = Overloads<TRpcMethods[TMethod]>;
type ArmedRpcReturner<TRpcMethods, TMethodImplementations> = UnionToIntersection<Flatten<{
[P in keyof TMethodImplementations]: TMethodImplementations[P] extends Callable ? (...args: Parameters<TMethodImplementations[P]>) => ArmedRpc<TRpcMethods, ReturnType<TMethodImplementations[P]>> : never;
type PendingRpcRequestBuilder<TMethodImplementations> = UnionToIntersection<Flatten<{
[P in keyof TMethodImplementations]: TMethodImplementations[P] extends Callable ? (...args: Parameters<TMethodImplementations[P]>) => PendingRpcRequest<ReturnType<TMethodImplementations[P]>> : never;
}>>;
type ArmedBatchRpcReturner<TRpcMethods, TMethodImplementations, TResponses extends unknown[]> = UnionToIntersection<Flatten<{
[P in keyof TMethodImplementations]: TMethodImplementations[P] extends Callable ? (...args: Parameters<TMethodImplementations[P]>) => ArmedBatchRpc<TRpcMethods, [...TResponses, ReturnType<TMethodImplementations[P]>]> : never;
}>>;
/**

@@ -51,0 +42,0 @@ * Utility types that do terrible, awful things.

{
"name": "@solana/rpc-transport",
"version": "2.0.0-experimental.982fafd",
"version": "2.0.0-experimental.a1e77c4",
"description": "Network transports for accessing the Solana JSON RPC API",

@@ -53,2 +53,3 @@ "exports": {

"@types/jest": "^29.5.0",
"@types/node": "^16",
"@typescript-eslint/eslint-plugin": "^5.57.1",

@@ -85,5 +86,2 @@ "@typescript-eslint/parser": "^5.57.1",

},
"dependencies": {
"node-fetch": "^3.3.1"
},
"scripts": {

@@ -90,0 +88,0 @@ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",

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