@chainlink/external-adapter-framework 0.5.0 → 0.5.2
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/basic.d.ts +90 -0
- package/adapter/basic.js +325 -0
- package/adapter/basic.js.map +1 -0
- package/adapter/endpoint.d.ts +17 -0
- package/adapter/endpoint.js +20 -0
- package/adapter/endpoint.js.map +1 -0
- package/adapter/index.d.ts +4 -0
- package/adapter/index.js +21 -0
- package/adapter/index.js.map +1 -0
- package/adapter/price.d.ts +77 -0
- package/adapter/price.js +88 -0
- package/adapter/price.js.map +1 -0
- package/adapter/types.d.ts +124 -0
- package/adapter/types.js +3 -0
- package/adapter/types.js.map +1 -0
- package/background-executor.d.ts +9 -0
- package/background-executor.js +97 -0
- package/background-executor.js.map +1 -0
- package/cache/factory.d.ts +6 -0
- package/cache/factory.js +24 -0
- package/cache/factory.js.map +1 -0
- package/cache/index.d.ts +87 -0
- package/cache/index.js +133 -0
- package/cache/index.js.map +1 -0
- package/cache/local.d.ts +23 -0
- package/cache/local.js +84 -0
- package/cache/local.js.map +1 -0
- package/cache/metrics.d.ts +27 -0
- package/cache/metrics.js +121 -0
- package/cache/metrics.js.map +1 -0
- package/cache/redis.d.ts +16 -0
- package/cache/redis.js +101 -0
- package/cache/redis.js.map +1 -0
- package/config/index.d.ts +298 -0
- package/config/index.js +359 -0
- package/config/index.js.map +1 -0
- package/config/provider-limits.d.ts +27 -0
- package/config/provider-limits.js +75 -0
- package/config/provider-limits.js.map +1 -0
- package/examples/bank-frick/accounts.d.ts +45 -0
- package/examples/bank-frick/accounts.js +203 -0
- package/examples/bank-frick/accounts.js.map +1 -0
- package/examples/bank-frick/config/index.d.ts +17 -0
- package/examples/bank-frick/config/index.js +55 -0
- package/examples/bank-frick/config/index.js.map +1 -0
- package/examples/bank-frick/index.d.ts +2 -0
- package/examples/bank-frick/index.js +16 -0
- package/examples/bank-frick/index.js.map +1 -0
- package/examples/bank-frick/util.d.ts +4 -0
- package/examples/bank-frick/util.js +40 -0
- package/examples/bank-frick/util.js.map +1 -0
- package/examples/coingecko/src/config/index.d.ts +2 -0
- package/examples/coingecko/src/config/index.js +6 -0
- package/examples/coingecko/src/config/index.js.map +1 -0
- package/examples/coingecko/src/config/overrides.json +10825 -0
- package/examples/coingecko/src/crypto-utils.d.ts +62 -0
- package/examples/coingecko/src/crypto-utils.js +60 -0
- package/examples/coingecko/src/crypto-utils.js.map +1 -0
- package/examples/coingecko/src/endpoint/coins.d.ts +26 -0
- package/examples/coingecko/src/endpoint/coins.js +37 -0
- package/examples/coingecko/src/endpoint/coins.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +30 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js +30 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto.js +28 -0
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -0
- package/examples/coingecko/src/endpoint/dominance.d.ts +3 -0
- package/examples/coingecko/src/endpoint/dominance.js +28 -0
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -0
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +3 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js +28 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/index.d.ts +6 -0
- package/examples/coingecko/src/endpoint/index.js +16 -0
- package/examples/coingecko/src/endpoint/index.js.map +1 -0
- package/examples/coingecko/src/global-utils.d.ts +42 -0
- package/examples/coingecko/src/global-utils.js +47 -0
- package/examples/coingecko/src/global-utils.js.map +1 -0
- package/examples/coingecko/src/index.d.ts +4 -0
- package/examples/coingecko/src/index.js +19 -0
- package/examples/coingecko/src/index.js.map +1 -0
- package/examples/cryptocompare/src/config/index.d.ts +2 -0
- package/examples/cryptocompare/src/config/index.js +6 -0
- package/examples/cryptocompare/src/config/index.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +40 -0
- package/examples/cryptocompare/src/endpoints/crypto.js +54 -0
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/index.d.ts +1 -0
- package/examples/cryptocompare/src/endpoints/index.js +6 -0
- package/examples/cryptocompare/src/endpoints/index.js.map +1 -0
- package/examples/cryptocompare/src/index.d.ts +4 -0
- package/examples/cryptocompare/src/index.js +14 -0
- package/examples/cryptocompare/src/index.js.map +1 -0
- package/examples/genesis/config/index.d.ts +7 -0
- package/examples/genesis/config/index.js +11 -0
- package/examples/genesis/config/index.js.map +1 -0
- package/examples/genesis/index.d.ts +2 -0
- package/examples/genesis/index.js +13 -0
- package/examples/genesis/index.js.map +1 -0
- package/examples/genesis/sseStream.d.ts +27 -0
- package/examples/genesis/sseStream.js +149 -0
- package/examples/genesis/sseStream.js.map +1 -0
- package/index.d.ts +17 -0
- package/index.js +174 -0
- package/index.js.map +1 -0
- package/metrics/constants.d.ts +16 -0
- package/metrics/constants.js +26 -0
- package/metrics/constants.js.map +1 -0
- package/metrics/index.d.ts +19 -0
- package/metrics/index.js +139 -0
- package/metrics/index.js.map +1 -0
- package/metrics/util.d.ts +7 -0
- package/metrics/util.js +10 -0
- package/metrics/util.js.map +1 -0
- package/package.json +50 -42
- package/rate-limiting/background/fixed-frequency.d.ts +10 -0
- package/rate-limiting/background/fixed-frequency.js +36 -0
- package/rate-limiting/background/fixed-frequency.js.map +1 -0
- package/rate-limiting/index.d.ts +56 -0
- package/rate-limiting/index.js +86 -0
- package/rate-limiting/index.js.map +1 -0
- package/rate-limiting/metrics.d.ts +3 -0
- package/rate-limiting/metrics.js +45 -0
- package/rate-limiting/metrics.js.map +1 -0
- package/rate-limiting/request/simple-counting.d.ts +20 -0
- package/rate-limiting/request/simple-counting.js +63 -0
- package/rate-limiting/request/simple-counting.js.map +1 -0
- package/transports/batch-warming.d.ts +53 -0
- package/transports/batch-warming.js +136 -0
- package/transports/batch-warming.js.map +1 -0
- package/transports/index.d.ts +108 -0
- package/transports/index.js +56 -0
- package/transports/index.js.map +1 -0
- package/transports/metrics.d.ts +25 -0
- package/transports/metrics.js +122 -0
- package/transports/metrics.js.map +1 -0
- package/transports/rest.d.ts +68 -0
- package/transports/rest.js +131 -0
- package/transports/rest.js.map +1 -0
- 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 +61 -0
- package/transports/sse.js +97 -0
- package/transports/sse.js.map +1 -0
- package/transports/util.d.ts +9 -0
- package/transports/util.js +87 -0
- package/transports/util.js.map +1 -0
- package/transports/websocket.d.ts +95 -0
- package/transports/websocket.js +164 -0
- package/transports/websocket.js.map +1 -0
- package/util/censor/censor-list.d.ts +9 -0
- package/util/censor/censor-list.js +13 -0
- package/util/censor/censor-list.js.map +1 -0
- package/util/index.d.ts +13 -0
- package/util/index.js +38 -0
- package/util/index.js.map +1 -0
- package/util/logger.d.ts +49 -0
- package/util/logger.js +123 -0
- package/util/logger.js.map +1 -0
- package/util/request.d.ts +138 -0
- package/util/request.js +3 -0
- package/util/request.js.map +1 -0
- package/util/subscription-set/expiring-sorted-set.d.ts +21 -0
- package/util/subscription-set/expiring-sorted-set.js +36 -0
- package/util/subscription-set/expiring-sorted-set.js.map +1 -0
- package/util/subscription-set/redis-sorted-set.d.ts +9 -0
- package/util/subscription-set/redis-sorted-set.js +29 -0
- package/util/subscription-set/redis-sorted-set.js.map +1 -0
- package/util/subscription-set/subscription-set.d.ts +19 -0
- package/util/subscription-set/subscription-set.js +28 -0
- package/util/subscription-set/subscription-set.js.map +1 -0
- package/util/test-payload-loader.d.ts +26 -0
- package/util/test-payload-loader.js +85 -0
- package/util/test-payload-loader.js.map +1 -0
- package/validation/error.d.ts +48 -0
- package/validation/error.js +78 -0
- package/validation/error.js.map +1 -0
- package/validation/index.d.ts +5 -0
- package/validation/index.js +102 -0
- package/validation/index.js.map +1 -0
- package/validation/input-params.d.ts +14 -0
- package/validation/input-params.js +3 -0
- package/validation/input-params.js.map +1 -0
- package/validation/input-validator.d.ts +16 -0
- package/validation/input-validator.js +123 -0
- package/validation/input-validator.js.map +1 -0
- package/README.md +0 -102
package/cache/local.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.LocalCache = void 0;
|
|
27
|
+
const util_1 = require("../util");
|
|
28
|
+
const cacheMetrics = __importStar(require("./metrics"));
|
|
29
|
+
const logger = (0, util_1.makeLogger)('LocalCache');
|
|
30
|
+
/**
|
|
31
|
+
* Local implementation of a Cache. It uses a simple js Object, storing entries with both
|
|
32
|
+
* a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
|
|
33
|
+
*
|
|
34
|
+
* @typeParam T - the type for the entries' values
|
|
35
|
+
*/
|
|
36
|
+
class LocalCache {
|
|
37
|
+
constructor() {
|
|
38
|
+
this.store = {};
|
|
39
|
+
}
|
|
40
|
+
async get(key) {
|
|
41
|
+
logger.trace(`Getting key ${key}`);
|
|
42
|
+
const entry = this.store[key];
|
|
43
|
+
if (!entry) {
|
|
44
|
+
logger.debug(`No entry in local cache for key "${key}", returning undefined`);
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const expired = entry.expirationTimestamp <= Date.now();
|
|
48
|
+
if (expired) {
|
|
49
|
+
logger.debug('Entry in local cache expired, deleting and returning undefined');
|
|
50
|
+
this.delete(key);
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
logger.debug('Found valid entry in local cache, returning value');
|
|
55
|
+
return entry.value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async delete(key) {
|
|
59
|
+
logger.trace(`Deleting key ${key}`);
|
|
60
|
+
delete this.store[key]; // Deletes are slower than ignoring or setting null, fyi
|
|
61
|
+
}
|
|
62
|
+
async set(key, value, ttl) {
|
|
63
|
+
logger.trace(`Setting key ${key} with ttl ${ttl}`);
|
|
64
|
+
this.store[key] = {
|
|
65
|
+
value,
|
|
66
|
+
expirationTimestamp: Date.now() + ttl,
|
|
67
|
+
};
|
|
68
|
+
// Only record metrics if feed Id is present, otherwise assuming value is not adapter response to record
|
|
69
|
+
const feedId = value.meta?.metrics?.feedId;
|
|
70
|
+
if (feedId) {
|
|
71
|
+
// Record cache set count, max age, and staleness (set to 0 for cache set)
|
|
72
|
+
const label = cacheMetrics.cacheMetricsLabel(key, feedId, cacheMetrics.CacheTypes.Local);
|
|
73
|
+
cacheMetrics.cacheSet(label, ttl);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async setMany(entries, ttl) {
|
|
77
|
+
logger.trace(`Setting a bunch of keys with ttl ${ttl}`);
|
|
78
|
+
for (const { key, value } of entries) {
|
|
79
|
+
this.set(key, value, ttl);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.LocalCache = LocalCache;
|
|
84
|
+
//# sourceMappingURL=local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../src/cache/local.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kCAAqD;AAErD,wDAAyC;AAEzC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,YAAY,CAAC,CAAA;AAYvC;;;;;GAKG;AACH,MAAa,UAAU;IAAvB;QACE,UAAK,GAAuC,EAAE,CAAA;IAiDhD,CAAC;IA/CC,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,CAAC,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC,CAAA;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE7B,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,oCAAoC,GAAG,wBAAwB,CAAC,CAAA;YAC7E,OAAO,SAAS,CAAA;SACjB;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,mBAAmB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAA;QACvD,IAAI,OAAO,EAAE;YACX,MAAM,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAA;YAC9E,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAChB,OAAO,SAAS,CAAA;SACjB;aAAM;YACL,MAAM,CAAC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participant_id: string;
|
|
4
|
+
feed_id: string;
|
|
5
|
+
cache_type: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const cacheGet: (label: CacheMetricsLabels, value: unknown, staleness: number) => void;
|
|
8
|
+
export declare const cacheSet: (label: CacheMetricsLabels, maxAge: number) => void;
|
|
9
|
+
export declare const cacheMetricsLabel: (cacheKey: string, feedId: string, cacheType: string) => {
|
|
10
|
+
participant_id: string;
|
|
11
|
+
feed_id: string;
|
|
12
|
+
cache_type: string;
|
|
13
|
+
};
|
|
14
|
+
export declare enum CacheTypes {
|
|
15
|
+
Redis = "redis",
|
|
16
|
+
Local = "local"
|
|
17
|
+
}
|
|
18
|
+
export declare enum CMD_SENT_STATUS {
|
|
19
|
+
TIMEOUT = "TIMEOUT",
|
|
20
|
+
FAIL = "FAIL",
|
|
21
|
+
SUCCESS = "SUCCESS"
|
|
22
|
+
}
|
|
23
|
+
export declare const redisConnectionsOpen: client.Counter<string>;
|
|
24
|
+
export declare const redisRetriesCount: client.Counter<string>;
|
|
25
|
+
export declare const redisCommandsSentCount: client.Counter<"status" | "function_name">;
|
|
26
|
+
export declare const cacheWarmerCount: client.Gauge<"isBatched">;
|
|
27
|
+
export {};
|
package/cache/metrics.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.cacheWarmerCount = exports.redisCommandsSentCount = exports.redisRetriesCount = exports.redisConnectionsOpen = exports.CMD_SENT_STATUS = exports.CacheTypes = exports.cacheMetricsLabel = exports.cacheSet = exports.cacheGet = void 0;
|
|
27
|
+
const client = __importStar(require("prom-client"));
|
|
28
|
+
const cacheGet = (label, value, staleness) => {
|
|
29
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
30
|
+
const parsedValue = Number(value);
|
|
31
|
+
if (!Number.isNaN(parsedValue) && Number.isFinite(parsedValue)) {
|
|
32
|
+
cacheDataGetValues.labels(label).set(parsedValue);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
cacheDataGetCount.labels(label).inc();
|
|
36
|
+
cacheDataStalenessSeconds.labels(label).set(staleness);
|
|
37
|
+
};
|
|
38
|
+
exports.cacheGet = cacheGet;
|
|
39
|
+
const cacheSet = (label, maxAge) => {
|
|
40
|
+
cacheDataSetCount.labels(label).inc();
|
|
41
|
+
cacheDataMaxAge.labels(label).set(maxAge);
|
|
42
|
+
cacheDataStalenessSeconds.labels(label).set(0);
|
|
43
|
+
};
|
|
44
|
+
exports.cacheSet = cacheSet;
|
|
45
|
+
const cacheMetricsLabel = (cacheKey, feedId, cacheType) => ({
|
|
46
|
+
participant_id: cacheKey,
|
|
47
|
+
feed_id: feedId,
|
|
48
|
+
cache_type: cacheType,
|
|
49
|
+
});
|
|
50
|
+
exports.cacheMetricsLabel = cacheMetricsLabel;
|
|
51
|
+
var CacheTypes;
|
|
52
|
+
(function (CacheTypes) {
|
|
53
|
+
CacheTypes["Redis"] = "redis";
|
|
54
|
+
CacheTypes["Local"] = "local";
|
|
55
|
+
})(CacheTypes = exports.CacheTypes || (exports.CacheTypes = {}));
|
|
56
|
+
var CMD_SENT_STATUS;
|
|
57
|
+
(function (CMD_SENT_STATUS) {
|
|
58
|
+
CMD_SENT_STATUS["TIMEOUT"] = "TIMEOUT";
|
|
59
|
+
CMD_SENT_STATUS["FAIL"] = "FAIL";
|
|
60
|
+
CMD_SENT_STATUS["SUCCESS"] = "SUCCESS";
|
|
61
|
+
})(CMD_SENT_STATUS = exports.CMD_SENT_STATUS || (exports.CMD_SENT_STATUS = {}));
|
|
62
|
+
const baseLabels = [
|
|
63
|
+
'feed_id',
|
|
64
|
+
'participant_id',
|
|
65
|
+
'cache_type',
|
|
66
|
+
'is_from_ws',
|
|
67
|
+
'experimental',
|
|
68
|
+
];
|
|
69
|
+
// Skipping this metrics for v3
|
|
70
|
+
// const cache_execution_duration_seconds = new client.Histogram({
|
|
71
|
+
// name: 'cache_execution_duration_seconds',
|
|
72
|
+
// help: 'A histogram bucket of the distribution of cache execution durations',
|
|
73
|
+
// labelNames: [...baseLabels, 'cache_hit'] as const,
|
|
74
|
+
// buckets: [0.01, 0.1, 1, 10],
|
|
75
|
+
// })
|
|
76
|
+
const cacheDataGetCount = new client.Counter({
|
|
77
|
+
name: 'cache_data_get_count',
|
|
78
|
+
help: 'A counter that increments every time a value is fetched from the cache',
|
|
79
|
+
labelNames: baseLabels,
|
|
80
|
+
});
|
|
81
|
+
const cacheDataGetValues = new client.Gauge({
|
|
82
|
+
name: 'cache_data_get_values',
|
|
83
|
+
help: 'A gauge keeping track of values being fetched from cache',
|
|
84
|
+
labelNames: baseLabels,
|
|
85
|
+
});
|
|
86
|
+
const cacheDataMaxAge = new client.Gauge({
|
|
87
|
+
name: 'cache_data_max_age',
|
|
88
|
+
help: 'A gauge tracking the max age of stored values in the cache',
|
|
89
|
+
labelNames: baseLabels,
|
|
90
|
+
});
|
|
91
|
+
const cacheDataSetCount = new client.Counter({
|
|
92
|
+
name: 'cache_data_set_count',
|
|
93
|
+
help: 'A counter that increments every time a value is set to the cache',
|
|
94
|
+
labelNames: [...baseLabels, 'status_code'],
|
|
95
|
+
});
|
|
96
|
+
const cacheDataStalenessSeconds = new client.Gauge({
|
|
97
|
+
name: 'cache_data_staleness_seconds',
|
|
98
|
+
help: 'Observes the staleness of the data returned',
|
|
99
|
+
labelNames: baseLabels,
|
|
100
|
+
});
|
|
101
|
+
// Redis Metrics
|
|
102
|
+
exports.redisConnectionsOpen = new client.Counter({
|
|
103
|
+
name: 'redis_connections_open',
|
|
104
|
+
help: 'The number of redis connections that are open',
|
|
105
|
+
});
|
|
106
|
+
exports.redisRetriesCount = new client.Counter({
|
|
107
|
+
name: 'redis_retries_count',
|
|
108
|
+
help: 'The number of retries that have been made to establish a redis connection',
|
|
109
|
+
});
|
|
110
|
+
exports.redisCommandsSentCount = new client.Counter({
|
|
111
|
+
name: 'redis_commands_sent_count',
|
|
112
|
+
help: 'The number of redis commands sent',
|
|
113
|
+
labelNames: ['status', 'function_name'],
|
|
114
|
+
});
|
|
115
|
+
// Cache Warmer Metrics
|
|
116
|
+
exports.cacheWarmerCount = new client.Gauge({
|
|
117
|
+
name: 'cache_warmer_get_count',
|
|
118
|
+
help: 'The number of cache warmers running',
|
|
119
|
+
labelNames: ['isBatched'],
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/cache/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AAS9B,MAAM,QAAQ,GAAG,CAA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AAE,wBAAwB;IAC9B,IAAI,EAAE,+CAA+C;CACtD,CAAC,CAAA;AAEW,QAAA,iBAAiB,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC;IAClD,IAAI,EAAE,qBAAqB;IAC3B,IAAI,EAAE,2EAA2E;CAClF,CAAC,CAAA;AAEW,QAAA,sBAAsB,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC;IACvD,IAAI,EAAE,2BAA2B;IACjC,IAAI,EAAE,mCAAmC;IACzC,UAAU,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC;CACxC,CAAC,CAAA;AAEF,uBAAuB;AACV,QAAA,gBAAgB,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC;IAC/C,IAAI,EAAE,wBAAwB;IAC9B,IAAI,EAAE,qCAAqC;IAC3C,UAAU,EAAE,CAAC,WAAW,CAAU;CACnC,CAAC,CAAA"}
|
package/cache/redis.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Redis from 'ioredis';
|
|
2
|
+
import { Cache, CacheEntry } from './index';
|
|
3
|
+
/**
|
|
4
|
+
* Redis implementation of a Cache. It uses a simple js Object, storing entries with both
|
|
5
|
+
* a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - the type for the entries' values
|
|
8
|
+
*/
|
|
9
|
+
export declare class RedisCache<T = unknown> implements Cache<T> {
|
|
10
|
+
private client;
|
|
11
|
+
constructor(client: Redis);
|
|
12
|
+
get(key: string): Promise<T | undefined>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
set(key: string, value: T, ttl: number): Promise<void>;
|
|
15
|
+
setMany(entries: CacheEntry<T>[], ttl: number): Promise<void>;
|
|
16
|
+
}
|
package/cache/redis.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.RedisCache = void 0;
|
|
27
|
+
const util_1 = require("../util");
|
|
28
|
+
const cacheMetrics = __importStar(require("./metrics"));
|
|
29
|
+
const logger = (0, util_1.makeLogger)('RedisCache');
|
|
30
|
+
/**
|
|
31
|
+
* Redis implementation of a Cache. It uses a simple js Object, storing entries with both
|
|
32
|
+
* a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
|
|
33
|
+
*
|
|
34
|
+
* @typeParam T - the type for the entries' values
|
|
35
|
+
*/
|
|
36
|
+
class RedisCache {
|
|
37
|
+
constructor(client) {
|
|
38
|
+
this.client = client;
|
|
39
|
+
}
|
|
40
|
+
async get(key) {
|
|
41
|
+
logger.trace(`Getting key ${key}`);
|
|
42
|
+
const value = await this.client.get(key);
|
|
43
|
+
// Record get command sent to Redis
|
|
44
|
+
cacheMetrics.redisCommandsSentCount
|
|
45
|
+
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'get' })
|
|
46
|
+
.inc();
|
|
47
|
+
if (!value) {
|
|
48
|
+
logger.debug(`No entry in redis cache for key "${key}", returning undefined`);
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return JSON.parse(value);
|
|
52
|
+
}
|
|
53
|
+
async delete(key) {
|
|
54
|
+
logger.trace(`Deleting key ${key}`);
|
|
55
|
+
await this.client.del(key);
|
|
56
|
+
// Record delete command sent to Redis
|
|
57
|
+
cacheMetrics.redisCommandsSentCount
|
|
58
|
+
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'delete' })
|
|
59
|
+
.inc();
|
|
60
|
+
}
|
|
61
|
+
async set(key, value, ttl) {
|
|
62
|
+
logger.trace(`Setting key ${key}`);
|
|
63
|
+
await this.client.set(key, JSON.stringify(value), 'PX', ttl);
|
|
64
|
+
// Only record metrics if feed Id is present, otherwise assuming value is not adapter response to record
|
|
65
|
+
const feedId = value.meta?.metrics?.feedId;
|
|
66
|
+
if (feedId) {
|
|
67
|
+
// Record cache set count, max age, and staleness (set to 0 for cache set)
|
|
68
|
+
const label = cacheMetrics.cacheMetricsLabel(key, feedId, cacheMetrics.CacheTypes.Redis);
|
|
69
|
+
cacheMetrics.cacheSet(label, ttl);
|
|
70
|
+
}
|
|
71
|
+
// Record set command sent to Redis
|
|
72
|
+
cacheMetrics.redisCommandsSentCount
|
|
73
|
+
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'set' })
|
|
74
|
+
.inc();
|
|
75
|
+
}
|
|
76
|
+
async setMany(entries, ttl) {
|
|
77
|
+
logger.trace(`Setting a bunch of keys`);
|
|
78
|
+
// Unfortunately, there's no ttl for mset
|
|
79
|
+
let chain = this.client.multi();
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
chain = chain.set(entry.key, JSON.stringify(entry.value), 'PX', ttl);
|
|
82
|
+
}
|
|
83
|
+
await chain.exec();
|
|
84
|
+
// Loop again, but this time to record these in metrics
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
// Only record metrics if feed Id is present, otherwise assuming value is not adapter response to record
|
|
87
|
+
const feedId = entry.value.meta?.metrics?.feedId;
|
|
88
|
+
if (feedId) {
|
|
89
|
+
// Record cache set count, max age, and staleness (set to 0 for cache set)
|
|
90
|
+
const label = cacheMetrics.cacheMetricsLabel(entry.key, feedId, cacheMetrics.CacheTypes.Redis);
|
|
91
|
+
cacheMetrics.cacheSet(label, ttl);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Record setMany command sent to Redis
|
|
95
|
+
cacheMetrics.redisCommandsSentCount
|
|
96
|
+
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'exec' })
|
|
97
|
+
.inc();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.RedisCache = RedisCache;
|
|
101
|
+
//# sourceMappingURL=redis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../src/cache/redis.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kCAAqD;AAErD,wDAAyC;AAEzC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,YAAY,CAAC,CAAA;AAEvC;;;;;GAKG;AACH,MAAa,UAAU;IACrB,YAAoB,MAAa;QAAb,WAAM,GAAN,MAAM,CAAO;IAAG,CAAC;IAErC,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,CAAC,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC,CAAA;QAClC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAExC,mCAAmC;QACnC,YAAY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@@
|
|
|
1
|
+
export declare const BaseSettings: {
|
|
2
|
+
readonly API_ENDPOINT: {
|
|
3
|
+
readonly description: "The URL that certain transports use to retrieve data";
|
|
4
|
+
readonly type: "string";
|
|
5
|
+
};
|
|
6
|
+
readonly API_KEY: {
|
|
7
|
+
readonly description: "Default setting for an EA key";
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly sensitive: true;
|
|
10
|
+
};
|
|
11
|
+
readonly API_TIMEOUT: {
|
|
12
|
+
readonly description: "The number of milliseconds a request can be pending before returning a timeout error for data provider request";
|
|
13
|
+
readonly type: "number";
|
|
14
|
+
readonly default: 30000;
|
|
15
|
+
};
|
|
16
|
+
readonly API_VERBOSE: {
|
|
17
|
+
readonly description: "Toggle whether the response from the EA should contain just the results or also include the full response body from the queried API.";
|
|
18
|
+
readonly type: "boolean";
|
|
19
|
+
readonly default: false;
|
|
20
|
+
};
|
|
21
|
+
readonly BASE_URL: {
|
|
22
|
+
readonly description: "Starting path for the EA handler endpoint";
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly default: "/";
|
|
25
|
+
};
|
|
26
|
+
readonly BATCH_TRANSPORT_SETUP_VALIDATION: {
|
|
27
|
+
readonly description: "Flag to toggle batch transport setup validation";
|
|
28
|
+
readonly type: "boolean";
|
|
29
|
+
readonly default: false;
|
|
30
|
+
};
|
|
31
|
+
readonly CACHE_MAX_AGE: {
|
|
32
|
+
readonly description: "Maximum amount of time (in ms) that a response will stay cached";
|
|
33
|
+
readonly type: "number";
|
|
34
|
+
readonly default: 90000;
|
|
35
|
+
};
|
|
36
|
+
readonly CACHE_REDIS_HOST: {
|
|
37
|
+
readonly description: "Hostname for the Redis instance to be used";
|
|
38
|
+
readonly type: "string";
|
|
39
|
+
readonly default: "127.0.0.1";
|
|
40
|
+
};
|
|
41
|
+
readonly CACHE_REDIS_PASSWORD: {
|
|
42
|
+
readonly description: "The password required for redis auth";
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
readonly sensitive: true;
|
|
45
|
+
};
|
|
46
|
+
readonly CACHE_REDIS_PATH: {
|
|
47
|
+
readonly description: "The UNIX socket string of the Redis server";
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
};
|
|
50
|
+
readonly CACHE_REDIS_PORT: {
|
|
51
|
+
readonly description: "Port for the Redis instance to be used";
|
|
52
|
+
readonly type: "number";
|
|
53
|
+
readonly default: 6379;
|
|
54
|
+
};
|
|
55
|
+
readonly CACHE_REDIS_TIMEOUT: {
|
|
56
|
+
readonly description: "Timeout to fail a Redis server request if no response (ms)";
|
|
57
|
+
readonly type: "number";
|
|
58
|
+
readonly default: 500;
|
|
59
|
+
};
|
|
60
|
+
readonly CACHE_TYPE: {
|
|
61
|
+
readonly description: "The type of cache to use throughout the EA";
|
|
62
|
+
readonly type: "enum";
|
|
63
|
+
readonly default: "local";
|
|
64
|
+
readonly options: readonly ["local", "redis"];
|
|
65
|
+
};
|
|
66
|
+
readonly CORRELATION_ID_ENABLED: {
|
|
67
|
+
readonly description: "Flag to enable correlation IDs for sent requests in logging";
|
|
68
|
+
readonly type: "boolean";
|
|
69
|
+
readonly default: true;
|
|
70
|
+
};
|
|
71
|
+
readonly DEBUG: {
|
|
72
|
+
readonly description: "Toggles debug mode";
|
|
73
|
+
readonly type: "boolean";
|
|
74
|
+
readonly default: false;
|
|
75
|
+
};
|
|
76
|
+
readonly EA_PORT: {
|
|
77
|
+
readonly description: "Port through which the EA will listen for REST requests (if mode is set to \"reader\" or \"reader-writer\")";
|
|
78
|
+
readonly type: "number";
|
|
79
|
+
readonly default: 8080;
|
|
80
|
+
};
|
|
81
|
+
readonly EXPERIMENTAL_METRICS_ENABLED: {
|
|
82
|
+
readonly description: "Flag to specify whether or not to collect metrics. Used as fallback for METRICS_ENABLED";
|
|
83
|
+
readonly type: "boolean";
|
|
84
|
+
readonly default: true;
|
|
85
|
+
};
|
|
86
|
+
readonly LOG_LEVEL: {
|
|
87
|
+
readonly description: "Minimum level required for logs to be output";
|
|
88
|
+
readonly type: "string";
|
|
89
|
+
readonly default: "info";
|
|
90
|
+
};
|
|
91
|
+
readonly METRICS_ENABLED: {
|
|
92
|
+
readonly description: "Flag to specify whether or not to startup the metrics server";
|
|
93
|
+
readonly type: "boolean";
|
|
94
|
+
readonly default: true;
|
|
95
|
+
};
|
|
96
|
+
readonly METRICS_NAME: {
|
|
97
|
+
readonly description: "Metrics name";
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
};
|
|
100
|
+
readonly METRICS_PORT: {
|
|
101
|
+
readonly description: "Port metrics will be exposed to";
|
|
102
|
+
readonly type: "number";
|
|
103
|
+
readonly default: 9080;
|
|
104
|
+
};
|
|
105
|
+
readonly METRICS_USE_BASE_URL: {
|
|
106
|
+
readonly description: "Flag to specify whether or not to prepend the BASE_URL to the metrics endpoint";
|
|
107
|
+
readonly type: "boolean";
|
|
108
|
+
};
|
|
109
|
+
readonly RATE_LIMIT_API_TIER: {
|
|
110
|
+
readonly description: "Rate limiting tier to use from the available options for the adapter. If not present, the adapter will run using the first tier on the list.";
|
|
111
|
+
readonly type: "string";
|
|
112
|
+
};
|
|
113
|
+
readonly RATE_LIMIT_CAPACITY: {
|
|
114
|
+
readonly description: "Used as rate limit capacity per minute and ignores tier settings if defined";
|
|
115
|
+
readonly type: "number";
|
|
116
|
+
};
|
|
117
|
+
readonly RATE_LIMIT_CAPACITY_MINUTE: {
|
|
118
|
+
readonly description: "Used as rate limit capacity per minute and ignores tier settings if defined. Supercedes RATE_LIMIT_CAPACITY if both vars are set";
|
|
119
|
+
readonly type: "number";
|
|
120
|
+
};
|
|
121
|
+
readonly RATE_LIMIT_CAPACITY_SECOND: {
|
|
122
|
+
readonly description: "Used as rate limit capacity per second and ignores tier settings if defined";
|
|
123
|
+
readonly type: "number";
|
|
124
|
+
};
|
|
125
|
+
readonly REQUEST_COALESCING_ENABLED: {
|
|
126
|
+
readonly description: "Enable request coalescing";
|
|
127
|
+
readonly type: "boolean";
|
|
128
|
+
readonly default: false;
|
|
129
|
+
};
|
|
130
|
+
readonly REQUEST_COALESCING_ENTROPY_MAX: {
|
|
131
|
+
readonly description: "Amount of random delay (entropy) in milliseconds that will be added to requests. Avoids issue where the request coalescing key will not be set before multiple other instances in a burst try to access the same key";
|
|
132
|
+
readonly type: "number";
|
|
133
|
+
readonly default: 0;
|
|
134
|
+
};
|
|
135
|
+
readonly SSE_SUBSCRIPTION_UPDATE_SLEEP: {
|
|
136
|
+
readonly description: "Maximum amount of time (in ms) between each update to the set of subscribed feeds";
|
|
137
|
+
readonly type: "number";
|
|
138
|
+
readonly default: 1000;
|
|
139
|
+
};
|
|
140
|
+
readonly SSE_KEEPALIVE_SLEEP: {
|
|
141
|
+
readonly description: "Maximum amount of time (in ms) between each SSE keepalive request";
|
|
142
|
+
readonly type: "number";
|
|
143
|
+
readonly default: 60000;
|
|
144
|
+
};
|
|
145
|
+
readonly SSE_SUBSCRIPTION_TTL: {
|
|
146
|
+
readonly description: "Maximum amount of time (in ms) an SSE subscription will be cached before being unsubscribed";
|
|
147
|
+
readonly type: "number";
|
|
148
|
+
readonly default: 300000;
|
|
149
|
+
};
|
|
150
|
+
readonly WARMUP_SUBSCRIPTION_TTL: {
|
|
151
|
+
readonly type: "number";
|
|
152
|
+
readonly description: "TTL for batch warmer subscriptions";
|
|
153
|
+
readonly default: 300000;
|
|
154
|
+
};
|
|
155
|
+
readonly WS_API_ENDPOINT: {
|
|
156
|
+
readonly description: "Override the base websocket URL within the EA.";
|
|
157
|
+
readonly type: "string";
|
|
158
|
+
};
|
|
159
|
+
readonly WS_API_KEY: {
|
|
160
|
+
readonly description: "The websocket API key to authenticate with";
|
|
161
|
+
readonly type: "string";
|
|
162
|
+
readonly sensitive: true;
|
|
163
|
+
};
|
|
164
|
+
readonly WS_SUBSCRIPTION_TTL: {
|
|
165
|
+
readonly description: "";
|
|
166
|
+
readonly type: "number";
|
|
167
|
+
readonly default: 120000;
|
|
168
|
+
};
|
|
169
|
+
readonly CACHE_POLLING_MAX_RETRIES: {
|
|
170
|
+
readonly description: "Max amount of times to attempt to find EA response in the cache after the Transport has been set up";
|
|
171
|
+
readonly type: "number";
|
|
172
|
+
readonly default: 10;
|
|
173
|
+
};
|
|
174
|
+
readonly CACHE_POLLING_SLEEP_MS: {
|
|
175
|
+
readonly description: "The number of ms to sleep between each retry to fetch the EA response in the cache";
|
|
176
|
+
readonly type: "number";
|
|
177
|
+
readonly default: 200;
|
|
178
|
+
};
|
|
179
|
+
readonly DEFAULT_CACHE_KEY: {
|
|
180
|
+
readonly description: "Default key to be used when one cannot be determined from request parameters";
|
|
181
|
+
readonly type: "string";
|
|
182
|
+
readonly default: "DEFAULT_CACHE_KEY";
|
|
183
|
+
};
|
|
184
|
+
readonly EA_HOST: {
|
|
185
|
+
readonly description: "Host this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
|
|
186
|
+
readonly type: "string";
|
|
187
|
+
readonly default: "::";
|
|
188
|
+
};
|
|
189
|
+
readonly EA_MODE: {
|
|
190
|
+
readonly description: "Port this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
|
|
191
|
+
readonly type: "enum";
|
|
192
|
+
readonly default: "reader-writer";
|
|
193
|
+
readonly options: readonly ["reader", "writer", "reader-writer"];
|
|
194
|
+
};
|
|
195
|
+
readonly MAX_COMMON_KEY_SIZE: {
|
|
196
|
+
readonly description: "Maximum amount of characters that the common part of the cache key or feed ID can have";
|
|
197
|
+
readonly type: "number";
|
|
198
|
+
readonly default: 300;
|
|
199
|
+
readonly validate: (value?: number) => "MAX_COMMON_KEY_SIZE must be a number between 150 and 500" | undefined;
|
|
200
|
+
};
|
|
201
|
+
readonly REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES: {
|
|
202
|
+
readonly description: "Maximum amount of times the Rest Transport will attempt to set up a request when blocked by the rate limiter";
|
|
203
|
+
readonly type: "number";
|
|
204
|
+
readonly default: 3;
|
|
205
|
+
};
|
|
206
|
+
readonly REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES: {
|
|
207
|
+
readonly description: "Time that the Rest Transport will wait between retries when blocked by the rate limiter";
|
|
208
|
+
readonly type: "number";
|
|
209
|
+
readonly default: 400;
|
|
210
|
+
};
|
|
211
|
+
readonly SMOKE_TEST_PAYLOAD_FILE_NAME: {
|
|
212
|
+
readonly description: "Name of the test payload file used for the smoke endpoint";
|
|
213
|
+
readonly type: "string";
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, }: {
|
|
217
|
+
overrides?: Partial<BaseAdapterConfig> | undefined;
|
|
218
|
+
customSettings?: SettingsMap | undefined;
|
|
219
|
+
}) => AdapterConfig<CustomSettings>;
|
|
220
|
+
export declare const validateAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>(adapterConfig: AdapterConfig<CustomSettings>, customSettings?: SettingsMap) => void;
|
|
221
|
+
declare type SettingValueType = string | number | boolean;
|
|
222
|
+
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;
|
|
223
|
+
declare type BaseSettingsType = typeof BaseSettings;
|
|
224
|
+
export declare type Setting = {
|
|
225
|
+
type: 'string';
|
|
226
|
+
description: string;
|
|
227
|
+
options?: never;
|
|
228
|
+
default?: string;
|
|
229
|
+
validate?: (value?: string) => ValidationErrorMessage;
|
|
230
|
+
required?: false;
|
|
231
|
+
sensitive?: boolean;
|
|
232
|
+
} | {
|
|
233
|
+
type: 'string';
|
|
234
|
+
description: string;
|
|
235
|
+
options?: never;
|
|
236
|
+
default?: string;
|
|
237
|
+
validate?: (value: string) => ValidationErrorMessage;
|
|
238
|
+
required: true;
|
|
239
|
+
sensitive?: boolean;
|
|
240
|
+
} | {
|
|
241
|
+
type: 'number';
|
|
242
|
+
description: string;
|
|
243
|
+
options?: never;
|
|
244
|
+
default?: number;
|
|
245
|
+
validate?: (value?: number) => ValidationErrorMessage;
|
|
246
|
+
required?: false;
|
|
247
|
+
} | {
|
|
248
|
+
type: 'number';
|
|
249
|
+
description: string;
|
|
250
|
+
options?: never;
|
|
251
|
+
default?: number;
|
|
252
|
+
validate?: (value: number) => ValidationErrorMessage;
|
|
253
|
+
required: true;
|
|
254
|
+
} | {
|
|
255
|
+
type: 'boolean';
|
|
256
|
+
description: string;
|
|
257
|
+
options?: never;
|
|
258
|
+
default?: boolean;
|
|
259
|
+
validate?: (value?: boolean) => ValidationErrorMessage;
|
|
260
|
+
required?: false;
|
|
261
|
+
} | {
|
|
262
|
+
type: 'boolean';
|
|
263
|
+
description: string;
|
|
264
|
+
options?: never;
|
|
265
|
+
default?: boolean;
|
|
266
|
+
validate?: (value: boolean) => ValidationErrorMessage;
|
|
267
|
+
required: true;
|
|
268
|
+
} | {
|
|
269
|
+
type: 'enum';
|
|
270
|
+
description: string;
|
|
271
|
+
default?: string;
|
|
272
|
+
options: readonly string[];
|
|
273
|
+
validate?: (value?: string) => ValidationErrorMessage;
|
|
274
|
+
required?: false;
|
|
275
|
+
} | {
|
|
276
|
+
type: 'enum';
|
|
277
|
+
description: string;
|
|
278
|
+
default?: string;
|
|
279
|
+
options: readonly string[];
|
|
280
|
+
validate?: (value: string) => ValidationErrorMessage;
|
|
281
|
+
required: true;
|
|
282
|
+
};
|
|
283
|
+
export declare type AdapterConfigFromSettings<T extends SettingsMap> = {
|
|
284
|
+
-readonly [K in keyof T as T[K] extends {
|
|
285
|
+
default: SettingValueType;
|
|
286
|
+
} ? K : T[K]['required'] extends true ? K : never]: SettingType<T[K]>;
|
|
287
|
+
} & {
|
|
288
|
+
-readonly [K in keyof T as T[K] extends {
|
|
289
|
+
default: SettingValueType;
|
|
290
|
+
} ? never : T[K]['required'] extends true ? never : K]?: SettingType<T[K]> | undefined;
|
|
291
|
+
};
|
|
292
|
+
export declare type BaseAdapterConfig = AdapterConfigFromSettings<BaseSettingsType>;
|
|
293
|
+
export declare type AdapterConfig<T extends CustomSettingsType<T> = SettingsMap> = AdapterConfigFromSettings<T> & BaseAdapterConfig;
|
|
294
|
+
export declare type CustomSettingsType<T = SettingsMap> = Record<keyof T, Setting>;
|
|
295
|
+
export declare type EmptySettings = Record<string, never>;
|
|
296
|
+
export declare type SettingsMap = Record<string, Setting>;
|
|
297
|
+
export declare type ValidationErrorMessage = string | undefined;
|
|
298
|
+
export {};
|