@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/transports/websocket.js
DELETED
|
@@ -1,165 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.WebSocketTransport = exports.WebSocketClassProvider = exports.WebSocket = void 0;
|
|
30
|
-
const ws_1 = __importDefault(require("ws"));
|
|
31
|
-
exports.WebSocket = ws_1.default;
|
|
32
|
-
const util_1 = require("../util");
|
|
33
|
-
const _1 = require("./");
|
|
34
|
-
const transportMetrics = __importStar(require("./metrics"));
|
|
35
|
-
const logger = (0, util_1.makeLogger)('WebSocketTransport');
|
|
36
|
-
class WebSocketClassProvider {
|
|
37
|
-
static set(ctor) {
|
|
38
|
-
this.ctor = ctor;
|
|
39
|
-
}
|
|
40
|
-
static get() {
|
|
41
|
-
return this.ctor;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.WebSocketClassProvider = WebSocketClassProvider;
|
|
45
|
-
WebSocketClassProvider.ctor = ws_1.default;
|
|
46
|
-
/**
|
|
47
|
-
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
48
|
-
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
49
|
-
*
|
|
50
|
-
* @typeParam AdapterParams - interface for the adapter request body
|
|
51
|
-
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
52
|
-
*/
|
|
53
|
-
class WebSocketTransport {
|
|
54
|
-
constructor(config) {
|
|
55
|
-
this.config = config;
|
|
56
|
-
// The double sets serve to create a simple polling mechanism instead of needing a subscription
|
|
57
|
-
// This one would not; this is always local state
|
|
58
|
-
this.localSubscriptions = [];
|
|
59
|
-
}
|
|
60
|
-
async initialize(dependencies, config, endpointName) {
|
|
61
|
-
this.cache = dependencies.cache;
|
|
62
|
-
this.rateLimiter = dependencies.backgroundExecuteRateLimiter;
|
|
63
|
-
this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
|
|
64
|
-
}
|
|
65
|
-
async registerRequest(req, config) {
|
|
66
|
-
logger.debug(`Adding entry to subscription set (ttl: ${config.WS_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
67
|
-
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
|
|
68
|
-
}
|
|
69
|
-
serializeMessage(payload) {
|
|
70
|
-
return typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
71
|
-
}
|
|
72
|
-
deserializeMessage(data) {
|
|
73
|
-
return JSON.parse(data.toString());
|
|
74
|
-
}
|
|
75
|
-
establishWsConnection(context) {
|
|
76
|
-
return new Promise((resolve) => {
|
|
77
|
-
const ctor = WebSocketClassProvider.get();
|
|
78
|
-
const url = context.adapterConfig.WS_API_ENDPOINT || this.config.url(context);
|
|
79
|
-
const options = this.config.options && this.config.options(context);
|
|
80
|
-
this.wsConnection = new ctor(url, undefined, options);
|
|
81
|
-
this.wsConnection.addEventListener('open', async (event) => {
|
|
82
|
-
logger.debug(`Opened websocket connection. (event type ${event.type})`);
|
|
83
|
-
await this.config.handlers.open(this.wsConnection, context);
|
|
84
|
-
logger.debug('Successfully executed connection opened handler');
|
|
85
|
-
// Record active ws connections by incrementing count on open
|
|
86
|
-
transportMetrics.wsConnectionActive.inc();
|
|
87
|
-
resolve(true);
|
|
88
|
-
});
|
|
89
|
-
this.wsConnection.addEventListener('message', async (event) => {
|
|
90
|
-
const parsed = this.deserializeMessage(event.data);
|
|
91
|
-
logger.trace(`Got ws message: ${parsed}`);
|
|
92
|
-
const results = this.config.handlers.message(parsed, context);
|
|
93
|
-
if (Array.isArray(results)) {
|
|
94
|
-
const responses = (0, _1.buildCacheEntriesFromResults)(results, context);
|
|
95
|
-
logger.trace(`Writing ${responses.length} responses to cache`);
|
|
96
|
-
await this.cache.setMany(responses, context.adapterConfig.CACHE_MAX_AGE);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
this.wsConnection.addEventListener('error', async (event) => {
|
|
100
|
-
logger.debug(`Error occurred in web socket connection. Error: ${event.error} ; Message: ${event.message}`);
|
|
101
|
-
// Record connection error count
|
|
102
|
-
transportMetrics.wsConnectionErrors
|
|
103
|
-
.labels(transportMetrics.connectionErrorLabels(event.message))
|
|
104
|
-
.inc();
|
|
105
|
-
});
|
|
106
|
-
this.wsConnection.addEventListener('close', (event) => {
|
|
107
|
-
logger.debug(`Closed websocket connection. Code: ${event.code} ; reason: ${event.reason?.toString()}`);
|
|
108
|
-
// Record active ws connections by decrementing count on close
|
|
109
|
-
// Using URL in label since connection_key is removed from v3
|
|
110
|
-
transportMetrics.wsConnectionActive.dec();
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
// Unlike cache warming, this execute will manage subscriptions
|
|
115
|
-
async backgroundExecute(context) {
|
|
116
|
-
logger.debug('Starting background execute, getting subscriptions from sorted set');
|
|
117
|
-
const desiredSubs = await this.subscriptionSet.getAll();
|
|
118
|
-
// Keep track of active subscriptions for background execute
|
|
119
|
-
transportMetrics.bgExecuteSubscriptionSetCount
|
|
120
|
-
.labels({ endpoint: context.adapterEndpoint.name, transport_type: 'websocket' })
|
|
121
|
-
.set(desiredSubs.length);
|
|
122
|
-
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
123
|
-
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.map((ls) => JSON.stringify(ls)).includes(JSON.stringify(s)));
|
|
124
|
-
const subscribes = subscribeParams
|
|
125
|
-
.map(this.config.builders.subscribeMessage)
|
|
126
|
-
.map(this.serializeMessage);
|
|
127
|
-
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.map((ds) => JSON.stringify(ds)).includes(JSON.stringify(s)));
|
|
128
|
-
const unsubscribes = unsubscribeParams
|
|
129
|
-
.map(this.config.builders.unsubscribeMessage)
|
|
130
|
-
.map(this.serializeMessage);
|
|
131
|
-
logger.debug(`${subscribes.length} new subscriptions; ${unsubscribes.length} to unsubscribe`);
|
|
132
|
-
if (subscribes.length) {
|
|
133
|
-
logger.trace(`Will subscribe to: ${subscribes}`);
|
|
134
|
-
}
|
|
135
|
-
if (unsubscribes.length) {
|
|
136
|
-
logger.trace(`Will unsubscribe to: ${unsubscribes}`);
|
|
137
|
-
}
|
|
138
|
-
// New subs && no connection -> connect -> add subs
|
|
139
|
-
// No new subs && no connection -> skip
|
|
140
|
-
// New subs && connection -> add subs
|
|
141
|
-
// No new subs && connection -> unsubs only
|
|
142
|
-
if (!subscribes.length && !this.wsConnection) {
|
|
143
|
-
logger.debug('No entries in subscription set and no established connection, skipping');
|
|
144
|
-
return this.rateLimiter.msUntilNextExecution(context.adapterEndpoint.name);
|
|
145
|
-
}
|
|
146
|
-
if (!this.wsConnection && subscribes.length) {
|
|
147
|
-
logger.debug('No established connection and new subscriptions available, connecting to WS');
|
|
148
|
-
await this.establishWsConnection(context);
|
|
149
|
-
}
|
|
150
|
-
logger.debug('Sending subs/unsubs if there are any');
|
|
151
|
-
const messages = unsubscribes.concat(subscribes);
|
|
152
|
-
for (const message of messages) {
|
|
153
|
-
logger.trace(`Sending message: ${JSON.stringify(message)}`);
|
|
154
|
-
this.wsConnection.send(message);
|
|
155
|
-
}
|
|
156
|
-
// Record WS message and subscription metrics
|
|
157
|
-
transportMetrics.recordWsMessageMetrics(context, subscribeParams, unsubscribeParams);
|
|
158
|
-
logger.debug('Setting local state to cache value');
|
|
159
|
-
this.localSubscriptions = desiredSubs;
|
|
160
|
-
logger.debug('Background execute complete');
|
|
161
|
-
return this.rateLimiter.msUntilNextExecution(context.adapterEndpoint.name);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.WebSocketTransport = WebSocketTransport;
|
|
165
|
-
//# sourceMappingURL=websocket.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAsD;AAW7C,oBAXF,YAAS,CAWE;AANlB,kCAAqD;AAErD,yBAAwF;AACxF,4DAA6C;AAK7C,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,oBAAoB,CAAC,CAAA;AAQ/C,MAAa,sBAAsB;IAGjC,MAAM,CAAC,GAAG,CAAC,IAAoB;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,GAAG;QACR,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;;AATH,wDAUC;AATQ,2BAAI,GAAmB,YAAS,CAAA;AAoEzC;;;;;;GAMG;AACH,MAAa,kBAAkB;IAgB7B,YACU,MAAoF;QAApF,WAAM,GAAN,MAAM,CAA8E;QAP9F,+FAA+F;QAC/F,iDAAiD;QACjD,uBAAkB,GAAoB,EAAE,CAAA;IAMrC,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,MAAqC,EACrC,YAAoB;QAEpB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAA2D,CAAA;QACrF,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,4BAA4B,CAAA;QAC5D,IAAI,CAA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AY,IAAI,UAAU,CAAC,MAAM,EAAE;YAC3C,MAAM,CAAC,KAAK,CAAC,6EAA6E,CAAC,CAAA;YAC3F,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;SAC1C;QAED,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAChD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC3D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAChC;QAED,6CAA6C;QAC7C,gBAAgB,CAAC,sBAAsB,CAAC,OAAO,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAA;QAEpF,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAA;QAErC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IAC5E,CAAC;CACF;AA/JD,gDA+JC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class CensorList {
|
|
4
|
-
static getAll() {
|
|
5
|
-
return this.censorList;
|
|
6
|
-
}
|
|
7
|
-
static set(censorList) {
|
|
8
|
-
this.censorList = censorList;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.default = CensorList;
|
|
12
|
-
CensorList.censorList = [];
|
|
13
|
-
//# sourceMappingURL=censor-list.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"censor-list.js","sourceRoot":"","sources":["../../../../src/util/censor/censor-list.ts"],"names":[],"mappings":";;AAAA,MAAqB,UAAU;IAE7B,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IACD,MAAM,CAAC,GAAG,CAAC,UAA4B;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;;AAPH,6BAQC;AAPQ,qBAAU,GAAqB,EAAE,CAAA"}
|
package/util/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from './request';
|
|
2
|
-
export * from './logger';
|
|
3
|
-
export * from './subscription-set/subscription-set';
|
|
4
|
-
/**
|
|
5
|
-
* Sleeps for the provided number of milliseconds
|
|
6
|
-
* @param ms - The number of milliseconds to sleep for
|
|
7
|
-
* @returns a Promise that resolves once the specified time passes
|
|
8
|
-
*/
|
|
9
|
-
export declare const sleep: (ms: number) => Promise<void>;
|
|
10
|
-
export declare const isObject: (o: unknown) => boolean;
|
|
11
|
-
export declare const isArray: (o: unknown) => boolean;
|
|
12
|
-
export declare const isEmpty: (o: unknown) => boolean;
|
|
13
|
-
export declare type PromiseOrValue<T> = Promise<T> | T;
|
package/util/index.js
DELETED
|
@@ -1,38 +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.isEmpty = exports.isArray = exports.isObject = exports.sleep = void 0;
|
|
18
|
-
__exportStar(require("./request"), exports);
|
|
19
|
-
__exportStar(require("./logger"), exports);
|
|
20
|
-
__exportStar(require("./subscription-set/subscription-set"), exports);
|
|
21
|
-
/**
|
|
22
|
-
* Sleeps for the provided number of milliseconds
|
|
23
|
-
* @param ms - The number of milliseconds to sleep for
|
|
24
|
-
* @returns a Promise that resolves once the specified time passes
|
|
25
|
-
*/
|
|
26
|
-
const sleep = (ms) => {
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
setTimeout(resolve, ms);
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
exports.sleep = sleep;
|
|
32
|
-
const isObject = (o) => o !== null && typeof o === 'object' && Array.isArray(o) === false;
|
|
33
|
-
exports.isObject = isObject;
|
|
34
|
-
const isArray = (o) => o !== null && typeof o === 'object' && Array.isArray(o);
|
|
35
|
-
exports.isArray = isArray;
|
|
36
|
-
const isEmpty = (o) => o === undefined || o === null || o === '';
|
|
37
|
-
exports.isEmpty = isEmpty;
|
|
38
|
-
//# sourceMappingURL=index.js.map
|
package/util/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,2CAAwB;AACxB,sEAAmD;AAEnD;;;;GAIG;AACI,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAJY,QAAA,KAAK,SAIjB;AAEM,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAW,EAAE,CAC9C,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,CAAA;AADtD,QAAA,QAAQ,YAC8C;AAE5D,MAAM,OAAO,GAAG,CAAC,CAAU,EAAW,EAAE,CAC7C,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAD5C,QAAA,OAAO,WACqC;AAElD,MAAM,OAAO,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAA;AAA5E,QAAA,OAAO,WAAqE"}
|
package/util/logger.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import pino from 'pino';
|
|
3
|
-
import { AdapterRequest } from './request';
|
|
4
|
-
import { FastifyReply, HookHandlerDoneFunction } from 'fastify';
|
|
5
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
-
import { CensorKeyValue } from './censor/censor-list';
|
|
7
|
-
export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
|
|
8
|
-
export declare type Store = {
|
|
9
|
-
correlationId: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const COLORS: string[];
|
|
12
|
-
export declare const colorFactory: (colors: string[]) => () => string;
|
|
13
|
-
/**
|
|
14
|
-
* Instead of using a global logger instance, we want to force using a child logger
|
|
15
|
-
* with a specific layer set in it, so that we can filter logs by where they're output from.
|
|
16
|
-
*
|
|
17
|
-
* Details on what each log level represents:
|
|
18
|
-
* "trace": Forensic debugging of issues on a local machine.
|
|
19
|
-
* "debug": Detailed logging level to get more context from users on their environments.
|
|
20
|
-
* "info": High-level informational messages, to describe at a glance the high level state of the system.
|
|
21
|
-
* "warn": A mild error occurred that might require non-urgent action.
|
|
22
|
-
* "error": An unexpected error occurred during the regular operation of a well-maintained EA.
|
|
23
|
-
* "fatal": The EA encountered an unrecoverable problem and had to exit.
|
|
24
|
-
*
|
|
25
|
-
* Full reference this is based on can be found at
|
|
26
|
-
* https://github.com/smartcontractkit/documentation/blob/main/docs/Node%20Operators/configuration-variables.md#log_level
|
|
27
|
-
*
|
|
28
|
-
* @param layer - the layer name to include in the logs (e.g. "SomeMiddleware", "RedisCache", etc.)
|
|
29
|
-
* @returns a layer specific logger
|
|
30
|
-
*/
|
|
31
|
-
export declare const makeLogger: (layer: string) => pino.Logger<{
|
|
32
|
-
level: string;
|
|
33
|
-
hooks: {
|
|
34
|
-
logMethod(this: pino.Logger<pino.LoggerOptions>, inputArgs: [msg: string, ...args: any[]], method: pino.LogFn): void;
|
|
35
|
-
};
|
|
36
|
-
mixin(): {};
|
|
37
|
-
transport: {
|
|
38
|
-
target: string;
|
|
39
|
-
options: {
|
|
40
|
-
levelFirst: boolean;
|
|
41
|
-
levelLabel: string;
|
|
42
|
-
ignore: string;
|
|
43
|
-
messageFormat: string;
|
|
44
|
-
translateTime: string;
|
|
45
|
-
};
|
|
46
|
-
} | undefined;
|
|
47
|
-
} & pino.ChildLoggerOptions>;
|
|
48
|
-
export declare const loggingContextMiddleware: (req: AdapterRequest, res: FastifyReply, done: HookHandlerDoneFunction) => void;
|
|
49
|
-
export declare function censor(obj: any, censorList: CensorKeyValue[]): any;
|
package/util/logger.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.censor = exports.loggingContextMiddleware = exports.makeLogger = exports.colorFactory = exports.COLORS = exports.asyncLocalStorage = void 0;
|
|
7
|
-
const pino_1 = __importDefault(require("pino"));
|
|
8
|
-
const config_1 = require("../config");
|
|
9
|
-
const crypto_1 = require("crypto");
|
|
10
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
11
|
-
const censor_list_1 = __importDefault(require("./censor/censor-list"));
|
|
12
|
-
exports.asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
13
|
-
const debugTransport = {
|
|
14
|
-
target: 'pino-pretty',
|
|
15
|
-
options: {
|
|
16
|
-
levelFirst: true,
|
|
17
|
-
levelLabel: 'level',
|
|
18
|
-
ignore: 'layer,pid,hostname,correlationId,color',
|
|
19
|
-
messageFormat: `\x1b[0m[{correlationId}] {color}[{layer}]\x1b[0m {msg}`,
|
|
20
|
-
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
// Base logger, shouldn't be used because we want layers to be specified
|
|
24
|
-
const baseLogger = (0, pino_1.default)({
|
|
25
|
-
level: process.env['LOG_LEVEL']?.toLowerCase() || config_1.BaseSettings.LOG_LEVEL.default,
|
|
26
|
-
hooks: {
|
|
27
|
-
logMethod(inputArgs, method) {
|
|
28
|
-
// Censor each argument of logger
|
|
29
|
-
const censorList = censor_list_1.default.getAll();
|
|
30
|
-
return method.apply(this, inputArgs.map((arg) => censor(arg, censorList)));
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
mixin() {
|
|
34
|
-
if (process.env['CORRELATION_ID_ENABLED'] !== 'false') {
|
|
35
|
-
const store = exports.asyncLocalStorage.getStore();
|
|
36
|
-
if (store) {
|
|
37
|
-
return store;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return {};
|
|
41
|
-
},
|
|
42
|
-
transport: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
|
|
43
|
-
? debugTransport
|
|
44
|
-
: undefined,
|
|
45
|
-
});
|
|
46
|
-
exports.COLORS = [
|
|
47
|
-
'\u001b[31;1m',
|
|
48
|
-
'\u001b[32m',
|
|
49
|
-
'\u001b[33m',
|
|
50
|
-
'\u001b[34m',
|
|
51
|
-
'\u001b[35m',
|
|
52
|
-
'\u001b[36m',
|
|
53
|
-
'\u001b[38;2;121;85;72m',
|
|
54
|
-
'\u001b[92m',
|
|
55
|
-
'\u001b[93m',
|
|
56
|
-
'\u001b[94m',
|
|
57
|
-
'\u001b[95m',
|
|
58
|
-
'\u001b[96m',
|
|
59
|
-
'\u001b[38;5;202m',
|
|
60
|
-
'\u001b[38;5;31m',
|
|
61
|
-
'\u001b[38;5;130m',
|
|
62
|
-
'\u001b[38;2;255;122;92m',
|
|
63
|
-
'\u001b[38;2;46;125;50m',
|
|
64
|
-
'\u001b[38;2;129;168;37m',
|
|
65
|
-
'\u001b[38;2;175;180;43m',
|
|
66
|
-
'\u001b[91m',
|
|
67
|
-
'\u001b[38;2;63;81;181m',
|
|
68
|
-
];
|
|
69
|
-
const colorFactory = (colors) => {
|
|
70
|
-
let index = -1;
|
|
71
|
-
return () => {
|
|
72
|
-
index++;
|
|
73
|
-
if (index > colors.length - 1) {
|
|
74
|
-
index = 0;
|
|
75
|
-
}
|
|
76
|
-
return colors[index];
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
exports.colorFactory = colorFactory;
|
|
80
|
-
const getNextColor = (0, exports.colorFactory)(exports.COLORS);
|
|
81
|
-
/**
|
|
82
|
-
* Instead of using a global logger instance, we want to force using a child logger
|
|
83
|
-
* with a specific layer set in it, so that we can filter logs by where they're output from.
|
|
84
|
-
*
|
|
85
|
-
* Details on what each log level represents:
|
|
86
|
-
* "trace": Forensic debugging of issues on a local machine.
|
|
87
|
-
* "debug": Detailed logging level to get more context from users on their environments.
|
|
88
|
-
* "info": High-level informational messages, to describe at a glance the high level state of the system.
|
|
89
|
-
* "warn": A mild error occurred that might require non-urgent action.
|
|
90
|
-
* "error": An unexpected error occurred during the regular operation of a well-maintained EA.
|
|
91
|
-
* "fatal": The EA encountered an unrecoverable problem and had to exit.
|
|
92
|
-
*
|
|
93
|
-
* Full reference this is based on can be found at
|
|
94
|
-
* https://github.com/smartcontractkit/documentation/blob/main/docs/Node%20Operators/configuration-variables.md#log_level
|
|
95
|
-
*
|
|
96
|
-
* @param layer - the layer name to include in the logs (e.g. "SomeMiddleware", "RedisCache", etc.)
|
|
97
|
-
* @returns a layer specific logger
|
|
98
|
-
*/
|
|
99
|
-
const makeLogger = (layer) => baseLogger.child({
|
|
100
|
-
layer,
|
|
101
|
-
color: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
|
|
102
|
-
? getNextColor()
|
|
103
|
-
: undefined,
|
|
104
|
-
});
|
|
105
|
-
exports.makeLogger = makeLogger;
|
|
106
|
-
const loggingContextMiddleware = (req, res, done) => {
|
|
107
|
-
const correlationId = req.headers['x-correlation-id'] || (0, crypto_1.randomUUID)();
|
|
108
|
-
exports.asyncLocalStorage.run({ correlationId: correlationId }, () => {
|
|
109
|
-
done();
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
exports.loggingContextMiddleware = loggingContextMiddleware;
|
|
113
|
-
// Obj is typed as "any" because it could be a variety of structures in the logger
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
115
|
-
function censor(obj, censorList) {
|
|
116
|
-
let stringified = JSON.stringify(obj);
|
|
117
|
-
censorList.forEach((entry) => {
|
|
118
|
-
stringified = stringified.replace(entry.value, `[${entry.key} REDACTED]`);
|
|
119
|
-
});
|
|
120
|
-
return JSON.parse(stringified);
|
|
121
|
-
}
|
|
122
|
-
exports.censor = censor;
|
|
123
|
-
//# sourceMappingURL=logger.js.map
|
package/util/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,sCAAwC;AAGxC,mCAAmC;AACnC,uDAAoD;AACpD,uEAAiE;AAEpD,Q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AC,CAAA;AACJ,CAAC,CAAA;AATY,QAAA,wBAAwB,4BASpC;AAED,kFAAkF;AAClF,8DAA8D;AAC9D,SAAgB,MAAM,CAAC,GAAQ,EAAE,UAA4B;IAC3D,IAAI,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACrC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3B,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,GAAG,YAAY,CAAC,CAAA;IAC3E,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AAChC,CAAC;AAND,wBAMC"}
|
package/util/request.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify';
|
|
2
|
-
import { Adapter } from '../adapter';
|
|
3
|
-
import { AdapterError } from '../validation/error';
|
|
4
|
-
declare module 'fastify' {
|
|
5
|
-
interface FastifyRequest {
|
|
6
|
-
requestContext: AdapterRequestContext;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Structure for the body of all requests that will be sent to the adapter
|
|
11
|
-
*/
|
|
12
|
-
export interface AdapterRequestBody<T = AdapterRequestData> {
|
|
13
|
-
/** Adapter endpoint (not to be confused with REST API endpoint) */
|
|
14
|
-
endpoint?: string;
|
|
15
|
-
/** Main data that will be validated and used on each adapter request */
|
|
16
|
-
data: T;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Object that will be added to the request on a successful validation.
|
|
20
|
-
* Contains all the necessary information the adapter will need across the request execution.
|
|
21
|
-
*/
|
|
22
|
-
export declare type AdapterRequestContext<T = AdapterRequestData> = {
|
|
23
|
-
/** Name of the endpoint this payload should be directed to */
|
|
24
|
-
endpointName: string;
|
|
25
|
-
/** Precalculated cache key used to get and set corresponding values from the cache and subscription sets */
|
|
26
|
-
cacheKey: string;
|
|
27
|
-
/** Normalized and validated data coming from the request body */
|
|
28
|
-
data: T;
|
|
29
|
-
/** Metadata relevant to this particular request */
|
|
30
|
-
meta?: AdapterRequestMeta;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Helper type to denote an empty body
|
|
34
|
-
*/
|
|
35
|
-
declare type EmptyBody = Record<string, never>;
|
|
36
|
-
/**
|
|
37
|
-
* Helper type to provide fastify for all adapter handlers
|
|
38
|
-
*/
|
|
39
|
-
export declare type AdapterRouteGeneric = {
|
|
40
|
-
/** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
|
|
41
|
-
Body: EmptyBody;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Structure for all requests incoming to this adapter
|
|
45
|
-
*/
|
|
46
|
-
export declare type AdapterRequest<T = AdapterRequestData> = FastifyRequest<AdapterRouteGeneric> & {
|
|
47
|
-
/** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
|
|
48
|
-
body: EmptyBody;
|
|
49
|
-
/** Container for all validated information that will be used by the framework across this request's lifecycle */
|
|
50
|
-
requestContext: AdapterRequestContext<T>;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Metadata for a particular request
|
|
54
|
-
*/
|
|
55
|
-
export interface AdapterRequestMeta {
|
|
56
|
-
/** Relevant metrics gathered for this request */
|
|
57
|
-
metrics?: AdapterMetricsMeta;
|
|
58
|
-
/** An error that ocurred somewhere along this requests' lifecycle */
|
|
59
|
-
error?: AdapterError | Error;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Meta info that pertains to exposing metrics
|
|
63
|
-
*/
|
|
64
|
-
export interface AdapterMetricsMeta {
|
|
65
|
-
/** String to uniquely identify a specific price feed */
|
|
66
|
-
feedId?: string;
|
|
67
|
-
/** Boolean to note if this request's response was found in the cache directly */
|
|
68
|
-
cacheHit?: boolean;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Basic shape for the data within the request body
|
|
72
|
-
*/
|
|
73
|
-
export declare type AdapterRequestData = Record<string, unknown> & {
|
|
74
|
-
endpoint?: string;
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to
|
|
78
|
-
*/
|
|
79
|
-
export interface ProviderResult<Params> {
|
|
80
|
-
/** The set of parameters that uniquely relate to the response */
|
|
81
|
-
params: Params;
|
|
82
|
-
/** */
|
|
83
|
-
value: unknown;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Shape of the response body from the adapter
|
|
87
|
-
*/
|
|
88
|
-
export declare type AdapterResponse<T = unknown> = {
|
|
89
|
-
/** HTTP status code */
|
|
90
|
-
statusCode: number;
|
|
91
|
-
/** Response data, holds "result" for Flux Monitor */
|
|
92
|
-
data: T;
|
|
93
|
-
/** Result value used for OCR */
|
|
94
|
-
result: unknown;
|
|
95
|
-
/** Number detailing the maximum age of the result in the cache, will be replaced by telemetry eventually */
|
|
96
|
-
maxAge?: number;
|
|
97
|
-
/** Metadata relevant to this request */
|
|
98
|
-
meta?: AdapterRequestMeta;
|
|
99
|
-
};
|
|
100
|
-
export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
|
|
101
|
-
export declare type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
|
|
102
|
-
export {};
|
package/util/request.js
DELETED
package/util/request.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/util/request.ts"],"names":[],"mappings":""}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SubscriptionSet } from './subscription-set';
|
|
2
|
-
/**
|
|
3
|
-
* An object describing an entry in the expiring sorted set.
|
|
4
|
-
* @typeParam T - the type of the entry's value
|
|
5
|
-
*/
|
|
6
|
-
interface ExpiringSortedSetEntry<T> {
|
|
7
|
-
value: T;
|
|
8
|
-
expirationTimestamp: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* This class implements a set of unique items, each of which has an expiration timestamp.
|
|
12
|
-
* On reads, items that have expired will be deleted from the set and not returned.
|
|
13
|
-
*
|
|
14
|
-
* @typeParam T - the type of the set entries' values
|
|
15
|
-
*/
|
|
16
|
-
export declare class ExpiringSortedSet<T> implements SubscriptionSet<T> {
|
|
17
|
-
map: Map<string, ExpiringSortedSetEntry<T>>;
|
|
18
|
-
add(key: string, value: T, ttl: number): void;
|
|
19
|
-
getAll(): T[];
|
|
20
|
-
}
|
|
21
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExpiringSortedSet = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* This class implements a set of unique items, each of which has an expiration timestamp.
|
|
6
|
-
* On reads, items that have expired will be deleted from the set and not returned.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam T - the type of the set entries' values
|
|
9
|
-
*/
|
|
10
|
-
class ExpiringSortedSet {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.map = new Map();
|
|
13
|
-
}
|
|
14
|
-
add(key, value, ttl) {
|
|
15
|
-
this.map.set(key, {
|
|
16
|
-
value,
|
|
17
|
-
expirationTimestamp: Date.now() + ttl,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
getAll() {
|
|
21
|
-
const results = [];
|
|
22
|
-
const now = Date.now();
|
|
23
|
-
// Since we're iterating, might as well prune here
|
|
24
|
-
for (const [key, entry] of this.map.entries()) {
|
|
25
|
-
if (entry.expirationTimestamp < now) {
|
|
26
|
-
this.map.delete(key); // In theory, this shouldn't happen frequently for feeds
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
results.push(entry.value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return results;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.ExpiringSortedSet = ExpiringSortedSet;
|
|
36
|
-
//# sourceMappingURL=expiring-sorted-set.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expiring-sorted-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/expiring-sorted-set.ts"],"names":[],"mappings":";;;AAWA;;;;;GAKG;AACH,MAAa,iBAAiB;IAA9B;QACE,QAAG,GAAG,IAAI,GAAG,EAAqC,CAAA;IAwBpD,CAAC;IAtBC,GAAG,CAAC,GAAW,EAAE,KAAQ,EAAE,GAAW;QACpC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,KAAK;YACL,mBAAmB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG;SACtC,CAAC,CAAA;IACJ,CAAC;IAED,MAAM;QACJ,MAAM,OAAO,GAAQ,EAAE,CAAA;QACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAEtB,kDAAkD;QAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE;YAC7C,IAAI,KAAK,CAAC,mBAAmB,GAAG,GAAG,EAAE;gBACnC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA,CAAC,wDAAwD;aAC9E;iBAAM;gBACL,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;aAC1B;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAzBD,8CAyBC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Redis from 'ioredis';
|
|
2
|
-
import { SubscriptionSet } from './subscription-set';
|
|
3
|
-
export declare class RedisSubscriptionSet<T> implements SubscriptionSet<T> {
|
|
4
|
-
private redisClient;
|
|
5
|
-
private subscriptionSetKey;
|
|
6
|
-
constructor(redisClient: Redis, subscriptionSetKey: string);
|
|
7
|
-
add(key: string, value: T, ttl: number): Promise<undefined>;
|
|
8
|
-
getAll(): Promise<T[]>;
|
|
9
|
-
}
|