@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.
Files changed (164) hide show
  1. package/adapter.js +114 -101
  2. package/cache/factory.js +3 -0
  3. package/chainlink-external-adapter-framework-v0.0.6.tgz +0 -0
  4. package/config/index.js +69 -83
  5. package/config/provider-limits.js +10 -15
  6. package/examples/bank-frick/accounts.js +3 -2
  7. package/examples/bank-frick/index.js +3 -2
  8. package/examples/coingecko/src/config/index.js +13 -0
  9. package/examples/coingecko/src/config/overrides.json +10826 -0
  10. package/examples/coingecko/src/cryptoUtils.js +41 -0
  11. package/examples/coingecko/src/endpoint/coins.js +33 -0
  12. package/examples/coingecko/src/endpoint/crypto-marketcap.js +46 -0
  13. package/examples/coingecko/src/endpoint/crypto-volume.js +46 -0
  14. package/examples/coingecko/src/endpoint/crypto.js +47 -0
  15. package/examples/coingecko/src/endpoint/dominance.js +26 -0
  16. package/examples/coingecko/src/endpoint/global-marketcap.js +26 -0
  17. package/examples/coingecko/src/endpoint/index.js +15 -0
  18. package/examples/coingecko/src/globalUtils.js +48 -0
  19. package/examples/coingecko/src/index.js +14 -0
  20. package/examples/coingecko/test/e2e/adapter.test.js +262 -0
  21. package/examples/coingecko/test/integration/adapter.test.js +264 -0
  22. package/examples/coingecko/test/integration/capturedRequests.json +1 -0
  23. package/examples/coingecko/test/integration/fixtures.js +41 -0
  24. package/{package/examples/coingecko → examples/coingecko-old}/batch-warming.js +4 -3
  25. package/examples/{coingecko → coingecko-old}/index.js +3 -2
  26. package/{package/examples/coingecko → examples/coingecko-old}/rest.js +3 -2
  27. package/examples/ncfx/index.js +3 -2
  28. package/examples/ncfx/websocket.js +3 -2
  29. package/index.js +17 -23
  30. package/package.json +5 -4
  31. package/rate-limiting/index.js +23 -2
  32. package/transports/batch-warming.js +1 -1
  33. package/transports/rest.js +9 -2
  34. package/transports/util.js +2 -1
  35. package/transports/websocket.js +4 -6
  36. package/util/recordRequests.js +45 -0
  37. package/{package/validation/override-functions.js → validation/overrideFunctions.js} +0 -0
  38. package/adapter.d.ts +0 -107
  39. package/background-executor.d.ts +0 -11
  40. package/cache/factory.d.ts +0 -6
  41. package/cache/index.d.ts +0 -94
  42. package/cache/local.d.ts +0 -23
  43. package/cache/metrics.d.ts +0 -27
  44. package/cache/redis.d.ts +0 -16
  45. package/chainlink-external-adapter-framework-0.0.6.tgz +0 -0
  46. package/config/index.d.ts +0 -209
  47. package/config/provider-limits.d.ts +0 -31
  48. package/examples/bank-frick/accounts.d.ts +0 -39
  49. package/examples/bank-frick/config/index.d.ts +0 -4
  50. package/examples/bank-frick/index.d.ts +0 -2
  51. package/examples/bank-frick/util.d.ts +0 -4
  52. package/examples/coingecko/batch-warming.d.ts +0 -2
  53. package/examples/coingecko/batch-warming.js +0 -52
  54. package/examples/coingecko/index.d.ts +0 -2
  55. package/examples/coingecko/rest.d.ts +0 -2
  56. package/examples/coingecko/rest.js +0 -50
  57. package/examples/ncfx/config/index.d.ts +0 -12
  58. package/examples/ncfx/index.d.ts +0 -2
  59. package/examples/ncfx/websocket.d.ts +0 -36
  60. package/index.d.ts +0 -11
  61. package/metrics/constants.d.ts +0 -16
  62. package/metrics/index.d.ts +0 -15
  63. package/metrics/util.d.ts +0 -7
  64. package/package/adapter.d.ts +0 -88
  65. package/package/adapter.js +0 -112
  66. package/package/background-executor.d.ts +0 -11
  67. package/package/background-executor.js +0 -45
  68. package/package/cache/factory.d.ts +0 -6
  69. package/package/cache/factory.js +0 -57
  70. package/package/cache/index.d.ts +0 -90
  71. package/package/cache/index.js +0 -169
  72. package/package/cache/local.d.ts +0 -23
  73. package/package/cache/local.js +0 -83
  74. package/package/cache/metrics.d.ts +0 -27
  75. package/package/cache/metrics.js +0 -120
  76. package/package/cache/redis.d.ts +0 -16
  77. package/package/cache/redis.js +0 -100
  78. package/package/config/index.d.ts +0 -195
  79. package/package/config/index.js +0 -365
  80. package/package/config/provider-limits.d.ts +0 -31
  81. package/package/config/provider-limits.js +0 -76
  82. package/package/examples/coingecko/batch-warming.d.ts +0 -2
  83. package/package/examples/coingecko/index.d.ts +0 -2
  84. package/package/examples/coingecko/index.js +0 -10
  85. package/package/examples/coingecko/rest.d.ts +0 -2
  86. package/package/examples/ncfx/config/index.d.ts +0 -12
  87. package/package/examples/ncfx/config/index.js +0 -15
  88. package/package/examples/ncfx/index.d.ts +0 -2
  89. package/package/examples/ncfx/index.js +0 -10
  90. package/package/examples/ncfx/websocket.d.ts +0 -36
  91. package/package/examples/ncfx/websocket.js +0 -72
  92. package/package/index.d.ts +0 -12
  93. package/package/index.js +0 -92
  94. package/package/metrics/constants.d.ts +0 -16
  95. package/package/metrics/constants.js +0 -25
  96. package/package/metrics/index.d.ts +0 -15
  97. package/package/metrics/index.js +0 -123
  98. package/package/metrics/util.d.ts +0 -3
  99. package/package/metrics/util.js +0 -9
  100. package/package/package.json +0 -72
  101. package/package/rate-limiting/background/fixed-frequency.d.ts +0 -10
  102. package/package/rate-limiting/background/fixed-frequency.js +0 -37
  103. package/package/rate-limiting/index.d.ts +0 -54
  104. package/package/rate-limiting/index.js +0 -63
  105. package/package/rate-limiting/metrics.d.ts +0 -3
  106. package/package/rate-limiting/metrics.js +0 -44
  107. package/package/rate-limiting/request/simple-counting.d.ts +0 -20
  108. package/package/rate-limiting/request/simple-counting.js +0 -62
  109. package/package/test.d.ts +0 -1
  110. package/package/test.js +0 -6
  111. package/package/transports/batch-warming.d.ts +0 -34
  112. package/package/transports/batch-warming.js +0 -101
  113. package/package/transports/index.d.ts +0 -87
  114. package/package/transports/index.js +0 -87
  115. package/package/transports/metrics.d.ts +0 -21
  116. package/package/transports/metrics.js +0 -105
  117. package/package/transports/rest.d.ts +0 -43
  118. package/package/transports/rest.js +0 -129
  119. package/package/transports/util.d.ts +0 -8
  120. package/package/transports/util.js +0 -85
  121. package/package/transports/websocket.d.ts +0 -80
  122. package/package/transports/websocket.js +0 -169
  123. package/package/util/expiring-sorted-set.d.ts +0 -21
  124. package/package/util/expiring-sorted-set.js +0 -47
  125. package/package/util/index.d.ts +0 -11
  126. package/package/util/index.js +0 -35
  127. package/package/util/logger.d.ts +0 -42
  128. package/package/util/logger.js +0 -62
  129. package/package/util/request.d.ts +0 -55
  130. package/package/util/request.js +0 -2
  131. package/package/validation/error.d.ts +0 -50
  132. package/package/validation/error.js +0 -79
  133. package/package/validation/index.d.ts +0 -5
  134. package/package/validation/index.js +0 -86
  135. package/package/validation/input-params.d.ts +0 -15
  136. package/package/validation/input-params.js +0 -30
  137. package/package/validation/override-functions.d.ts +0 -3
  138. package/package/validation/preset-tokens.json +0 -23
  139. package/package/validation/validator.d.ts +0 -47
  140. package/package/validation/validator.js +0 -303
  141. package/rate-limiting/background/fixed-frequency.d.ts +0 -10
  142. package/rate-limiting/index.d.ts +0 -54
  143. package/rate-limiting/metrics.d.ts +0 -3
  144. package/rate-limiting/request/simple-counting.d.ts +0 -20
  145. package/test.d.ts +0 -1
  146. package/transports/batch-warming.d.ts +0 -35
  147. package/transports/index.d.ts +0 -70
  148. package/transports/metrics.d.ts +0 -21
  149. package/transports/rest.d.ts +0 -44
  150. package/transports/util.d.ts +0 -8
  151. package/transports/websocket.d.ts +0 -81
  152. package/util/expiring-sorted-set.d.ts +0 -21
  153. package/util/expiring-sorted-set.js +0 -47
  154. package/util/index.d.ts +0 -12
  155. package/util/logger.d.ts +0 -42
  156. package/util/request.d.ts +0 -57
  157. package/util/subscription-set/expiring-sorted-set.d.ts +0 -22
  158. package/util/subscription-set/subscription-set.d.ts +0 -18
  159. package/util/test-payload-loader.d.ts +0 -25
  160. package/validation/error.d.ts +0 -50
  161. package/validation/index.d.ts +0 -5
  162. package/validation/input-params.d.ts +0 -15
  163. package/validation/override-functions.d.ts +0 -3
  164. package/validation/validator.d.ts +0 -47
