@chainlink/external-adapter-framework 0.3.7 → 0.4.0
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 +102 -0
- package/package.json +42 -50
- package/adapter/basic.d.ts +0 -86
- package/adapter/basic.js +0 -323
- package/adapter/basic.js.map +0 -1
- package/adapter/endpoint.d.ts +0 -17
- package/adapter/endpoint.js +0 -19
- package/adapter/endpoint.js.map +0 -1
- package/adapter/index.d.ts +0 -4
- package/adapter/index.js +0 -21
- package/adapter/index.js.map +0 -1
- package/adapter/price.d.ts +0 -75
- package/adapter/price.js +0 -88
- package/adapter/price.js.map +0 -1
- package/adapter/types.d.ts +0 -118
- package/adapter/types.js +0 -3
- package/adapter/types.js.map +0 -1
- package/background-executor.d.ts +0 -9
- package/background-executor.js +0 -97
- package/background-executor.js.map +0 -1
- package/cache/factory.d.ts +0 -6
- package/cache/factory.js +0 -24
- package/cache/factory.js.map +0 -1
- package/cache/index.d.ts +0 -87
- package/cache/index.js +0 -133
- package/cache/index.js.map +0 -1
- package/cache/local.d.ts +0 -23
- package/cache/local.js +0 -84
- package/cache/local.js.map +0 -1
- package/cache/metrics.d.ts +0 -27
- package/cache/metrics.js +0 -121
- package/cache/metrics.js.map +0 -1
- package/cache/redis.d.ts +0 -16
- package/cache/redis.js +0 -101
- package/cache/redis.js.map +0 -1
- package/config/index.d.ts +0 -297
- package/config/index.js +0 -353
- package/config/index.js.map +0 -1
- package/config/provider-limits.d.ts +0 -27
- package/config/provider-limits.js +0 -75
- package/config/provider-limits.js.map +0 -1
- package/examples/bank-frick/accounts.d.ts +0 -52
- package/examples/bank-frick/accounts.js +0 -190
- package/examples/bank-frick/accounts.js.map +0 -1
- package/examples/bank-frick/config/index.d.ts +0 -17
- package/examples/bank-frick/config/index.js +0 -55
- package/examples/bank-frick/config/index.js.map +0 -1
- package/examples/bank-frick/index.d.ts +0 -16
- package/examples/bank-frick/index.js +0 -16
- package/examples/bank-frick/index.js.map +0 -1
- package/examples/bank-frick/util.d.ts +0 -4
- package/examples/bank-frick/util.js +0 -40
- package/examples/bank-frick/util.js.map +0 -1
- package/examples/coingecko/src/config/index.d.ts +0 -2
- package/examples/coingecko/src/config/index.js +0 -6
- package/examples/coingecko/src/config/index.js.map +0 -1
- package/examples/coingecko/src/config/overrides.json +0 -10825
- package/examples/coingecko/src/crypto-utils.d.ts +0 -48
- package/examples/coingecko/src/crypto-utils.js +0 -60
- package/examples/coingecko/src/crypto-utils.js.map +0 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +0 -9
- package/examples/coingecko/src/endpoint/coins.js +0 -37
- package/examples/coingecko/src/endpoint/coins.js.map +0 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +0 -3
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +0 -30
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +0 -1
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +0 -3
- package/examples/coingecko/src/endpoint/crypto-volume.js +0 -30
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +0 -1
- package/examples/coingecko/src/endpoint/crypto.d.ts +0 -2
- package/examples/coingecko/src/endpoint/crypto.js +0 -28
- package/examples/coingecko/src/endpoint/crypto.js.map +0 -1
- package/examples/coingecko/src/endpoint/dominance.d.ts +0 -3
- package/examples/coingecko/src/endpoint/dominance.js +0 -28
- package/examples/coingecko/src/endpoint/dominance.js.map +0 -1
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +0 -3
- package/examples/coingecko/src/endpoint/global-marketcap.js +0 -28
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +0 -1
- package/examples/coingecko/src/endpoint/index.d.ts +0 -6
- package/examples/coingecko/src/endpoint/index.js +0 -16
- package/examples/coingecko/src/endpoint/index.js.map +0 -1
- package/examples/coingecko/src/global-utils.d.ts +0 -27
- package/examples/coingecko/src/global-utils.js +0 -47
- package/examples/coingecko/src/global-utils.js.map +0 -1
- package/examples/coingecko/src/index.d.ts +0 -4
- package/examples/coingecko/src/index.js +0 -19
- package/examples/coingecko/src/index.js.map +0 -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/cryptocompare/src/config/index.d.ts +0 -2
- package/examples/cryptocompare/src/config/index.js +0 -6
- package/examples/cryptocompare/src/config/index.js.map +0 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +0 -28
- package/examples/cryptocompare/src/endpoints/crypto.js +0 -54
- package/examples/cryptocompare/src/endpoints/crypto.js.map +0 -1
- package/examples/cryptocompare/src/endpoints/index.d.ts +0 -1
- package/examples/cryptocompare/src/endpoints/index.js +0 -6
- package/examples/cryptocompare/src/endpoints/index.js.map +0 -1
- package/examples/cryptocompare/src/index.d.ts +0 -4
- package/examples/cryptocompare/src/index.js +0 -14
- package/examples/cryptocompare/src/index.js.map +0 -1
- package/examples/genesis/config/index.d.ts +0 -7
- package/examples/genesis/config/index.js +0 -11
- package/examples/genesis/config/index.js.map +0 -1
- package/examples/genesis/index.d.ts +0 -2
- package/examples/genesis/index.js +0 -13
- package/examples/genesis/index.js.map +0 -1
- package/examples/genesis/sseStream.d.ts +0 -16
- package/examples/genesis/sseStream.js +0 -149
- package/examples/genesis/sseStream.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/index.d.ts +0 -17
- package/index.js +0 -174
- package/index.js.map +0 -1
- package/metrics/constants.d.ts +0 -16
- package/metrics/constants.js +0 -26
- package/metrics/constants.js.map +0 -1
- package/metrics/index.d.ts +0 -19
- package/metrics/index.js +0 -139
- package/metrics/index.js.map +0 -1
- package/metrics/util.d.ts +0 -7
- package/metrics/util.js +0 -10
- package/metrics/util.js.map +0 -1
- package/rate-limiting/background/fixed-frequency.d.ts +0 -11
- package/rate-limiting/background/fixed-frequency.js +0 -36
- package/rate-limiting/background/fixed-frequency.js.map +0 -1
- package/rate-limiting/index.d.ts +0 -56
- package/rate-limiting/index.js +0 -86
- package/rate-limiting/index.js.map +0 -1
- package/rate-limiting/metrics.d.ts +0 -3
- package/rate-limiting/metrics.js +0 -45
- package/rate-limiting/metrics.js.map +0 -1
- package/rate-limiting/request/simple-counting.d.ts +0 -21
- package/rate-limiting/request/simple-counting.js +0 -63
- package/rate-limiting/request/simple-counting.js.map +0 -1
- package/transports/batch-warming.d.ts +0 -35
- package/transports/batch-warming.js +0 -138
- package/transports/batch-warming.js.map +0 -1
- package/transports/index.d.ts +0 -87
- package/transports/index.js +0 -56
- package/transports/index.js.map +0 -1
- package/transports/metrics.d.ts +0 -25
- package/transports/metrics.js +0 -122
- package/transports/metrics.js.map +0 -1
- package/transports/rest.d.ts +0 -51
- package/transports/rest.js +0 -133
- package/transports/rest.js.map +0 -1
- package/transports/routing.d.ts +0 -23
- package/transports/routing.js +0 -52
- package/transports/routing.js.map +0 -1
- package/transports/sse.d.ts +0 -40
- package/transports/sse.js +0 -92
- package/transports/sse.js.map +0 -1
- package/transports/util.d.ts +0 -9
- package/transports/util.js +0 -87
- package/transports/util.js.map +0 -1
- package/transports/websocket.d.ts +0 -81
- package/transports/websocket.js +0 -165
- package/transports/websocket.js.map +0 -1
- package/util/censor/censor-list.d.ts +0 -9
- package/util/censor/censor-list.js +0 -13
- package/util/censor/censor-list.js.map +0 -1
- package/util/index.d.ts +0 -13
- package/util/index.js +0 -38
- package/util/index.js.map +0 -1
- package/util/logger.d.ts +0 -49
- package/util/logger.js +0 -123
- package/util/logger.js.map +0 -1
- package/util/request.d.ts +0 -102
- package/util/request.js +0 -3
- package/util/request.js.map +0 -1
- package/util/subscription-set/expiring-sorted-set.d.ts +0 -21
- package/util/subscription-set/expiring-sorted-set.js +0 -36
- package/util/subscription-set/expiring-sorted-set.js.map +0 -1
- package/util/subscription-set/redis-sorted-set.d.ts +0 -9
- package/util/subscription-set/redis-sorted-set.js +0 -29
- package/util/subscription-set/redis-sorted-set.js.map +0 -1
- package/util/subscription-set/subscription-set.d.ts +0 -19
- package/util/subscription-set/subscription-set.js +0 -28
- package/util/subscription-set/subscription-set.js.map +0 -1
- package/util/test-payload-loader.d.ts +0 -26
- package/util/test-payload-loader.js +0 -85
- package/util/test-payload-loader.js.map +0 -1
- package/validation/error.d.ts +0 -48
- package/validation/error.js +0 -78
- package/validation/error.js.map +0 -1
- package/validation/index.d.ts +0 -5
- package/validation/index.js +0 -91
- package/validation/index.js.map +0 -1
- package/validation/input-params.d.ts +0 -14
- package/validation/input-params.js +0 -3
- package/validation/input-params.js.map +0 -1
- package/validation/input-validator.d.ts +0 -16
- package/validation/input-validator.js +0 -123
- package/validation/input-validator.js.map +0 -1
package/cache/index.js
DELETED
|
@@ -1,133 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.pollResponseFromCache = exports.calculateStaleness = exports.calculateKey = exports.calculateFeedId = exports.calculateCacheKey = void 0;
|
|
18
|
-
const util_1 = require("../util");
|
|
19
|
-
__exportStar(require("./factory"), exports);
|
|
20
|
-
__exportStar(require("./local"), exports);
|
|
21
|
-
__exportStar(require("./redis"), exports);
|
|
22
|
-
const logger = (0, util_1.makeLogger)('Cache');
|
|
23
|
-
// Uses calculateKey to generate a unique key from the endpoint name, data, and input parameters
|
|
24
|
-
const calculateCacheKey = ({ adapterEndpoint, adapterConfig, }, data) => {
|
|
25
|
-
const paramNames = Object.keys(adapterEndpoint.inputParameters);
|
|
26
|
-
if (paramNames.length === 0) {
|
|
27
|
-
logger.trace(`Using default cache key ${adapterConfig.DEFAULT_CACHE_KEY}`);
|
|
28
|
-
return adapterConfig.DEFAULT_CACHE_KEY;
|
|
29
|
-
}
|
|
30
|
-
const cacheKey = `${adapterEndpoint.name}-${(0, exports.calculateKey)(data, paramNames, adapterConfig)}`;
|
|
31
|
-
logger.trace(`Generated cache key for request: "${cacheKey}"`);
|
|
32
|
-
return cacheKey;
|
|
33
|
-
};
|
|
34
|
-
exports.calculateCacheKey = calculateCacheKey;
|
|
35
|
-
const calculateFeedId = ({ adapterEndpoint, adapterConfig, }, data) => {
|
|
36
|
-
const paramNames = Object.keys(adapterEndpoint.inputParameters);
|
|
37
|
-
if (paramNames.length === 0) {
|
|
38
|
-
logger.trace(`Cannot generate Feed ID without input parameters`);
|
|
39
|
-
return 'N/A';
|
|
40
|
-
}
|
|
41
|
-
return (0, exports.calculateKey)(data, paramNames, adapterConfig);
|
|
42
|
-
};
|
|
43
|
-
exports.calculateFeedId = calculateFeedId;
|
|
44
|
-
/**
|
|
45
|
-
* Calculates a unique key from the provided data.
|
|
46
|
-
*
|
|
47
|
-
* @param data - the request data/body, i.e. the adapter input params
|
|
48
|
-
* @param paramNames - the keys from adapter endpoint input parameters
|
|
49
|
-
* @returns the calculated unique key
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```
|
|
53
|
-
* calculateKey({ base: 'ETH', quote: 'BTC' }, ['base','quote'])
|
|
54
|
-
* // equals `|base:eth|quote:btc`
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
const calculateKey = (data, paramNames, adapterConfig) => {
|
|
58
|
-
if (data && typeof data !== 'object') {
|
|
59
|
-
throw new Error('Data to calculate cache key should be an object');
|
|
60
|
-
}
|
|
61
|
-
const params = data;
|
|
62
|
-
let cacheKey = '';
|
|
63
|
-
for (const paramName of paramNames) {
|
|
64
|
-
const param = params[paramName];
|
|
65
|
-
if (param === undefined) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
cacheKey += `|${paramName}:`;
|
|
69
|
-
switch (typeof param) {
|
|
70
|
-
case 'string':
|
|
71
|
-
cacheKey += param.toLowerCase();
|
|
72
|
-
break;
|
|
73
|
-
case 'number':
|
|
74
|
-
case 'boolean':
|
|
75
|
-
cacheKey += param.toString();
|
|
76
|
-
break;
|
|
77
|
-
case 'object':
|
|
78
|
-
// Force cache keys to only use performant properties of the input params.
|
|
79
|
-
// If the object were to be used, we'd have to sort its properties.
|
|
80
|
-
logger.debug(`Property "${paramName}" in request parameters is of type object, and won't be used in the cacheKey`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (cacheKey.length > adapterConfig.MAX_COMMON_KEY_SIZE) {
|
|
84
|
-
logger.warn(`Generated cache key for adapter request is bigger than the MAX_COMMON_KEY_SIZE and will be truncated`);
|
|
85
|
-
cacheKey = cacheKey.slice(0, adapterConfig.MAX_COMMON_KEY_SIZE);
|
|
86
|
-
}
|
|
87
|
-
return cacheKey;
|
|
88
|
-
};
|
|
89
|
-
exports.calculateKey = calculateKey;
|
|
90
|
-
// Calculate the amount of time a non-expired entry has been in the cache
|
|
91
|
-
const calculateStaleness = (expirationTimestamp, ttl) => {
|
|
92
|
-
if (expirationTimestamp) {
|
|
93
|
-
const createTimestamp = expirationTimestamp - ttl;
|
|
94
|
-
return (Date.now() - createTimestamp) / 1000;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// If expirationTimestamp is not available, staleness cannot be calculated
|
|
98
|
-
// Defaults to ttl for metrics purposes
|
|
99
|
-
return ttl;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
exports.calculateStaleness = calculateStaleness;
|
|
103
|
-
/**
|
|
104
|
-
* Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
|
|
105
|
-
* amount of retries is exceeded, it returns undefined instead.
|
|
106
|
-
*
|
|
107
|
-
* @param cache - a Cache instance
|
|
108
|
-
* @param key - the key generated from an AdapterRequest that corresponds to the desired AdapterResponse
|
|
109
|
-
* @param retry - current retry, only for internal use
|
|
110
|
-
* @returns the AdapterResponse if found, else undefined
|
|
111
|
-
*/
|
|
112
|
-
const pollResponseFromCache = async (cache, key, options, retry = 0) => {
|
|
113
|
-
if (retry > options.maxRetries) {
|
|
114
|
-
// Ideally this shouldn't happen often (p99 of reqs should be found in the cache)
|
|
115
|
-
logger.info('Exceeded max cache polling retries');
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
logger.trace('Getting response from cache...');
|
|
119
|
-
const response = await cache.get(key);
|
|
120
|
-
if (response) {
|
|
121
|
-
logger.trace('Got response from cache');
|
|
122
|
-
return response;
|
|
123
|
-
}
|
|
124
|
-
if (options.maxRetries === 0) {
|
|
125
|
-
logger.debug(`Response not found, retries disabled`);
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
logger.debug(`Response not found, sleeping ${options.sleep} milliseconds...`);
|
|
129
|
-
await (0, util_1.sleep)(options.sleep);
|
|
130
|
-
return (0, exports.pollResponseFromCache)(cache, key, options, retry + 1);
|
|
131
|
-
};
|
|
132
|
-
exports.pollResponseFromCache = pollResponseFromCache;
|
|
133
|
-
//# sourceMappingURL=index.js.map
|
package/cache/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,CAAA;IAC/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,MAAM,CAAC,KAAK,CAAC,2BAA2B,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAA;QAC1E,OAAO,aAAa,CAAC,iBAAiB,CAAA;KACvC;IACD,MAAM,QAAQ,GAAG,GAAG,eAAe,CAAC,IAAI,IAAI,IAAA,oBAAY,EAAC,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,CAAA;IAC3F,MAAM,CAAC,KAAK,CAAC,qCAAqC,QAAQ,GAAG,CAAC,CAAA;IAC9D,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAlBY,QAAA,iBAAiB,qBAkB7B;AAEM,MAAM,eAAe,GAAG,CAC7B,EACE,eAAe,EACf,aAAa,GAId,EACD,IAAa,EACL,EAAE;IACV,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IAC/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;Q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AE,OAAO,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;AAC9D,CAAC,CAAA;AA/BY,QAAA,qBAAqB,yBA+BjC"}
|
package/cache/local.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Cache, CacheEntry } from './index';
|
|
2
|
-
/**
|
|
3
|
-
* Type for a value stored in a LocalCache entry.
|
|
4
|
-
*
|
|
5
|
-
* @typeParam T - the type for the entry's value
|
|
6
|
-
*/
|
|
7
|
-
export interface LocalCacheEntry<T> {
|
|
8
|
-
expirationTimestamp: number;
|
|
9
|
-
value: T;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Local implementation of a Cache. It uses a simple js Object, storing entries with both
|
|
13
|
-
* a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
|
|
14
|
-
*
|
|
15
|
-
* @typeParam T - the type for the entries' values
|
|
16
|
-
*/
|
|
17
|
-
export declare class LocalCache<T = unknown> implements Cache<T> {
|
|
18
|
-
store: Record<string, LocalCacheEntry<T>>;
|
|
19
|
-
get(key: string): Promise<T | undefined>;
|
|
20
|
-
delete(key: string): Promise<void>;
|
|
21
|
-
set(key: string, value: T, ttl: number): Promise<void>;
|
|
22
|
-
setMany(entries: CacheEntry<T>[], ttl: number): Promise<void>;
|
|
23
|
-
}
|
package/cache/local.js
DELETED
|
@@ -1,84 +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;
|
|
84
|
-
//# sourceMappingURL=local.js.map
|
package/cache/local.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;I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,YAAY,CAAC,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YACxF,YAAY,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;SAClC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwB,EAAE,GAAW;QACjD,MAAM,CAAC,KAAK,CAAC,oCAAoC,GAAG,EAAE,CAAC,CAAA;QACvD,KAAK,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE;YACpC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;SAC1B;IACH,CAAC;CACF;AAlDD,gCAkDC"}
|
package/cache/metrics.d.ts
DELETED
|
@@ -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 {};
|
package/cache/metrics.js
DELETED
|
@@ -1,121 +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
|
-
});
|
|
121
|
-
//# sourceMappingURL=metrics.js.map
|
package/cache/metrics.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/cache/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AAS9B,MAAM,QAAQ,GAAG,CAAC,KAAyB,EAAE,KAAc,EAAE,SAAiB,EAAE,EAAE;IACvF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC1D,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QACjC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;YAC9D,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;SAClD;KACF;IACD,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAA;IACrC,yBAAyB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AACxD,CAAC,CAAA;AATY,QAAA,QAAQ,YASpB;AAEM,MAAM,QAAQ,GAAG,CAAC,KAAyB,EAAE,MAAc,EAAE,EAAE;IACpE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|
-
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
DELETED
|
@@ -1,101 +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
|
-
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
|
package/cache/redis.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,CAAC,sBAAsB;aAChC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;aAC9E,GAAG,EAAE,CAAA;QAER,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,oCAAoC,GAAG,wBAAwB,CAAC,CAAA;YAC7E,OAAO,SAAS,CAAA;SACjB;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM,CAAA;IAC/B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,CAAC,KAAK,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAA;QACnC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE1B,sCAAsC;QACtC,YAAY,CAAC,sBAAsB;aAChC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,eAAe,CAAC,OAAO,EAAE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