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 0.0.0-experimental.2 to 2.0.0-experimental.021b83f

dist/types/http-request-errors.d.ts.map

134

dist/index.browser.js
import 'node-fetch';
// ../fetch-impl-browser/dist/index.browser.js
var { fetch } = globalThis;
var src_default = fetch;
// src/http-request-errors.ts

@@ -18,2 +14,6 @@ var SolanaHttpError = class extends Error {

};
// ../fetch-impl-browser/dist/index.browser.js
var { fetch } = globalThis;
var src_default = fetch;
async function makeHttpRequest({ payload, url }) {

@@ -40,3 +40,3 @@ const requestInfo = {

// src/json-rpc-errors.ts
// src/json-rpc-transport/json-rpc-errors.ts
var SolanaJsonRpcError = class extends Error {

@@ -54,3 +54,3 @@ constructor(details) {

// src/json-rpc-message-id.ts
// src/json-rpc-transport/json-rpc-message-id.ts
var _nextMessageId = 0;

@@ -63,3 +63,3 @@ function getNextMessageId() {

// src/json-rpc-message.ts
// src/json-rpc-transport/json-rpc-message.ts
function createJsonRpcMessage(method, params) {

@@ -74,51 +74,44 @@ return {

// src/params-patcher.ts
function visitNode(value, keyPath, onIntegerOverflow) {
if (Array.isArray(value)) {
return value.map(
(element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow)
);
} else if (typeof value === "object" && value !== null) {
const out = {};
for (const propName in value) {
if (Object.prototype.hasOwnProperty.call(value, propName)) {
out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow);
// src/json-rpc-transport/index.ts
function createArmedJsonRpcTransport(transportConfig, pendingRequest) {
const overrides = {
async send() {
const { methodName, params, responseProcessor } = pendingRequest;
const payload = createJsonRpcMessage(methodName, params);
const response = await makeHttpRequest({
payload,
url: transportConfig.url
});
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
return responseProcessor ? responseProcessor(response.result) : response.result;
}
}
return out;
} else if (typeof value === "bigint") {
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) {
onIntegerOverflow(keyPath, value);
}
return Number(value);
} else {
return value;
}
}
function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) {
return visitNode(params, [], onIntegerOverflow);
}
// src/json-rpc-transport.ts
function createArmedJsonRpcTransport(transportConfig, pendingMessage) {
const { url } = transportConfig;
const transport = {
async send() {
return await sendPayload(pendingMessage, url);
}
};
return makeProxy(transport, transportConfig, pendingMessage);
return makeProxy(transportConfig, overrides, pendingRequest);
}
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) {
const { url } = transportConfig;
const transport = {
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) {
const overrides = {
async sendBatch() {
return await sendPayload(pendingMessages, url);
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params));
const responses = await makeHttpRequest({
payload,
url: transportConfig.url
});
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(transport, transportConfig, pendingMessages);
return makeProxy(transportConfig, overrides, pendingRequests);
}
function makeProxy(transport, transportConfig, pendingRequestOrRequests) {
const { onIntegerOverflow } = transportConfig;
return new Proxy(transport, {
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) {
return new Proxy(transportConfig.api, {
defineProperty() {

@@ -130,18 +123,15 @@ return false;

},
get(...args) {
const [target, p] = args;
return p in target ? Reflect.get(...args) : function(...params) {
get(target, p, receiver) {
if (overrides && Reflect.has(overrides, p)) {
return Reflect.get(overrides, p, receiver);
}
return function(...rawParams) {
const methodName = p.toString();
const patchedParams = patchParamsForSolanaLabsRpc(
params,
onIntegerOverflow ? (keyPath, value) => {
onIntegerOverflow(methodName, keyPath, value);
} : void 0
);
const newMessage = createJsonRpcMessage(methodName, patchedParams);
const createTransportRequest = Reflect.get(target, methodName, receiver);
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams };
if (pendingRequestOrRequests == null) {
return createArmedJsonRpcTransport(transportConfig, newMessage);
return createArmedJsonRpcTransport(transportConfig, newRequest);
} else {
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage];
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages);
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest];
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests);
}

@@ -152,24 +142,4 @@ };

}
function processResponse(response) {
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
return response.result;
}
}
async function sendPayload(payload, url) {
const responseOrResponses = await makeHttpRequest({
payload,
url
});
if (Array.isArray(responseOrResponses)) {
const requestOrder = payload.map((p) => p.id);
return responseOrResponses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map(processResponse);
} else {
return processResponse(responseOrResponses);
}
}
function createJsonRpcTransport(transportConfig) {
const transport = {};
return makeProxy(transport, transportConfig);
return makeProxy(transportConfig);
}

@@ -176,0 +146,0 @@

import 'node-fetch';
// ../fetch-impl-browser/dist/index.browser.js
var { fetch } = globalThis;
var src_default = fetch;
// src/http-request-errors.ts

@@ -18,2 +14,6 @@ var SolanaHttpError = class extends Error {

};
// ../fetch-impl-browser/dist/index.browser.js
var { fetch } = globalThis;
var src_default = fetch;
async function makeHttpRequest({ payload, url }) {

@@ -40,3 +40,3 @@ const requestInfo = {

// src/json-rpc-errors.ts
// src/json-rpc-transport/json-rpc-errors.ts
var SolanaJsonRpcError = class extends Error {

@@ -54,3 +54,3 @@ constructor(details) {

// src/json-rpc-message-id.ts
// src/json-rpc-transport/json-rpc-message-id.ts
var _nextMessageId = 0;

@@ -63,3 +63,3 @@ function getNextMessageId() {

// src/json-rpc-message.ts
// src/json-rpc-transport/json-rpc-message.ts
function createJsonRpcMessage(method, params) {

@@ -74,51 +74,44 @@ return {

// src/params-patcher.ts
function visitNode(value, keyPath, onIntegerOverflow) {
if (Array.isArray(value)) {
return value.map(
(element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow)
);
} else if (typeof value === "object" && value !== null) {
const out = {};
for (const propName in value) {
if (Object.prototype.hasOwnProperty.call(value, propName)) {
out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow);
// src/json-rpc-transport/index.ts
function createArmedJsonRpcTransport(transportConfig, pendingRequest) {
const overrides = {
async send() {
const { methodName, params, responseProcessor } = pendingRequest;
const payload = createJsonRpcMessage(methodName, params);
const response = await makeHttpRequest({
payload,
url: transportConfig.url
});
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
return responseProcessor ? responseProcessor(response.result) : response.result;
}
}
return out;
} else if (typeof value === "bigint") {
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) {
onIntegerOverflow(keyPath, value);
}
return Number(value);
} else {
return value;
}
}
function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) {
return visitNode(params, [], onIntegerOverflow);
}
// src/json-rpc-transport.ts
function createArmedJsonRpcTransport(transportConfig, pendingMessage) {
const { url } = transportConfig;
const transport = {
async send() {
return await sendPayload(pendingMessage, url);
}
};
return makeProxy(transport, transportConfig, pendingMessage);
return makeProxy(transportConfig, overrides, pendingRequest);
}
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) {
const { url } = transportConfig;
const transport = {
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) {
const overrides = {
async sendBatch() {
return await sendPayload(pendingMessages, url);
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params));
const responses = await makeHttpRequest({
payload,
url: transportConfig.url
});
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(transport, transportConfig, pendingMessages);
return makeProxy(transportConfig, overrides, pendingRequests);
}
function makeProxy(transport, transportConfig, pendingRequestOrRequests) {
const { onIntegerOverflow } = transportConfig;
return new Proxy(transport, {
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) {
return new Proxy(transportConfig.api, {
defineProperty() {

@@ -130,18 +123,15 @@ return false;

},
get(...args) {
const [target, p] = args;
return p in target ? Reflect.get(...args) : function(...params) {
get(target, p, receiver) {
if (overrides && Reflect.has(overrides, p)) {
return Reflect.get(overrides, p, receiver);
}
return function(...rawParams) {
const methodName = p.toString();
const patchedParams = patchParamsForSolanaLabsRpc(
params,
onIntegerOverflow ? (keyPath, value) => {
onIntegerOverflow(methodName, keyPath, value);
} : void 0
);
const newMessage = createJsonRpcMessage(methodName, patchedParams);
const createTransportRequest = Reflect.get(target, methodName, receiver);
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams };
if (pendingRequestOrRequests == null) {
return createArmedJsonRpcTransport(transportConfig, newMessage);
return createArmedJsonRpcTransport(transportConfig, newRequest);
} else {
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage];
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages);
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest];
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests);
}

@@ -152,24 +142,4 @@ };

}
function processResponse(response) {
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
return response.result;
}
}
async function sendPayload(payload, url) {
const responseOrResponses = await makeHttpRequest({
payload,
url
});
if (Array.isArray(responseOrResponses)) {
const requestOrder = payload.map((p) => p.id);
return responseOrResponses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map(processResponse);
} else {
return processResponse(responseOrResponses);
}
}
function createJsonRpcTransport(transportConfig) {
const transport = {};
return makeProxy(transport, transportConfig);
return makeProxy(transportConfig);
}

@@ -176,0 +146,0 @@

@@ -35,3 +35,3 @@ import fetchImplNode from 'node-fetch';

// src/json-rpc-errors.ts
// src/json-rpc-transport/json-rpc-errors.ts
var SolanaJsonRpcError = class extends Error {

@@ -49,3 +49,3 @@ constructor(details) {

// src/json-rpc-message-id.ts
// src/json-rpc-transport/json-rpc-message-id.ts
var _nextMessageId = 0;

@@ -58,3 +58,3 @@ function getNextMessageId() {

// src/json-rpc-message.ts
// src/json-rpc-transport/json-rpc-message.ts
function createJsonRpcMessage(method, params) {

@@ -69,51 +69,44 @@ return {

// src/params-patcher.ts
function visitNode(value, keyPath, onIntegerOverflow) {
if (Array.isArray(value)) {
return value.map(
(element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow)
);
} else if (typeof value === "object" && value !== null) {
const out = {};
for (const propName in value) {
if (Object.prototype.hasOwnProperty.call(value, propName)) {
out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow);
// src/json-rpc-transport/index.ts
function createArmedJsonRpcTransport(transportConfig, pendingRequest) {
const overrides = {
async send() {
const { methodName, params, responseProcessor } = pendingRequest;
const payload = createJsonRpcMessage(methodName, params);
const response = await makeHttpRequest({
payload,
url: transportConfig.url
});
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
return responseProcessor ? responseProcessor(response.result) : response.result;
}
}
return out;
} else if (typeof value === "bigint") {
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) {
onIntegerOverflow(keyPath, value);
}
return Number(value);
} else {
return value;
}
}
function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) {
return visitNode(params, [], onIntegerOverflow);
}
// src/json-rpc-transport.ts
function createArmedJsonRpcTransport(transportConfig, pendingMessage) {
const { url } = transportConfig;
const transport = {
async send() {
return await sendPayload(pendingMessage, url);
}
};
return makeProxy(transport, transportConfig, pendingMessage);
return makeProxy(transportConfig, overrides, pendingRequest);
}
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) {
const { url } = transportConfig;
const transport = {
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) {
const overrides = {
async sendBatch() {
return await sendPayload(pendingMessages, url);
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params));
const responses = await makeHttpRequest({
payload,
url: transportConfig.url
});
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(transport, transportConfig, pendingMessages);
return makeProxy(transportConfig, overrides, pendingRequests);
}
function makeProxy(transport, transportConfig, pendingRequestOrRequests) {
const { onIntegerOverflow } = transportConfig;
return new Proxy(transport, {
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) {
return new Proxy(transportConfig.api, {
defineProperty() {

@@ -125,18 +118,15 @@ return false;

},
get(...args) {
const [target, p] = args;
return p in target ? Reflect.get(...args) : function(...params) {
get(target, p, receiver) {
if (overrides && Reflect.has(overrides, p)) {
return Reflect.get(overrides, p, receiver);
}
return function(...rawParams) {
const methodName = p.toString();
const patchedParams = patchParamsForSolanaLabsRpc(
params,
onIntegerOverflow ? (keyPath, value) => {
onIntegerOverflow(methodName, keyPath, value);
} : void 0
);
const newMessage = createJsonRpcMessage(methodName, patchedParams);
const createTransportRequest = Reflect.get(target, methodName, receiver);
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams };
if (pendingRequestOrRequests == null) {
return createArmedJsonRpcTransport(transportConfig, newMessage);
return createArmedJsonRpcTransport(transportConfig, newRequest);
} else {
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage];
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages);
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest];
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests);
}

@@ -147,24 +137,4 @@ };

}
function processResponse(response) {
if ("error" in response) {
throw new SolanaJsonRpcError(response.error);
} else {
return response.result;
}
}
async function sendPayload(payload, url) {
const responseOrResponses = await makeHttpRequest({
payload,
url
});
if (Array.isArray(responseOrResponses)) {
const requestOrder = payload.map((p) => p.id);
return responseOrResponses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map(processResponse);
} else {
return processResponse(responseOrResponses);
}
}
function createJsonRpcTransport(transportConfig) {
const transport = {};
return makeProxy(transport, transportConfig);
return makeProxy(transportConfig);
}

@@ -171,0 +141,0 @@

{
"name": "@solana/rpc-transport",
"version": "0.0.0-experimental.2",
"version": "2.0.0-experimental.021b83f",
"description": "Network transports for accessing the Solana JSON RPC API",

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

"devDependencies": {
"@solana/eslint-config-solana": "^0.0.4",
"@solana/eslint-config-solana": "^1.0.0",
"@swc/core": "^1.3.18",

@@ -55,6 +55,6 @@ "@swc/jest": "^0.2.23",

"@types/node-fetch": "2",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"agadoo": "^2.0.0",
"eslint": "^8.27.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"agadoo": "^3.0.0",
"eslint": "^8.37.0",
"eslint-plugin-jest": "^27.1.5",

@@ -66,3 +66,3 @@ "eslint-plugin-react-hooks": "^4.6.0",

"jest-fetch-mock": "^3.0.3",
"jest-runner-eslint": "^1.1.0",
"jest-runner-eslint": "^2.0.0",
"jest-runner-prettier": "^1.0.0",

@@ -72,6 +72,6 @@ "postcss": "^8.4.12",

"ts-node": "^10.9.1",
"tsup": "6.5.0",
"tsup": "6.7.0",
"turbo": "^1.6.3",
"typescript": "^4.9",
"@solana/fetch-impl-browser": "0.0.0-development",
"typescript": "^5.0.3",
"version-from-git": "^1.1.1",
"build-scripts": "0.0.0",

@@ -90,5 +90,5 @@ "test-config": "0.0.0",

"dependencies": {
"@solana/keys": "^0.0.0-experimental.1",
"@solana/rpc-core": "^0.0.0-experimental.2",
"node-fetch": "^2.6.7"
"node-fetch": "^2.6.7",
"@solana/keys": "2.0.0-experimental.021b83f",
"fetch-impl-browser": "0.0.0"
},

@@ -99,2 +99,3 @@ "scripts": {

"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",

@@ -101,0 +102,0 @@ "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",

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