@@ -1,83 +0,0 @@
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;
@@ -1,27 +0,0 @@
1
- import * as client from 'prom-client';
2
- interface CacheMetricsLabels {
3
- 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 {};
@@ -1,120 +0,0 @@
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
- });
@@ -1,16 +0,0 @@
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
- }
@@ -1,100 +0,0 @@
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
- // TODO: Add error handling for redis command failures
37
- class RedisCache {
38
- constructor(client) {
39
- this.client = client;
40
- }
41
- async get(key) {
42
- logger.trace(`Getting key ${key}`);
43
- const value = await this.client.get(key);
44
- // Record get command sent to Redis
45
- cacheMetrics.redisCommandsSentCount
46
- .labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'get' })
47
- .inc();
48
- if (!value) {
49
- logger.debug(`No entry in redis cache for key "${key}", returning undefined`);
50
- return undefined;
51
- }
52
- return JSON.parse(value); // TODO: Check for invalid parsing
53
- }
54
- async delete(key) {
55
- logger.trace(`Deleting key ${key}`);
56
- await this.client.del(key);
57
- // Record delete command sent to Redis
58
- cacheMetrics.redisCommandsSentCount
59
- .labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'delete' })
60
- .inc();
61
- }
62
- async set(key, value, ttl) {
63
- logger.trace(`Setting key ${key}`);
64
- // TODO: Check for invalid stringify
65
- await this.client.set(key, JSON.stringify(value), 'PX', ttl);
66
- // Only record metrics if feed Id is present, otherwise assuming value is not adapter response to record
67
- const feedId = value.meta?.metrics?.feedId;
68
- if (feedId) {
69
- // Record cache set count, max age, and staleness (set to 0 for cache set)
70
- const label = cacheMetrics.cacheMetricsLabel(key, feedId, cacheMetrics.CacheTypes.Redis);
71
- cacheMetrics.cacheSet(label, ttl);
72
- }
73
- // Record set command sent to Redis
74
- cacheMetrics.redisCommandsSentCount
75
- .labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'set' })
76
- .inc();
77
- }
78
- async setMany(entries, ttl) {
79
- logger.trace(`Setting a bunch of keys`);
80
- // Unfortunately, there's no ttl for mset
81
- let chain = this.client.multi();
82
- for (const entry of entries) {
83
- chain = chain.set(entry.key, JSON.stringify(entry.value), 'PX', ttl);
84
- // TODO: Move to after error handling once implemented to avoid recording cache sets that failed
85
- // Only record metrics if feed Id is present, otherwise assuming value is not adapter response to record
86
- const feedId = entry.value.meta?.metrics?.feedId;
87
- if (feedId) {
88
- // Record cache set count, max age, and staleness (set to 0 for cache set)
89
- const label = cacheMetrics.cacheMetricsLabel(entry.key, feedId, cacheMetrics.CacheTypes.Redis);
90
- cacheMetrics.cacheSet(label, ttl);
91
- }
92
- }
93
- await chain.exec();
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;
@@ -1,195 +0,0 @@
1
- export declare const BaseSettings: {
2
- readonly API_KEY: {
3
- readonly description: "Default setting for an EA key";
4
- readonly type: "string";
5
- };
6
- readonly BASE_URL: {
7
- readonly description: "Starting path for the EA handler endpoint";
8
- readonly type: "string";
9
- readonly default: "/";
10
- };
11
- readonly CACHE_MAX_AGE: {
12
- readonly description: "Maximum amount of time (in ms) that a response will stay cached";
13
- readonly type: "number";
14
- readonly default: 90000;
15
- };
16
- readonly CACHE_REDIS_HOST: {
17
- readonly description: "Hostname for the Redis instance to be used";
18
- readonly type: "string";
19
- readonly default: "127.0.0.1";
20
- };
21
- readonly CACHE_REDIS_PORT: {
22
- readonly description: "Port for the Redis instance to be used";
23
- readonly type: "number";
24
- readonly default: 6379;
25
- };
26
- readonly CACHE_TYPE: {
27
- readonly description: "The type of cache to use throughout the EA";
28
- readonly type: "enum";
29
- readonly default: "local";
30
- readonly options: readonly ["local", "redis"];
31
- };
32
- readonly CORRELATION_ID_ENABLED: {
33
- readonly description: "Flag to enable correlation IDs for sent requests in logging";
34
- readonly type: "boolean";
35
- readonly default: true;
36
- };
37
- readonly EA_PORT: {
38
- readonly description: "Port through which the EA will listen for REST requests (if mode is set to \"reader\" or \"reader-writer\")";
39
- readonly type: "number";
40
- readonly default: 8080;
41
- };
42
- readonly EXPERIMENTAL_METRICS_ENABLED: {
43
- readonly description: "Flag to specify whether or not to collect metrics. Used as fallback for METRICS_ENABLED";
44
- readonly type: "boolean";
45
- readonly default: true;
46
- };
47
- readonly LOG_LEVEL: {
48
- readonly description: "Minimum level required for logs to be output";
49
- readonly type: "string";
50
- readonly default: "info";
51
- };
52
- readonly METRICS_ENABLED: {
53
- readonly description: "Flag to specify whether or not to startup the metrics server";
54
- readonly type: "boolean";
55
- readonly default: true;
56
- };
57
- readonly METRICS_NAME: {
58
- readonly description: "Metrics name";
59
- readonly type: "string";
60
- };
61
- readonly METRICS_PORT: {
62
- readonly description: "Port metrics will be exposed to";
63
- readonly type: "number";
64
- readonly default: 9080;
65
- };
66
- readonly METRICS_USE_BASE_URL: {
67
- readonly description: "Flag to specify whether or not to prepend the BASE_URL to the metrics endpoint";
68
- readonly type: "boolean";
69
- };
70
- readonly RATE_LIMIT_API_TIER: {
71
- 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.";
72
- readonly type: "string";
73
- };
74
- readonly WARMUP_SUBSCRIPTION_TTL: {
75
- readonly type: "number";
76
- readonly description: "";
77
- readonly default: 10000;
78
- };
79
- readonly CACHE_POLLING_MAX_RETRIES: {
80
- readonly description: "Max amount of times to attempt to find EA response in the cache after the Transport has been set up";
81
- readonly type: "number";
82
- readonly default: 10;
83
- };
84
- readonly CACHE_POLLING_SLEEP_MS: {
85
- readonly description: "The number of ms to sleep between each retry to fetch the EA response in the cache";
86
- readonly type: "number";
87
- readonly default: 200;
88
- };
89
- readonly DEFAULT_CACHE_KEY: {
90
- readonly description: "Default key to be used when one cannot be determined from request parameters";
91
- readonly type: "string";
92
- readonly default: "DEFAULT_CACHE_KEY";
93
- };
94
- readonly EA_HOST: {
95
- readonly description: "Host this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
96
- readonly type: "string";
97
- readonly default: "::";
98
- };
99
- readonly EA_MODE: {
100
- readonly description: "Port this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
101
- readonly type: "enum";
102
- readonly default: "reader-writer";
103
- readonly options: readonly ["reader", "writer", "reader-writer"];
104
- };
105
- readonly REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES: {
106
- readonly description: "Maximum amount of times the Rest Transport will attempt to set up a request when blocked by the rate limiter";
107
- readonly type: "number";
108
- readonly default: 3;
109
- };
110
- readonly REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES: {
111
- readonly description: "Time that the Rest Transport will wait between retries when blocked by the rate limiter";
112
- readonly type: "number";
113
- readonly default: 400;
114
- };
115
- };
116
- export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, }: {
117
- overrides?: Partial<BaseAdapterConfig> | undefined;
118
- customSettings?: SettingsMap | undefined;
119
- }) => AdapterConfig<CustomSettings>;
120
- declare type SettingValueType = string | number | boolean;
121
- 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;
122
- declare type BaseSettingsType = typeof BaseSettings;
123
- export declare type Setting = {
124
- type: 'string';
125
- description: string;
126
- options?: never;
127
- default?: string;
128
- validate?: (value?: string) => ValidationErrorMessage;
129
- required?: false;
130
- } | {
131
- type: 'string';
132
- description: string;
133
- options?: never;
134
- default?: string;
135
- validate?: (value: string) => ValidationErrorMessage;
136
- required: true;
137
- } | {
138
- type: 'number';
139
- description: string;
140
- options?: never;
141
- default?: number;
142
- validate?: (value?: number) => ValidationErrorMessage;
143
- required?: false;
144
- } | {
145
- type: 'number';
146
- description: string;
147
- options?: never;
148
- default?: number;
149
- validate?: (value: number) => ValidationErrorMessage;
150
- required: true;
151
- } | {
152
- type: 'boolean';
153
- description: string;
154
- options?: never;
155
- default?: boolean;
156
- validate?: (value?: boolean) => ValidationErrorMessage;
157
- required?: false;
158
- } | {
159
- type: 'boolean';
160
- description: string;
161
- options?: never;
162
- default?: boolean;
163
- validate?: (value: boolean) => ValidationErrorMessage;
164
- required: true;
165
- } | {
166
- type: 'enum';
167
- description: string;
168
- default?: string;
169
- options: readonly string[];
170
- validate?: (value?: string) => ValidationErrorMessage;
171
- required?: false;
172
- } | {
173
- type: 'enum';
174
- description: string;
175
- default?: string;
176
- options: readonly string[];
177
- validate?: (value: string) => ValidationErrorMessage;
178
- required: true;
179
- };
180
- export declare type AdapterConfigFromSettings<T extends SettingsMap> = {
181
- -readonly [K in keyof T as T[K] extends {
182
- default: SettingValueType;
183
- } ? K : T[K]['required'] extends true ? K : never]: SettingType<T[K]>;
184
- } & {
185
- -readonly [K in keyof T as T[K] extends {
186
- default: SettingValueType;
187
- } ? never : T[K]['required'] extends true ? never : K]?: SettingType<T[K]> | undefined;
188
- };
189
- export declare type BaseAdapterConfig = AdapterConfigFromSettings<BaseSettingsType>;
190
- export declare type AdapterConfig<T extends CustomSettingsType<T> = SettingsMap> = AdapterConfigFromSettings<T> & BaseAdapterConfig;
191
- export declare type CustomSettingsType<T = SettingsMap> = Record<keyof T, Setting>;
192
- export declare type EmptySettings = Record<string, never>;
193
- export declare type SettingsMap = Record<string, Setting>;
194
- export declare type ValidationErrorMessage = string | undefined;
195
- export {};