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.5108520

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

142

dist/index.browser.js

@@ -1,7 +0,1 @@

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

@@ -18,2 +12,7 @@ var SolanaHttpError = class extends Error {

};
// ../fetch-impl/dist/index.browser.js
var e = globalThis.fetch;
// src/http-request.ts
async function makeHttpRequest({ payload, url }) {

@@ -27,6 +26,3 @@ const requestInfo = {

};
let response;
{
response = await src_default(url, requestInfo);
}
const response = await e(url, requestInfo);
if (!response.ok) {

@@ -41,3 +37,3 @@ throw new SolanaHttpError({

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

@@ -55,3 +51,3 @@ constructor(details) {

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

@@ -64,3 +60,3 @@ function getNextMessageId() {

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

@@ -75,51 +71,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() {

@@ -131,18 +120,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);
}

@@ -153,24 +139,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);
}

@@ -177,0 +143,0 @@

@@ -1,7 +0,1 @@

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

@@ -18,2 +12,7 @@ var SolanaHttpError = class extends Error {

};
// ../fetch-impl/dist/index.browser.js
var e = globalThis.fetch;
// src/http-request.ts
async function makeHttpRequest({ payload, url }) {

@@ -27,6 +26,3 @@ const requestInfo = {

};
let response;
{
response = await src_default(url, requestInfo);
}
const response = await e(url, requestInfo);
if (!response.ok) {

@@ -41,3 +37,3 @@ throw new SolanaHttpError({

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

@@ -55,3 +51,3 @@ constructor(details) {

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

@@ -64,3 +60,3 @@ function getNextMessageId() {

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

@@ -75,51 +71,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() {

@@ -131,18 +120,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);
}

@@ -153,24 +139,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);
}

@@ -177,0 +143,0 @@

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

import fetchImplNode from 'node-fetch';
import t from 'node-fetch';

@@ -14,2 +14,5 @@ // src/http-request-errors.ts

};
var f = t;
// src/http-request.ts
async function makeHttpRequest({ payload, url }) {

@@ -23,6 +26,3 @@ const requestInfo = {

};
let response;
{
response = await fetchImplNode(url, requestInfo);
}
const response = await f(url, requestInfo);
if (!response.ok) {

@@ -37,3 +37,3 @@ throw new SolanaHttpError({

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

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

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

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

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

@@ -71,51 +71,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() {

@@ -127,18 +120,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);
}

@@ -149,24 +139,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);
}

@@ -173,0 +143,0 @@

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

@@ -49,11 +49,10 @@ "exports": {

"devDependencies": {
"@solana/eslint-config-solana": "^0.0.4",
"@solana/eslint-config-solana": "^1.0.0",
"@swc/core": "^1.3.18",
"@swc/jest": "^0.2.23",
"@types/jest": "^29.5.0",
"@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",

@@ -65,3 +64,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",

@@ -71,7 +70,7 @@ "postcss": "^8.4.12",

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

@@ -89,5 +88,3 @@ "tsconfig": "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": "^3.3.1"
},

@@ -98,2 +95,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",

@@ -100,0 +98,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