@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
package/adapter/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import type EventSource from 'eventsource';
|
|
1
2
|
import Redis from 'ioredis';
|
|
2
|
-
import { AdapterEndpoint } from './endpoint';
|
|
3
|
-
import { CustomSettingsType, SettingsMap, AdapterConfig, BaseAdapterConfig } from '../config';
|
|
4
|
-
import { RequestRateLimiter, BackgroundExecuteRateLimiter, AdapterRateLimitTier } from '../rate-limiting';
|
|
5
|
-
import { Transport } from '../transports';
|
|
6
|
-
import { SubscriptionSetFactory } from '../util';
|
|
7
|
-
import { InputParameters } from '../validation';
|
|
8
3
|
import { Cache } from '../cache';
|
|
9
|
-
import
|
|
4
|
+
import { AdapterConfig, BaseAdapterConfig, SettingsMap } from '../config';
|
|
5
|
+
import { AdapterRateLimitTier, BackgroundExecuteRateLimiter, RequestRateLimiter } from '../rate-limiting';
|
|
6
|
+
import { Transport, TransportGenerics } from '../transports';
|
|
7
|
+
import { AdapterRequest, SubscriptionSetFactory } from '../util';
|
|
8
|
+
import { InputParameters } from '../validation';
|
|
9
|
+
import { Adapter } from './basic';
|
|
10
|
+
import { AdapterEndpoint } from './endpoint';
|
|
10
11
|
export declare type CustomAdapterSettings = SettingsMap & NegatedAdapterSettings;
|
|
11
12
|
declare type NegatedAdapterSettings = {
|
|
12
13
|
[K in keyof BaseAdapterConfig]?: never;
|
|
@@ -32,11 +33,11 @@ export interface AdapterDependencies {
|
|
|
32
33
|
* Context that will be used on background executions of a Transport.
|
|
33
34
|
* For example, the endpointName used to log statements or generate Cache keys.
|
|
34
35
|
*/
|
|
35
|
-
export interface AdapterContext<
|
|
36
|
+
export interface AdapterContext<T extends EndpointGenerics> {
|
|
36
37
|
/** Endpoint instance within the adapter that the Transport is related to */
|
|
37
|
-
adapterEndpoint: AdapterEndpoint<
|
|
38
|
+
adapterEndpoint: AdapterEndpoint<T>;
|
|
38
39
|
/** Initialized config for the adapter that the Transport can access */
|
|
39
|
-
adapterConfig: AdapterConfig<CustomSettings>;
|
|
40
|
+
adapterConfig: AdapterConfig<T['CustomSettings']>;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* Structure to describe rate limits specs for the Adapter
|
|
@@ -45,12 +46,24 @@ export interface AdapterRateLimitingConfig {
|
|
|
45
46
|
/** Adapter rate limits, gotten from the specific tier requested */
|
|
46
47
|
tiers: Record<string, AdapterRateLimitTier>;
|
|
47
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Type to perform arbitrary modifications on an adapter request
|
|
51
|
+
*/
|
|
52
|
+
export declare type RequestTransform = (req: AdapterRequest) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Map of overrides objects (symbol -\> symbol) per adapter name
|
|
55
|
+
*/
|
|
56
|
+
export declare type Overrides = {
|
|
57
|
+
[adapterName: string]: {
|
|
58
|
+
[symbol: string]: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
48
61
|
/**
|
|
49
62
|
* Main structure of an External Adapter
|
|
50
63
|
*/
|
|
51
64
|
export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
52
65
|
/** Name of the adapter */
|
|
53
|
-
name: string
|
|
66
|
+
name: Uppercase<string>;
|
|
54
67
|
/** If present, the string that will be used for requests with no specified endpoint */
|
|
55
68
|
defaultEndpoint?: string;
|
|
56
69
|
/**
|
|
@@ -62,7 +75,7 @@ export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
|
62
75
|
* We also can't use generics, because if we had more than one transport with different requests (very likely)
|
|
63
76
|
* then those new types wouldn't match with each other.
|
|
64
77
|
*/
|
|
65
|
-
endpoints: AdapterEndpoint<any
|
|
78
|
+
endpoints: AdapterEndpoint<any>[];
|
|
66
79
|
/** Map of overrides to the default config values for an Adapter */
|
|
67
80
|
envDefaultOverrides?: Partial<BaseAdapterConfig>;
|
|
68
81
|
/** List of custom env vars for this particular adapter (e.g. RPC_URL) */
|
|
@@ -71,6 +84,10 @@ export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
|
71
84
|
rateLimiting?: AdapterRateLimitingConfig;
|
|
72
85
|
/** Overrides for converting the 'base' parameter that are hardcoded into the adapter. */
|
|
73
86
|
overrides?: Record<string, string>;
|
|
87
|
+
/** Transforms that will apply to the request before submitting it through the adapter request flow */
|
|
88
|
+
requestTransforms?: RequestTransform[];
|
|
89
|
+
/** Bootstrap function that will run when initializing the adapter */
|
|
90
|
+
bootstrap?: (adapter: Adapter<CustomSettings>) => Promise<void>;
|
|
74
91
|
}
|
|
75
92
|
/**
|
|
76
93
|
* Structure to describe rate limits specs for a specific adapter endpoint
|
|
@@ -83,19 +100,25 @@ export interface EndpointRateLimitingConfig {
|
|
|
83
100
|
*/
|
|
84
101
|
allocationPercentage: number;
|
|
85
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Helper type structure that contains the different types passed to the generic parameters of an AdapterEndpoint
|
|
105
|
+
*/
|
|
106
|
+
export declare type EndpointGenerics = TransportGenerics;
|
|
86
107
|
/**
|
|
87
108
|
* Structure to describe a specific endpoint in an [[Adapter]]
|
|
88
109
|
*/
|
|
89
|
-
export interface AdapterEndpointParams<
|
|
110
|
+
export interface AdapterEndpointParams<T extends EndpointGenerics> {
|
|
90
111
|
/** Name that will be used to match input params to this endpoint (case insensitive) */
|
|
91
112
|
name: string;
|
|
92
113
|
/** List of alternative endpoint names that will resolve to this same transport (case insensitive) */
|
|
93
114
|
aliases?: string[];
|
|
94
115
|
/** Transport that will be used to handle data processing and communication for this endpoint */
|
|
95
|
-
transport: Transport<
|
|
116
|
+
transport: Transport<T>;
|
|
96
117
|
/** Specification of what the body of a request hitting this endpoint should look like (used for validation) */
|
|
97
118
|
inputParameters: InputParameters;
|
|
98
119
|
/** Specific details related to the rate limiting for this endpoint in particular */
|
|
99
120
|
rateLimiting?: EndpointRateLimitingConfig;
|
|
121
|
+
/** Custom function that generates cache keys */
|
|
122
|
+
cacheKeyGenerator?: (data: Record<string, unknown>) => string;
|
|
100
123
|
}
|
|
101
124
|
export {};
|
package/background-executor.js
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.callBackgroundExecutes = void 0;
|
|
27
|
-
const util_1 = require("./util");
|
|
28
27
|
const metrics = __importStar(require("./metrics"));
|
|
28
|
+
const util_1 = require("./util");
|
|
29
29
|
const logger = (0, util_1.makeLogger)('BackgroundExecutor');
|
|
30
30
|
/**
|
|
31
31
|
* Very simple background loop that will call the [[Transport.backgroundExecute]] functions in all Transports.
|
|
@@ -47,11 +47,12 @@ async function callBackgroundExecutes(adapter, apiShutdownPromise) {
|
|
|
47
47
|
clearTimeout(timeoutsMap[endpointName]);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// Checks if an individual transport has a backgroundExecute function, and executes it if it does
|
|
51
|
+
const callBackgroundExecute = (endpoint, transport) => {
|
|
52
|
+
const backgroundExecute = transport.backgroundExecute?.bind(transport);
|
|
52
53
|
if (!backgroundExecute) {
|
|
53
54
|
logger.debug(`Endpoint "${endpoint.name}" has no background execute, skipping...`);
|
|
54
|
-
|
|
55
|
+
return;
|
|
55
56
|
}
|
|
56
57
|
const context = {
|
|
57
58
|
adapterEndpoint: endpoint,
|
|
@@ -76,6 +77,20 @@ async function callBackgroundExecutes(adapter, apiShutdownPromise) {
|
|
|
76
77
|
};
|
|
77
78
|
// Start recursive async calls
|
|
78
79
|
handler();
|
|
80
|
+
};
|
|
81
|
+
for (const endpoint of adapter.endpoints) {
|
|
82
|
+
const { transport } = endpoint;
|
|
83
|
+
// Check if transport is a MetaTransport by casting and checking a known property (transports)
|
|
84
|
+
const castMeta = transport;
|
|
85
|
+
if (castMeta.transports) {
|
|
86
|
+
logger.debug(`Encountered MetaTransport ${transport.constructor.name}, calling backgroundExecute on all transports`);
|
|
87
|
+
for (const nestedTransport of Object.values(castMeta.transports)) {
|
|
88
|
+
callBackgroundExecute(endpoint, nestedTransport);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
callBackgroundExecute(endpoint, transport);
|
|
93
|
+
}
|
|
79
94
|
}
|
|
80
95
|
}
|
|
81
96
|
exports.callBackgroundExecutes = callBackgroundExecutes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-executor.js","sourceRoot":"","sources":["../../src/background-executor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"background-executor.js","sourceRoot":"","sources":["../../src/background-executor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAoC;AAEpC,iCAAmC;AAEnC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,oBAAoB,CAAC,CAAA;AAE/C;;;;;;GAMG;AACI,KAAK,UAAU,sBAAsB,CAAC,OAAgB,EAAE,kBAAkC;IAC/F,uFAAuF;IACvF,4FAA4F;IAC5F,IAAI,YAAY,GAAG,KAAK,CAAA;IACxB,MAAM,WAAW,GAEb,EAAE,CAAA;IAEN,kBAAkB,EAAE,IAAI,CAAC,GAAG,EAAE;QAC5B,YAAY,GAAG,IAAI,CAAA;QACnB,KAAK,MAAM,YAAY,IAAI,WAAW,EAAE;YACtC,MAAM,CAAC,KAA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E,CAAA;YACd,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QAC9D,CAAC,CAAA;QAED,8BAA8B;QAC9B,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;IAED,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE;QACxC,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAA;QAE9B,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,SAA6C,CAAA;QAC9D,IAAI,QAAQ,CAAC,UAAU,EAAE;YACvB,MAAM,CAAC,KAAK,CACV,6BAA6B,SAAS,CAAC,WAAW,CAAC,IAAI,+CAA+C,CACvG,CAAA;YACD,KAAK,MAAM,eAAe,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;gBAChE,qBAAqB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;aACjD;SACF;aAAM;YACL,qBAAqB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;SAC3C;KACF;AACH,CAAC;AA5ED,wDA4EC"}
|
package/cache/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AdapterEndpoint } from '../adapter';
|
|
2
2
|
import { AdapterConfig, SettingsMap } from '../config';
|
|
3
|
-
import {
|
|
3
|
+
import { AdapterResponse, sleep } from '../util';
|
|
4
|
+
export * from './factory';
|
|
4
5
|
export * from './local';
|
|
5
6
|
export * from './redis';
|
|
6
|
-
export * from './factory';
|
|
7
7
|
/**
|
|
8
8
|
* An object describing an entry in the cache.
|
|
9
9
|
* @typeParam T - the type of the entry's value
|
|
@@ -49,13 +49,13 @@ export interface Cache<T = unknown> {
|
|
|
49
49
|
*/
|
|
50
50
|
delete: (key: string) => Promise<void>;
|
|
51
51
|
}
|
|
52
|
-
export declare const calculateCacheKey: <
|
|
53
|
-
adapterEndpoint: AdapterEndpoint<
|
|
54
|
-
adapterConfig: AdapterConfig<CustomSettings>;
|
|
52
|
+
export declare const calculateCacheKey: <T extends import("../transports").TransportGenerics>({ adapterEndpoint, adapterConfig, }: {
|
|
53
|
+
adapterEndpoint: AdapterEndpoint<T>;
|
|
54
|
+
adapterConfig: AdapterConfig<T["CustomSettings"]>;
|
|
55
55
|
}, data: unknown) => string;
|
|
56
|
-
export declare const calculateFeedId: <
|
|
57
|
-
adapterEndpoint: AdapterEndpoint<
|
|
58
|
-
adapterConfig: AdapterConfig<CustomSettings>;
|
|
56
|
+
export declare const calculateFeedId: <T extends import("../transports").TransportGenerics>({ adapterEndpoint, adapterConfig, }: {
|
|
57
|
+
adapterEndpoint: AdapterEndpoint<T>;
|
|
58
|
+
adapterConfig: AdapterConfig<T["CustomSettings"]>;
|
|
59
59
|
}, data: unknown) => string;
|
|
60
60
|
/**
|
|
61
61
|
* Calculates a unique key from the provided data.
|
|
@@ -71,6 +71,7 @@ export declare const calculateFeedId: <Params, Result, CustomSettings extends Se
|
|
|
71
71
|
* ```
|
|
72
72
|
*/
|
|
73
73
|
export declare const calculateKey: <CustomSettings extends SettingsMap>(data: unknown, paramNames: string[], adapterConfig: AdapterConfig<CustomSettings>) => string;
|
|
74
|
+
export declare const calculateStaleness: (expirationTimestamp: number | undefined, ttl: number) => number;
|
|
74
75
|
/**
|
|
75
76
|
* Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
|
|
76
77
|
* amount of retries is exceeded, it returns undefined instead.
|
|
@@ -84,11 +85,3 @@ export declare const pollResponseFromCache: (cache: Cache<AdapterResponse>, key:
|
|
|
84
85
|
maxRetries: number;
|
|
85
86
|
sleep: number;
|
|
86
87
|
}, retry?: number) => Promise<AdapterResponse | undefined>;
|
|
87
|
-
/**
|
|
88
|
-
* Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
|
|
89
|
-
* a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
|
|
90
|
-
*
|
|
91
|
-
* @param adapter - an initialized adapter
|
|
92
|
-
* @returns the cache middleware function
|
|
93
|
-
*/
|
|
94
|
-
export declare const buildCacheMiddleware: AdapterMiddlewareBuilder;
|
package/cache/index.js
CHANGED
|
@@ -10,28 +10,15 @@ 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.pollResponseFromCache = exports.calculateStaleness = exports.calculateKey = exports.calculateFeedId = exports.calculateCacheKey = void 0;
|
|
30
18
|
const util_1 = require("../util");
|
|
31
|
-
|
|
19
|
+
__exportStar(require("./factory"), exports);
|
|
32
20
|
__exportStar(require("./local"), exports);
|
|
33
21
|
__exportStar(require("./redis"), exports);
|
|
34
|
-
__exportStar(require("./factory"), exports);
|
|
35
22
|
const logger = (0, util_1.makeLogger)('Cache');
|
|
36
23
|
// Uses calculateKey to generate a unique key from the endpoint name, data, and input parameters
|
|
37
24
|
const calculateCacheKey = ({ adapterEndpoint, adapterConfig, }, data) => {
|
|
@@ -74,10 +61,6 @@ const calculateKey = (data, paramNames, adapterConfig) => {
|
|
|
74
61
|
const params = data;
|
|
75
62
|
let cacheKey = '';
|
|
76
63
|
for (const paramName of paramNames) {
|
|
77
|
-
// Ignore overrides param when generating cache keys
|
|
78
|
-
if (paramName === 'overrides') {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
64
|
const param = params[paramName];
|
|
82
65
|
if (param === undefined) {
|
|
83
66
|
continue;
|
|
@@ -104,7 +87,7 @@ const calculateKey = (data, paramNames, adapterConfig) => {
|
|
|
104
87
|
return cacheKey;
|
|
105
88
|
};
|
|
106
89
|
exports.calculateKey = calculateKey;
|
|
107
|
-
// Calculate the amount of time
|
|
90
|
+
// Calculate the amount of time a non-expired entry has been in the cache
|
|
108
91
|
const calculateStaleness = (expirationTimestamp, ttl) => {
|
|
109
92
|
if (expirationTimestamp) {
|
|
110
93
|
const createTimestamp = expirationTimestamp - ttl;
|
|
@@ -116,6 +99,7 @@ const calculateStaleness = (expirationTimestamp, ttl) => {
|
|
|
116
99
|
return ttl;
|
|
117
100
|
}
|
|
118
101
|
};
|
|
102
|
+
exports.calculateStaleness = calculateStaleness;
|
|
119
103
|
/**
|
|
120
104
|
* Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
|
|
121
105
|
* amount of retries is exceeded, it returns undefined instead.
|
|
@@ -146,30 +130,4 @@ const pollResponseFromCache = async (cache, key, options, retry = 0) => {
|
|
|
146
130
|
return (0, exports.pollResponseFromCache)(cache, key, options, retry + 1);
|
|
147
131
|
};
|
|
148
132
|
exports.pollResponseFromCache = pollResponseFromCache;
|
|
149
|
-
/**
|
|
150
|
-
* Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
|
|
151
|
-
* a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
|
|
152
|
-
*
|
|
153
|
-
* @param adapter - an initialized adapter
|
|
154
|
-
* @returns the cache middleware function
|
|
155
|
-
*/
|
|
156
|
-
const buildCacheMiddleware = (adapter) => async (req, res) => {
|
|
157
|
-
const response = await adapter.dependencies.cache.get(req.requestContext.cacheKey);
|
|
158
|
-
if (response) {
|
|
159
|
-
logger.debug('Found response from cache, sending that');
|
|
160
|
-
if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
161
|
-
const label = cacheMetrics.cacheMetricsLabel(req.requestContext.cacheKey, req.requestContext.meta?.metrics?.feedId || 'N/A', adapter.config.CACHE_TYPE);
|
|
162
|
-
// Record cache staleness and cache get count and value
|
|
163
|
-
const staleness = calculateStaleness(response.maxAge, adapter.config.CACHE_MAX_AGE);
|
|
164
|
-
cacheMetrics.cacheGet(label, response.result, staleness);
|
|
165
|
-
req.requestContext.meta = {
|
|
166
|
-
...req.requestContext.meta,
|
|
167
|
-
metrics: { ...req.requestContext.meta?.metrics, cacheHit: true },
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
return res.send(response);
|
|
171
|
-
}
|
|
172
|
-
logger.debug('Did not find response in cache, moving to next middleware');
|
|
173
|
-
};
|
|
174
|
-
exports.buildCacheMiddleware = buildCacheMiddleware;
|
|
175
133
|
//# sourceMappingURL=index.js.map
|
package/cache/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,kCAA4D;AAE5D,4CAAyB;AACzB,0CAAuB;AACvB,0CAAuB;AAEvB,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,OAAO,CAAC,CAAA;AAoDlC,gGAAgG;AACzF,MAAM,iBAAiB,GAAG,CAC/B,EACE,eAAe,EACf,aAAa,GAId,EACD,IAAa,EACL,EAAE;IACV,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,C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QAC9B,iFAAiF;QACjF,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;QACjD,OAAO,SAAS,CAAA;KACjB;IAED,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;IAC9C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACrC,IAAI,QAAQ,EAAE;QACZ,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAA;QACvC,OAAO,QAAQ,CAAA;KAChB;IAED,IAAI,OAAO,CAAC,UAAU,KAAK,CAAC,EAAE;QAC5B,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACpD,OAAO,SAAS,CAAA;KACjB;IAED,MAAM,CAAC,KAAK,CAAC,gCAAgC,OAAO,CAAC,KAAK,kBAAkB,CAAC,CAAA;IAC7E,MAAM,IAAA,YAAK,EAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,IAAA,6BAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;AAC9D,CAAC,CAAA;AA/BY,QAAA,qBAAqB,yBA+BjC"}
|
package/config/index.d.ts
CHANGED
|
@@ -3,11 +3,6 @@ export declare const BaseSettings: {
|
|
|
3
3
|
readonly description: "The URL that certain transports use to retrieve data";
|
|
4
4
|
readonly type: "string";
|
|
5
5
|
};
|
|
6
|
-
readonly API_KEY: {
|
|
7
|
-
readonly description: "Default setting for an EA key";
|
|
8
|
-
readonly type: "string";
|
|
9
|
-
readonly sensitive: true;
|
|
10
|
-
};
|
|
11
6
|
readonly API_TIMEOUT: {
|
|
12
7
|
readonly description: "The number of milliseconds a request can be pending before returning a timeout error for data provider request";
|
|
13
8
|
readonly type: "number";
|
|
@@ -23,16 +18,31 @@ export declare const BaseSettings: {
|
|
|
23
18
|
readonly type: "string";
|
|
24
19
|
readonly default: "/";
|
|
25
20
|
};
|
|
21
|
+
readonly BATCH_TRANSPORT_SETUP_VALIDATION: {
|
|
22
|
+
readonly description: "Flag to toggle batch transport setup validation";
|
|
23
|
+
readonly type: "boolean";
|
|
24
|
+
readonly default: false;
|
|
25
|
+
};
|
|
26
26
|
readonly CACHE_MAX_AGE: {
|
|
27
27
|
readonly description: "Maximum amount of time (in ms) that a response will stay cached";
|
|
28
28
|
readonly type: "number";
|
|
29
29
|
readonly default: 90000;
|
|
30
30
|
};
|
|
31
|
+
readonly CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
32
|
+
readonly description: "Connection timeout for redis client";
|
|
33
|
+
readonly type: "number";
|
|
34
|
+
readonly default: 15000;
|
|
35
|
+
};
|
|
31
36
|
readonly CACHE_REDIS_HOST: {
|
|
32
37
|
readonly description: "Hostname for the Redis instance to be used";
|
|
33
38
|
readonly type: "string";
|
|
34
39
|
readonly default: "127.0.0.1";
|
|
35
40
|
};
|
|
41
|
+
readonly CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
42
|
+
readonly description: "Max cooldown (in ms) before attempting redis reconnection";
|
|
43
|
+
readonly type: "number";
|
|
44
|
+
readonly default: 3000;
|
|
45
|
+
};
|
|
36
46
|
readonly CACHE_REDIS_PASSWORD: {
|
|
37
47
|
readonly description: "The password required for redis auth";
|
|
38
48
|
readonly type: "string";
|
|
@@ -151,11 +161,6 @@ export declare const BaseSettings: {
|
|
|
151
161
|
readonly description: "Override the base websocket URL within the EA.";
|
|
152
162
|
readonly type: "string";
|
|
153
163
|
};
|
|
154
|
-
readonly WS_API_KEY: {
|
|
155
|
-
readonly description: "The websocket API key to authenticate with";
|
|
156
|
-
readonly type: "string";
|
|
157
|
-
readonly sensitive: true;
|
|
158
|
-
};
|
|
159
164
|
readonly WS_SUBSCRIPTION_TTL: {
|
|
160
165
|
readonly description: "";
|
|
161
166
|
readonly type: "number";
|
|
@@ -208,10 +213,13 @@ export declare const BaseSettings: {
|
|
|
208
213
|
readonly type: "string";
|
|
209
214
|
};
|
|
210
215
|
};
|
|
211
|
-
export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, }: {
|
|
216
|
+
export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, envVarsPrefix, }: {
|
|
212
217
|
overrides?: Partial<BaseAdapterConfig> | undefined;
|
|
213
218
|
customSettings?: SettingsMap | undefined;
|
|
219
|
+
envVarsPrefix?: string | undefined;
|
|
214
220
|
}) => AdapterConfig<CustomSettings>;
|
|
221
|
+
export declare const validateAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>(adapterConfig: AdapterConfig<CustomSettings>, customSettings?: SettingsMap) => void;
|
|
222
|
+
export declare const getEnv: (name: string, config: Setting, prefix?: string) => SettingValueType | null;
|
|
215
223
|
declare type SettingValueType = string | number | boolean;
|
|
216
224
|
declare type SettingType<C extends Setting> = C['type'] extends 'string' ? string : C['type'] extends 'number' ? number : C['type'] extends 'boolean' ? boolean : C['type'] extends 'enum' ? C['options'] extends readonly string[] ? C['options'][number] : never : never;
|
|
217
225
|
declare type BaseSettingsType = typeof BaseSettings;
|
package/config/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Import { getRandomRequiredEnv, getRandomEnv, getEnv } from '../util'
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.buildAdapterConfig = exports.BaseSettings = void 0;
|
|
3
|
+
exports.getEnv = exports.validateAdapterConfig = exports.buildAdapterConfig = exports.BaseSettings = void 0;
|
|
5
4
|
exports.BaseSettings = {
|
|
6
5
|
// V2 compat
|
|
7
6
|
// ADAPTER_URL: {
|
|
@@ -12,11 +11,6 @@ exports.BaseSettings = {
|
|
|
12
11
|
description: 'The URL that certain transports use to retrieve data',
|
|
13
12
|
type: 'string',
|
|
14
13
|
},
|
|
15
|
-
API_KEY: {
|
|
16
|
-
description: 'Default setting for an EA key',
|
|
17
|
-
type: 'string',
|
|
18
|
-
sensitive: true,
|
|
19
|
-
},
|
|
20
14
|
API_TIMEOUT: {
|
|
21
15
|
description: 'The number of milliseconds a request can be pending before returning a timeout error for data provider request',
|
|
22
16
|
type: 'number',
|
|
@@ -32,6 +26,11 @@ exports.BaseSettings = {
|
|
|
32
26
|
type: 'string',
|
|
33
27
|
default: '/',
|
|
34
28
|
},
|
|
29
|
+
BATCH_TRANSPORT_SETUP_VALIDATION: {
|
|
30
|
+
description: 'Flag to toggle batch transport setup validation',
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
default: false,
|
|
33
|
+
},
|
|
35
34
|
CACHE_MAX_AGE: {
|
|
36
35
|
description: 'Maximum amount of time (in ms) that a response will stay cached',
|
|
37
36
|
type: 'number',
|
|
@@ -45,10 +44,11 @@ exports.BaseSettings = {
|
|
|
45
44
|
// type: 'number',
|
|
46
45
|
// default: 30000,
|
|
47
46
|
// },
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
48
|
+
description: 'Connection timeout for redis client',
|
|
49
|
+
type: 'number',
|
|
50
|
+
default: 15000,
|
|
51
|
+
},
|
|
52
52
|
CACHE_REDIS_HOST: {
|
|
53
53
|
description: 'Hostname for the Redis instance to be used',
|
|
54
54
|
type: 'string',
|
|
@@ -59,10 +59,11 @@ exports.BaseSettings = {
|
|
|
59
59
|
// type: 'number',
|
|
60
60
|
// default: 500,
|
|
61
61
|
// },
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
63
|
+
description: 'Max cooldown (in ms) before attempting redis reconnection',
|
|
64
|
+
type: 'number',
|
|
65
|
+
default: 3000,
|
|
66
|
+
},
|
|
66
67
|
CACHE_REDIS_PASSWORD: {
|
|
67
68
|
description: 'The password required for redis auth',
|
|
68
69
|
type: 'string',
|
|
@@ -220,11 +221,6 @@ exports.BaseSettings = {
|
|
|
220
221
|
description: 'Override the base websocket URL within the EA.',
|
|
221
222
|
type: 'string',
|
|
222
223
|
},
|
|
223
|
-
WS_API_KEY: {
|
|
224
|
-
description: 'The websocket API key to authenticate with',
|
|
225
|
-
type: 'string',
|
|
226
|
-
sensitive: true,
|
|
227
|
-
},
|
|
228
224
|
WS_SUBSCRIPTION_TTL: {
|
|
229
225
|
description: '',
|
|
230
226
|
type: 'number',
|
|
@@ -290,12 +286,11 @@ exports.BaseSettings = {
|
|
|
290
286
|
type: 'string',
|
|
291
287
|
},
|
|
292
288
|
};
|
|
293
|
-
const buildAdapterConfig = ({ overrides = {}, customSettings = {}, }) => {
|
|
294
|
-
const validationErrors = [];
|
|
289
|
+
const buildAdapterConfig = ({ overrides = {}, customSettings = {}, envVarsPrefix = '', }) => {
|
|
295
290
|
const vars = {};
|
|
296
291
|
// Iterate base adapter env vars
|
|
297
292
|
for (const [key, config] of Object.entries(exports.BaseSettings)) {
|
|
298
|
-
const value = getEnv(key, config) ?? overrides?.[key] ?? config.default;
|
|
293
|
+
const value = (0, exports.getEnv)(key, config, envVarsPrefix) ?? overrides?.[key] ?? config.default;
|
|
299
294
|
vars[key] = value;
|
|
300
295
|
}
|
|
301
296
|
// Iterate custom vars
|
|
@@ -303,28 +298,47 @@ const buildAdapterConfig = ({ overrides = {}, customSettings = {}, }) => {
|
|
|
303
298
|
if (exports.BaseSettings[key]) {
|
|
304
299
|
throw new Error(`Custom env var "${key}" declared, but a base framework env var with that name already exists.`);
|
|
305
300
|
}
|
|
306
|
-
const value = getEnv(key, config) ?? config.default;
|
|
307
|
-
// Check if a required setting has been provided
|
|
308
|
-
if (config.required && value === null) {
|
|
309
|
-
validationErrors.push(`${key}: Value is required, but none was provided`);
|
|
310
|
-
}
|
|
311
|
-
else if (config.validate) {
|
|
312
|
-
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
313
|
-
const validationRes = config.validate(value);
|
|
314
|
-
if (validationRes) {
|
|
315
|
-
validationErrors.push(`${key}: ${validationRes}`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
301
|
+
const value = (0, exports.getEnv)(key, config, envVarsPrefix) ?? config.default;
|
|
318
302
|
vars[key] = value;
|
|
319
303
|
}
|
|
304
|
+
return vars;
|
|
305
|
+
};
|
|
306
|
+
exports.buildAdapterConfig = buildAdapterConfig;
|
|
307
|
+
const validateAdapterConfig = (adapterConfig, customSettings = {}) => {
|
|
308
|
+
const validationErrors = [];
|
|
309
|
+
Object.entries(exports.BaseSettings)
|
|
310
|
+
.concat(Object.entries(customSettings || {}))
|
|
311
|
+
.forEach(([name, setting]) => {
|
|
312
|
+
validateSetting(name, adapterConfig[name], setting, validationErrors);
|
|
313
|
+
});
|
|
320
314
|
if (validationErrors.length > 0) {
|
|
321
315
|
throw new Error(`Validation failed for the following variables:\n ${validationErrors.join('\n')}`);
|
|
322
316
|
}
|
|
323
|
-
return vars;
|
|
324
317
|
};
|
|
325
|
-
exports.
|
|
326
|
-
const
|
|
327
|
-
|
|
318
|
+
exports.validateAdapterConfig = validateAdapterConfig;
|
|
319
|
+
const validateSetting = (key, value, config, validationErrors) => {
|
|
320
|
+
// Check if a required setting has been provided
|
|
321
|
+
if (config.required && (value === null || value === undefined)) {
|
|
322
|
+
validationErrors.push(`${key}: Value is required, but none was provided`);
|
|
323
|
+
}
|
|
324
|
+
else if (config.validate) {
|
|
325
|
+
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
326
|
+
const validationRes = config.validate(value);
|
|
327
|
+
if (validationRes) {
|
|
328
|
+
validationErrors.push(`${key}: ${validationRes}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const getEnvName = (name, prefix = '') => {
|
|
333
|
+
const envName = prefix ? `${prefix}_${name}` : name;
|
|
334
|
+
if (!isEnvNameValid(envName)) {
|
|
335
|
+
throw new Error(`Invalid environment var name: ${envName}. Only '/^[_a-z0-9]+$/i' is supported.`);
|
|
336
|
+
}
|
|
337
|
+
return envName;
|
|
338
|
+
};
|
|
339
|
+
const isEnvNameValid = (name) => /^[_a-z0-9]+$/i.test(name);
|
|
340
|
+
const getEnv = (name, config, prefix = '') => {
|
|
341
|
+
const value = process.env[getEnvName(name, prefix)];
|
|
328
342
|
if (!value) {
|
|
329
343
|
return null;
|
|
330
344
|
}
|
|
@@ -342,4 +356,5 @@ const getEnv = (name, config) => {
|
|
|
342
356
|
return value;
|
|
343
357
|
}
|
|
344
358
|
};
|
|
359
|
+
exports.getEnv = getEnv;
|
|
345
360
|
//# sourceMappingURL=index.js.map
|
package/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG;IAC1B,YAAY;IACZ,iBAAiB;IACjB,qFAAqF;IACrF,oBAAoB;IACpB,KAAK;IACL,YAAY,EAAE;QACZ,WAAW,EAAE,sDAAsD;QACnE,IAAI,EAAE,QAAQ;KACf;IACD,WAAW,EAAE;QACX,WAAW,EACT,gHAAgH;QAClH,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,KAAK;KACf;IACD,WAAW,EAAE;QACX,WAAW,EACT,sIAAsI;QACxI,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACf;IACD,QAAQ,EAAE;QACR,WAAW,EAAE,2CAA2C;QACxD,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,GAAG;KACb;IACD,gCAAgC,EAAE;QAChC,WAAW,EAAE,iDAAiD;QAC9D,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACf;IACD,aAAa,EAAE;QACb,WAAW,EAAE,iEAAiE;QAC9E,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,KAAK;KACf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