@solana/rpc-transport
Advanced tools
Comparing version 2.0.0-experimental.149244b to 2.0.0-experimental.15440e6
@@ -1,41 +0,33 @@ | ||
import 'node-fetch'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// ../fetch-impl-browser/dist/index.browser.js | ||
var { fetch } = globalThis; | ||
var src_default = fetch; | ||
// src/http-request-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
async function makeHttpRequest({ payload, url }) { | ||
const requestInfo = { | ||
body: JSON.stringify(payload), | ||
headers: { | ||
"Content-type": "application/json" | ||
// src/apis/methods/methods-api.ts | ||
function createJsonRpcApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
method: "POST" | ||
}; | ||
let response; | ||
{ | ||
response = await src_default(url, requestInfo); | ||
} | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
} | ||
return await response.json(); | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const methodName = p.toString(); | ||
return function(...rawParams) { | ||
const params = config?.parametersTransformer ? config?.parametersTransformer(rawParams, methodName) : rawParams; | ||
const responseTransformer = config?.responseTransformer ? config?.responseTransformer : (rawResponse) => rawResponse; | ||
return { | ||
methodName, | ||
params, | ||
responseTransformer | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
// src/json-rpc-transport/json-rpc-errors.ts | ||
// src/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
code; | ||
data; | ||
constructor(details) { | ||
@@ -52,3 +44,3 @@ super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
// src/json-rpc-transport/json-rpc-message-id.ts | ||
// src/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
@@ -61,3 +53,3 @@ function getNextMessageId() { | ||
// src/json-rpc-transport/json-rpc-message.ts | ||
// src/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
@@ -72,90 +64,109 @@ 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.ts | ||
function createPendingRpcRequest(rpcConfig, pendingRequest) { | ||
return { | ||
async send(options) { | ||
const { methodName, params, responseTransformer } = 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 responseTransformer ? responseTransformer(response.result, methodName) : 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/response-patcher-types.ts | ||
var KEYPATH_WILDCARD = {}; | ||
// src/response-patcher-allowed-numeric-values.ts | ||
var ALLOWED_NUMERIC_KEYPATHS = { | ||
getInflationReward: [[KEYPATH_WILDCARD, "commission"]] | ||
}; | ||
// src/response-patcher.ts | ||
function getNextAllowedKeypaths(keyPaths, property) { | ||
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1)); | ||
} | ||
function visitNode2(value, allowedKeypaths) { | ||
if (Array.isArray(value)) { | ||
return value.map((element, ii) => { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, ii); | ||
return visitNode2(element, nextAllowedKeypaths); | ||
}); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const propName in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, propName)) { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName); | ||
out[propName] = visitNode2(value[propName], nextAllowedKeypaths); | ||
} | ||
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); | ||
}; | ||
} | ||
return out; | ||
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted; | ||
// Upcast the value to `bigint` unless an allowed keypath is present. | ||
allowedKeypaths.length === 0) { | ||
return BigInt(value); | ||
} else { | ||
return value; | ||
} | ||
}); | ||
} | ||
function patchResponseForSolanaLabsRpc(response, methodName) { | ||
return visitNode2(response, (methodName && ALLOWED_NUMERIC_KEYPATHS[methodName]) ?? []); | ||
function createJsonRpc(rpcConfig) { | ||
return makeProxy(rpcConfig); | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingMessage) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
async send() { | ||
return await sendPayload(pendingMessage, url); | ||
// src/json-rpc-subscription.ts | ||
function registerIterableCleanup(iterable, cleanupFn) { | ||
(async () => { | ||
try { | ||
for await (const _ of iterable) | ||
; | ||
} catch { | ||
} finally { | ||
cleanupFn(); | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessage); | ||
})(); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
async sendBatch() { | ||
return await sendPayload(pendingMessages, url); | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseTransformer }) { | ||
return { | ||
async subscribe({ abortSignal }) { | ||
abortSignal.throwIfAborted(); | ||
let subscriptionId; | ||
function handleCleanup() { | ||
if (subscriptionId !== void 0) { | ||
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]); | ||
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => { | ||
connectionAbortController.abort(); | ||
}); | ||
} else { | ||
connectionAbortController.abort(); | ||
} | ||
} | ||
abortSignal.addEventListener("abort", handleCleanup); | ||
const connectionAbortController = new AbortController(); | ||
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params); | ||
const connection = await rpcConfig.transport({ | ||
payload: subscribeMessage, | ||
signal: connectionAbortController.signal | ||
}); | ||
function handleConnectionCleanup() { | ||
abortSignal.removeEventListener("abort", handleCleanup); | ||
} | ||
registerIterableCleanup(connection, handleConnectionCleanup); | ||
for await (const message of connection) { | ||
if ("id" in message && message.id === subscribeMessage.id) { | ||
if ("error" in message) { | ||
throw new SolanaJsonRpcError(message.error); | ||
} else { | ||
subscriptionId = message.result; | ||
break; | ||
} | ||
} | ||
} | ||
if (subscriptionId == null) { | ||
throw new Error("Failed to obtain a subscription id from the server"); | ||
} | ||
return { | ||
async *[Symbol.asyncIterator]() { | ||
for await (const message of connection) { | ||
if (!("params" in message) || message.params.subscription !== subscriptionId) { | ||
continue; | ||
} | ||
const notification = message.params.result; | ||
yield responseTransformer ? responseTransformer(notification) : notification; | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessages); | ||
} | ||
function makeProxy(transport, transportConfig, pendingRequestOrRequests) { | ||
const { onIntegerOverflow } = transportConfig; | ||
return new Proxy(transport, { | ||
function makeProxy2(rpcConfig) { | ||
return new Proxy(rpcConfig.api, { | ||
defineProperty() { | ||
@@ -167,19 +178,17 @@ return false; | ||
}, | ||
get(...args) { | ||
const [target, p] = args; | ||
return p in target ? Reflect.get(...args) : function(...params) { | ||
get(target, 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); | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newMessage); | ||
} else { | ||
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages); | ||
const createRpcSubscription = Reflect.get(target, methodName, receiver); | ||
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) { | ||
throw new Error( | ||
"Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names." | ||
); | ||
} | ||
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : { | ||
params: rawParams, | ||
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"), | ||
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe") | ||
}; | ||
return createPendingRpcSubscription(rpcConfig, newRequest); | ||
}; | ||
@@ -189,33 +198,280 @@ } | ||
} | ||
function processResponse(response, methodName) { | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
const patchedResponse = patchResponseForSolanaLabsRpc( | ||
response.result, | ||
methodName | ||
// FIXME: Untangle these types by moving the patcher into `rpc-core` | ||
function createJsonSubscriptionRpc(rpcConfig) { | ||
return makeProxy2(rpcConfig); | ||
} | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/transports/http/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/transports/http/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
accept: true, | ||
"content-length": true, | ||
"content-type": true | ||
}; | ||
var FORBIDDEN_HEADERS = { | ||
"accept-charset": true, | ||
"accept-encoding": true, | ||
"access-control-request-headers": true, | ||
"access-control-request-method": true, | ||
connection: true, | ||
"content-length": true, | ||
cookie: true, | ||
date: true, | ||
dnt: true, | ||
expect: true, | ||
host: true, | ||
"keep-alive": true, | ||
origin: true, | ||
"permissions-policy": true, | ||
// No currently available Typescript technique allows you to match on a prefix. | ||
// 'proxy-':true, | ||
// 'sec-':true, | ||
referer: true, | ||
te: true, | ||
trailer: true, | ||
"transfer-encoding": true, | ||
upgrade: true, | ||
via: true | ||
}; | ||
function assertIsAllowedHttpRequestHeaders(headers) { | ||
const badHeaders = Object.keys(headers).filter((headerName) => { | ||
const lowercaseHeaderName = headerName.toLowerCase(); | ||
return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-"); | ||
}); | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
return patchedResponse; | ||
} | ||
} | ||
async function sendPayload(payload, url) { | ||
const responseOrResponses = await makeHttpRequest({ | ||
function normalizeHeaders(headers) { | ||
const out = {}; | ||
for (const headerName in headers) { | ||
out[headerName.toLowerCase()] = headers[headerName]; | ||
} | ||
return out; | ||
} | ||
// src/transports/http/http-transport.ts | ||
function createHttpTransport({ headers, url }) { | ||
if (__DEV__ && headers) { | ||
assertIsAllowedHttpRequestHeaders(headers); | ||
} | ||
const customHeaders = headers && normalizeHeaders(headers); | ||
return async function makeHttpRequest({ | ||
payload, | ||
url | ||
signal | ||
}) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
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 | ||
}); | ||
} | ||
return await response.json(); | ||
}; | ||
} | ||
// ../ws-impl/dist/index.browser.js | ||
var e2 = globalThis.WebSocket; | ||
// src/transports/websocket/websocket-connection.ts | ||
var EXPLICIT_ABORT_TOKEN = Symbol( | ||
__DEV__ ? "This symbol is thrown from a socket's iterator when the connection is explicitly aborted by the user" : void 0 | ||
); | ||
async function createWebSocketConnection({ | ||
sendBufferHighWatermark, | ||
signal, | ||
url | ||
}) { | ||
return new Promise((resolve, reject) => { | ||
signal.addEventListener("abort", handleAbort, { once: true }); | ||
const iteratorState = /* @__PURE__ */ new Map(); | ||
function errorAndClearAllIteratorStates(reason) { | ||
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError); | ||
iteratorState.clear(); | ||
errorCallbacks.forEach((cb) => { | ||
try { | ||
cb(reason); | ||
} catch { | ||
} | ||
}); | ||
} | ||
function handleAbort() { | ||
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN); | ||
if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) { | ||
webSocket.close(1e3); | ||
} | ||
} | ||
function handleClose(ev) { | ||
bufferDrainWatcher?.onCancel(); | ||
signal.removeEventListener("abort", handleAbort); | ||
webSocket.removeEventListener("close", handleClose); | ||
webSocket.removeEventListener("error", handleError); | ||
webSocket.removeEventListener("open", handleOpen); | ||
webSocket.removeEventListener("message", handleMessage); | ||
errorAndClearAllIteratorStates(ev); | ||
} | ||
function handleError(ev) { | ||
if (!hasConnected) { | ||
reject( | ||
// TODO: Coded error | ||
new Error("WebSocket failed to connect", { cause: ev }) | ||
); | ||
} | ||
} | ||
let hasConnected = false; | ||
let bufferDrainWatcher; | ||
function handleOpen() { | ||
hasConnected = true; | ||
resolve({ | ||
async send(payload) { | ||
const message = JSON.stringify(payload); | ||
if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) { | ||
let onCancel; | ||
const promise = new Promise((resolve2, reject2) => { | ||
const intervalId = setInterval(() => { | ||
if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) { | ||
clearInterval(intervalId); | ||
bufferDrainWatcher = void 0; | ||
resolve2(); | ||
} | ||
}, 16); | ||
onCancel = () => { | ||
bufferDrainWatcher = void 0; | ||
clearInterval(intervalId); | ||
reject2( | ||
// TODO: Coded error | ||
new Error("WebSocket was closed before payload could be sent") | ||
); | ||
}; | ||
}); | ||
bufferDrainWatcher = { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
onCancel, | ||
promise | ||
}; | ||
} | ||
if (bufferDrainWatcher) { | ||
await bufferDrainWatcher.promise; | ||
} | ||
webSocket.send(message); | ||
}, | ||
async *[Symbol.asyncIterator]() { | ||
const iteratorKey = Symbol(); | ||
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] }); | ||
try { | ||
while (true) { | ||
const state = iteratorState.get(iteratorKey); | ||
if (!state) { | ||
throw new Error("Invariant: WebSocket message iterator is missing state storage"); | ||
} | ||
if (state.__hasPolled) { | ||
throw new Error( | ||
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise" | ||
); | ||
} | ||
const queuedMessages = state.queuedMessages; | ||
if (queuedMessages.length) { | ||
state.queuedMessages = []; | ||
yield* queuedMessages; | ||
} else { | ||
try { | ||
yield await new Promise((resolve2, reject2) => { | ||
iteratorState.set(iteratorKey, { | ||
__hasPolled: true, | ||
onError: reject2, | ||
onMessage: resolve2 | ||
}); | ||
}); | ||
} catch (e3) { | ||
if (e3 === EXPLICIT_ABORT_TOKEN) { | ||
return; | ||
} else { | ||
throw new Error("WebSocket connection closed", { cause: e3 }); | ||
} | ||
} | ||
} | ||
} | ||
} finally { | ||
iteratorState.delete(iteratorKey); | ||
} | ||
} | ||
}); | ||
} | ||
function handleMessage({ data }) { | ||
const message = JSON.parse(data); | ||
iteratorState.forEach((state, iteratorKey) => { | ||
if (state.__hasPolled) { | ||
const { onMessage } = state; | ||
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] }); | ||
onMessage(message); | ||
} else { | ||
state.queuedMessages.push(message); | ||
} | ||
}); | ||
} | ||
const webSocket = new e2(url); | ||
webSocket.addEventListener("close", handleClose); | ||
webSocket.addEventListener("error", handleError); | ||
webSocket.addEventListener("open", handleOpen); | ||
webSocket.addEventListener("message", handleMessage); | ||
}); | ||
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((response, ii) => processResponse(response, payload[ii].method)); | ||
} else { | ||
return processResponse(responseOrResponses, payload.method); | ||
} | ||
// src/transports/websocket/websocket-transport.ts | ||
function createWebSocketTransport({ sendBufferHighWatermark, url }) { | ||
if (/^wss?:/i.test(url) === false) { | ||
const protocolMatch = url.match(/^([^:]+):/); | ||
throw new DOMException( | ||
protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.` | ||
); | ||
} | ||
return async function sendWebSocketMessage({ payload, signal }) { | ||
signal?.throwIfAborted(); | ||
const connection = await createWebSocketConnection({ | ||
sendBufferHighWatermark, | ||
signal, | ||
url | ||
}); | ||
signal?.throwIfAborted(); | ||
await connection.send(payload); | ||
return { | ||
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection), | ||
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection) | ||
}; | ||
}; | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
const transport = {}; | ||
return makeProxy(transport, transportConfig); | ||
} | ||
export { createJsonRpcTransport }; | ||
export { createHttpTransport, createJsonRpc, createJsonRpcApi, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -1,41 +0,33 @@ | ||
import 'node-fetch'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// ../fetch-impl-browser/dist/index.browser.js | ||
var { fetch } = globalThis; | ||
var src_default = fetch; | ||
// src/http-request-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
async function makeHttpRequest({ payload, url }) { | ||
const requestInfo = { | ||
body: JSON.stringify(payload), | ||
headers: { | ||
"Content-type": "application/json" | ||
// src/apis/methods/methods-api.ts | ||
function createJsonRpcApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
method: "POST" | ||
}; | ||
let response; | ||
{ | ||
response = await src_default(url, requestInfo); | ||
} | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
} | ||
return await response.json(); | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const methodName = p.toString(); | ||
return function(...rawParams) { | ||
const params = config?.parametersTransformer ? config?.parametersTransformer(rawParams, methodName) : rawParams; | ||
const responseTransformer = config?.responseTransformer ? config?.responseTransformer : (rawResponse) => rawResponse; | ||
return { | ||
methodName, | ||
params, | ||
responseTransformer | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
// src/json-rpc-transport/json-rpc-errors.ts | ||
// src/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
code; | ||
data; | ||
constructor(details) { | ||
@@ -52,3 +44,3 @@ super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
// src/json-rpc-transport/json-rpc-message-id.ts | ||
// src/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
@@ -61,3 +53,3 @@ function getNextMessageId() { | ||
// src/json-rpc-transport/json-rpc-message.ts | ||
// src/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
@@ -72,90 +64,109 @@ 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.ts | ||
function createPendingRpcRequest(rpcConfig, pendingRequest) { | ||
return { | ||
async send(options) { | ||
const { methodName, params, responseTransformer } = 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 responseTransformer ? responseTransformer(response.result, methodName) : 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/response-patcher-types.ts | ||
var KEYPATH_WILDCARD = {}; | ||
// src/response-patcher-allowed-numeric-values.ts | ||
var ALLOWED_NUMERIC_KEYPATHS = { | ||
getInflationReward: [[KEYPATH_WILDCARD, "commission"]] | ||
}; | ||
// src/response-patcher.ts | ||
function getNextAllowedKeypaths(keyPaths, property) { | ||
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1)); | ||
} | ||
function visitNode2(value, allowedKeypaths) { | ||
if (Array.isArray(value)) { | ||
return value.map((element, ii) => { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, ii); | ||
return visitNode2(element, nextAllowedKeypaths); | ||
}); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const propName in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, propName)) { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName); | ||
out[propName] = visitNode2(value[propName], nextAllowedKeypaths); | ||
} | ||
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); | ||
}; | ||
} | ||
return out; | ||
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted; | ||
// Upcast the value to `bigint` unless an allowed keypath is present. | ||
allowedKeypaths.length === 0) { | ||
return BigInt(value); | ||
} else { | ||
return value; | ||
} | ||
}); | ||
} | ||
function patchResponseForSolanaLabsRpc(response, methodName) { | ||
return visitNode2(response, (methodName && ALLOWED_NUMERIC_KEYPATHS[methodName]) ?? []); | ||
function createJsonRpc(rpcConfig) { | ||
return makeProxy(rpcConfig); | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingMessage) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
async send() { | ||
return await sendPayload(pendingMessage, url); | ||
// src/json-rpc-subscription.ts | ||
function registerIterableCleanup(iterable, cleanupFn) { | ||
(async () => { | ||
try { | ||
for await (const _ of iterable) | ||
; | ||
} catch { | ||
} finally { | ||
cleanupFn(); | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessage); | ||
})(); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
async sendBatch() { | ||
return await sendPayload(pendingMessages, url); | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseTransformer }) { | ||
return { | ||
async subscribe({ abortSignal }) { | ||
abortSignal.throwIfAborted(); | ||
let subscriptionId; | ||
function handleCleanup() { | ||
if (subscriptionId !== void 0) { | ||
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]); | ||
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => { | ||
connectionAbortController.abort(); | ||
}); | ||
} else { | ||
connectionAbortController.abort(); | ||
} | ||
} | ||
abortSignal.addEventListener("abort", handleCleanup); | ||
const connectionAbortController = new AbortController(); | ||
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params); | ||
const connection = await rpcConfig.transport({ | ||
payload: subscribeMessage, | ||
signal: connectionAbortController.signal | ||
}); | ||
function handleConnectionCleanup() { | ||
abortSignal.removeEventListener("abort", handleCleanup); | ||
} | ||
registerIterableCleanup(connection, handleConnectionCleanup); | ||
for await (const message of connection) { | ||
if ("id" in message && message.id === subscribeMessage.id) { | ||
if ("error" in message) { | ||
throw new SolanaJsonRpcError(message.error); | ||
} else { | ||
subscriptionId = message.result; | ||
break; | ||
} | ||
} | ||
} | ||
if (subscriptionId == null) { | ||
throw new Error("Failed to obtain a subscription id from the server"); | ||
} | ||
return { | ||
async *[Symbol.asyncIterator]() { | ||
for await (const message of connection) { | ||
if (!("params" in message) || message.params.subscription !== subscriptionId) { | ||
continue; | ||
} | ||
const notification = message.params.result; | ||
yield responseTransformer ? responseTransformer(notification) : notification; | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessages); | ||
} | ||
function makeProxy(transport, transportConfig, pendingRequestOrRequests) { | ||
const { onIntegerOverflow } = transportConfig; | ||
return new Proxy(transport, { | ||
function makeProxy2(rpcConfig) { | ||
return new Proxy(rpcConfig.api, { | ||
defineProperty() { | ||
@@ -167,19 +178,17 @@ return false; | ||
}, | ||
get(...args) { | ||
const [target, p] = args; | ||
return p in target ? Reflect.get(...args) : function(...params) { | ||
get(target, 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); | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newMessage); | ||
} else { | ||
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages); | ||
const createRpcSubscription = Reflect.get(target, methodName, receiver); | ||
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) { | ||
throw new Error( | ||
"Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names." | ||
); | ||
} | ||
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : { | ||
params: rawParams, | ||
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"), | ||
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe") | ||
}; | ||
return createPendingRpcSubscription(rpcConfig, newRequest); | ||
}; | ||
@@ -189,33 +198,280 @@ } | ||
} | ||
function processResponse(response, methodName) { | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
const patchedResponse = patchResponseForSolanaLabsRpc( | ||
response.result, | ||
methodName | ||
// FIXME: Untangle these types by moving the patcher into `rpc-core` | ||
function createJsonSubscriptionRpc(rpcConfig) { | ||
return makeProxy2(rpcConfig); | ||
} | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/transports/http/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/transports/http/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
accept: true, | ||
"content-length": true, | ||
"content-type": true | ||
}; | ||
var FORBIDDEN_HEADERS = { | ||
"accept-charset": true, | ||
"accept-encoding": true, | ||
"access-control-request-headers": true, | ||
"access-control-request-method": true, | ||
connection: true, | ||
"content-length": true, | ||
cookie: true, | ||
date: true, | ||
dnt: true, | ||
expect: true, | ||
host: true, | ||
"keep-alive": true, | ||
origin: true, | ||
"permissions-policy": true, | ||
// No currently available Typescript technique allows you to match on a prefix. | ||
// 'proxy-':true, | ||
// 'sec-':true, | ||
referer: true, | ||
te: true, | ||
trailer: true, | ||
"transfer-encoding": true, | ||
upgrade: true, | ||
via: true | ||
}; | ||
function assertIsAllowedHttpRequestHeaders(headers) { | ||
const badHeaders = Object.keys(headers).filter((headerName) => { | ||
const lowercaseHeaderName = headerName.toLowerCase(); | ||
return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-"); | ||
}); | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
return patchedResponse; | ||
} | ||
} | ||
async function sendPayload(payload, url) { | ||
const responseOrResponses = await makeHttpRequest({ | ||
function normalizeHeaders(headers) { | ||
const out = {}; | ||
for (const headerName in headers) { | ||
out[headerName.toLowerCase()] = headers[headerName]; | ||
} | ||
return out; | ||
} | ||
// src/transports/http/http-transport.ts | ||
function createHttpTransport({ headers, url }) { | ||
if (__DEV__ && headers) { | ||
assertIsAllowedHttpRequestHeaders(headers); | ||
} | ||
const customHeaders = headers && normalizeHeaders(headers); | ||
return async function makeHttpRequest({ | ||
payload, | ||
url | ||
signal | ||
}) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
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 | ||
}); | ||
} | ||
return await response.json(); | ||
}; | ||
} | ||
// ../ws-impl/dist/index.browser.js | ||
var e2 = globalThis.WebSocket; | ||
// src/transports/websocket/websocket-connection.ts | ||
var EXPLICIT_ABORT_TOKEN = Symbol( | ||
__DEV__ ? "This symbol is thrown from a socket's iterator when the connection is explicitly aborted by the user" : void 0 | ||
); | ||
async function createWebSocketConnection({ | ||
sendBufferHighWatermark, | ||
signal, | ||
url | ||
}) { | ||
return new Promise((resolve, reject) => { | ||
signal.addEventListener("abort", handleAbort, { once: true }); | ||
const iteratorState = /* @__PURE__ */ new Map(); | ||
function errorAndClearAllIteratorStates(reason) { | ||
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError); | ||
iteratorState.clear(); | ||
errorCallbacks.forEach((cb) => { | ||
try { | ||
cb(reason); | ||
} catch { | ||
} | ||
}); | ||
} | ||
function handleAbort() { | ||
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN); | ||
if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) { | ||
webSocket.close(1e3); | ||
} | ||
} | ||
function handleClose(ev) { | ||
bufferDrainWatcher?.onCancel(); | ||
signal.removeEventListener("abort", handleAbort); | ||
webSocket.removeEventListener("close", handleClose); | ||
webSocket.removeEventListener("error", handleError); | ||
webSocket.removeEventListener("open", handleOpen); | ||
webSocket.removeEventListener("message", handleMessage); | ||
errorAndClearAllIteratorStates(ev); | ||
} | ||
function handleError(ev) { | ||
if (!hasConnected) { | ||
reject( | ||
// TODO: Coded error | ||
new Error("WebSocket failed to connect", { cause: ev }) | ||
); | ||
} | ||
} | ||
let hasConnected = false; | ||
let bufferDrainWatcher; | ||
function handleOpen() { | ||
hasConnected = true; | ||
resolve({ | ||
async send(payload) { | ||
const message = JSON.stringify(payload); | ||
if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) { | ||
let onCancel; | ||
const promise = new Promise((resolve2, reject2) => { | ||
const intervalId = setInterval(() => { | ||
if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) { | ||
clearInterval(intervalId); | ||
bufferDrainWatcher = void 0; | ||
resolve2(); | ||
} | ||
}, 16); | ||
onCancel = () => { | ||
bufferDrainWatcher = void 0; | ||
clearInterval(intervalId); | ||
reject2( | ||
// TODO: Coded error | ||
new Error("WebSocket was closed before payload could be sent") | ||
); | ||
}; | ||
}); | ||
bufferDrainWatcher = { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
onCancel, | ||
promise | ||
}; | ||
} | ||
if (bufferDrainWatcher) { | ||
await bufferDrainWatcher.promise; | ||
} | ||
webSocket.send(message); | ||
}, | ||
async *[Symbol.asyncIterator]() { | ||
const iteratorKey = Symbol(); | ||
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] }); | ||
try { | ||
while (true) { | ||
const state = iteratorState.get(iteratorKey); | ||
if (!state) { | ||
throw new Error("Invariant: WebSocket message iterator is missing state storage"); | ||
} | ||
if (state.__hasPolled) { | ||
throw new Error( | ||
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise" | ||
); | ||
} | ||
const queuedMessages = state.queuedMessages; | ||
if (queuedMessages.length) { | ||
state.queuedMessages = []; | ||
yield* queuedMessages; | ||
} else { | ||
try { | ||
yield await new Promise((resolve2, reject2) => { | ||
iteratorState.set(iteratorKey, { | ||
__hasPolled: true, | ||
onError: reject2, | ||
onMessage: resolve2 | ||
}); | ||
}); | ||
} catch (e3) { | ||
if (e3 === EXPLICIT_ABORT_TOKEN) { | ||
return; | ||
} else { | ||
throw new Error("WebSocket connection closed", { cause: e3 }); | ||
} | ||
} | ||
} | ||
} | ||
} finally { | ||
iteratorState.delete(iteratorKey); | ||
} | ||
} | ||
}); | ||
} | ||
function handleMessage({ data }) { | ||
const message = JSON.parse(data); | ||
iteratorState.forEach((state, iteratorKey) => { | ||
if (state.__hasPolled) { | ||
const { onMessage } = state; | ||
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] }); | ||
onMessage(message); | ||
} else { | ||
state.queuedMessages.push(message); | ||
} | ||
}); | ||
} | ||
const webSocket = new e2(url); | ||
webSocket.addEventListener("close", handleClose); | ||
webSocket.addEventListener("error", handleError); | ||
webSocket.addEventListener("open", handleOpen); | ||
webSocket.addEventListener("message", handleMessage); | ||
}); | ||
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((response, ii) => processResponse(response, payload[ii].method)); | ||
} else { | ||
return processResponse(responseOrResponses, payload.method); | ||
} | ||
// src/transports/websocket/websocket-transport.ts | ||
function createWebSocketTransport({ sendBufferHighWatermark, url }) { | ||
if (/^wss?:/i.test(url) === false) { | ||
const protocolMatch = url.match(/^([^:]+):/); | ||
throw new DOMException( | ||
protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.` | ||
); | ||
} | ||
return async function sendWebSocketMessage({ payload, signal }) { | ||
signal?.throwIfAborted(); | ||
const connection = await createWebSocketConnection({ | ||
sendBufferHighWatermark, | ||
signal, | ||
url | ||
}); | ||
signal?.throwIfAborted(); | ||
await connection.send(payload); | ||
return { | ||
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection), | ||
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection) | ||
}; | ||
}; | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
const transport = {}; | ||
return makeProxy(transport, transportConfig); | ||
} | ||
export { createJsonRpcTransport }; | ||
export { createHttpTransport, createJsonRpc, createJsonRpcApi, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -1,37 +0,35 @@ | ||
import fetchImplNode from 'node-fetch'; | ||
import e2 from 'ws'; | ||
// src/http-request-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
async function makeHttpRequest({ payload, url }) { | ||
const requestInfo = { | ||
body: JSON.stringify(payload), | ||
headers: { | ||
"Content-type": "application/json" | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/apis/methods/methods-api.ts | ||
function createJsonRpcApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
method: "POST" | ||
}; | ||
let response; | ||
{ | ||
response = await fetchImplNode(url, requestInfo); | ||
} | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
message: response.statusText, | ||
statusCode: response.status | ||
}); | ||
} | ||
return await response.json(); | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const methodName = p.toString(); | ||
return function(...rawParams) { | ||
const params = config?.parametersTransformer ? config?.parametersTransformer(rawParams, methodName) : rawParams; | ||
const responseTransformer = config?.responseTransformer ? config?.responseTransformer : (rawResponse) => rawResponse; | ||
return { | ||
methodName, | ||
params, | ||
responseTransformer | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
// src/json-rpc-transport/json-rpc-errors.ts | ||
// src/json-rpc-errors.ts | ||
var SolanaJsonRpcError = class extends Error { | ||
code; | ||
data; | ||
constructor(details) { | ||
@@ -48,3 +46,3 @@ super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`); | ||
// src/json-rpc-transport/json-rpc-message-id.ts | ||
// src/json-rpc-message-id.ts | ||
var _nextMessageId = 0; | ||
@@ -57,3 +55,3 @@ function getNextMessageId() { | ||
// src/json-rpc-transport/json-rpc-message.ts | ||
// src/json-rpc-message.ts | ||
function createJsonRpcMessage(method, params) { | ||
@@ -68,90 +66,109 @@ 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.ts | ||
function createPendingRpcRequest(rpcConfig, pendingRequest) { | ||
return { | ||
async send(options) { | ||
const { methodName, params, responseTransformer } = 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 responseTransformer ? responseTransformer(response.result, methodName) : 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/response-patcher-types.ts | ||
var KEYPATH_WILDCARD = {}; | ||
// src/response-patcher-allowed-numeric-values.ts | ||
var ALLOWED_NUMERIC_KEYPATHS = { | ||
getInflationReward: [[KEYPATH_WILDCARD, "commission"]] | ||
}; | ||
// src/response-patcher.ts | ||
function getNextAllowedKeypaths(keyPaths, property) { | ||
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1)); | ||
} | ||
function visitNode2(value, allowedKeypaths) { | ||
if (Array.isArray(value)) { | ||
return value.map((element, ii) => { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, ii); | ||
return visitNode2(element, nextAllowedKeypaths); | ||
}); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const propName in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, propName)) { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName); | ||
out[propName] = visitNode2(value[propName], nextAllowedKeypaths); | ||
} | ||
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); | ||
}; | ||
} | ||
return out; | ||
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted; | ||
// Upcast the value to `bigint` unless an allowed keypath is present. | ||
allowedKeypaths.length === 0) { | ||
return BigInt(value); | ||
} else { | ||
return value; | ||
} | ||
}); | ||
} | ||
function patchResponseForSolanaLabsRpc(response, methodName) { | ||
return visitNode2(response, (methodName && ALLOWED_NUMERIC_KEYPATHS[methodName]) ?? []); | ||
function createJsonRpc(rpcConfig) { | ||
return makeProxy(rpcConfig); | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingMessage) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
async send() { | ||
return await sendPayload(pendingMessage, url); | ||
// src/json-rpc-subscription.ts | ||
function registerIterableCleanup(iterable, cleanupFn) { | ||
(async () => { | ||
try { | ||
for await (const _ of iterable) | ||
; | ||
} catch { | ||
} finally { | ||
cleanupFn(); | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessage); | ||
})(); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
async sendBatch() { | ||
return await sendPayload(pendingMessages, url); | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseTransformer }) { | ||
return { | ||
async subscribe({ abortSignal }) { | ||
abortSignal.throwIfAborted(); | ||
let subscriptionId; | ||
function handleCleanup() { | ||
if (subscriptionId !== void 0) { | ||
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]); | ||
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => { | ||
connectionAbortController.abort(); | ||
}); | ||
} else { | ||
connectionAbortController.abort(); | ||
} | ||
} | ||
abortSignal.addEventListener("abort", handleCleanup); | ||
const connectionAbortController = new AbortController(); | ||
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params); | ||
const connection = await rpcConfig.transport({ | ||
payload: subscribeMessage, | ||
signal: connectionAbortController.signal | ||
}); | ||
function handleConnectionCleanup() { | ||
abortSignal.removeEventListener("abort", handleCleanup); | ||
} | ||
registerIterableCleanup(connection, handleConnectionCleanup); | ||
for await (const message of connection) { | ||
if ("id" in message && message.id === subscribeMessage.id) { | ||
if ("error" in message) { | ||
throw new SolanaJsonRpcError(message.error); | ||
} else { | ||
subscriptionId = message.result; | ||
break; | ||
} | ||
} | ||
} | ||
if (subscriptionId == null) { | ||
throw new Error("Failed to obtain a subscription id from the server"); | ||
} | ||
return { | ||
async *[Symbol.asyncIterator]() { | ||
for await (const message of connection) { | ||
if (!("params" in message) || message.params.subscription !== subscriptionId) { | ||
continue; | ||
} | ||
const notification = message.params.result; | ||
yield responseTransformer ? responseTransformer(notification) : notification; | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessages); | ||
} | ||
function makeProxy(transport, transportConfig, pendingRequestOrRequests) { | ||
const { onIntegerOverflow } = transportConfig; | ||
return new Proxy(transport, { | ||
function makeProxy2(rpcConfig) { | ||
return new Proxy(rpcConfig.api, { | ||
defineProperty() { | ||
@@ -163,19 +180,17 @@ return false; | ||
}, | ||
get(...args) { | ||
const [target, p] = args; | ||
return p in target ? Reflect.get(...args) : function(...params) { | ||
get(target, 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); | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newMessage); | ||
} else { | ||
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages); | ||
const createRpcSubscription = Reflect.get(target, methodName, receiver); | ||
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) { | ||
throw new Error( | ||
"Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names." | ||
); | ||
} | ||
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : { | ||
params: rawParams, | ||
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"), | ||
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe") | ||
}; | ||
return createPendingRpcSubscription(rpcConfig, newRequest); | ||
}; | ||
@@ -185,33 +200,278 @@ } | ||
} | ||
function processResponse(response, methodName) { | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
const patchedResponse = patchResponseForSolanaLabsRpc( | ||
response.result, | ||
methodName | ||
// FIXME: Untangle these types by moving the patcher into `rpc-core` | ||
function createJsonSubscriptionRpc(rpcConfig) { | ||
return makeProxy2(rpcConfig); | ||
} | ||
// ../fetch-impl/dist/index.node.js | ||
var e = globalThis.fetch; | ||
// src/transports/http/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/transports/http/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
accept: true, | ||
"content-length": true, | ||
"content-type": true | ||
}; | ||
var FORBIDDEN_HEADERS = { | ||
"accept-charset": true, | ||
"accept-encoding": true, | ||
"access-control-request-headers": true, | ||
"access-control-request-method": true, | ||
connection: true, | ||
"content-length": true, | ||
cookie: true, | ||
date: true, | ||
dnt: true, | ||
expect: true, | ||
host: true, | ||
"keep-alive": true, | ||
origin: true, | ||
"permissions-policy": true, | ||
// No currently available Typescript technique allows you to match on a prefix. | ||
// 'proxy-':true, | ||
// 'sec-':true, | ||
referer: true, | ||
te: true, | ||
trailer: true, | ||
"transfer-encoding": true, | ||
upgrade: true, | ||
via: true | ||
}; | ||
function assertIsAllowedHttpRequestHeaders(headers) { | ||
const badHeaders = Object.keys(headers).filter((headerName) => { | ||
const lowercaseHeaderName = headerName.toLowerCase(); | ||
return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-"); | ||
}); | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
return patchedResponse; | ||
} | ||
} | ||
async function sendPayload(payload, url) { | ||
const responseOrResponses = await makeHttpRequest({ | ||
function normalizeHeaders(headers) { | ||
const out = {}; | ||
for (const headerName in headers) { | ||
out[headerName.toLowerCase()] = headers[headerName]; | ||
} | ||
return out; | ||
} | ||
// src/transports/http/http-transport.ts | ||
function createHttpTransport({ headers, url }) { | ||
if (__DEV__ && headers) { | ||
assertIsAllowedHttpRequestHeaders(headers); | ||
} | ||
const customHeaders = headers && normalizeHeaders(headers); | ||
return async function makeHttpRequest({ | ||
payload, | ||
url | ||
signal | ||
}) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
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 | ||
}); | ||
} | ||
return await response.json(); | ||
}; | ||
} | ||
var t = e2; | ||
// src/transports/websocket/websocket-connection.ts | ||
var EXPLICIT_ABORT_TOKEN = Symbol( | ||
__DEV__ ? "This symbol is thrown from a socket's iterator when the connection is explicitly aborted by the user" : void 0 | ||
); | ||
async function createWebSocketConnection({ | ||
sendBufferHighWatermark, | ||
signal, | ||
url | ||
}) { | ||
return new Promise((resolve, reject) => { | ||
signal.addEventListener("abort", handleAbort, { once: true }); | ||
const iteratorState = /* @__PURE__ */ new Map(); | ||
function errorAndClearAllIteratorStates(reason) { | ||
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError); | ||
iteratorState.clear(); | ||
errorCallbacks.forEach((cb) => { | ||
try { | ||
cb(reason); | ||
} catch { | ||
} | ||
}); | ||
} | ||
function handleAbort() { | ||
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN); | ||
if (webSocket.readyState !== t.CLOSED && webSocket.readyState !== t.CLOSING) { | ||
webSocket.close(1e3); | ||
} | ||
} | ||
function handleClose(ev) { | ||
bufferDrainWatcher?.onCancel(); | ||
signal.removeEventListener("abort", handleAbort); | ||
webSocket.removeEventListener("close", handleClose); | ||
webSocket.removeEventListener("error", handleError); | ||
webSocket.removeEventListener("open", handleOpen); | ||
webSocket.removeEventListener("message", handleMessage); | ||
errorAndClearAllIteratorStates(ev); | ||
} | ||
function handleError(ev) { | ||
if (!hasConnected) { | ||
reject( | ||
// TODO: Coded error | ||
new Error("WebSocket failed to connect", { cause: ev }) | ||
); | ||
} | ||
} | ||
let hasConnected = false; | ||
let bufferDrainWatcher; | ||
function handleOpen() { | ||
hasConnected = true; | ||
resolve({ | ||
async send(payload) { | ||
const message = JSON.stringify(payload); | ||
if (!bufferDrainWatcher && webSocket.readyState === t.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) { | ||
let onCancel; | ||
const promise = new Promise((resolve2, reject2) => { | ||
const intervalId = setInterval(() => { | ||
if (webSocket.readyState !== t.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) { | ||
clearInterval(intervalId); | ||
bufferDrainWatcher = void 0; | ||
resolve2(); | ||
} | ||
}, 16); | ||
onCancel = () => { | ||
bufferDrainWatcher = void 0; | ||
clearInterval(intervalId); | ||
reject2( | ||
// TODO: Coded error | ||
new Error("WebSocket was closed before payload could be sent") | ||
); | ||
}; | ||
}); | ||
bufferDrainWatcher = { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
onCancel, | ||
promise | ||
}; | ||
} | ||
if (bufferDrainWatcher) { | ||
await bufferDrainWatcher.promise; | ||
} | ||
webSocket.send(message); | ||
}, | ||
async *[Symbol.asyncIterator]() { | ||
const iteratorKey = Symbol(); | ||
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] }); | ||
try { | ||
while (true) { | ||
const state = iteratorState.get(iteratorKey); | ||
if (!state) { | ||
throw new Error("Invariant: WebSocket message iterator is missing state storage"); | ||
} | ||
if (state.__hasPolled) { | ||
throw new Error( | ||
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise" | ||
); | ||
} | ||
const queuedMessages = state.queuedMessages; | ||
if (queuedMessages.length) { | ||
state.queuedMessages = []; | ||
yield* queuedMessages; | ||
} else { | ||
try { | ||
yield await new Promise((resolve2, reject2) => { | ||
iteratorState.set(iteratorKey, { | ||
__hasPolled: true, | ||
onError: reject2, | ||
onMessage: resolve2 | ||
}); | ||
}); | ||
} catch (e3) { | ||
if (e3 === EXPLICIT_ABORT_TOKEN) { | ||
return; | ||
} else { | ||
throw new Error("WebSocket connection closed", { cause: e3 }); | ||
} | ||
} | ||
} | ||
} | ||
} finally { | ||
iteratorState.delete(iteratorKey); | ||
} | ||
} | ||
}); | ||
} | ||
function handleMessage({ data }) { | ||
const message = JSON.parse(data); | ||
iteratorState.forEach((state, iteratorKey) => { | ||
if (state.__hasPolled) { | ||
const { onMessage } = state; | ||
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] }); | ||
onMessage(message); | ||
} else { | ||
state.queuedMessages.push(message); | ||
} | ||
}); | ||
} | ||
const webSocket = new t(url); | ||
webSocket.addEventListener("close", handleClose); | ||
webSocket.addEventListener("error", handleError); | ||
webSocket.addEventListener("open", handleOpen); | ||
webSocket.addEventListener("message", handleMessage); | ||
}); | ||
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((response, ii) => processResponse(response, payload[ii].method)); | ||
} else { | ||
return processResponse(responseOrResponses, payload.method); | ||
} | ||
// src/transports/websocket/websocket-transport.ts | ||
function createWebSocketTransport({ sendBufferHighWatermark, url }) { | ||
if (/^wss?:/i.test(url) === false) { | ||
const protocolMatch = url.match(/^([^:]+):/); | ||
throw new DOMException( | ||
protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.` | ||
); | ||
} | ||
return async function sendWebSocketMessage({ payload, signal }) { | ||
signal?.throwIfAborted(); | ||
const connection = await createWebSocketConnection({ | ||
sendBufferHighWatermark, | ||
signal, | ||
url | ||
}); | ||
signal?.throwIfAborted(); | ||
await connection.send(payload); | ||
return { | ||
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection), | ||
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection) | ||
}; | ||
}; | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
const transport = {}; | ||
return makeProxy(transport, transportConfig); | ||
} | ||
export { createJsonRpcTransport }; | ||
export { createHttpTransport, createJsonRpc, createJsonRpcApi, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -1,2 +0,11 @@ | ||
export * from './json-rpc-transport'; | ||
export * from './apis/api-types.js'; | ||
export * from './apis/methods/methods-api.js'; | ||
export * from './json-rpc.js'; | ||
export type { SolanaJsonRpcErrorCode } from './json-rpc-errors.js'; | ||
export * from './json-rpc-subscription.js'; | ||
export type { IRpcApi, IRpcSubscriptionsApi, IRpcWebSocketTransport, PendingRpcSubscription, Rpc, RpcRequest, RpcSubscription, RpcSubscriptions, } from './json-rpc-types.js'; | ||
export * from './transports/http/http-transport.js'; | ||
export * from './transports/websocket/websocket-transport.js'; | ||
export type { IRpcTransport } from './transports/transport-types.js'; | ||
export * from './transports/websocket/websocket-transport.js'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@solana/rpc-transport", | ||
"version": "2.0.0-experimental.149244b", | ||
"version": "2.0.0-experimental.15440e6", | ||
"description": "Network transports for accessing the Solana JSON RPC API", | ||
@@ -49,31 +49,32 @@ "exports": { | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^0.0.4", | ||
"@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", | ||
"eslint-plugin-jest": "^27.1.5", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"@solana/eslint-config-solana": "^1.0.2", | ||
"@swc/jest": "^0.2.29", | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "18.11.19", | ||
"@typescript-eslint/eslint-plugin": "^6.13.2", | ||
"@typescript-eslint/parser": "^6.3.0", | ||
"agadoo": "^3.0.0", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-jest": "^27.4.2", | ||
"eslint-plugin-sort-keys-fix": "^1.1.2", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"jest-fetch-mock": "^3.0.3", | ||
"jest-runner-eslint": "^2.0.0", | ||
"fast-stable-stringify": "^1.0.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jest-fetch-mock-fork": "^3.0.4", | ||
"jest-runner-eslint": "^2.1.2", | ||
"jest-runner-prettier": "^1.0.0", | ||
"postcss": "^8.4.12", | ||
"prettier": "^2.7.1", | ||
"ts-node": "^10.9.1", | ||
"tsup": "6.7.0", | ||
"turbo": "^1.6.3", | ||
"typescript": "^4.9", | ||
"jest-websocket-mock": "^2.5.0", | ||
"prettier": "^3.1", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.2.2", | ||
"version-from-git": "^1.1.1", | ||
"@solana/fetch-impl-browser": "0.0.0-development", | ||
"build-scripts": "0.0.0", | ||
"fetch-impl": "0.0.0", | ||
"test-config": "0.0.0", | ||
"tsconfig": "0.0.0" | ||
"tsconfig": "0.0.0", | ||
"ws-impl": "0.0.0" | ||
}, | ||
"peerDependencies": { | ||
"ws": "^8.14.0" | ||
}, | ||
"bundlewatch": { | ||
@@ -87,21 +88,17 @@ "defaultCompression": "gzip", | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^2.6.7", | ||
"@solana/keys": "2.0.0-experimental.149244b", | ||
"@solana/rpc-core": "2.0.0-experimental.149244b" | ||
}, | ||
"scripts": { | ||
"compile:js": "tsup --config build-scripts/tsup.config.package.ts", | ||
"compile:typedefs": "tsc -p ./tsconfig.declarations.json", | ||
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --watch", | ||
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs", | ||
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch", | ||
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks", | ||
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json", | ||
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent", | ||
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent", | ||
"test:treeshakability:browser": "agadoo dist/index.browser.js", | ||
"test:treeshakability:native": "agadoo dist/index.node.js", | ||
"test:treeshakability:node": "agadoo dist/index.native.js", | ||
"test:treeshakability:native": "agadoo dist/index.native.js", | ||
"test:treeshakability:node": "agadoo dist/index.node.js", | ||
"test:typecheck": "tsc --noEmit", | ||
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --silent", | ||
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --silent" | ||
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent", | ||
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Network access
Supply chain riskThis module accesses the network.
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
364353
1
26
44
3645
1
83
1
+ Addedws@8.18.0(transitive)
- Removednode-fetch@^2.6.7
- Removed@solana/keys@2.0.0-experimental.149244b(transitive)
- Removed@solana/rpc-core@2.0.0-experimental.149244b(transitive)
- Removedbase-x@4.0.0(transitive)
- Removedbs58@5.0.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)