@chainlink/external-adapter-framework 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/adapter/basic.d.ts +50 -6
- package/adapter/basic.js +165 -2
- package/adapter/basic.js.map +1 -1
- package/adapter/endpoint.d.ts +6 -6
- package/adapter/endpoint.js +1 -0
- package/adapter/endpoint.js.map +1 -1
- package/adapter/price.d.ts +38 -8
- package/adapter/price.js +43 -1
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +37 -14
- package/background-executor.js +19 -4
- package/background-executor.js.map +1 -1
- package/cache/index.d.ts +9 -16
- package/cache/index.js +4 -46
- package/cache/index.js.map +1 -1
- package/config/index.d.ts +19 -11
- package/config/index.js +54 -39
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +17 -25
- package/examples/bank-frick/accounts.js +23 -13
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/config/index.d.ts +5 -0
- package/examples/bank-frick/config/index.js +5 -0
- package/examples/bank-frick/config/index.js.map +1 -1
- package/examples/bank-frick/index.d.ts +1 -15
- package/examples/bank-frick/index.js +1 -1
- package/examples/coingecko/src/config/index.d.ts +7 -0
- package/examples/coingecko/src/config/index.js +8 -1
- package/examples/coingecko/src/config/index.js.map +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +19 -4
- package/examples/coingecko/src/crypto-utils.js +1 -2
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +20 -3
- package/examples/coingecko/src/endpoint/coins.js +2 -2
- package/examples/coingecko/src/endpoint/coins.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto.d.ts +2 -4
- package/examples/coingecko/src/endpoint/crypto.js +2 -2
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -1
- package/examples/coingecko/src/endpoint/dominance.d.ts +2 -2
- package/examples/coingecko/src/endpoint/dominance.js +2 -2
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -1
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -1
- package/examples/coingecko/src/global-utils.d.ts +18 -3
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.js +3 -1
- package/examples/coingecko/src/index.js.map +1 -1
- package/examples/cryptocompare/src/config/index.d.ts +7 -0
- package/examples/cryptocompare/src/config/index.js +8 -1
- package/examples/cryptocompare/src/config/index.js.map +1 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +14 -2
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -1
- package/examples/cryptocompare/src/index.js +3 -1
- package/examples/cryptocompare/src/index.js.map +1 -1
- package/examples/genesis/config/index.d.ts +5 -0
- package/examples/genesis/config/index.js +5 -0
- package/examples/genesis/config/index.js.map +1 -1
- package/examples/genesis/index.js +1 -1
- package/examples/genesis/sseStream.d.ts +13 -2
- package/examples/genesis/sseStream.js +4 -1
- package/examples/genesis/sseStream.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +4 -6
- package/index.js.map +1 -1
- package/metrics/index.d.ts +2 -0
- package/metrics/index.js +5 -4
- package/metrics/index.js.map +1 -1
- package/metrics/util.d.ts +5 -5
- package/metrics/util.js.map +1 -1
- package/package.json +7 -9
- package/rate-limiting/background/fixed-frequency.d.ts +2 -3
- package/rate-limiting/background/fixed-frequency.js.map +1 -1
- package/rate-limiting/index.d.ts +4 -4
- package/rate-limiting/index.js +1 -1
- package/rate-limiting/index.js.map +1 -1
- package/rate-limiting/request/simple-counting.d.ts +2 -3
- package/rate-limiting/request/simple-counting.js.map +1 -1
- package/transports/batch-warming.d.ts +39 -17
- package/transports/batch-warming.js +43 -16
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +65 -31
- package/transports/index.js +2 -59
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +2 -2
- package/transports/metrics.js +2 -2
- package/transports/metrics.js.map +1 -1
- package/transports/rest.d.ts +42 -30
- package/transports/rest.js +17 -25
- package/transports/rest.js.map +1 -1
- package/transports/routing.d.ts +21 -0
- package/transports/routing.js +50 -0
- package/transports/routing.js.map +1 -0
- package/transports/sse.d.ts +40 -20
- package/transports/sse.js +10 -8
- package/transports/sse.js.map +1 -1
- package/transports/websocket.d.ts +40 -25
- package/transports/websocket.js +13 -16
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +2 -0
- package/util/logger.js +4 -7
- package/util/logger.js.map +1 -1
- package/util/request.d.ts +46 -10
- package/util/subscription-set/subscription-set.d.ts +1 -1
- package/util/subscription-set/subscription-set.js +1 -1
- package/util/subscription-set/subscription-set.js.map +1 -1
- package/util/test-payload-loader.d.ts +1 -0
- package/util/test-payload-loader.js +2 -1
- package/util/test-payload-loader.js.map +1 -1
- package/validation/error.d.ts +1 -3
- package/validation/error.js +2 -4
- package/validation/error.js.map +1 -1
- package/validation/index.js +26 -17
- package/validation/index.js.map +1 -1
- package/validation/input-params.d.ts +0 -1
- package/validation/input-params.js +0 -28
- package/validation/input-params.js.map +1 -1
- package/validation/input-validator.js +1 -2
- package/validation/input-validator.js.map +1 -1
- package/examples/coingecko-old/batch-warming.d.ts +0 -7
- package/examples/coingecko-old/batch-warming.js +0 -54
- package/examples/coingecko-old/batch-warming.js.map +0 -1
- package/examples/coingecko-old/index.d.ts +0 -2
- package/examples/coingecko-old/index.js +0 -12
- package/examples/coingecko-old/index.js.map +0 -1
- package/examples/coingecko-old/rest.d.ts +0 -12
- package/examples/coingecko-old/rest.js +0 -55
- package/examples/coingecko-old/rest.js.map +0 -1
- package/examples/ncfx/config/index.d.ts +0 -12
- package/examples/ncfx/config/index.js +0 -16
- package/examples/ncfx/config/index.js.map +0 -1
- package/examples/ncfx/index.d.ts +0 -13
- package/examples/ncfx/index.js +0 -12
- package/examples/ncfx/index.js.map +0 -1
- package/examples/ncfx/websocket.d.ts +0 -47
- package/examples/ncfx/websocket.js +0 -74
- package/examples/ncfx/websocket.js.map +0 -1
- package/validation/override-functions.d.ts +0 -3
- package/validation/override-functions.js +0 -41
- package/validation/override-functions.js.map +0 -1
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { Cache } from '../cache';
|
|
3
|
-
import { AdapterConfig
|
|
3
|
+
import { AdapterConfig } from '../config';
|
|
4
4
|
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
5
5
|
import { SubscriptionSet } from '../util';
|
|
6
|
-
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
7
|
-
import { Transport } from './';
|
|
6
|
+
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
7
|
+
import { Transport, TransportGenerics } from './';
|
|
8
8
|
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
9
|
+
/**
|
|
10
|
+
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
11
|
+
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
12
|
+
*/
|
|
13
|
+
declare type BatchWarmingTransportGenerics = TransportGenerics & {
|
|
14
|
+
/**
|
|
15
|
+
* Type details for any provider specific interfaces.
|
|
16
|
+
*/
|
|
17
|
+
Provider: {
|
|
18
|
+
/**
|
|
19
|
+
* Structure of the body of the request that will be sent to the data provider.
|
|
20
|
+
*/
|
|
21
|
+
RequestBody: unknown;
|
|
22
|
+
/**
|
|
23
|
+
* Structure for the body of the response coming from the data provider.
|
|
24
|
+
*/
|
|
25
|
+
ResponseBody: unknown;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Config object that is provided to the BatchWarmingTransport constructor.
|
|
30
|
+
*/
|
|
31
|
+
export interface BatchWarmingTransportConfig<T extends BatchWarmingTransportGenerics> {
|
|
32
|
+
prepareRequest: (params: T['Request']['Params'][], config: AdapterConfig<T['CustomSettings']>) => AxiosRequestConfig<T['Provider']['RequestBody']>;
|
|
33
|
+
parseResponse: (params: T['Request']['Params'][], res: AxiosResponse<T['Provider']['ResponseBody']>, config: AdapterConfig<T['CustomSettings']>) => ProviderResult<T>[];
|
|
34
|
+
}
|
|
9
35
|
/**
|
|
10
36
|
* Transport implementation that takes incoming batches requests and keeps a warm cache of values.
|
|
11
37
|
* Within the setup function, adapter params are added to an set that also keeps track and expires values.
|
|
@@ -14,22 +40,18 @@ import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
|
14
40
|
* The Data Provider response is, they are passed through the `parseResponse` function to create a [[CacheEntry]] list.
|
|
15
41
|
* Finally, the items in that [[CacheEntry]] list are set in the Cache so the Adapter can fetch values from there.
|
|
16
42
|
*
|
|
17
|
-
* @typeParam
|
|
18
|
-
* @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
|
|
19
|
-
* @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
|
|
43
|
+
* @typeParam T - all types related to the [[Transport]]
|
|
20
44
|
*/
|
|
21
|
-
export declare class BatchWarmingTransport<
|
|
45
|
+
export declare class BatchWarmingTransport<T extends BatchWarmingTransportGenerics> implements Transport<T> {
|
|
22
46
|
private config;
|
|
23
|
-
cache: Cache
|
|
47
|
+
cache: Cache<AdapterResponse<T['Response']>>;
|
|
24
48
|
rateLimiter: BackgroundExecuteRateLimiter;
|
|
25
|
-
subscriptionSet: SubscriptionSet<
|
|
49
|
+
subscriptionSet: SubscriptionSet<T['Request']['Params']>;
|
|
26
50
|
WARMER_ACTIVE: boolean;
|
|
27
|
-
constructor(config:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
hasBeenSetUp(): Promise<boolean>;
|
|
33
|
-
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
34
|
-
backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
|
|
51
|
+
constructor(config: BatchWarmingTransportConfig<T>);
|
|
52
|
+
initialize(dependencies: AdapterDependencies, _: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
53
|
+
registerRequest(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
54
|
+
backgroundExecute(context: AdapterContext<T>): Promise<number>;
|
|
55
|
+
private makeRequest;
|
|
35
56
|
}
|
|
57
|
+
export {};
|
|
@@ -30,6 +30,7 @@ const util_2 = require("./util");
|
|
|
30
30
|
const rateLimitMetrics = __importStar(require("../rate-limiting/metrics"));
|
|
31
31
|
const cacheMetrics = __importStar(require("../cache/metrics"));
|
|
32
32
|
const transportMetrics = __importStar(require("./metrics"));
|
|
33
|
+
const error_1 = require("../validation/error");
|
|
33
34
|
const WARMUP_BATCH_REQUEST_ID = '9002';
|
|
34
35
|
const logger = (0, util_1.makeLogger)('BatchWarmingTransport');
|
|
35
36
|
/**
|
|
@@ -40,9 +41,7 @@ const logger = (0, util_1.makeLogger)('BatchWarmingTransport');
|
|
|
40
41
|
* The Data Provider response is, they are passed through the `parseResponse` function to create a [[CacheEntry]] list.
|
|
41
42
|
* Finally, the items in that [[CacheEntry]] list are set in the Cache so the Adapter can fetch values from there.
|
|
42
43
|
*
|
|
43
|
-
* @typeParam
|
|
44
|
-
* @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
|
|
45
|
-
* @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
|
|
44
|
+
* @typeParam T - all types related to the [[Transport]]
|
|
46
45
|
*/
|
|
47
46
|
class BatchWarmingTransport {
|
|
48
47
|
constructor(config) {
|
|
@@ -57,11 +56,19 @@ class BatchWarmingTransport {
|
|
|
57
56
|
this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
|
|
58
57
|
}
|
|
59
58
|
// This might need coalescing to avoid too frequent ttl updates
|
|
60
|
-
async
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
async registerRequest(req, config) {
|
|
60
|
+
logger.debug(`Adding entry to subscription set (ttl ${config.WARMUP_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
61
|
+
if (config.BATCH_TRANSPORT_SETUP_VALIDATION) {
|
|
62
|
+
const response = await this.makeRequest([req.requestContext.data], config);
|
|
63
|
+
if (!response.results.length) {
|
|
64
|
+
throw new error_1.AdapterError({
|
|
65
|
+
statusCode: 200,
|
|
66
|
+
providerStatusCode: response.providerResponse.status,
|
|
67
|
+
message: response.providerResponse.message ||
|
|
68
|
+
'There was an error while validating the incoming request before adding to the batch subscription set',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
65
72
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WARMUP_SUBSCRIPTION_TTL);
|
|
66
73
|
}
|
|
67
74
|
async backgroundExecute(context) {
|
|
@@ -86,16 +93,15 @@ class BatchWarmingTransport {
|
|
|
86
93
|
cacheMetrics.cacheWarmerCount.labels({ isBatched: 'true' }).inc();
|
|
87
94
|
this.WARMER_ACTIVE = true;
|
|
88
95
|
}
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
const adapterResponses = (0, _1.buildCacheEntriesFromResults)(results, context);
|
|
96
|
+
const response = await this.makeRequest(entries, context.adapterConfig);
|
|
97
|
+
if (!response.results?.length) {
|
|
98
|
+
return interval;
|
|
99
|
+
}
|
|
100
|
+
const cacheEntries = (0, _1.buildCacheEntriesFromResults)(response.results, context);
|
|
95
101
|
logger.debug('Setting adapter responses in cache');
|
|
96
|
-
await this.cache.setMany(
|
|
102
|
+
await this.cache.setMany(cacheEntries, context.adapterConfig.CACHE_MAX_AGE);
|
|
97
103
|
// Record cost of data provider call
|
|
98
|
-
const cost = rateLimitMetrics.retrieveCost(providerResponse.data);
|
|
104
|
+
const cost = rateLimitMetrics.retrieveCost(response.providerResponse.data);
|
|
99
105
|
rateLimitMetrics.rateLimitCreditsSpentTotal
|
|
100
106
|
.labels({
|
|
101
107
|
feed_id: 'N/A',
|
|
@@ -104,6 +110,27 @@ class BatchWarmingTransport {
|
|
|
104
110
|
.inc(cost);
|
|
105
111
|
return interval;
|
|
106
112
|
}
|
|
113
|
+
async makeRequest(entries, config) {
|
|
114
|
+
logger.trace(`Have ${entries.length} entries in batch, preparing request...`);
|
|
115
|
+
const request = this.config.prepareRequest(entries, config);
|
|
116
|
+
logger.trace(`Sending request to data provider: ${JSON.stringify(request)}`);
|
|
117
|
+
let providerResponse;
|
|
118
|
+
try {
|
|
119
|
+
providerResponse = await (0, util_2.axiosRequest)(request, config);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
logger.warn(`There was an error while performing the batch request: ${e}`);
|
|
123
|
+
return {
|
|
124
|
+
results: [],
|
|
125
|
+
providerResponse: e,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
logger.debug(`Got response from provider, parsing (raw body: ${providerResponse.data})`);
|
|
129
|
+
return {
|
|
130
|
+
results: this.config.parseResponse(entries, providerResponse, config),
|
|
131
|
+
providerResponse,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
107
134
|
}
|
|
108
135
|
exports.BatchWarmingTransport = BatchWarmingTransport;
|
|
109
136
|
//# sourceMappingURL=batch-warming.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-warming.js","sourceRoot":"","sources":["../../../src/transports/batch-warming.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kCAAq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,GAAG,MAAM,IAAA,mBAAY,EAInC,OAAO,EAAE,MAAM,CAAC,CAAA;SACnB;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,0DAA0D,CAAC,EAAE,CAAC,CAAA;YAC1E,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,gBAAgB,EAAE,CAAkB;aACrC,CAAA;SACF;QAED,MAAM,CAAC,KAAK,CAAC,kDAAkD,gBAAgB,CAAC,IAAI,GAAG,CAAC,CAAA;QACxF,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC;YACrE,gBAAgB;SACjB,CAAA;IACH,CAAC;CACF;AArID,sDAqIC"}
|
package/transports/index.d.ts
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { CacheEntry } from '../cache';
|
|
1
|
+
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
2
|
+
import { Cache, CacheEntry } from '../cache';
|
|
4
3
|
import { AdapterConfig, SettingsMap } from '../config';
|
|
5
|
-
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
4
|
+
import { AdapterRequest, AdapterResponse, ProviderResult, RequestGenerics, ResponseGenerics } from '../util/request';
|
|
6
5
|
export * from './batch-warming';
|
|
7
6
|
export * from './rest';
|
|
8
|
-
export * from './websocket';
|
|
9
7
|
export * from './sse';
|
|
8
|
+
export * from './websocket';
|
|
9
|
+
/**
|
|
10
|
+
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
11
|
+
* Within the transport, given a generic param T extends TransportGenerics, these will be used like so:
|
|
12
|
+
*
|
|
13
|
+
* const request: AdapterRequest\<T['Request']\> = ...
|
|
14
|
+
*
|
|
15
|
+
* (ignore the slash characters, they're just for proper doc syntax \<)
|
|
16
|
+
*/
|
|
17
|
+
export declare type TransportGenerics = {
|
|
18
|
+
/**
|
|
19
|
+
* Type details about incoming Adapter requests to this Transport
|
|
20
|
+
*/
|
|
21
|
+
Request: RequestGenerics;
|
|
22
|
+
/**
|
|
23
|
+
* Type details about outbound responses from this Transport
|
|
24
|
+
*/
|
|
25
|
+
Response: ResponseGenerics;
|
|
26
|
+
/**
|
|
27
|
+
* Type for any custom settings used for this Transport
|
|
28
|
+
*/
|
|
29
|
+
CustomSettings: SettingsMap;
|
|
30
|
+
};
|
|
10
31
|
/**
|
|
11
32
|
* Generic interface for a Transport.
|
|
12
33
|
* A Transport defines the way in which an AdapterEndpoint will process incoming requests to
|
|
@@ -15,10 +36,10 @@ export * from './sse';
|
|
|
15
36
|
* This separation gives us the ability of splitting these concerns, and optionally parallelizing
|
|
16
37
|
* the reading and writing of data to a centralized Cache.
|
|
17
38
|
*
|
|
18
|
-
* @typeParam
|
|
19
|
-
* @typeParam Result - the structure of the AdapterResponse's body
|
|
39
|
+
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[TransportGenerics]])
|
|
20
40
|
*/
|
|
21
|
-
export interface Transport<
|
|
41
|
+
export interface Transport<T extends TransportGenerics> {
|
|
42
|
+
cache?: Cache<AdapterResponse<T['Response']>>;
|
|
22
43
|
/**
|
|
23
44
|
* Initializes the transport in the Adapter context.
|
|
24
45
|
*
|
|
@@ -26,33 +47,56 @@ export interface Transport<Params, Result, CustomSettings extends SettingsMap> {
|
|
|
26
47
|
* @param config - Adapter config containing env vars
|
|
27
48
|
* @returns an empty Promise
|
|
28
49
|
*/
|
|
29
|
-
initialize: (dependencies: AdapterDependencies, config: AdapterConfig
|
|
50
|
+
initialize: (dependencies: AdapterDependencies, config: AdapterConfig<T['CustomSettings']>, endpointName: string) => Promise<void>;
|
|
30
51
|
/**
|
|
31
|
-
*
|
|
32
|
-
* This
|
|
52
|
+
* Registers a request within the context of the transport.
|
|
53
|
+
* This means things like adding the request to a subscription set.
|
|
33
54
|
*
|
|
34
55
|
* @param req - the incoming AdapterRequest
|
|
35
|
-
* @
|
|
56
|
+
* @param config - common configuration for the Adapter as a whole
|
|
57
|
+
* @returns an empty Promise
|
|
36
58
|
*/
|
|
37
|
-
|
|
59
|
+
registerRequest?: (req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>) => Promise<void>;
|
|
38
60
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
61
|
+
* Performs a synchronous fetch/processing of information within the lifecycle of an incoming request.
|
|
62
|
+
* This is mostly intended to be used as a backwards compatibility mechanism, or for very specific cases where
|
|
63
|
+
* processing is expected to be very simple. Things like rate limiting for example won't be able to be applied
|
|
64
|
+
* to this method with more than one EA instance. It's heavily encouraged to instead rework adapter logic
|
|
65
|
+
* to perform as much of the work as possible (or all of it) in the backgroundExecute method.
|
|
42
66
|
*
|
|
43
67
|
* @param req - the incoming AdapterRequest
|
|
44
68
|
* @param config - common configuration for the Adapter as a whole
|
|
45
69
|
* @returns a Promise that _optionally_ returns an AdapterResponse, if the Transport has the capability of
|
|
46
70
|
* immediately fetching data and returning it without the background process.
|
|
47
71
|
*/
|
|
48
|
-
|
|
72
|
+
foregroundExecute?: (req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>) => Promise<AdapterResponse<{
|
|
73
|
+
Data: T['Response']['Data'];
|
|
74
|
+
Result: T['Response']['Result'];
|
|
75
|
+
}> | void>;
|
|
49
76
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
77
|
+
* Main function that will be called by the main background loop of the writer EA.
|
|
78
|
+
* All logic fetching from providers should live here.
|
|
52
79
|
*
|
|
53
80
|
* @param context - background context for the execution (e.g. endpoint name)
|
|
81
|
+
* @returns an empty Promise
|
|
54
82
|
*/
|
|
55
|
-
backgroundExecute?: (context: AdapterContext<
|
|
83
|
+
backgroundExecute?: (context: AdapterContext<T>) => Promise<number>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generic interface for a Transport that contains or manages other transports.
|
|
87
|
+
* Some transports, such as the RoutingTransport, do not directly fetch data from a Data Provider, but
|
|
88
|
+
* instead coordinate the execution of other transports for fetching and transforming data.
|
|
89
|
+
* These transports have alternative initialization procedures, which typically involve
|
|
90
|
+
* initializing each downstream transport.
|
|
91
|
+
*
|
|
92
|
+
* @typeParam Params - the structure of the AdapterRequest's body
|
|
93
|
+
* @typeParam Result - the structure of the AdapterResponse's body
|
|
94
|
+
* @typeParam CustomSettings - custom settings for the Adapter, or the default SettingsMap
|
|
95
|
+
*/
|
|
96
|
+
export interface MetaTransport<T extends TransportGenerics> extends Transport<T> {
|
|
97
|
+
transports: {
|
|
98
|
+
[key: string]: Transport<T>;
|
|
99
|
+
};
|
|
56
100
|
}
|
|
57
101
|
/**
|
|
58
102
|
* Helper method to build cache entries to set after getting a bunch of responses from a DP.
|
|
@@ -61,14 +105,4 @@ export interface Transport<Params, Result, CustomSettings extends SettingsMap> {
|
|
|
61
105
|
* @param context - context for the Adapter
|
|
62
106
|
* @returns a list of CacheEntries of AdapterResponses
|
|
63
107
|
*/
|
|
64
|
-
export declare const buildCacheEntriesFromResults: <
|
|
65
|
-
result: unknown;
|
|
66
|
-
}>>[];
|
|
67
|
-
/**
|
|
68
|
-
* Takes an Adapter, its configuration, and its dependencies, and it creates an express middleware
|
|
69
|
-
* that will pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
|
|
70
|
-
*
|
|
71
|
-
* @param adapter - main adapter object, already initialized
|
|
72
|
-
* @returns the transport handler middleware function
|
|
73
|
-
*/
|
|
74
|
-
export declare const buildTransportHandler: (adapter: Adapter) => (req: AdapterRequest, reply: FastifyReply) => Promise<never>;
|
|
108
|
+
export declare const buildCacheEntriesFromResults: <T extends TransportGenerics>(results: ProviderResult<T>[], context: AdapterContext<T>) => CacheEntry<AdapterResponse<T["Response"]>>[];
|
package/transports/index.js
CHANGED
|
@@ -10,31 +10,16 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
15
|
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
17
|
+
exports.buildCacheEntriesFromResults = void 0;
|
|
30
18
|
const cache_1 = require("../cache");
|
|
31
|
-
const util_1 = require("../util");
|
|
32
|
-
const transportMetrics = __importStar(require("./metrics"));
|
|
33
19
|
__exportStar(require("./batch-warming"), exports);
|
|
34
20
|
__exportStar(require("./rest"), exports);
|
|
35
|
-
__exportStar(require("./websocket"), exports);
|
|
36
21
|
__exportStar(require("./sse"), exports);
|
|
37
|
-
|
|
22
|
+
__exportStar(require("./websocket"), exports);
|
|
38
23
|
/**
|
|
39
24
|
* Helper method to build cache entries to set after getting a bunch of responses from a DP.
|
|
40
25
|
*
|
|
@@ -68,46 +53,4 @@ const buildCacheEntriesFromResults = (results, context) => results.map((r) => {
|
|
|
68
53
|
return cacheEntry;
|
|
69
54
|
});
|
|
70
55
|
exports.buildCacheEntriesFromResults = buildCacheEntriesFromResults;
|
|
71
|
-
/**
|
|
72
|
-
* Takes an Adapter, its configuration, and its dependencies, and it creates an express middleware
|
|
73
|
-
* that will pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
|
|
74
|
-
*
|
|
75
|
-
* @param adapter - main adapter object, already initialized
|
|
76
|
-
* @returns the transport handler middleware function
|
|
77
|
-
*/
|
|
78
|
-
const buildTransportHandler = (adapter) => async (req, reply) => {
|
|
79
|
-
// Get transport, must be here because it's already checked in the validator
|
|
80
|
-
const transport = adapter.endpointsMap[req.requestContext.endpointName].transport;
|
|
81
|
-
// Set up transport if it hasn't been done already
|
|
82
|
-
if (!(await transport.hasBeenSetUp(req))) {
|
|
83
|
-
logger.debug('Transport not set up yet, doing so...');
|
|
84
|
-
const immediateResponse = await transport.setup(req, adapter.config);
|
|
85
|
-
if (immediateResponse) {
|
|
86
|
-
logger.debug('Got immediate response from transport, sending as response');
|
|
87
|
-
return reply.send(immediateResponse);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Observe the idle time taken for polling response
|
|
91
|
-
const metricsTimer = transportMetrics.transportPollingDurationSeconds
|
|
92
|
-
.labels({ endpoint: req.requestContext.endpointName })
|
|
93
|
-
.startTimer();
|
|
94
|
-
logger.debug('Transport is set up, polling cache for response...');
|
|
95
|
-
const response = await (0, cache_1.pollResponseFromCache)(adapter.dependencies.cache, req.requestContext.cacheKey, {
|
|
96
|
-
maxRetries: adapter.config.CACHE_POLLING_MAX_RETRIES,
|
|
97
|
-
sleep: adapter.config.CACHE_POLLING_SLEEP_MS,
|
|
98
|
-
});
|
|
99
|
-
metricsTimer({ succeeded: String(!!response) });
|
|
100
|
-
if (response) {
|
|
101
|
-
logger.debug('Got a response from the cache, sending that back');
|
|
102
|
-
return reply.send(response);
|
|
103
|
-
}
|
|
104
|
-
// Record polling mechanism failure to return response
|
|
105
|
-
transportMetrics.transportPollingFailureCount
|
|
106
|
-
.labels({ endpoint: req.requestContext.endpointName })
|
|
107
|
-
.inc();
|
|
108
|
-
logger.debug('Ran out of polling attempts, returning timeout');
|
|
109
|
-
reply.statusCode = 504;
|
|
110
|
-
return reply.send();
|
|
111
|
-
};
|
|
112
|
-
exports.buildTransportHandler = buildTransportHandler;
|
|
113
56
|
//# sourceMappingURL=index.js.map
|
package/transports/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transports/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,oCAAgF;AAUhF,kDAA+B;AAC/B,yCAAsB;AACtB,wCAAqB;AACrB,8CAA2B;AAgH3B;;;;;;GAMG;AACI,MAAM,4BAA4B,GAAG,CAC1C,OAA4B,EAC5B,OAA0B,EACoB,EAAE,CAChD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;IAChB,MAAM,UAAU,GAAG;QACjB,GAAG,EAAE,IAAA,yBAAiB,EAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QACzC,KAAK,EAAE;YACL,MAAM,EAAE,CAAC,CAAC,KAAK;YACf,UAAU,EAAE,GAAG;YACf,IAAI,EAAE;gBACJ,MAAM,EAAE,CAAC,CAAC,KAAK;aAChB;SACF;KACF,CAAA;IAED,IACE,OAAO,CAAC,aAAa,CAAC,eAAe;QACrC,OAAO,CAAC,aAAa,CAAC,4BAA4B,EAClD;QACA,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,aAAa;YACxD,IAAI,EAAE;gBACJ,OAAO,EAAE;oBACP,MAAM,EAAE,IAAA,uBAAe,EAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;iBAC3C;aACF;SACF,CAAA;QACD,UAAU,CAAC,KAAK,GAAG,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,CAAA;KACvD;IACD,OAAO,UAAU,CAAA;AACnB,CAAC,CAAC,CAAA;AA/BS,QAAA,4BAA4B,gCA+BrC"}
|
package/transports/metrics.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as client from 'prom-client';
|
|
2
|
+
import { TransportGenerics } from '.';
|
|
2
3
|
import { AdapterContext } from '../adapter';
|
|
3
|
-
import { SettingsMap } from '../config';
|
|
4
4
|
export declare const dataProviderMetricsLabel: (providerStatusCode?: number, method?: string) => {
|
|
5
5
|
provider_status_code: number | undefined;
|
|
6
6
|
method: string;
|
|
@@ -14,7 +14,7 @@ export declare const messageSubsLabels: (feed_id: string, cache_key: string) =>
|
|
|
14
14
|
feed_id: string;
|
|
15
15
|
subscription_key: string;
|
|
16
16
|
};
|
|
17
|
-
export declare const recordWsMessageMetrics: <
|
|
17
|
+
export declare const recordWsMessageMetrics: <T extends TransportGenerics>(context: AdapterContext<T>, subscribes: T["Request"]["Params"][], unsubscribes: T["Request"]["Params"][]) => void;
|
|
18
18
|
export declare const wsConnectionActive: client.Gauge<"url">;
|
|
19
19
|
export declare const wsConnectionErrors: client.Counter<"message" | "url">;
|
|
20
20
|
export declare const wsSubscriptionActive: client.Gauge<"feed_id" | "connection_url" | "subscription_key">;
|
package/transports/metrics.js
CHANGED
|
@@ -57,7 +57,7 @@ exports.messageSubsLabels = messageSubsLabels;
|
|
|
57
57
|
// Record WS message and subscription metrics
|
|
58
58
|
// Recalculate cacheKey and feedId for metrics
|
|
59
59
|
// since avoiding storing extra info in expiring sorted set
|
|
60
|
-
const recordWsMessageMetrics = (context, subscribes,
|
|
60
|
+
const recordWsMessageMetrics = (context, subscribes, unsubscribes) => {
|
|
61
61
|
subscribes.forEach((param) => {
|
|
62
62
|
const feedId = (0, cache_1.calculateFeedId)(context, param);
|
|
63
63
|
const cacheKey = (0, cache_1.calculateCacheKey)(context, param);
|
|
@@ -68,7 +68,7 @@ const recordWsMessageMetrics = (context, subscribes, unsubscrices) => {
|
|
|
68
68
|
// Record number of active ws subscriptions
|
|
69
69
|
exports.wsSubscriptionActive.labels((0, exports.messageSubsLabels)(feedId, cacheKey)).inc();
|
|
70
70
|
});
|
|
71
|
-
|
|
71
|
+
unsubscribes.forEach((param) => {
|
|
72
72
|
const feedId = (0, cache_1.calculateFeedId)(context, param);
|
|
73
73
|
const cacheKey = (0, cache_1.calculateCacheKey)(context, param);
|
|
74
74
|
// Record total number of ws messages sent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/transports/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/transports/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AAGrC,oCAA6D;AAC7D,oDAA6D;AAE7D,wBAAwB;AACjB,MAAM,wBAAwB,GAAG,CAAC,kBAA2B,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC;IACxF,oBAAoB,EAAE,kBAAkB;IACxC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;CAC7B,CAAC,CAAA;AAHW,QAAA,wBAAwB,4BAGnC;AAEW,QAAA,oBAAoB,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC;IACrD,IAAI,EAAE,wBAAwB;IAC9B,IAAI,EAAE,8DAA8D;IACpE,UAAU,EAAE,CAAC,QAAQ,EAAE,sBAAsB,CAAU;CACxD,CAAC,CAAA;AAEW,QAAA,kCAAkC,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC;IACrE,IAAI,EAAE,wCAAwC;IAC9C,IAAI,EAAE,2EAA2E;IACjF,OAAO,EAAE,kCAAsB;CAChC,CAAC,CAAA;AAEF,oBAAoB;AACb,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,CAAC;IACzD,OAAO;IACP,OAAO;CACR,CAAC,CAAA;AAHW,QA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IAChE,UAAU,EAAE,CAAC,UAAU,EAAE,gBAAgB,CAAU;CACpD,CAAC,CAAA;AAEW,QAAA,4BAA4B,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC;IAC7D,IAAI,EAAE,iCAAiC;IACvC,IAAI,EAAE,+FAA+F;IACrG,UAAU,EAAE,CAAC,UAAU,CAAU;CAClC,CAAC,CAAA;AAEW,QAAA,+BAA+B,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC;IAC9D,IAAI,EAAE,oCAAoC;IAC1C,IAAI,EAAE,iFAAiF;IACvF,UAAU,EAAE,CAAC,UAAU,EAAE,WAAW,CAAU;CAC/C,CAAC,CAAA"}
|
package/transports/rest.d.ts
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
import { AdapterRequest, AdapterResponse } from '../util/request';
|
|
2
|
-
import { Transport } from './';
|
|
2
|
+
import { Transport, TransportGenerics } from './';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
4
|
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
5
|
-
import { AdapterConfig
|
|
5
|
+
import { AdapterConfig } from '../config';
|
|
6
6
|
import { RequestRateLimiter } from '../rate-limiting';
|
|
7
7
|
import { AdapterDependencies } from '../adapter';
|
|
8
8
|
export { AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse };
|
|
9
|
+
/**
|
|
10
|
+
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
11
|
+
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
12
|
+
*/
|
|
13
|
+
declare type RestTransportGenerics = TransportGenerics & {
|
|
14
|
+
/**
|
|
15
|
+
* Type details for any provider specific interfaces.
|
|
16
|
+
*/
|
|
17
|
+
Provider: {
|
|
18
|
+
/**
|
|
19
|
+
* Structure of the body of the request that will be sent to the data provider.
|
|
20
|
+
*/
|
|
21
|
+
RequestBody: unknown;
|
|
22
|
+
/**
|
|
23
|
+
* Structure for the body of the response coming from the data provider.
|
|
24
|
+
*/
|
|
25
|
+
ResponseBody: unknown;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Config object that is provided to the RestTransport constructor.
|
|
30
|
+
*/
|
|
31
|
+
export interface RestTransportConfig<T extends RestTransportGenerics> {
|
|
32
|
+
prepareRequest: (req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>) => AxiosRequestConfig<T['Provider']['RequestBody']> | Promise<AxiosRequestConfig<T['Provider']['RequestBody']>>;
|
|
33
|
+
parseResponse: (req: AdapterRequest<T['Request']>, res: AxiosResponse<T['Provider']['ResponseBody']>, config: AdapterConfig<T['CustomSettings']>) => AdapterResponse<T['Response']> | Promise<AdapterResponse<T['Response']>>;
|
|
34
|
+
options: {
|
|
35
|
+
requestCoalescing: {
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
entropyMax?: number;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
9
41
|
/**
|
|
10
42
|
* Transport implementation that takes incoming requests, transforms them into a DataProvider request,
|
|
11
43
|
* and executes that request returning the response immediately from the `setup` function.
|
|
@@ -13,39 +45,19 @@ export { AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse
|
|
|
13
45
|
* new adapter requests for the same feed will not trigger a new one, but return an empty promise from
|
|
14
46
|
* the setup instead so the normal cache polling mechanism is used.
|
|
15
47
|
*
|
|
16
|
-
* @typeParam
|
|
17
|
-
* @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
|
|
18
|
-
* @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
|
|
48
|
+
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[RestTransportGenerics]])
|
|
19
49
|
*/
|
|
20
|
-
export declare class RestTransport<
|
|
21
|
-
protected config:
|
|
22
|
-
prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
|
|
23
|
-
parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
|
|
24
|
-
options: {
|
|
25
|
-
requestCoalescing: {
|
|
26
|
-
enabled: boolean;
|
|
27
|
-
entropyMax?: number;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
50
|
+
export declare class RestTransport<T extends RestTransportGenerics> implements Transport<T> {
|
|
51
|
+
protected config: RestTransportConfig<T>;
|
|
31
52
|
inFlightPrefix: string;
|
|
32
|
-
cache: Cache
|
|
53
|
+
cache: Cache<AdapterResponse<T['Response']>>;
|
|
54
|
+
inFlightCache: Cache<boolean>;
|
|
33
55
|
rateLimiter: RequestRateLimiter;
|
|
34
|
-
constructor(config:
|
|
35
|
-
|
|
36
|
-
parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
|
|
37
|
-
options: {
|
|
38
|
-
requestCoalescing: {
|
|
39
|
-
enabled: boolean;
|
|
40
|
-
entropyMax?: number;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
initialize(dependencies: AdapterDependencies, config: AdapterConfig): Promise<void>;
|
|
45
|
-
hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
|
|
56
|
+
constructor(config: RestTransportConfig<T>);
|
|
57
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
46
58
|
protected waitUntilUnderRateLimit(options: {
|
|
47
59
|
maxRetries: number;
|
|
48
60
|
msBetweenRetries: number;
|
|
49
61
|
}, retry?: number): Promise<void>;
|
|
50
|
-
|
|
62
|
+
foregroundExecute(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<AdapterResponse<T['Response']> | undefined>;
|
|
51
63
|
}
|