web3-core
Advanced tools
Comparing version 4.3.3-dev.16a2c27.0 to 4.3.3-dev.1ab7a6b.0
@@ -1,2 +0,2 @@ | ||
import { HexString, Transaction } from 'web3-types'; | ||
import { HexString, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIRequest, Web3APIReturnType } from 'web3-types'; | ||
export declare type TransactionTypeParser = (transaction: Transaction) => HexString | undefined; | ||
@@ -11,1 +11,9 @@ export interface Method { | ||
} | ||
export interface RequestManagerMiddleware<API> { | ||
processRequest<AnotherMethod extends Web3APIMethod<API>>(request: Web3APIRequest<API, AnotherMethod>, options?: { | ||
[key: string]: unknown; | ||
}): Promise<Web3APIRequest<API, AnotherMethod>>; | ||
processResponse<AnotherMethod extends Web3APIMethod<API>, ResponseType = Web3APIReturnType<API, AnotherMethod>>(response: JsonRpcResponse<ResponseType>, options?: { | ||
[key: string]: unknown; | ||
}): Promise<JsonRpcResponse<ResponseType>>; | ||
} |
import { EthExecutionAPI, HexString, Numbers, SupportedProviders, Transaction, Web3AccountProvider, Web3APISpec, Web3BaseProvider, Web3BaseWallet, Web3BaseWalletAccount } from 'web3-types'; | ||
import { BaseTransaction } from 'web3-eth-accounts'; | ||
import { ExtensionObject } from './types.js'; | ||
import { ExtensionObject, RequestManagerMiddleware } from './types.js'; | ||
import { Web3BatchRequest } from './web3_batch_request.js'; | ||
@@ -31,2 +31,3 @@ import { Web3Config, Web3ConfigOptions } from './web3_config.js'; | ||
wallet?: Web3BaseWallet<Web3BaseWalletAccount>; | ||
requestManagerMiddleware?: RequestManagerMiddleware<API>; | ||
}; | ||
@@ -156,2 +157,3 @@ export declare type Web3ContextConstructor<T extends Web3Context, T2 extends unknown[]> = new (...args: [...extras: T2, context: Web3ContextObject]) => T; | ||
setProvider(provider?: SupportedProviders<API> | string): boolean; | ||
setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void; | ||
/** | ||
@@ -158,0 +160,0 @@ * Will return the {@link Web3BatchRequest} constructor. |
@@ -52,6 +52,6 @@ "use strict"; | ||
} | ||
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, } = providerOrContext; | ||
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, requestManagerMiddleware } = providerOrContext; | ||
this.setConfig(config !== null && config !== void 0 ? config : {}); | ||
this._requestManager = | ||
requestManager !== null && requestManager !== void 0 ? requestManager : new web3_request_manager_js_1.Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout); | ||
requestManager !== null && requestManager !== void 0 ? requestManager : new web3_request_manager_js_1.Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout, requestManagerMiddleware); | ||
if (subscriptionManager) { | ||
@@ -238,2 +238,5 @@ this._subscriptionManager = subscriptionManager; | ||
} | ||
setRequestManagerMiddleware(requestManagerMiddleware) { | ||
this.requestManager.setMiddleware(requestManagerMiddleware); | ||
} | ||
/** | ||
@@ -240,0 +243,0 @@ * Will return the {@link Web3BatchRequest} constructor. |
import { EthExecutionAPI, JsonRpcBatchRequest, JsonRpcBatchResponse, SupportedProviders, Web3APIMethod, Web3APIRequest, Web3APIReturnType, Web3APISpec, Web3BaseProviderConstructor } from 'web3-types'; | ||
import { Web3EventEmitter } from './web3_event_emitter.js'; | ||
import { RequestManagerMiddleware } from './types.js'; | ||
export declare enum Web3RequestManagerEvent { | ||
@@ -12,3 +13,4 @@ PROVIDER_CHANGED = "PROVIDER_CHANGED", | ||
private readonly useRpcCallSpecification?; | ||
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean); | ||
middleware?: RequestManagerMiddleware<API>; | ||
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean, requestManagerMiddleware?: RequestManagerMiddleware<API>); | ||
/** | ||
@@ -40,2 +42,3 @@ * Will return all available providers | ||
setProvider(provider?: SupportedProviders<API> | string): boolean; | ||
setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void; | ||
/** | ||
@@ -42,0 +45,0 @@ * |
@@ -48,3 +48,3 @@ "use strict"; | ||
class Web3RequestManager extends web3_event_emitter_js_1.Web3EventEmitter { | ||
constructor(provider, useRpcCallSpecification) { | ||
constructor(provider, useRpcCallSpecification, requestManagerMiddleware) { | ||
super(); | ||
@@ -55,2 +55,4 @@ if (!(0, web3_utils_1.isNullish)(provider)) { | ||
this.useRpcCallSpecification = useRpcCallSpecification; | ||
if (!(0, web3_utils_1.isNullish)(requestManagerMiddleware)) | ||
this.middleware = requestManagerMiddleware; | ||
} | ||
@@ -111,2 +113,5 @@ /** | ||
} | ||
setMiddleware(requestManagerMiddleware) { | ||
this.middleware = requestManagerMiddleware; | ||
} | ||
/** | ||
@@ -123,3 +128,8 @@ * | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this._sendRequest(request); | ||
let requestObj = Object.assign({}, request); | ||
if (!(0, web3_utils_1.isNullish)(this.middleware)) | ||
requestObj = yield this.middleware.processRequest(requestObj); | ||
let response = yield this._sendRequest(requestObj); | ||
if (!(0, web3_utils_1.isNullish)(this.middleware)) | ||
response = yield this.middleware.processResponse(response); | ||
if (web3_utils_1.jsonRpc.isResponseWithResult(response)) { | ||
@@ -126,0 +136,0 @@ return response.result; |
@@ -49,6 +49,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, } = providerOrContext; | ||
const { config, provider, requestManager, subscriptionManager, registeredSubscriptions, accountProvider, wallet, requestManagerMiddleware } = providerOrContext; | ||
this.setConfig(config !== null && config !== void 0 ? config : {}); | ||
this._requestManager = | ||
requestManager !== null && requestManager !== void 0 ? requestManager : new Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout); | ||
requestManager !== null && requestManager !== void 0 ? requestManager : new Web3RequestManager(provider, (_a = config === null || config === void 0 ? void 0 : config.enableExperimentalFeatures) === null || _a === void 0 ? void 0 : _a.useSubscriptionWhenCheckingBlockTimeout, requestManagerMiddleware); | ||
if (subscriptionManager) { | ||
@@ -235,2 +235,5 @@ this._subscriptionManager = subscriptionManager; | ||
} | ||
setRequestManagerMiddleware(requestManagerMiddleware) { | ||
this.requestManager.setMiddleware(requestManagerMiddleware); | ||
} | ||
/** | ||
@@ -237,0 +240,0 @@ * Will return the {@link Web3BatchRequest} constructor. |
@@ -42,3 +42,3 @@ /* | ||
export class Web3RequestManager extends Web3EventEmitter { | ||
constructor(provider, useRpcCallSpecification) { | ||
constructor(provider, useRpcCallSpecification, requestManagerMiddleware) { | ||
super(); | ||
@@ -49,2 +49,4 @@ if (!isNullish(provider)) { | ||
this.useRpcCallSpecification = useRpcCallSpecification; | ||
if (!isNullish(requestManagerMiddleware)) | ||
this.middleware = requestManagerMiddleware; | ||
} | ||
@@ -105,2 +107,5 @@ /** | ||
} | ||
setMiddleware(requestManagerMiddleware) { | ||
this.middleware = requestManagerMiddleware; | ||
} | ||
/** | ||
@@ -117,3 +122,8 @@ * | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this._sendRequest(request); | ||
let requestObj = Object.assign({}, request); | ||
if (!isNullish(this.middleware)) | ||
requestObj = yield this.middleware.processRequest(requestObj); | ||
let response = yield this._sendRequest(requestObj); | ||
if (!isNullish(this.middleware)) | ||
response = yield this.middleware.processResponse(response); | ||
if (jsonRpc.isResponseWithResult(response)) { | ||
@@ -120,0 +130,0 @@ return response.result; |
@@ -1,2 +0,2 @@ | ||
import { HexString, Transaction } from 'web3-types'; | ||
import { HexString, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIRequest, Web3APIReturnType } from 'web3-types'; | ||
export declare type TransactionTypeParser = (transaction: Transaction) => HexString | undefined; | ||
@@ -11,2 +11,10 @@ export interface Method { | ||
} | ||
export interface RequestManagerMiddleware<API> { | ||
processRequest<AnotherMethod extends Web3APIMethod<API>>(request: Web3APIRequest<API, AnotherMethod>, options?: { | ||
[key: string]: unknown; | ||
}): Promise<Web3APIRequest<API, AnotherMethod>>; | ||
processResponse<AnotherMethod extends Web3APIMethod<API>, ResponseType = Web3APIReturnType<API, AnotherMethod>>(response: JsonRpcResponse<ResponseType>, options?: { | ||
[key: string]: unknown; | ||
}): Promise<JsonRpcResponse<ResponseType>>; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
import { EthExecutionAPI, HexString, Numbers, SupportedProviders, Transaction, Web3AccountProvider, Web3APISpec, Web3BaseProvider, Web3BaseWallet, Web3BaseWalletAccount } from 'web3-types'; | ||
import { BaseTransaction } from 'web3-eth-accounts'; | ||
import { ExtensionObject } from './types.js'; | ||
import { ExtensionObject, RequestManagerMiddleware } from './types.js'; | ||
import { Web3BatchRequest } from './web3_batch_request.js'; | ||
@@ -31,2 +31,3 @@ import { Web3Config, Web3ConfigOptions } from './web3_config.js'; | ||
wallet?: Web3BaseWallet<Web3BaseWalletAccount>; | ||
requestManagerMiddleware?: RequestManagerMiddleware<API>; | ||
}; | ||
@@ -156,2 +157,3 @@ export declare type Web3ContextConstructor<T extends Web3Context, T2 extends unknown[]> = new (...args: [...extras: T2, context: Web3ContextObject]) => T; | ||
setProvider(provider?: SupportedProviders<API> | string): boolean; | ||
setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void; | ||
/** | ||
@@ -158,0 +160,0 @@ * Will return the {@link Web3BatchRequest} constructor. |
import { EthExecutionAPI, JsonRpcBatchRequest, JsonRpcBatchResponse, SupportedProviders, Web3APIMethod, Web3APIRequest, Web3APIReturnType, Web3APISpec, Web3BaseProviderConstructor } from 'web3-types'; | ||
import { Web3EventEmitter } from './web3_event_emitter.js'; | ||
import { RequestManagerMiddleware } from './types.js'; | ||
export declare enum Web3RequestManagerEvent { | ||
@@ -12,3 +13,4 @@ PROVIDER_CHANGED = "PROVIDER_CHANGED", | ||
private readonly useRpcCallSpecification?; | ||
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean); | ||
middleware?: RequestManagerMiddleware<API>; | ||
constructor(provider?: SupportedProviders<API> | string, useRpcCallSpecification?: boolean, requestManagerMiddleware?: RequestManagerMiddleware<API>); | ||
/** | ||
@@ -40,2 +42,3 @@ * Will return all available providers | ||
setProvider(provider?: SupportedProviders<API> | string): boolean; | ||
setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>): void; | ||
/** | ||
@@ -42,0 +45,0 @@ * |
{ | ||
"name": "web3-core", | ||
"version": "4.3.3-dev.16a2c27.0+16a2c27", | ||
"version": "4.3.3-dev.1ab7a6b.0+1ab7a6b", | ||
"description": "Web3 core tools for sub-packages. This is an internal package.", | ||
@@ -45,13 +45,13 @@ "main": "./lib/commonjs/index.js", | ||
"dependencies": { | ||
"web3-errors": "1.1.5-dev.16a2c27.0+16a2c27", | ||
"web3-eth-accounts": "4.1.2-dev.16a2c27.0+16a2c27", | ||
"web3-eth-iban": "4.0.8-dev.16a2c27.0+16a2c27", | ||
"web3-providers-http": "4.1.1-dev.16a2c27.0+16a2c27", | ||
"web3-providers-ws": "4.0.8-dev.16a2c27.0+16a2c27", | ||
"web3-types": "1.5.1-dev.16a2c27.0+16a2c27", | ||
"web3-utils": "4.2.2-dev.16a2c27.0+16a2c27", | ||
"web3-validator": "2.0.5-dev.16a2c27.0+16a2c27" | ||
"web3-errors": "1.1.5-dev.1ab7a6b.0+1ab7a6b", | ||
"web3-eth-accounts": "4.1.3-dev.1ab7a6b.0+1ab7a6b", | ||
"web3-eth-iban": "4.0.8-dev.1ab7a6b.0+1ab7a6b", | ||
"web3-providers-http": "4.1.1-dev.1ab7a6b.0+1ab7a6b", | ||
"web3-providers-ws": "4.0.8-dev.1ab7a6b.0+1ab7a6b", | ||
"web3-types": "1.6.1-dev.1ab7a6b.0+1ab7a6b", | ||
"web3-utils": "4.2.4-dev.1ab7a6b.0+1ab7a6b", | ||
"web3-validator": "2.0.6-dev.1ab7a6b.0+1ab7a6b" | ||
}, | ||
"optionalDependencies": { | ||
"web3-providers-ipc": "4.0.8-dev.16a2c27.0+16a2c27" | ||
"web3-providers-ipc": "4.0.8-dev.1ab7a6b.0+1ab7a6b" | ||
}, | ||
@@ -74,3 +74,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "16a2c27ba0eeb70d25a6e4e3fdb8bf5c2630753f" | ||
"gitHead": "1ab7a6b8aa46d5984d41fd69c78103fcf1f0973b" | ||
} |
@@ -18,3 +18,3 @@ /* | ||
import { HexString, Transaction } from 'web3-types'; | ||
import { HexString, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIRequest, Web3APIReturnType } from 'web3-types'; | ||
@@ -34,1 +34,16 @@ export type TransactionTypeParser = ( | ||
} | ||
export interface RequestManagerMiddleware<API> { | ||
processRequest< | ||
AnotherMethod extends Web3APIMethod<API> | ||
>( | ||
request: Web3APIRequest<API, AnotherMethod>, | ||
options?: { [key: string]: unknown }): Promise<Web3APIRequest<API, AnotherMethod>>; | ||
processResponse< | ||
AnotherMethod extends Web3APIMethod<API>, | ||
ResponseType = Web3APIReturnType<API, AnotherMethod>> | ||
( | ||
response: JsonRpcResponse<ResponseType>, | ||
options?: { [key: string]: unknown }): Promise<JsonRpcResponse<ResponseType>>; | ||
} |
@@ -28,3 +28,3 @@ /* | ||
// eslint-disable-next-line import/no-cycle | ||
import { ExtensionObject } from './types.js'; | ||
import { ExtensionObject, RequestManagerMiddleware } from './types.js'; | ||
import { Web3BatchRequest } from './web3_batch_request.js'; | ||
@@ -69,2 +69,3 @@ // eslint-disable-next-line import/no-cycle | ||
wallet?: Web3BaseWallet<Web3BaseWalletAccount>; | ||
requestManagerMiddleware?: RequestManagerMiddleware<API>; | ||
}; | ||
@@ -134,2 +135,3 @@ | ||
wallet, | ||
requestManagerMiddleware | ||
} = providerOrContext as Web3ContextInitOptions<API, RegisteredSubs>; | ||
@@ -144,2 +146,3 @@ | ||
config?.enableExperimentalFeatures?.useSubscriptionWhenCheckingBlockTimeout, | ||
requestManagerMiddleware | ||
); | ||
@@ -359,2 +362,7 @@ | ||
} | ||
public setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>){ | ||
this.requestManager.setMiddleware(requestManagerMiddleware); | ||
} | ||
/** | ||
@@ -361,0 +369,0 @@ * Will return the {@link Web3BatchRequest} constructor. |
@@ -55,2 +55,3 @@ /* | ||
import { Web3EventEmitter } from './web3_event_emitter.js'; | ||
import { RequestManagerMiddleware } from './types.js'; | ||
@@ -77,5 +78,8 @@ export enum Web3RequestManagerEvent { | ||
private readonly useRpcCallSpecification?: boolean; | ||
public middleware?: RequestManagerMiddleware<API>; | ||
public constructor( | ||
provider?: SupportedProviders<API> | string, | ||
useRpcCallSpecification?: boolean, | ||
requestManagerMiddleware?: RequestManagerMiddleware<API> | ||
) { | ||
@@ -88,4 +92,8 @@ super(); | ||
this.useRpcCallSpecification = useRpcCallSpecification; | ||
if (!isNullish(requestManagerMiddleware)) | ||
this.middleware = requestManagerMiddleware; | ||
} | ||
/** | ||
@@ -148,2 +156,6 @@ * Will return all available providers | ||
public setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>){ | ||
this.middleware = requestManagerMiddleware; | ||
} | ||
/** | ||
@@ -162,3 +174,13 @@ * | ||
>(request: Web3APIRequest<API, Method>): Promise<ResponseType> { | ||
const response = await this._sendRequest<Method, ResponseType>(request); | ||
let requestObj = {...request}; | ||
if (!isNullish(this.middleware)) | ||
requestObj = await this.middleware.processRequest(requestObj); | ||
let response = await this._sendRequest<Method, ResponseType>(requestObj); | ||
if (!isNullish(this.middleware)) | ||
response = await this.middleware.processResponse(response); | ||
if (jsonRpc.isResponseWithResult(response)) { | ||
@@ -165,0 +187,0 @@ return response.result; |
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
477827
8402