@solana/rpc-transport
Advanced tools
Comparing version 2.0.0-experimental.cf4231e to 2.0.0-experimental.f10010c
@@ -70,90 +70,44 @@ import 'node-fetch'; | ||
// 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); | ||
} | ||
} | ||
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); | ||
} | ||
} | ||
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]) ?? []); | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingMessage) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
function createArmedJsonRpcTransport(transportConfig, pendingRequest) { | ||
const overrides = { | ||
async send() { | ||
return await sendPayload(pendingMessage, url); | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
payload, | ||
url: transportConfig.url | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessage); | ||
return makeProxy(transportConfig, overrides, pendingRequest); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) { | ||
const overrides = { | ||
async sendBatch() { | ||
return await sendPayload(pendingMessages, url); | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
payload, | ||
url: transportConfig.url | ||
}); | ||
const requestOrder = payload.map((p) => p.id); | ||
return responses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => { | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
const { responseProcessor } = pendingRequests[ii]; | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
}); | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessages); | ||
return makeProxy(transportConfig, overrides, pendingRequests); | ||
} | ||
function makeProxy(transport, transportConfig, pendingRequestOrRequests) { | ||
const { onIntegerOverflow } = transportConfig; | ||
return new Proxy(transport, { | ||
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) { | ||
return new Proxy(transportConfig.api, { | ||
defineProperty() { | ||
@@ -165,18 +119,15 @@ return false; | ||
}, | ||
get(...args) { | ||
const [target, p] = args; | ||
return p in target ? Reflect.get(...args) : function(...params) { | ||
get(target, p, receiver) { | ||
if (overrides && Reflect.has(overrides, p)) { | ||
return Reflect.get(overrides, p, receiver); | ||
} | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const patchedParams = patchParamsForSolanaLabsRpc( | ||
params, | ||
onIntegerOverflow ? (keyPath, value) => { | ||
onIntegerOverflow(methodName, keyPath, value); | ||
} : void 0 | ||
); | ||
const newMessage = createJsonRpcMessage(methodName, patchedParams); | ||
const createTransportRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams }; | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newMessage); | ||
return createArmedJsonRpcTransport(transportConfig, newRequest); | ||
} else { | ||
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages); | ||
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests); | ||
} | ||
@@ -187,29 +138,4 @@ }; | ||
} | ||
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` | ||
); | ||
return patchedResponse; | ||
} | ||
} | ||
async function sendPayload(payload, url) { | ||
const responseOrResponses = await makeHttpRequest({ | ||
payload, | ||
url | ||
}); | ||
if (Array.isArray(responseOrResponses)) { | ||
const requestOrder = payload.map((p) => p.id); | ||
return responseOrResponses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => processResponse(response, payload[ii].method)); | ||
} else { | ||
return processResponse(responseOrResponses, payload.method); | ||
} | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
const transport = {}; | ||
return makeProxy(transport, transportConfig); | ||
return makeProxy(transportConfig); | ||
} | ||
@@ -216,0 +142,0 @@ |
@@ -70,90 +70,44 @@ import 'node-fetch'; | ||
// 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); | ||
} | ||
} | ||
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); | ||
} | ||
} | ||
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]) ?? []); | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingMessage) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
function createArmedJsonRpcTransport(transportConfig, pendingRequest) { | ||
const overrides = { | ||
async send() { | ||
return await sendPayload(pendingMessage, url); | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
payload, | ||
url: transportConfig.url | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessage); | ||
return makeProxy(transportConfig, overrides, pendingRequest); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) { | ||
const overrides = { | ||
async sendBatch() { | ||
return await sendPayload(pendingMessages, url); | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
payload, | ||
url: transportConfig.url | ||
}); | ||
const requestOrder = payload.map((p) => p.id); | ||
return responses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => { | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
const { responseProcessor } = pendingRequests[ii]; | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
}); | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessages); | ||
return makeProxy(transportConfig, overrides, pendingRequests); | ||
} | ||
function makeProxy(transport, transportConfig, pendingRequestOrRequests) { | ||
const { onIntegerOverflow } = transportConfig; | ||
return new Proxy(transport, { | ||
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) { | ||
return new Proxy(transportConfig.api, { | ||
defineProperty() { | ||
@@ -165,18 +119,15 @@ return false; | ||
}, | ||
get(...args) { | ||
const [target, p] = args; | ||
return p in target ? Reflect.get(...args) : function(...params) { | ||
get(target, p, receiver) { | ||
if (overrides && Reflect.has(overrides, p)) { | ||
return Reflect.get(overrides, p, receiver); | ||
} | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const patchedParams = patchParamsForSolanaLabsRpc( | ||
params, | ||
onIntegerOverflow ? (keyPath, value) => { | ||
onIntegerOverflow(methodName, keyPath, value); | ||
} : void 0 | ||
); | ||
const newMessage = createJsonRpcMessage(methodName, patchedParams); | ||
const createTransportRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams }; | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newMessage); | ||
return createArmedJsonRpcTransport(transportConfig, newRequest); | ||
} else { | ||
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages); | ||
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests); | ||
} | ||
@@ -187,29 +138,4 @@ }; | ||
} | ||
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` | ||
); | ||
return patchedResponse; | ||
} | ||
} | ||
async function sendPayload(payload, url) { | ||
const responseOrResponses = await makeHttpRequest({ | ||
payload, | ||
url | ||
}); | ||
if (Array.isArray(responseOrResponses)) { | ||
const requestOrder = payload.map((p) => p.id); | ||
return responseOrResponses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => processResponse(response, payload[ii].method)); | ||
} else { | ||
return processResponse(responseOrResponses, payload.method); | ||
} | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
const transport = {}; | ||
return makeProxy(transport, transportConfig); | ||
return makeProxy(transportConfig); | ||
} | ||
@@ -216,0 +142,0 @@ |
@@ -66,90 +66,44 @@ import fetchImplNode from 'node-fetch'; | ||
// 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); | ||
} | ||
} | ||
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); | ||
} | ||
} | ||
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]) ?? []); | ||
} | ||
// src/json-rpc-transport/index.ts | ||
function createArmedJsonRpcTransport(transportConfig, pendingMessage) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
function createArmedJsonRpcTransport(transportConfig, pendingRequest) { | ||
const overrides = { | ||
async send() { | ||
return await sendPayload(pendingMessage, url); | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
payload, | ||
url: transportConfig.url | ||
}); | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessage); | ||
return makeProxy(transportConfig, overrides, pendingRequest); | ||
} | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingMessages) { | ||
const { url } = transportConfig; | ||
const transport = { | ||
function createArmedBatchJsonRpcTransport(transportConfig, pendingRequests) { | ||
const overrides = { | ||
async sendBatch() { | ||
return await sendPayload(pendingMessages, url); | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
payload, | ||
url: transportConfig.url | ||
}); | ||
const requestOrder = payload.map((p) => p.id); | ||
return responses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => { | ||
if ("error" in response) { | ||
throw new SolanaJsonRpcError(response.error); | ||
} else { | ||
const { responseProcessor } = pendingRequests[ii]; | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
} | ||
}); | ||
} | ||
}; | ||
return makeProxy(transport, transportConfig, pendingMessages); | ||
return makeProxy(transportConfig, overrides, pendingRequests); | ||
} | ||
function makeProxy(transport, transportConfig, pendingRequestOrRequests) { | ||
const { onIntegerOverflow } = transportConfig; | ||
return new Proxy(transport, { | ||
function makeProxy(transportConfig, overrides, pendingRequestOrRequests) { | ||
return new Proxy(transportConfig.api, { | ||
defineProperty() { | ||
@@ -161,18 +115,15 @@ return false; | ||
}, | ||
get(...args) { | ||
const [target, p] = args; | ||
return p in target ? Reflect.get(...args) : function(...params) { | ||
get(target, p, receiver) { | ||
if (overrides && Reflect.has(overrides, p)) { | ||
return Reflect.get(overrides, p, receiver); | ||
} | ||
return function(...rawParams) { | ||
const methodName = p.toString(); | ||
const patchedParams = patchParamsForSolanaLabsRpc( | ||
params, | ||
onIntegerOverflow ? (keyPath, value) => { | ||
onIntegerOverflow(methodName, keyPath, value); | ||
} : void 0 | ||
); | ||
const newMessage = createJsonRpcMessage(methodName, patchedParams); | ||
const createTransportRequest = Reflect.get(target, methodName, receiver); | ||
const newRequest = createTransportRequest ? createTransportRequest(...rawParams) : { methodName, params: rawParams }; | ||
if (pendingRequestOrRequests == null) { | ||
return createArmedJsonRpcTransport(transportConfig, newMessage); | ||
return createArmedJsonRpcTransport(transportConfig, newRequest); | ||
} else { | ||
const nextPendingMessages = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newMessage] : [pendingRequestOrRequests, newMessage]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingMessages); | ||
const nextPendingRequests = Array.isArray(pendingRequestOrRequests) ? [...pendingRequestOrRequests, newRequest] : [pendingRequestOrRequests, newRequest]; | ||
return createArmedBatchJsonRpcTransport(transportConfig, nextPendingRequests); | ||
} | ||
@@ -183,29 +134,4 @@ }; | ||
} | ||
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` | ||
); | ||
return patchedResponse; | ||
} | ||
} | ||
async function sendPayload(payload, url) { | ||
const responseOrResponses = await makeHttpRequest({ | ||
payload, | ||
url | ||
}); | ||
if (Array.isArray(responseOrResponses)) { | ||
const requestOrder = payload.map((p) => p.id); | ||
return responseOrResponses.sort((a, b) => requestOrder.indexOf(a.id) - requestOrder.indexOf(b.id)).map((response, ii) => processResponse(response, payload[ii].method)); | ||
} else { | ||
return processResponse(responseOrResponses, payload.method); | ||
} | ||
} | ||
function createJsonRpcTransport(transportConfig) { | ||
const transport = {}; | ||
return makeProxy(transport, transportConfig); | ||
return makeProxy(transportConfig); | ||
} | ||
@@ -212,0 +138,0 @@ |
@@ -1,296 +0,3 @@ | ||
import { ArmedTransport } from './json-rpc-transport-types'; | ||
type TransportConfig = Readonly<{ | ||
onIntegerOverflow?: (method: string, keyPath: (number | string)[], value: bigint) => void; | ||
url: string; | ||
}>; | ||
export declare function createJsonRpcTransport<TRpcApi extends object>(transportConfig: TransportConfig): { [TMethodName in keyof TRpcApi]: ((((TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never) extends infer T ? { [P in keyof T]: (TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P] extends (...args: any[]) => any ? (...args: Parameters<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>) => ArmedTransport<TRpcApi, ReturnType<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>> : never; } : never) extends infer T_2 ? T_2 extends ((TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never) extends infer T ? { [P in keyof T]: (TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P] extends (...args: any[]) => any ? (...args: Parameters<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>) => ArmedTransport<TRpcApi, ReturnType<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>> : never; } : never) ? T_2 extends (infer Item)[] ? Item : never : never : never) extends infer T_3 ? T_3 extends (((TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never) extends infer T ? { [P in keyof T]: (TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P] extends (...args: any[]) => any ? (...args: Parameters<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>) => ArmedTransport<TRpcApi, ReturnType<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>> : never; } : never) extends infer T_2 ? T_2 extends ((TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never) extends infer T ? { [P in keyof T]: (TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P] extends (...args: any[]) => any ? (...args: Parameters<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>) => ArmedTransport<TRpcApi, ReturnType<(TRpcApi[TMethodName] extends infer T_1 ? T_1 extends TRpcApi[TMethodName] ? T_1 extends { | ||
(...args: infer A1): infer R1; | ||
(...args: infer A2): infer R2; | ||
(...args: infer A3): infer R3; | ||
(...args: infer A4): infer R4; | ||
(...args: infer A5): infer R5; | ||
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T_1 extends { | ||
(...args: infer A1_1): infer R1_1; | ||
(...args: infer A2_1): infer R2_1; | ||
(...args: infer A3_1): infer R3_1; | ||
(...args: infer A4_1): infer R4_1; | ||
} ? [(...args: A1_1) => R1_1, (...args: A2_1) => R2_1, (...args: A3_1) => R3_1, (...args: A4_1) => R4_1] : T_1 extends { | ||
(...args: infer A1_2): infer R1_2; | ||
(...args: infer A2_2): infer R2_2; | ||
(...args: infer A3_2): infer R3_2; | ||
} ? [(...args: A1_2) => R1_2, (...args: A2_2) => R2_2, (...args: A3_2) => R3_2] : T_1 extends { | ||
(...args: infer A1_3): infer R1_3; | ||
(...args: infer A2_3): infer R2_3; | ||
} ? [(...args: A1_3) => R1_3, (...args: A2_3) => R2_3] : T_1 extends (...args: infer A1_4) => infer R1_4 ? [(...args: A1_4) => R1_4] : unknown : never : never)[P]>> : never; } : never) ? T_2 extends (infer Item)[] ? Item : never : never : never) ? T_3 extends unknown ? (x: T_3) => unknown : never : never : never) extends (x: infer R) => unknown ? R : never; }; | ||
export {}; | ||
import { Transport, TransportConfig } from './json-rpc-transport-types'; | ||
export declare function createJsonRpcTransport<TRpcMethods>(transportConfig: TransportConfig<TRpcMethods>): Transport<TRpcMethods>; | ||
//# sourceMappingURL=index.d.ts.map |
/** | ||
* Public API. | ||
*/ | ||
export type Transport<TApi> = TransportMethods<TApi>; | ||
export type ArmedTransport<TApi, TResponse> = ArmedTransportMethods<TApi, TResponse> & { | ||
export type IRpcApi<TRpcMethods> = { | ||
[MethodName in keyof TRpcMethods]: TRpcMethods[MethodName] extends Callable ? (...rawParams: unknown[]) => TransportRequest<ReturnType<TRpcMethods[MethodName]>> : never; | ||
}; | ||
export type Transport<TRpcMethods> = TransportMethods<TRpcMethods>; | ||
export type TransportConfig<TRpcMethods> = Readonly<{ | ||
api: IRpcApi<TRpcMethods>; | ||
url: string; | ||
}>; | ||
export type TransportRequest<TResponse> = { | ||
methodName: string; | ||
params: unknown[]; | ||
responseProcessor?: (response: unknown) => TResponse; | ||
}; | ||
export interface ArmedTransportOwnMethods<TResponse> { | ||
send(): Promise<TResponse>; | ||
}; | ||
export type ArmedBatchTransport<TApi, TResponses extends unknown[]> = ArmedBatchTransportMethods<TApi, TResponses> & { | ||
} | ||
export type ArmedTransport<TRpcMethods, TResponse> = ArmedTransportMethods<TRpcMethods, TResponse> & ArmedTransportOwnMethods<TResponse>; | ||
export interface ArmedBatchTransportOwnMethods<TResponses> { | ||
sendBatch(): Promise<TResponses>; | ||
}; | ||
} | ||
export type ArmedBatchTransport<TRpcMethods, TResponses extends unknown[]> = ArmedBatchTransportMethods<TRpcMethods, TResponses> & ArmedBatchTransportOwnMethods<TResponses>; | ||
/** | ||
* Private transport-building types. | ||
*/ | ||
type TransportMethods<TApi> = { | ||
[TMethodName in keyof TApi]: ArmedTransportReturner<TApi, ApiMethodImplementations<TApi, TMethodName>>; | ||
type TransportMethods<TRpcMethods> = { | ||
[TMethodName in keyof TRpcMethods]: ArmedTransportReturner<TRpcMethods, ApiMethodImplementations<TRpcMethods, TMethodName>>; | ||
}; | ||
type ArmedTransportMethods<TApi, TResponse> = ArmedBatchTransportMethods<TApi, [TResponse]>; | ||
type ArmedBatchTransportMethods<TApi, TResponses extends unknown[]> = { | ||
[TMethodName in keyof TApi]: ArmedBatchTransportReturner<TApi, ApiMethodImplementations<TApi, TMethodName>, TResponses>; | ||
type ArmedTransportMethods<TRpcMethods, TResponse> = ArmedBatchTransportMethods<TRpcMethods, [TResponse]>; | ||
type ArmedBatchTransportMethods<TRpcMethods, TResponses extends unknown[]> = { | ||
[TMethodName in keyof TRpcMethods]: ArmedBatchTransportReturner<TRpcMethods, ApiMethodImplementations<TRpcMethods, TMethodName>, TResponses>; | ||
}; | ||
type ApiMethodImplementations<TApi, TMethod extends keyof TApi> = Overloads<TApi[TMethod]>; | ||
type ArmedTransportReturner<TApi, TMethodImplementations> = UnionToIntersection<Flatten<{ | ||
[P in keyof TMethodImplementations]: TMethodImplementations[P] extends Callable ? (...args: Parameters<TMethodImplementations[P]>) => ArmedTransport<TApi, ReturnType<TMethodImplementations[P]>> : never; | ||
type ApiMethodImplementations<TRpcMethods, TMethod extends keyof TRpcMethods> = Overloads<TRpcMethods[TMethod]>; | ||
type ArmedTransportReturner<TRpcMethods, TMethodImplementations> = UnionToIntersection<Flatten<{ | ||
[P in keyof TMethodImplementations]: TMethodImplementations[P] extends Callable ? (...args: Parameters<TMethodImplementations[P]>) => ArmedTransport<TRpcMethods, ReturnType<TMethodImplementations[P]>> : never; | ||
}>>; | ||
type ArmedBatchTransportReturner<TApi, TMethodImplementations, TResponses extends unknown[]> = UnionToIntersection<Flatten<{ | ||
[P in keyof TMethodImplementations]: TMethodImplementations[P] extends Callable ? (...args: Parameters<TMethodImplementations[P]>) => ArmedBatchTransport<TApi, [...TResponses, ReturnType<TMethodImplementations[P]>]> : never; | ||
type ArmedBatchTransportReturner<TRpcMethods, TMethodImplementations, TResponses extends unknown[]> = UnionToIntersection<Flatten<{ | ||
[P in keyof TMethodImplementations]: TMethodImplementations[P] extends Callable ? (...args: Parameters<TMethodImplementations[P]>) => ArmedBatchTransport<TRpcMethods, [...TResponses, ReturnType<TMethodImplementations[P]>]> : never; | ||
}>>; | ||
@@ -28,0 +42,0 @@ /** |
{ | ||
"name": "@solana/rpc-transport", | ||
"version": "2.0.0-experimental.cf4231e", | ||
"version": "2.0.0-experimental.f10010c", | ||
"description": "Network transports for accessing the Solana JSON RPC API", | ||
@@ -49,3 +49,3 @@ "exports": { | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^0.0.4", | ||
"@solana/eslint-config-solana": "^1.0.0", | ||
"@swc/core": "^1.3.18", | ||
@@ -55,6 +55,6 @@ "@swc/jest": "^0.2.23", | ||
"@types/node-fetch": "2", | ||
"@typescript-eslint/eslint-plugin": "^5.43.0", | ||
"@typescript-eslint/parser": "^5.43.0", | ||
"agadoo": "^2.0.0", | ||
"eslint": "^8.27.0", | ||
"@typescript-eslint/eslint-plugin": "^5.57.1", | ||
"@typescript-eslint/parser": "^5.57.1", | ||
"agadoo": "^3.0.0", | ||
"eslint": "^8.37.0", | ||
"eslint-plugin-jest": "^27.1.5", | ||
@@ -73,3 +73,3 @@ "eslint-plugin-react-hooks": "^4.6.0", | ||
"turbo": "^1.6.3", | ||
"typescript": "^4.9", | ||
"typescript": "^5.0.3", | ||
"version-from-git": "^1.1.1", | ||
@@ -91,4 +91,3 @@ "@solana/fetch-impl-browser": "0.0.0-development", | ||
"node-fetch": "^2.6.7", | ||
"@solana/keys": "2.0.0-experimental.cf4231e", | ||
"@solana/rpc-core": "2.0.0-experimental.cf4231e" | ||
"@solana/keys": "2.0.0-experimental.f10010c" | ||
}, | ||
@@ -98,3 +97,3 @@ "scripts": { | ||
"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", | ||
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch", | ||
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks", | ||
@@ -107,5 +106,5 @@ "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent", | ||
"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
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
2
109527
29
928
+ Added@solana/keys@2.0.0-experimental.f10010c(transitive)
- Removed@solana/keys@2.0.0-experimental.cf4231e(transitive)
- Removed@solana/rpc-core@2.0.0-experimental.cf4231e(transitive)