@chainlink/external-adapter-framework 0.0.14 → 0.0.16
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/adapter.js +114 -101
- package/cache/factory.js +3 -0
- package/chainlink-external-adapter-framework-v0.0.6.tgz +0 -0
- package/config/index.js +69 -83
- package/config/provider-limits.js +10 -15
- package/examples/bank-frick/accounts.js +3 -2
- package/examples/bank-frick/index.js +3 -2
- package/examples/coingecko/src/config/index.js +13 -0
- package/examples/coingecko/src/config/overrides.json +10826 -0
- package/examples/coingecko/src/cryptoUtils.js +41 -0
- package/examples/coingecko/src/endpoint/coins.js +33 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +46 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js +46 -0
- package/examples/coingecko/src/endpoint/crypto.js +47 -0
- package/examples/coingecko/src/endpoint/dominance.js +26 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js +26 -0
- package/examples/coingecko/src/endpoint/index.js +15 -0
- package/examples/coingecko/src/globalUtils.js +48 -0
- package/examples/coingecko/src/index.js +14 -0
- package/examples/coingecko/test/e2e/adapter.test.js +262 -0
- package/examples/coingecko/test/integration/adapter.test.js +264 -0
- package/examples/coingecko/test/integration/capturedRequests.json +1 -0
- package/examples/coingecko/test/integration/fixtures.js +41 -0
- package/{package/examples/coingecko → examples/coingecko-old}/batch-warming.js +4 -3
- package/examples/{coingecko → coingecko-old}/index.js +3 -2
- package/{package/examples/coingecko → examples/coingecko-old}/rest.js +3 -2
- package/examples/ncfx/index.js +3 -2
- package/examples/ncfx/websocket.js +3 -2
- package/index.js +17 -23
- package/package.json +5 -4
- package/rate-limiting/index.js +23 -2
- package/transports/batch-warming.js +1 -1
- package/transports/rest.js +9 -2
- package/transports/util.js +2 -1
- package/transports/websocket.js +4 -6
- package/util/recordRequests.js +45 -0
- package/{package/validation/override-functions.js → validation/overrideFunctions.js} +0 -0
- package/adapter.d.ts +0 -107
- package/background-executor.d.ts +0 -11
- package/cache/factory.d.ts +0 -6
- package/cache/index.d.ts +0 -94
- package/cache/local.d.ts +0 -23
- package/cache/metrics.d.ts +0 -27
- package/cache/redis.d.ts +0 -16
- package/chainlink-external-adapter-framework-0.0.6.tgz +0 -0
- package/config/index.d.ts +0 -209
- package/config/provider-limits.d.ts +0 -31
- package/examples/bank-frick/accounts.d.ts +0 -39
- package/examples/bank-frick/config/index.d.ts +0 -4
- package/examples/bank-frick/index.d.ts +0 -2
- package/examples/bank-frick/util.d.ts +0 -4
- package/examples/coingecko/batch-warming.d.ts +0 -2
- package/examples/coingecko/batch-warming.js +0 -52
- package/examples/coingecko/index.d.ts +0 -2
- package/examples/coingecko/rest.d.ts +0 -2
- package/examples/coingecko/rest.js +0 -50
- package/examples/ncfx/config/index.d.ts +0 -12
- package/examples/ncfx/index.d.ts +0 -2
- package/examples/ncfx/websocket.d.ts +0 -36
- package/index.d.ts +0 -11
- package/metrics/constants.d.ts +0 -16
- package/metrics/index.d.ts +0 -15
- package/metrics/util.d.ts +0 -7
- package/package/adapter.d.ts +0 -88
- package/package/adapter.js +0 -112
- package/package/background-executor.d.ts +0 -11
- package/package/background-executor.js +0 -45
- package/package/cache/factory.d.ts +0 -6
- package/package/cache/factory.js +0 -57
- package/package/cache/index.d.ts +0 -90
- package/package/cache/index.js +0 -169
- package/package/cache/local.d.ts +0 -23
- package/package/cache/local.js +0 -83
- package/package/cache/metrics.d.ts +0 -27
- package/package/cache/metrics.js +0 -120
- package/package/cache/redis.d.ts +0 -16
- package/package/cache/redis.js +0 -100
- package/package/config/index.d.ts +0 -195
- package/package/config/index.js +0 -365
- package/package/config/provider-limits.d.ts +0 -31
- package/package/config/provider-limits.js +0 -76
- package/package/examples/coingecko/batch-warming.d.ts +0 -2
- package/package/examples/coingecko/index.d.ts +0 -2
- package/package/examples/coingecko/index.js +0 -10
- package/package/examples/coingecko/rest.d.ts +0 -2
- package/package/examples/ncfx/config/index.d.ts +0 -12
- package/package/examples/ncfx/config/index.js +0 -15
- package/package/examples/ncfx/index.d.ts +0 -2
- package/package/examples/ncfx/index.js +0 -10
- package/package/examples/ncfx/websocket.d.ts +0 -36
- package/package/examples/ncfx/websocket.js +0 -72
- package/package/index.d.ts +0 -12
- package/package/index.js +0 -92
- package/package/metrics/constants.d.ts +0 -16
- package/package/metrics/constants.js +0 -25
- package/package/metrics/index.d.ts +0 -15
- package/package/metrics/index.js +0 -123
- package/package/metrics/util.d.ts +0 -3
- package/package/metrics/util.js +0 -9
- package/package/package.json +0 -72
- package/package/rate-limiting/background/fixed-frequency.d.ts +0 -10
- package/package/rate-limiting/background/fixed-frequency.js +0 -37
- package/package/rate-limiting/index.d.ts +0 -54
- package/package/rate-limiting/index.js +0 -63
- package/package/rate-limiting/metrics.d.ts +0 -3
- package/package/rate-limiting/metrics.js +0 -44
- package/package/rate-limiting/request/simple-counting.d.ts +0 -20
- package/package/rate-limiting/request/simple-counting.js +0 -62
- package/package/test.d.ts +0 -1
- package/package/test.js +0 -6
- package/package/transports/batch-warming.d.ts +0 -34
- package/package/transports/batch-warming.js +0 -101
- package/package/transports/index.d.ts +0 -87
- package/package/transports/index.js +0 -87
- package/package/transports/metrics.d.ts +0 -21
- package/package/transports/metrics.js +0 -105
- package/package/transports/rest.d.ts +0 -43
- package/package/transports/rest.js +0 -129
- package/package/transports/util.d.ts +0 -8
- package/package/transports/util.js +0 -85
- package/package/transports/websocket.d.ts +0 -80
- package/package/transports/websocket.js +0 -169
- package/package/util/expiring-sorted-set.d.ts +0 -21
- package/package/util/expiring-sorted-set.js +0 -47
- package/package/util/index.d.ts +0 -11
- package/package/util/index.js +0 -35
- package/package/util/logger.d.ts +0 -42
- package/package/util/logger.js +0 -62
- package/package/util/request.d.ts +0 -55
- package/package/util/request.js +0 -2
- package/package/validation/error.d.ts +0 -50
- package/package/validation/error.js +0 -79
- package/package/validation/index.d.ts +0 -5
- package/package/validation/index.js +0 -86
- package/package/validation/input-params.d.ts +0 -15
- package/package/validation/input-params.js +0 -30
- package/package/validation/override-functions.d.ts +0 -3
- package/package/validation/preset-tokens.json +0 -23
- package/package/validation/validator.d.ts +0 -47
- package/package/validation/validator.js +0 -303
- package/rate-limiting/background/fixed-frequency.d.ts +0 -10
- package/rate-limiting/index.d.ts +0 -54
- package/rate-limiting/metrics.d.ts +0 -3
- package/rate-limiting/request/simple-counting.d.ts +0 -20
- package/test.d.ts +0 -1
- package/transports/batch-warming.d.ts +0 -35
- package/transports/index.d.ts +0 -70
- package/transports/metrics.d.ts +0 -21
- package/transports/rest.d.ts +0 -44
- package/transports/util.d.ts +0 -8
- package/transports/websocket.d.ts +0 -81
- package/util/expiring-sorted-set.d.ts +0 -21
- package/util/expiring-sorted-set.js +0 -47
- package/util/index.d.ts +0 -12
- package/util/logger.d.ts +0 -42
- package/util/request.d.ts +0 -57
- package/util/subscription-set/expiring-sorted-set.d.ts +0 -22
- package/util/subscription-set/subscription-set.d.ts +0 -18
- package/util/test-payload-loader.d.ts +0 -25
- package/validation/error.d.ts +0 -50
- package/validation/index.d.ts +0 -5
- package/validation/input-params.d.ts +0 -15
- package/validation/override-functions.d.ts +0 -3
- package/validation/validator.d.ts +0 -47
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AdapterRateLimitTier, RateLimiter } from '..';
|
|
2
|
-
import { AdapterEndpoint } from '../../adapter';
|
|
3
|
-
/**
|
|
4
|
-
* This rate limiter is the simplest stateful option.
|
|
5
|
-
* On startup, it'll compare the different thresholds for each tier, calculate them all
|
|
6
|
-
* in the finest window we'll use (seconds), and use the most restrictive one.
|
|
7
|
-
* This is so if the EA were to restart, we don't need to worry about persisting state
|
|
8
|
-
* for things like daily quotas. The downside is that this does not work well for bursty
|
|
9
|
-
* loads or spikes, in cases where e.g. the per second limit is high but daily quotas low.
|
|
10
|
-
*/
|
|
11
|
-
export declare class SimpleCountingRateLimiter implements RateLimiter {
|
|
12
|
-
latestSecondInterval: number;
|
|
13
|
-
requestsThisSecond: number;
|
|
14
|
-
latestMinuteInterval: number;
|
|
15
|
-
requestsThisMinute: number;
|
|
16
|
-
perSecondLimit: number;
|
|
17
|
-
perMinuteLimit: number;
|
|
18
|
-
initialize(endpoints: AdapterEndpoint[], limits?: AdapterRateLimitTier): this;
|
|
19
|
-
isUnderLimits(): boolean;
|
|
20
|
-
}
|
package/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { Cache } from '../cache';
|
|
3
|
-
import { AdapterConfig, SettingsMap } from '../config';
|
|
4
|
-
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
5
|
-
import { SubscriptionSet } from '../util';
|
|
6
|
-
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
7
|
-
import { Transport } from './';
|
|
8
|
-
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
9
|
-
/**
|
|
10
|
-
* Transport implementation that takes incoming batches requests and keeps a warm cache of values.
|
|
11
|
-
* Within the setup function, adapter params are added to an set that also keeps track and expires values.
|
|
12
|
-
* In the background execute, the list of non-expired items in the set is fetched.
|
|
13
|
-
* Then, the list is passed through the `prepareRequest` function, that returns an AxiosRequestConfig.
|
|
14
|
-
* The Data Provider response is, they are passed through the `parseResponse` function to create a [[CacheEntry]] list.
|
|
15
|
-
* Finally, the items in that [[CacheEntry]] list are set in the Cache so the Adapter can fetch values from there.
|
|
16
|
-
*
|
|
17
|
-
* @typeParam AdapterParams - interface for the adapter request body
|
|
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
|
|
20
|
-
*/
|
|
21
|
-
export declare class BatchWarmingTransport<AdapterParams, ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, ProviderResponseBody, CustomSettings> {
|
|
22
|
-
private config;
|
|
23
|
-
cache: Cache;
|
|
24
|
-
rateLimiter: BackgroundExecuteRateLimiter;
|
|
25
|
-
subscriptionSet: SubscriptionSet<AdapterParams>;
|
|
26
|
-
WARMER_ACTIVE: boolean;
|
|
27
|
-
constructor(config: {
|
|
28
|
-
prepareRequest: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
|
|
29
|
-
parseResponse: (res: AxiosResponse<ProviderResponseBody>, context: AdapterContext<CustomSettings>) => ProviderResult<AdapterParams>[];
|
|
30
|
-
});
|
|
31
|
-
initialize(dependencies: AdapterDependencies): Promise<void>;
|
|
32
|
-
hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
|
|
33
|
-
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
34
|
-
backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
|
|
35
|
-
}
|
package/transports/index.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { FastifyReply } from 'fastify';
|
|
2
|
-
import { AdapterContext, AdapterDependencies, InitializedAdapter } from '../adapter';
|
|
3
|
-
import { CacheEntry } from '../cache';
|
|
4
|
-
import { AdapterConfig, SettingsMap } from '../config';
|
|
5
|
-
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
6
|
-
export * from './batch-warming';
|
|
7
|
-
export * from './rest';
|
|
8
|
-
export * from './websocket';
|
|
9
|
-
/**
|
|
10
|
-
* Generic interface for a Transport.
|
|
11
|
-
* A Transport defines the way in which an AdapterEndpoint will process incoming requests to
|
|
12
|
-
* fetch data from a Data Provider. The setup phase will take care of the former, while the
|
|
13
|
-
* backgroundExecute will be in charge of the latter.
|
|
14
|
-
* This separation gives us the ability of splitting these concerns, and optionally parallelizing
|
|
15
|
-
* the reading and writing of data to a centralized Cache.
|
|
16
|
-
*
|
|
17
|
-
* @typeParam Params - the structure of the AdapterRequest's body
|
|
18
|
-
* @typeParam Result - the structure of the AdapterResponse's body
|
|
19
|
-
*/
|
|
20
|
-
export interface Transport<Params, Result, CustomSettings extends SettingsMap> {
|
|
21
|
-
/**
|
|
22
|
-
* Initializes the transport in the Adapter context.
|
|
23
|
-
*
|
|
24
|
-
* @param dependencies - Adapter dependencies (e.g. cache instance)
|
|
25
|
-
* @returns an empty Promise
|
|
26
|
-
*/
|
|
27
|
-
initialize: (dependencies: AdapterDependencies) => Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Checks if the Transport has already set up the incoming request.
|
|
30
|
-
* This will likely use the cacheKey generated in the provided request.
|
|
31
|
-
*
|
|
32
|
-
* @param req - the incoming AdapterRequest
|
|
33
|
-
* @returns a Promise that returns true if setup is in place
|
|
34
|
-
*/
|
|
35
|
-
hasBeenSetUp: (req: AdapterRequest<Params>) => Promise<boolean>;
|
|
36
|
-
/**
|
|
37
|
-
* Sets up the incoming request within the Transport.
|
|
38
|
-
* In other words, it means that the Adapter has recognized this request, and will begin
|
|
39
|
-
* fetching the necessary data from a Data Provider.
|
|
40
|
-
*
|
|
41
|
-
* @param req - the incoming AdapterRequest
|
|
42
|
-
* @param config - common configuration for the Adapter as a whole
|
|
43
|
-
* @returns a Promise that _optionally_ returns an AdapterResponse, if the Transport has the capability of
|
|
44
|
-
* immediately fetching data and returning it without the background process.
|
|
45
|
-
*/
|
|
46
|
-
setup: (req: AdapterRequest<Params>, config: AdapterConfig<CustomSettings>) => Promise<AdapterResponse<Result> | void>;
|
|
47
|
-
/**
|
|
48
|
-
* If the Transport relies on an async mechanism, implementing this function will make it
|
|
49
|
-
* so the background task executor calls it on Adapter startup.
|
|
50
|
-
*
|
|
51
|
-
* @param context - background context for the execution (e.g. endpoint name)
|
|
52
|
-
*/
|
|
53
|
-
backgroundExecute?: (context: AdapterContext<CustomSettings>) => Promise<number>;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Helper method to build cache entries to set after getting a bunch of responses from a DP.
|
|
57
|
-
*
|
|
58
|
-
* @param results - a list of results coming from a DataProvider
|
|
59
|
-
* @param context - context for the Adapter
|
|
60
|
-
* @returns a list of CacheEntries of AdapterResponses
|
|
61
|
-
*/
|
|
62
|
-
export declare const buildCacheEntriesFromResults: <Params, CustomSettings extends SettingsMap>(results: ProviderResult<Params>[], context: AdapterContext<CustomSettings>) => CacheEntry<AdapterResponse<null>>[];
|
|
63
|
-
/**
|
|
64
|
-
* Takes an Adapter, its configuration, and its dependencies, and it creates an express middleware
|
|
65
|
-
* that will pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
|
|
66
|
-
*
|
|
67
|
-
* @param adapter - main adapter object, already initialized
|
|
68
|
-
* @returns the transport handler middleware function
|
|
69
|
-
*/
|
|
70
|
-
export declare const buildTransportHandler: (adapter: InitializedAdapter) => (req: AdapterRequest, reply: FastifyReply) => Promise<never>;
|
package/transports/metrics.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as client from 'prom-client';
|
|
2
|
-
import { AdapterContext } from '../adapter';
|
|
3
|
-
export declare const dataProviderMetricsLabel: (providerStatusCode?: number, method?: string) => {
|
|
4
|
-
provider_status_code: number | undefined;
|
|
5
|
-
method: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const dataProviderRequests: client.Counter<"method" | "provider_status_code">;
|
|
8
|
-
export declare const dataProviderRequestDurationSeconds: client.Histogram<string>;
|
|
9
|
-
export declare const connectionErrorLabels: (message: string) => {
|
|
10
|
-
message: string;
|
|
11
|
-
};
|
|
12
|
-
export declare const messageSubsLabels: (feed_id: string, cache_key: string) => {
|
|
13
|
-
feed_id: string;
|
|
14
|
-
subscription_key: string;
|
|
15
|
-
};
|
|
16
|
-
export declare const recordWsMessageMetrics: <AdapterParams>(context: AdapterContext, subscribes: AdapterParams[], unsubscrices: AdapterParams[]) => void;
|
|
17
|
-
export declare const wsConnectionActive: client.Gauge<"url">;
|
|
18
|
-
export declare const wsConnectionErrors: client.Counter<"message" | "url">;
|
|
19
|
-
export declare const wsSubscriptionActive: client.Gauge<"feed_id" | "connection_url" | "subscription_key">;
|
|
20
|
-
export declare const wsSubscriptionTotal: client.Counter<"feed_id" | "connection_url" | "subscription_key">;
|
|
21
|
-
export declare const wsMessageTotal: client.Counter<"feed_id" | "subscription_key">;
|
package/transports/rest.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { AdapterRequest, AdapterResponse } from '../util/request';
|
|
2
|
-
import { Transport } from './';
|
|
3
|
-
import { Cache } from '../cache';
|
|
4
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
5
|
-
import { AdapterConfig, SettingsMap } from '../config';
|
|
6
|
-
import { RequestRateLimiter } from '../rate-limiting';
|
|
7
|
-
import { AdapterDependencies } from '../adapter';
|
|
8
|
-
/**
|
|
9
|
-
* Transport implementation that takes incoming requests, transforms them into a DataProvider request,
|
|
10
|
-
* and executes that request returning the response immediately from the `setup` function.
|
|
11
|
-
* Optionally, setting the `coalescing` option to `true` will make it so once a request is in flight,
|
|
12
|
-
* new adapter requests for the same feed will not trigger a new one, but return an empty promise from
|
|
13
|
-
* the setup instead so the normal cache polling mechanism is used.
|
|
14
|
-
*
|
|
15
|
-
* @typeParam AdapterParams - interface for the adapter request body
|
|
16
|
-
* @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
|
|
17
|
-
* @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
|
|
18
|
-
*/
|
|
19
|
-
export declare class RestTransport<AdapterParams, ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, ProviderResponseBody, CustomSettings> {
|
|
20
|
-
protected config: {
|
|
21
|
-
prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
|
|
22
|
-
parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
|
|
23
|
-
options: {
|
|
24
|
-
coalescing: boolean;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
inFlightPrefix: string;
|
|
28
|
-
cache: Cache;
|
|
29
|
-
rateLimiter: RequestRateLimiter;
|
|
30
|
-
constructor(config: {
|
|
31
|
-
prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
|
|
32
|
-
parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
|
|
33
|
-
options: {
|
|
34
|
-
coalescing: boolean;
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
initialize(dependencies: AdapterDependencies): Promise<void>;
|
|
38
|
-
hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
|
|
39
|
-
protected waitUntilUnderRateLimit(options: {
|
|
40
|
-
maxRetries: number;
|
|
41
|
-
msBetweenRetries: number;
|
|
42
|
-
}, retry?: number): Promise<void>;
|
|
43
|
-
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<AdapterResponse<ProviderResponseBody> | undefined>;
|
|
44
|
-
}
|
package/transports/util.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
/**
|
|
3
|
-
* Performs axios request along with metrics recording and error handling
|
|
4
|
-
*
|
|
5
|
-
* @param request - axios request config
|
|
6
|
-
* @returns axios response for the request
|
|
7
|
-
*/
|
|
8
|
-
export declare function axiosRequest<ProviderRequestBody, ProviderResponseBody>(request: AxiosRequestConfig<ProviderRequestBody>): Promise<AxiosResponse<ProviderResponseBody>>;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
3
|
-
import { Cache } from '../cache';
|
|
4
|
-
import { SettingsMap } from '../config';
|
|
5
|
-
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
6
|
-
import { SubscriptionSet } from '../util';
|
|
7
|
-
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
8
|
-
import { Transport } from './';
|
|
9
|
-
export declare const DEFAULT_WS_TTL = 10000;
|
|
10
|
-
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined) => WebSocket;
|
|
11
|
-
export declare class WebSocketClassProvider {
|
|
12
|
-
static ctor: WebSocketClass;
|
|
13
|
-
static set(ctor: WebSocketClass): void;
|
|
14
|
-
static get(): WebSocketClass;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Config object that is provided to the WebSocketTransport constructor.
|
|
18
|
-
*/
|
|
19
|
-
export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> {
|
|
20
|
-
/** Endpoint to which to open the WS connection*/
|
|
21
|
-
url: string;
|
|
22
|
-
/** Map of handlers for different WS lifecycle events */
|
|
23
|
-
handlers: {
|
|
24
|
-
/**
|
|
25
|
-
* Handles when the WS is successfully opened
|
|
26
|
-
*
|
|
27
|
-
* @param wsConnection - the WebSocket with an established connection
|
|
28
|
-
* @returns an empty Promise, or void
|
|
29
|
-
*/
|
|
30
|
-
open: (wsConnection: WebSocket, context: AdapterContext<CustomSettings>) => Promise<void> | void;
|
|
31
|
-
/**
|
|
32
|
-
* Handles when the WS receives a message
|
|
33
|
-
*
|
|
34
|
-
* @param message - the message received by the WS
|
|
35
|
-
* @param context - the background context for the Adapter
|
|
36
|
-
* @returns a list of cache entries of adapter responses to set in the cache
|
|
37
|
-
*/
|
|
38
|
-
message: (message: ProviderDataMessage, context: AdapterContext<CustomSettings>) => ProviderResult<AdapterParams>[];
|
|
39
|
-
};
|
|
40
|
-
/** Map of "builders", functions that will be used to prepare specific WS messages */
|
|
41
|
-
builders: {
|
|
42
|
-
/**
|
|
43
|
-
* Builds a WS message that will be sent to subscribe to a specific feed
|
|
44
|
-
*
|
|
45
|
-
* @param params - the body of the adapter request
|
|
46
|
-
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
47
|
-
*/
|
|
48
|
-
subscribeMessage: (params: AdapterParams) => unknown;
|
|
49
|
-
/**
|
|
50
|
-
* Builds a WS message that will be sent to unsubscribe to a specific feed
|
|
51
|
-
*
|
|
52
|
-
* @param params - the body of the adapter request
|
|
53
|
-
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
54
|
-
*/
|
|
55
|
-
unsubscribeMessage: (params: AdapterParams) => unknown;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
60
|
-
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
61
|
-
*
|
|
62
|
-
* @typeParam AdapterParams - interface for the adapter request body
|
|
63
|
-
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
64
|
-
*/
|
|
65
|
-
export declare class WebSocketTransport<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> implements Transport<AdapterParams, null, CustomSettings> {
|
|
66
|
-
private config;
|
|
67
|
-
cache: Cache;
|
|
68
|
-
rateLimiter: BackgroundExecuteRateLimiter;
|
|
69
|
-
subscriptionSet: SubscriptionSet<AdapterParams>;
|
|
70
|
-
localSubscriptions: AdapterParams[];
|
|
71
|
-
wsConnection: WebSocket;
|
|
72
|
-
constructor(config: WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings>);
|
|
73
|
-
initialize(dependencies: AdapterDependencies): Promise<void>;
|
|
74
|
-
hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
|
|
75
|
-
setup(req: AdapterRequest<AdapterParams>): Promise<void>;
|
|
76
|
-
serializeMessage(payload: unknown): string;
|
|
77
|
-
deserializeMessage(data: WebSocket.Data): ProviderDataMessage;
|
|
78
|
-
establishWsConnection(context: AdapterContext<CustomSettings>): Promise<unknown>;
|
|
79
|
-
backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
|
|
80
|
-
}
|
|
81
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An object describing an entry in the expiring sorted set.
|
|
3
|
-
* @typeParam T - the type of the entry's value
|
|
4
|
-
*/
|
|
5
|
-
interface ExpiringSortedSetEntry<T> {
|
|
6
|
-
value: T;
|
|
7
|
-
expirationTimestamp: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* This class implements a set of unique items, each of which has an expiration timestamp.
|
|
11
|
-
* On reads, items that have expired will be deleted from the set and not returned.
|
|
12
|
-
*
|
|
13
|
-
* @typeParam T - the type of the set entries' values
|
|
14
|
-
*/
|
|
15
|
-
export declare class ExpiringSortedSet<T> {
|
|
16
|
-
map: Map<string, ExpiringSortedSetEntry<T>>;
|
|
17
|
-
add(key: string, value: T, ttl: number): void;
|
|
18
|
-
get(key: string): T | undefined;
|
|
19
|
-
getAll(): T[];
|
|
20
|
-
}
|
|
21
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExpiringSortedSet = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* This class implements a set of unique items, each of which has an expiration timestamp.
|
|
6
|
-
* On reads, items that have expired will be deleted from the set and not returned.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam T - the type of the set entries' values
|
|
9
|
-
*/
|
|
10
|
-
class ExpiringSortedSet {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.map = new Map();
|
|
13
|
-
}
|
|
14
|
-
add(key, value, ttl) {
|
|
15
|
-
this.map.set(key, {
|
|
16
|
-
value,
|
|
17
|
-
expirationTimestamp: Date.now() + ttl,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
get(key) {
|
|
21
|
-
const entry = this.map.get(key);
|
|
22
|
-
if (!entry) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
else if (entry.expirationTimestamp < Date.now()) {
|
|
26
|
-
return entry.value;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
this.map.delete(key);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
getAll() {
|
|
33
|
-
const results = [];
|
|
34
|
-
const now = Date.now();
|
|
35
|
-
// Since we're iterating, might as well prune here
|
|
36
|
-
for (const [key, entry] of this.map.entries()) {
|
|
37
|
-
if (entry.expirationTimestamp < now) {
|
|
38
|
-
this.map.delete(key); // In theory, this shouldn't happen frequently for feeds
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
results.push(entry.value);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return results;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.ExpiringSortedSet = ExpiringSortedSet;
|
package/util/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from './request';
|
|
2
|
-
export * from './logger';
|
|
3
|
-
export * from './subscription-set/subscription-set';
|
|
4
|
-
/**
|
|
5
|
-
* Sleeps for the provided number of milliseconds
|
|
6
|
-
* @param ms - The number of milliseconds to sleep for
|
|
7
|
-
* @returns a Promise that resolves once the specified time passes
|
|
8
|
-
*/
|
|
9
|
-
export declare const sleep: (ms: number) => Promise<void>;
|
|
10
|
-
export declare const isObject: (o: unknown) => boolean;
|
|
11
|
-
export declare const isArray: (o: unknown) => boolean;
|
|
12
|
-
export declare type PromiseOrValue<T> = Promise<T> | T;
|
package/util/logger.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import pino from 'pino';
|
|
3
|
-
import { AdapterRequest } from './request';
|
|
4
|
-
import { FastifyReply, HookHandlerDoneFunction } from 'fastify';
|
|
5
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
-
export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
|
|
7
|
-
export declare type Store = {
|
|
8
|
-
correlationId: string;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Instead of using a global logger instance, we want to force using a child logger
|
|
12
|
-
* with a specific layer set in it, so that we can filter logs by where they're output from.
|
|
13
|
-
*
|
|
14
|
-
* Details on what each log level represents:
|
|
15
|
-
* "trace": Forensic debugging of issues on a local machine.
|
|
16
|
-
* "debug": Detailed logging level to get more context from users on their environments.
|
|
17
|
-
* "info": High-level informational messages, to describe at a glance the high level state of the system.
|
|
18
|
-
* "warn": A mild error occurred that might require non-urgent action.
|
|
19
|
-
* "error": An unexpected error occurred during the regular operation of a well-maintained EA.
|
|
20
|
-
* "fatal": The EA encountered an unrecoverable problem and had to exit.
|
|
21
|
-
*
|
|
22
|
-
* Full reference this is based on can be found at
|
|
23
|
-
* https://github.com/smartcontractkit/documentation/blob/main/docs/Node%20Operators/configuration-variables.md#log_level
|
|
24
|
-
*
|
|
25
|
-
* @param layer - the layer name to include in the logs (e.g. "SomeMiddleware", "RedisCache", etc.)
|
|
26
|
-
* @returns a layer specific logger
|
|
27
|
-
*/
|
|
28
|
-
export declare const makeLogger: (layer: string) => pino.Logger<{
|
|
29
|
-
level: string;
|
|
30
|
-
mixin(): {};
|
|
31
|
-
transport: {
|
|
32
|
-
target: string;
|
|
33
|
-
options: {
|
|
34
|
-
levelFirst: boolean;
|
|
35
|
-
levelLabel: string;
|
|
36
|
-
ignore: string;
|
|
37
|
-
messageFormat: string;
|
|
38
|
-
translateTime: string;
|
|
39
|
-
};
|
|
40
|
-
} | undefined;
|
|
41
|
-
} & pino.ChildLoggerOptions>;
|
|
42
|
-
export declare const loggingContextMiddleware: (req: AdapterRequest, res: FastifyReply, done: HookHandlerDoneFunction) => void;
|
package/util/request.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify';
|
|
2
|
-
import { InitializedAdapter } from '../adapter';
|
|
3
|
-
import { AdapterError } from '../validation/error';
|
|
4
|
-
declare module 'fastify' {
|
|
5
|
-
interface FastifyRequest {
|
|
6
|
-
requestContext: AdapterRequestContext;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export interface AdapterRequestBody<T = AdapterRequestData> {
|
|
10
|
-
endpoint?: string;
|
|
11
|
-
data: T;
|
|
12
|
-
id?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare type AdapterRequestContext<T = AdapterRequestData> = {
|
|
15
|
-
id: string;
|
|
16
|
-
endpointName: string;
|
|
17
|
-
cacheKey: string;
|
|
18
|
-
data: T;
|
|
19
|
-
meta?: AdapterRequestMeta;
|
|
20
|
-
};
|
|
21
|
-
export declare type AdapterRouteGeneric<T = AdapterRequestData> = {
|
|
22
|
-
Body: AdapterRequestBody<T>;
|
|
23
|
-
};
|
|
24
|
-
export declare type AdapterRequest<T = AdapterRequestData> = FastifyRequest<AdapterRouteGeneric<T>> & {
|
|
25
|
-
requestContext: AdapterRequestContext<T>;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Meta info that pertains to exposing metrics
|
|
29
|
-
*/
|
|
30
|
-
export interface AdapterRequestMeta {
|
|
31
|
-
metrics?: AdapterMetricsMeta;
|
|
32
|
-
error?: AdapterError | Error;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Meta info that pertains to exposing metrics
|
|
36
|
-
*/
|
|
37
|
-
export interface AdapterMetricsMeta {
|
|
38
|
-
feedId?: string;
|
|
39
|
-
cacheHit?: boolean;
|
|
40
|
-
}
|
|
41
|
-
export declare type AdapterRequestData = Record<string, unknown> & {
|
|
42
|
-
endpoint?: string;
|
|
43
|
-
};
|
|
44
|
-
export interface ProviderResult<Params> {
|
|
45
|
-
params: Params;
|
|
46
|
-
value: unknown;
|
|
47
|
-
}
|
|
48
|
-
export declare type AdapterResponse<T = unknown> = {
|
|
49
|
-
statusCode: number;
|
|
50
|
-
data: T;
|
|
51
|
-
result: unknown;
|
|
52
|
-
maxAge?: number;
|
|
53
|
-
meta?: AdapterRequestMeta;
|
|
54
|
-
providerStatusCode?: number;
|
|
55
|
-
};
|
|
56
|
-
export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
|
|
57
|
-
export declare type AdapterMiddlewareBuilder = (adapter: InitializedAdapter) => Middleware;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { SubscriptionSet } from './subscription-set';
|
|
2
|
-
/**
|
|
3
|
-
* An object describing an entry in the expiring sorted set.
|
|
4
|
-
* @typeParam T - the type of the entry's value
|
|
5
|
-
*/
|
|
6
|
-
interface ExpiringSortedSetEntry<T> {
|
|
7
|
-
value: T;
|
|
8
|
-
expirationTimestamp: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* This class implements a set of unique items, each of which has an expiration timestamp.
|
|
12
|
-
* On reads, items that have expired will be deleted from the set and not returned.
|
|
13
|
-
*
|
|
14
|
-
* @typeParam T - the type of the set entries' values
|
|
15
|
-
*/
|
|
16
|
-
export declare class ExpiringSortedSet<T> implements SubscriptionSet<T> {
|
|
17
|
-
map: Map<string, ExpiringSortedSetEntry<T>>;
|
|
18
|
-
add(key: string, value: T, ttl: number): void;
|
|
19
|
-
get(key: string): T | undefined;
|
|
20
|
-
getAll(): T[];
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { PromiseOrValue } from '..';
|
|
2
|
-
import { AdapterConfig } from '../../config';
|
|
3
|
-
/**
|
|
4
|
-
* Set to hold items to subscribe to from a provider (regardless of protocol)
|
|
5
|
-
*/
|
|
6
|
-
export interface SubscriptionSet<T> {
|
|
7
|
-
/** Add a new subscription to the set */
|
|
8
|
-
add(key: string, value: T, ttl: number): PromiseOrValue<void>;
|
|
9
|
-
/** Get a specific subscription from the set */
|
|
10
|
-
get(key: string): PromiseOrValue<T | undefined>;
|
|
11
|
-
/** Get all subscriptions from the set as a list */
|
|
12
|
-
getAll(): PromiseOrValue<T[]>;
|
|
13
|
-
}
|
|
14
|
-
export declare class SubscriptionSetFactory {
|
|
15
|
-
private cacheType;
|
|
16
|
-
constructor(config: AdapterConfig);
|
|
17
|
-
buildSet<T>(): SubscriptionSet<T>;
|
|
18
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { AdapterRequestData } from './request';
|
|
2
|
-
/**
|
|
3
|
-
* The test payload read in from filesystem
|
|
4
|
-
*/
|
|
5
|
-
export interface Payload {
|
|
6
|
-
requests: Array<AdapterRequestData>;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Test payload with discriminated union so we can tell when we should just do
|
|
10
|
-
* a simple liveness check rather than a sample request
|
|
11
|
-
*/
|
|
12
|
-
declare type TestPayload = (Payload & {
|
|
13
|
-
isDefault: false;
|
|
14
|
-
}) | {
|
|
15
|
-
isDefault: true;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Load in a JSON file containing a test payload for the current adapter,
|
|
19
|
-
* used in healthchecks to make sample requests
|
|
20
|
-
*
|
|
21
|
-
* @param fileName - name of file that contains the test payload data for the smoke endpoint
|
|
22
|
-
* @returns the parsed payload with individual requests
|
|
23
|
-
*/
|
|
24
|
-
export declare function loadTestPayload(fileName?: string): TestPayload;
|
|
25
|
-
export {};
|
package/validation/error.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { HttpRequestType } from '../metrics/constants';
|
|
2
|
-
declare type ErrorBasic = {
|
|
3
|
-
name: string;
|
|
4
|
-
message: string;
|
|
5
|
-
};
|
|
6
|
-
declare type ErrorFull = ErrorBasic & {
|
|
7
|
-
stack: string;
|
|
8
|
-
cause: string;
|
|
9
|
-
};
|
|
10
|
-
export declare type AdapterErrorResponse = {
|
|
11
|
-
jobRunID: string;
|
|
12
|
-
status: string;
|
|
13
|
-
statusCode: number;
|
|
14
|
-
providerStatusCode?: number;
|
|
15
|
-
error: ErrorBasic | ErrorFull;
|
|
16
|
-
};
|
|
17
|
-
export declare class AdapterError extends Error {
|
|
18
|
-
jobRunID: string;
|
|
19
|
-
status: string;
|
|
20
|
-
statusCode: number;
|
|
21
|
-
cause: any;
|
|
22
|
-
url?: string;
|
|
23
|
-
errorResponse: any;
|
|
24
|
-
feedID?: string;
|
|
25
|
-
providerStatusCode?: number;
|
|
26
|
-
metricsLabel?: HttpRequestType;
|
|
27
|
-
name: string;
|
|
28
|
-
message: string;
|
|
29
|
-
constructor({ jobRunID, status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
|
|
30
|
-
toJSONResponse(): AdapterErrorResponse;
|
|
31
|
-
}
|
|
32
|
-
export declare class AdapterInputError extends AdapterError {
|
|
33
|
-
constructor(input: Partial<AdapterError>);
|
|
34
|
-
}
|
|
35
|
-
export declare class AdapterRateLimitError extends AdapterError {
|
|
36
|
-
constructor(input: Partial<AdapterError>);
|
|
37
|
-
}
|
|
38
|
-
export declare class AdapterTimeoutError extends AdapterError {
|
|
39
|
-
constructor(input: Partial<AdapterError>);
|
|
40
|
-
}
|
|
41
|
-
export declare class AdapterDataProviderError extends AdapterError {
|
|
42
|
-
constructor(input: Partial<AdapterError>);
|
|
43
|
-
}
|
|
44
|
-
export declare class AdapterConnectionError extends AdapterError {
|
|
45
|
-
constructor(input: Partial<AdapterError>);
|
|
46
|
-
}
|
|
47
|
-
export declare class AdapterCustomError extends AdapterError {
|
|
48
|
-
constructor(input: Partial<AdapterError>);
|
|
49
|
-
}
|
|
50
|
-
export {};
|
package/validation/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import { AdapterMiddlewareBuilder } from '../util/request';
|
|
3
|
-
export { InputParameters } from './input-params';
|
|
4
|
-
export declare const validatorMiddleware: AdapterMiddlewareBuilder;
|
|
5
|
-
export declare const errorCatchingMiddleware: (err: Error, req: FastifyRequest, res: FastifyReply) => void;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare type Override = Map<string, Map<string, string>>;
|
|
2
|
-
export declare type InputParameter = {
|
|
3
|
-
aliases?: string[];
|
|
4
|
-
description?: string;
|
|
5
|
-
type?: 'bigint' | 'boolean' | 'array' | 'number' | 'object' | 'string';
|
|
6
|
-
required?: boolean;
|
|
7
|
-
options?: unknown[];
|
|
8
|
-
default?: unknown;
|
|
9
|
-
dependsOn?: string[];
|
|
10
|
-
exclusive?: string[];
|
|
11
|
-
};
|
|
12
|
-
export declare type InputParameters = {
|
|
13
|
-
[name: string]: InputParameter | boolean | string[];
|
|
14
|
-
};
|
|
15
|
-
export declare const baseInputParameters: InputParameters;
|