@solana/rpc-transport
Advanced tools
Comparing version 2.0.0-experimental.50ab13b to 2.0.0-experimental.527bafd
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/http-request-errors.ts | ||
// src/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
constructor(details) { | ||
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.code = details.code; | ||
this.data = details.data; | ||
} | ||
get name() { | ||
return "SolanaJsonRpcError"; | ||
} | ||
}; | ||
// src/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
function getNextMessageId() { | ||
const id = _nextMessageId; | ||
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; | ||
return id; | ||
} | ||
// src/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
return { | ||
id: getNextMessageId(), | ||
jsonrpc: "2.0", | ||
method, | ||
params | ||
}; | ||
} | ||
// src/json-rpc.ts | ||
function createPendingRpcRequest(rpcConfig, pendingRequest) { | ||
return { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await rpcConfig.transport({ | ||
payload, | ||
signal: options?.abortSignal | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
}; | ||
} | ||
function makeProxy(rpcConfig) { | ||
return new Proxy(rpcConfig.api, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(target, p, receiver) { | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const createRpcRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams }; | ||
return createPendingRpcRequest(rpcConfig, newRequest); | ||
}; | ||
} | ||
}); | ||
} | ||
function createJsonRpc(rpcConfig) { | ||
return makeProxy(rpcConfig); | ||
} | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/transports/http/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
@@ -16,3 +90,3 @@ constructor(details) { | ||
// src/http-request-headers.ts | ||
// src/transports/http/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -67,140 +141,45 @@ accept: true, | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/http-request.ts | ||
async function makeHttpRequest({ headers, payload, signal, url }) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
body, | ||
headers: { | ||
...headers && normalizeHeaders(headers), | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST", | ||
signal | ||
}; | ||
const response = await e(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
// src/transports/http/http-transport.ts | ||
function createHttpTransport({ httpAgentNodeOnly, headers, url }) { | ||
if (__DEV__ && headers) { | ||
assertIsAllowedHttpRequestHeaders(headers); | ||
} | ||
return await response.json(); | ||
} | ||
// src/json-rpc-transport/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
constructor(details) { | ||
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.code = details.code; | ||
this.data = details.data; | ||
const agent = void 0; | ||
if (__DEV__ && httpAgentNodeOnly != null) { | ||
console.warn( | ||
"createHttpTransport(): The `httpAgentNodeOnly` config you supplied has been ignored; HTTP agents are only usable in Node environments." | ||
); | ||
} | ||
get name() { | ||
return "SolanaJsonRpcError"; | ||
} | ||
}; | ||
// src/json-rpc-transport/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
function getNextMessageId() { | ||
const id = _nextMessageId; | ||
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; | ||
return id; | ||
} | ||
// src/json-rpc-transport/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
return { | ||
id: getNextMessageId(), | ||
jsonrpc: "2.0", | ||
method, | ||
params | ||
}; | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingRequest) { | ||
const overrides = { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
const customHeaders = headers && normalizeHeaders(headers); | ||
return async function makeHttpRequest({ | ||
payload, | ||
signal | ||
}) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
agent, | ||
body, | ||
headers: { | ||
...customHeaders, | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST", | ||
signal | ||
}; | ||
const response = await e(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
return await response.json(); | ||
}; | ||
return makeProxy(transportConfig, overrides, pendingRequest); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) { | ||
const overrides = { | ||
async sendBatch(options) { | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
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(transportConfig, overrides, pendingRequests); | ||
} | ||
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) { | ||
return new Proxy(transportConfig.api, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(target, p, receiver) { | ||
if (overrides && Reflect.has(overrides, p)) { | ||
return Reflect.get(overrides, p, receiver); | ||
} | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const createTransportRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams }; | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newRequest); | ||
} else { | ||
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests); | ||
} | ||
}; | ||
} | ||
}); | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
if (__DEV__ && transportConfig.headers) { | ||
assertIsAllowedHttpRequestHeaders(transportConfig.headers); | ||
} | ||
return makeProxy(transportConfig); | ||
} | ||
export { createJsonRpcTransport }; | ||
export { createHttpTransport, createJsonRpc }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/http-request-errors.ts | ||
// src/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
constructor(details) { | ||
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.code = details.code; | ||
this.data = details.data; | ||
} | ||
get name() { | ||
return "SolanaJsonRpcError"; | ||
} | ||
}; | ||
// src/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
function getNextMessageId() { | ||
const id = _nextMessageId; | ||
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; | ||
return id; | ||
} | ||
// src/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
return { | ||
id: getNextMessageId(), | ||
jsonrpc: "2.0", | ||
method, | ||
params | ||
}; | ||
} | ||
// src/json-rpc.ts | ||
function createPendingRpcRequest(rpcConfig, pendingRequest) { | ||
return { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await rpcConfig.transport({ | ||
payload, | ||
signal: options?.abortSignal | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
}; | ||
} | ||
function makeProxy(rpcConfig) { | ||
return new Proxy(rpcConfig.api, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(target, p, receiver) { | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const createRpcRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams }; | ||
return createPendingRpcRequest(rpcConfig, newRequest); | ||
}; | ||
} | ||
}); | ||
} | ||
function createJsonRpc(rpcConfig) { | ||
return makeProxy(rpcConfig); | ||
} | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/transports/http/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
@@ -16,3 +90,3 @@ constructor(details) { | ||
// src/http-request-headers.ts | ||
// src/transports/http/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -67,140 +141,45 @@ accept: true, | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/http-request.ts | ||
async function makeHttpRequest({ headers, payload, signal, url }) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
body, | ||
headers: { | ||
...headers && normalizeHeaders(headers), | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST", | ||
signal | ||
}; | ||
const response = await e(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
// src/transports/http/http-transport.ts | ||
function createHttpTransport({ httpAgentNodeOnly, headers, url }) { | ||
if (__DEV__ && headers) { | ||
assertIsAllowedHttpRequestHeaders(headers); | ||
} | ||
return await response.json(); | ||
} | ||
// src/json-rpc-transport/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
constructor(details) { | ||
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.code = details.code; | ||
this.data = details.data; | ||
const agent = void 0; | ||
if (__DEV__ && httpAgentNodeOnly != null) { | ||
console.warn( | ||
"createHttpTransport(): The `httpAgentNodeOnly` config you supplied has been ignored; HTTP agents are only usable in Node environments." | ||
); | ||
} | ||
get name() { | ||
return "SolanaJsonRpcError"; | ||
} | ||
}; | ||
// src/json-rpc-transport/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
function getNextMessageId() { | ||
const id = _nextMessageId; | ||
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; | ||
return id; | ||
} | ||
// src/json-rpc-transport/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
return { | ||
id: getNextMessageId(), | ||
jsonrpc: "2.0", | ||
method, | ||
params | ||
}; | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingRequest) { | ||
const overrides = { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
const customHeaders = headers && normalizeHeaders(headers); | ||
return async function makeHttpRequest({ | ||
payload, | ||
signal | ||
}) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
agent, | ||
body, | ||
headers: { | ||
...customHeaders, | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST", | ||
signal | ||
}; | ||
const response = await e(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
return await response.json(); | ||
}; | ||
return makeProxy(transportConfig, overrides, pendingRequest); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) { | ||
const overrides = { | ||
async sendBatch(options) { | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
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(transportConfig, overrides, pendingRequests); | ||
} | ||
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) { | ||
return new Proxy(transportConfig.api, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(target, p, receiver) { | ||
if (overrides && Reflect.has(overrides, p)) { | ||
return Reflect.get(overrides, p, receiver); | ||
} | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const createTransportRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams }; | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newRequest); | ||
} else { | ||
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests); | ||
} | ||
}; | ||
} | ||
}); | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
if (__DEV__ && transportConfig.headers) { | ||
assertIsAllowedHttpRequestHeaders(transportConfig.headers); | ||
} | ||
return makeProxy(transportConfig); | ||
} | ||
export { createJsonRpcTransport }; | ||
export { createHttpTransport, createJsonRpc }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -6,3 +6,75 @@ import t from 'node-fetch'; | ||
// src/http-request-errors.ts | ||
// src/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
constructor(details) { | ||
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.code = details.code; | ||
this.data = details.data; | ||
} | ||
get name() { | ||
return "SolanaJsonRpcError"; | ||
} | ||
}; | ||
// src/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
function getNextMessageId() { | ||
const id = _nextMessageId; | ||
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; | ||
return id; | ||
} | ||
// src/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
return { | ||
id: getNextMessageId(), | ||
jsonrpc: "2.0", | ||
method, | ||
params | ||
}; | ||
} | ||
// src/json-rpc.ts | ||
function createPendingRpcRequest(rpcConfig, pendingRequest) { | ||
return { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await rpcConfig.transport({ | ||
payload, | ||
signal: options?.abortSignal | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
}; | ||
} | ||
function makeProxy(rpcConfig) { | ||
return new Proxy(rpcConfig.api, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(target, p, receiver) { | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const createRpcRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams }; | ||
return createPendingRpcRequest(rpcConfig, newRequest); | ||
}; | ||
} | ||
}); | ||
} | ||
function createJsonRpc(rpcConfig) { | ||
return makeProxy(rpcConfig); | ||
} | ||
var f = t; | ||
// src/transports/http/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
@@ -19,3 +91,3 @@ constructor(details) { | ||
// src/http-request-headers.ts | ||
// src/transports/http/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -69,139 +141,46 @@ accept: true, | ||
} | ||
var f = t; | ||
// src/http-request.ts | ||
async function makeHttpRequest({ headers, payload, signal, url }) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
body, | ||
headers: { | ||
...headers && normalizeHeaders(headers), | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST", | ||
signal | ||
}; | ||
const response = await f(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
// src/transports/http/http-transport.ts | ||
function createHttpTransport({ httpAgentNodeOnly, headers, url }) { | ||
if (__DEV__ && headers) { | ||
assertIsAllowedHttpRequestHeaders(headers); | ||
} | ||
return await response.json(); | ||
} | ||
// src/json-rpc-transport/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
constructor(details) { | ||
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.code = details.code; | ||
this.data = details.data; | ||
const agent = httpAgentNodeOnly ; | ||
if (__DEV__ && httpAgentNodeOnly != null) { | ||
console.warn( | ||
"createHttpTransport(): The `httpAgentNodeOnly` config you supplied has been ignored; HTTP agents are only usable in Node environments." | ||
); | ||
} | ||
get name() { | ||
return "SolanaJsonRpcError"; | ||
} | ||
}; | ||
// src/json-rpc-transport/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
function getNextMessageId() { | ||
const id = _nextMessageId; | ||
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; | ||
return id; | ||
} | ||
// src/json-rpc-transport/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
return { | ||
id: getNextMessageId(), | ||
jsonrpc: "2.0", | ||
method, | ||
params | ||
}; | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingRequest) { | ||
const overrides = { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
const customHeaders = headers && normalizeHeaders(headers); | ||
return async function makeHttpRequest({ | ||
payload, | ||
signal | ||
}) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
agent, | ||
body, | ||
headers: { | ||
...customHeaders, | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST", | ||
signal | ||
}; | ||
const response = await f(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
return await response.json(); | ||
}; | ||
return makeProxy(transportConfig, overrides, pendingRequest); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) { | ||
const overrides = { | ||
async sendBatch(options) { | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
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(transportConfig, overrides, pendingRequests); | ||
} | ||
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) { | ||
return new Proxy(transportConfig.api, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(target, p, receiver) { | ||
if (overrides && Reflect.has(overrides, p)) { | ||
return Reflect.get(overrides, p, receiver); | ||
} | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const createTransportRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams }; | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newRequest); | ||
} else { | ||
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests); | ||
} | ||
}; | ||
} | ||
}); | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
if (__DEV__ && transportConfig.headers) { | ||
assertIsAllowedHttpRequestHeaders(transportConfig.headers); | ||
} | ||
return makeProxy(transportConfig); | ||
} | ||
export { createJsonRpcTransport }; | ||
export { createHttpTransport, createJsonRpc }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -1,2 +0,3 @@ | ||
export * from './json-rpc-transport'; | ||
export * from './json-rpc'; | ||
export * from './transports/http/http-transport'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@solana/rpc-transport", | ||
"version": "2.0.0-experimental.50ab13b", | ||
"version": "2.0.0-experimental.527bafd", | ||
"description": "Network transports for accessing the Solana JSON RPC API", | ||
@@ -49,6 +49,7 @@ "exports": { | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^1.0.0", | ||
"@solana/eslint-config-solana": "^1.0.1", | ||
"@swc/core": "^1.3.18", | ||
"@swc/jest": "^0.2.23", | ||
"@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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
0
24
0
83
122370
27
1203
- Removednode-fetch@^3.3.1
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)