@solana/rpc-transport
Advanced tools
Comparing version 2.0.0-experimental.63c7492 to 2.0.0-experimental.6466d76
// ../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; | ||
}, | ||
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/apis/subscriptions/subscriptions-api.ts | ||
function createJsonRpcSubscriptionsApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const notificationName = p.toString(); | ||
return function(...rawParams) { | ||
const params = config?.parametersTransformer ? config?.parametersTransformer(rawParams, notificationName) : rawParams; | ||
const responseTransformer = config?.responseTransformer ? config?.responseTransformer : (rawResponse) => rawResponse; | ||
const subscribeMethodName = config?.subscribeNotificationNameTransformer ? config?.subscribeNotificationNameTransformer(notificationName) : notificationName; | ||
const unsubscribeMethodName = config?.unsubscribeNotificationNameTransformer ? config?.unsubscribeNotificationNameTransformer(notificationName) : notificationName; | ||
return { | ||
params, | ||
responseTransformer, | ||
subscribeMethodName, | ||
unsubscribeMethodName | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
// src/json-rpc-errors.ts | ||
@@ -41,3 +94,3 @@ var SolanaJsonRpcError = class extends Error { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const { methodName, params, responseTransformer } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
@@ -51,3 +104,3 @@ const response = await rpcConfig.transport({ | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
return responseTransformer ? responseTransformer(response.result, methodName) : response.result; | ||
} | ||
@@ -91,3 +144,3 @@ } | ||
} | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) { | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseTransformer }) { | ||
return { | ||
@@ -138,3 +191,3 @@ async subscribe({ abortSignal }) { | ||
const notification = message.params.result; | ||
yield responseProcessor ? responseProcessor(notification) : notification; | ||
yield responseTransformer ? responseTransformer(notification, subscribeMethodName) : notification; | ||
} | ||
@@ -449,4 +502,4 @@ } | ||
export { createHttpTransport, createJsonRpc, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
export { createHttpTransport, createJsonRpc, createJsonRpcApi, createJsonRpcSubscriptionsApi, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
// ../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; | ||
}, | ||
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/apis/subscriptions/subscriptions-api.ts | ||
function createJsonRpcSubscriptionsApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const notificationName = p.toString(); | ||
return function(...rawParams) { | ||
const params = config?.parametersTransformer ? config?.parametersTransformer(rawParams, notificationName) : rawParams; | ||
const responseTransformer = config?.responseTransformer ? config?.responseTransformer : (rawResponse) => rawResponse; | ||
const subscribeMethodName = config?.subscribeNotificationNameTransformer ? config?.subscribeNotificationNameTransformer(notificationName) : notificationName; | ||
const unsubscribeMethodName = config?.unsubscribeNotificationNameTransformer ? config?.unsubscribeNotificationNameTransformer(notificationName) : notificationName; | ||
return { | ||
params, | ||
responseTransformer, | ||
subscribeMethodName, | ||
unsubscribeMethodName | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
// src/json-rpc-errors.ts | ||
@@ -41,3 +94,3 @@ var SolanaJsonRpcError = class extends Error { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const { methodName, params, responseTransformer } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
@@ -51,3 +104,3 @@ const response = await rpcConfig.transport({ | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
return responseTransformer ? responseTransformer(response.result, methodName) : response.result; | ||
} | ||
@@ -91,3 +144,3 @@ } | ||
} | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) { | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseTransformer }) { | ||
return { | ||
@@ -138,3 +191,3 @@ async subscribe({ abortSignal }) { | ||
const notification = message.params.result; | ||
yield responseProcessor ? responseProcessor(notification) : notification; | ||
yield responseTransformer ? responseTransformer(notification, subscribeMethodName) : notification; | ||
} | ||
@@ -449,4 +502,4 @@ } | ||
export { createHttpTransport, createJsonRpc, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
export { createHttpTransport, createJsonRpc, createJsonRpcApi, createJsonRpcSubscriptionsApi, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -6,2 +6,55 @@ import e2 from 'ws'; | ||
// src/apis/methods/methods-api.ts | ||
function createJsonRpcApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
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/apis/subscriptions/subscriptions-api.ts | ||
function createJsonRpcSubscriptionsApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const notificationName = p.toString(); | ||
return function(...rawParams) { | ||
const params = config?.parametersTransformer ? config?.parametersTransformer(rawParams, notificationName) : rawParams; | ||
const responseTransformer = config?.responseTransformer ? config?.responseTransformer : (rawResponse) => rawResponse; | ||
const subscribeMethodName = config?.subscribeNotificationNameTransformer ? config?.subscribeNotificationNameTransformer(notificationName) : notificationName; | ||
const unsubscribeMethodName = config?.unsubscribeNotificationNameTransformer ? config?.unsubscribeNotificationNameTransformer(notificationName) : notificationName; | ||
return { | ||
params, | ||
responseTransformer, | ||
subscribeMethodName, | ||
unsubscribeMethodName | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
// src/json-rpc-errors.ts | ||
@@ -44,3 +97,3 @@ var SolanaJsonRpcError = class extends Error { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const { methodName, params, responseTransformer } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
@@ -54,3 +107,3 @@ const response = await rpcConfig.transport({ | ||
} else { | ||
return responseProcessor ? responseProcessor(response.result) : response.result; | ||
return responseTransformer ? responseTransformer(response.result, methodName) : response.result; | ||
} | ||
@@ -94,3 +147,3 @@ } | ||
} | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) { | ||
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseTransformer }) { | ||
return { | ||
@@ -141,3 +194,3 @@ async subscribe({ abortSignal }) { | ||
const notification = message.params.result; | ||
yield responseProcessor ? responseProcessor(notification) : notification; | ||
yield responseTransformer ? responseTransformer(notification, subscribeMethodName) : notification; | ||
} | ||
@@ -450,4 +503,4 @@ } | ||
export { createHttpTransport, createJsonRpc, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
export { createHttpTransport, createJsonRpc, createJsonRpcApi, createJsonRpcSubscriptionsApi, createJsonSubscriptionRpc, createWebSocketTransport }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -0,1 +1,4 @@ | ||
export * from './apis/api-types.js'; | ||
export * from './apis/methods/methods-api.js'; | ||
export * from './apis/subscriptions/subscriptions-api.js'; | ||
export * from './json-rpc.js'; | ||
@@ -2,0 +5,0 @@ export type { SolanaJsonRpcErrorCode } from './json-rpc-errors.js'; |
@@ -27,7 +27,7 @@ import { IRpcTransport, IRpcWebSocketTransport } from './transports/transport-types.js'; | ||
params: unknown[]; | ||
responseProcessor?: (response: unknown) => TResponse; | ||
responseTransformer?: (response: unknown, methodName: string) => TResponse; | ||
}; | ||
export type RpcSubscription<TResponse> = { | ||
params: unknown[]; | ||
responseProcessor?: (response: unknown) => TResponse; | ||
responseTransformer?: (response: unknown, notificationName: string) => TResponse; | ||
subscribeMethodName: string; | ||
@@ -34,0 +34,0 @@ unsubscribeMethodName: string; |
{ | ||
"name": "@solana/rpc-transport", | ||
"version": "2.0.0-experimental.63c7492", | ||
"version": "2.0.0-experimental.6466d76", | ||
"description": "Network transports for accessing the Solana JSON RPC API", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -58,3 +58,3 @@ [![npm][npm-image]][npm-url] | ||
// Provide an optional function to modify the response. | ||
responseProcessor: response => ({ | ||
responseTransformer: response => ({ | ||
confirmedBlocks: response, | ||
@@ -61,0 +61,0 @@ queryRange: [startSlot, endSlot], |
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
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
388032
46
3816