@chainlink/external-adapter-framework 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter/basic.d.ts +90 -0
- package/adapter/basic.js +325 -0
- package/adapter/basic.js.map +1 -0
- package/adapter/endpoint.d.ts +17 -0
- package/adapter/endpoint.js +20 -0
- package/adapter/endpoint.js.map +1 -0
- package/adapter/index.d.ts +4 -0
- package/adapter/index.js +21 -0
- package/adapter/index.js.map +1 -0
- package/adapter/price.d.ts +77 -0
- package/adapter/price.js +88 -0
- package/adapter/price.js.map +1 -0
- package/adapter/types.d.ts +124 -0
- package/adapter/types.js +3 -0
- package/adapter/types.js.map +1 -0
- package/background-executor.d.ts +9 -0
- package/background-executor.js +97 -0
- package/background-executor.js.map +1 -0
- package/cache/factory.d.ts +6 -0
- package/cache/factory.js +24 -0
- package/cache/factory.js.map +1 -0
- package/cache/index.d.ts +87 -0
- package/cache/index.js +133 -0
- package/cache/index.js.map +1 -0
- package/cache/local.d.ts +23 -0
- package/cache/local.js +84 -0
- package/cache/local.js.map +1 -0
- package/cache/metrics.d.ts +27 -0
- package/cache/metrics.js +121 -0
- package/cache/metrics.js.map +1 -0
- package/cache/redis.d.ts +16 -0
- package/cache/redis.js +101 -0
- package/cache/redis.js.map +1 -0
- package/config/index.d.ts +298 -0
- package/config/index.js +359 -0
- package/config/index.js.map +1 -0
- package/config/provider-limits.d.ts +27 -0
- package/config/provider-limits.js +75 -0
- package/config/provider-limits.js.map +1 -0
- package/examples/bank-frick/accounts.d.ts +45 -0
- package/examples/bank-frick/accounts.js +203 -0
- package/examples/bank-frick/accounts.js.map +1 -0
- package/examples/bank-frick/config/index.d.ts +17 -0
- package/examples/bank-frick/config/index.js +55 -0
- package/examples/bank-frick/config/index.js.map +1 -0
- package/examples/bank-frick/index.d.ts +2 -0
- package/examples/bank-frick/index.js +16 -0
- package/examples/bank-frick/index.js.map +1 -0
- package/examples/bank-frick/util.d.ts +4 -0
- package/examples/bank-frick/util.js +40 -0
- package/examples/bank-frick/util.js.map +1 -0
- package/examples/coingecko/src/config/index.d.ts +2 -0
- package/examples/coingecko/src/config/index.js +6 -0
- package/examples/coingecko/src/config/index.js.map +1 -0
- package/examples/coingecko/src/config/overrides.json +10825 -0
- package/examples/coingecko/src/crypto-utils.d.ts +62 -0
- package/examples/coingecko/src/crypto-utils.js +60 -0
- package/examples/coingecko/src/crypto-utils.js.map +1 -0
- package/examples/coingecko/src/endpoint/coins.d.ts +26 -0
- package/examples/coingecko/src/endpoint/coins.js +37 -0
- package/examples/coingecko/src/endpoint/coins.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +30 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js +30 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto.js +28 -0
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -0
- package/examples/coingecko/src/endpoint/dominance.d.ts +3 -0
- package/examples/coingecko/src/endpoint/dominance.js +28 -0
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -0
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +3 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js +28 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/index.d.ts +6 -0
- package/examples/coingecko/src/endpoint/index.js +16 -0
- package/examples/coingecko/src/endpoint/index.js.map +1 -0
- package/examples/coingecko/src/global-utils.d.ts +42 -0
- package/examples/coingecko/src/global-utils.js +47 -0
- package/examples/coingecko/src/global-utils.js.map +1 -0
- package/examples/coingecko/src/index.d.ts +4 -0
- package/examples/coingecko/src/index.js +19 -0
- package/examples/coingecko/src/index.js.map +1 -0
- package/examples/coingecko-old/batch-warming.d.ts +7 -0
- package/examples/coingecko-old/batch-warming.js +54 -0
- package/examples/coingecko-old/batch-warming.js.map +1 -0
- package/examples/coingecko-old/index.d.ts +2 -0
- package/examples/coingecko-old/index.js +12 -0
- package/examples/coingecko-old/index.js.map +1 -0
- package/examples/coingecko-old/rest.d.ts +12 -0
- package/examples/coingecko-old/rest.js +55 -0
- package/examples/coingecko-old/rest.js.map +1 -0
- package/examples/cryptocompare/src/config/index.d.ts +2 -0
- package/examples/cryptocompare/src/config/index.js +6 -0
- package/examples/cryptocompare/src/config/index.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +40 -0
- package/examples/cryptocompare/src/endpoints/crypto.js +54 -0
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/index.d.ts +1 -0
- package/examples/cryptocompare/src/endpoints/index.js +6 -0
- package/examples/cryptocompare/src/endpoints/index.js.map +1 -0
- package/examples/cryptocompare/src/index.d.ts +4 -0
- package/examples/cryptocompare/src/index.js +14 -0
- package/examples/cryptocompare/src/index.js.map +1 -0
- package/examples/genesis/config/index.d.ts +7 -0
- package/examples/genesis/config/index.js +11 -0
- package/examples/genesis/config/index.js.map +1 -0
- package/examples/genesis/index.d.ts +2 -0
- package/examples/genesis/index.js +13 -0
- package/examples/genesis/index.js.map +1 -0
- package/examples/genesis/sseStream.d.ts +27 -0
- package/examples/genesis/sseStream.js +149 -0
- package/examples/genesis/sseStream.js.map +1 -0
- package/examples/ncfx/config/index.d.ts +12 -0
- package/examples/ncfx/config/index.js +16 -0
- package/examples/ncfx/config/index.js.map +1 -0
- package/examples/ncfx/index.d.ts +2 -0
- package/examples/ncfx/index.js +12 -0
- package/examples/ncfx/index.js.map +1 -0
- package/examples/ncfx/websocket.d.ts +37 -0
- package/examples/ncfx/websocket.js +74 -0
- package/examples/ncfx/websocket.js.map +1 -0
- package/index.d.ts +17 -0
- package/index.js +174 -0
- package/index.js.map +1 -0
- package/metrics/constants.d.ts +16 -0
- package/metrics/constants.js +26 -0
- package/metrics/constants.js.map +1 -0
- package/metrics/index.d.ts +19 -0
- package/metrics/index.js +139 -0
- package/metrics/index.js.map +1 -0
- package/metrics/util.d.ts +7 -0
- package/metrics/util.js +10 -0
- package/metrics/util.js.map +1 -0
- package/package.json +50 -42
- package/rate-limiting/background/fixed-frequency.d.ts +10 -0
- package/rate-limiting/background/fixed-frequency.js +36 -0
- package/rate-limiting/background/fixed-frequency.js.map +1 -0
- package/rate-limiting/index.d.ts +56 -0
- package/rate-limiting/index.js +86 -0
- package/rate-limiting/index.js.map +1 -0
- package/rate-limiting/metrics.d.ts +3 -0
- package/rate-limiting/metrics.js +45 -0
- package/rate-limiting/metrics.js.map +1 -0
- package/rate-limiting/request/simple-counting.d.ts +20 -0
- package/rate-limiting/request/simple-counting.js +63 -0
- package/rate-limiting/request/simple-counting.js.map +1 -0
- package/transports/batch-warming.d.ts +53 -0
- package/transports/batch-warming.js +136 -0
- package/transports/batch-warming.js.map +1 -0
- package/transports/index.d.ts +108 -0
- package/transports/index.js +56 -0
- package/transports/index.js.map +1 -0
- package/transports/inference-test.d.ts +0 -0
- package/transports/inference-test.js +202 -0
- package/transports/inference-test.js.map +1 -0
- package/transports/metrics.d.ts +25 -0
- package/transports/metrics.js +122 -0
- package/transports/metrics.js.map +1 -0
- package/transports/rest.d.ts +68 -0
- package/transports/rest.js +131 -0
- package/transports/rest.js.map +1 -0
- package/transports/routing.d.ts +21 -0
- package/transports/routing.js +50 -0
- package/transports/routing.js.map +1 -0
- package/transports/sse.d.ts +61 -0
- package/transports/sse.js +97 -0
- package/transports/sse.js.map +1 -0
- package/transports/util.d.ts +9 -0
- package/transports/util.js +87 -0
- package/transports/util.js.map +1 -0
- package/transports/websocket.d.ts +95 -0
- package/transports/websocket.js +164 -0
- package/transports/websocket.js.map +1 -0
- package/util/censor/censor-list.d.ts +9 -0
- package/util/censor/censor-list.js +13 -0
- package/util/censor/censor-list.js.map +1 -0
- package/util/index.d.ts +13 -0
- package/util/index.js +38 -0
- package/util/index.js.map +1 -0
- package/util/logger.d.ts +49 -0
- package/util/logger.js +123 -0
- package/util/logger.js.map +1 -0
- package/util/request.d.ts +138 -0
- package/util/request.js +3 -0
- package/util/request.js.map +1 -0
- package/util/subscription-set/expiring-sorted-set.d.ts +21 -0
- package/util/subscription-set/expiring-sorted-set.js +36 -0
- package/util/subscription-set/expiring-sorted-set.js.map +1 -0
- package/util/subscription-set/redis-sorted-set.d.ts +9 -0
- package/util/subscription-set/redis-sorted-set.js +29 -0
- package/util/subscription-set/redis-sorted-set.js.map +1 -0
- package/util/subscription-set/subscription-set.d.ts +19 -0
- package/util/subscription-set/subscription-set.js +28 -0
- package/util/subscription-set/subscription-set.js.map +1 -0
- package/util/test-payload-loader.d.ts +26 -0
- package/util/test-payload-loader.js +85 -0
- package/util/test-payload-loader.js.map +1 -0
- package/validation/error.d.ts +48 -0
- package/validation/error.js +78 -0
- package/validation/error.js.map +1 -0
- package/validation/index.d.ts +5 -0
- package/validation/index.js +102 -0
- package/validation/index.js.map +1 -0
- package/validation/input-params.d.ts +14 -0
- package/validation/input-params.js +3 -0
- package/validation/input-params.js.map +1 -0
- package/validation/input-validator.d.ts +16 -0
- package/validation/input-validator.js +123 -0
- package/validation/input-validator.js.map +1 -0
- package/README.md +0 -102
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../src/transports/routing.ts"],"names":[],"mappings":";;;AAEA,kCAAoC;AAEpC,+CAAkD;AAGlD,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,kBAAkB,CAAC,CAAA;AAE7C;;;;GAIG;AACH,MAAa,gBAAgB;IAI3B;IACE,6GAA6G;IACtG,UAA2C;IAElD,+FAA+F;IACvF,KAGG;QANJ,eAAU,GAAV,UAAU,CAAiC;QAG1C,UAAK,GAAL,KAAK,CA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gB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QAC3D,IAAI,SAAS,CAAC,iBAAiB,EAAE;YAC/B,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAA;YAChE,OAAO,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;SACvD;QACD,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAA;IACzE,CAAC;CACF;AAtDD,4CAsDC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import EventSource from 'eventsource';
|
|
3
|
+
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
4
|
+
import { Cache } from '../cache';
|
|
5
|
+
import { AdapterConfig } from '../config';
|
|
6
|
+
import { SubscriptionSet } from '../util';
|
|
7
|
+
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
8
|
+
import { Transport, TransportGenerics } from './';
|
|
9
|
+
export interface SSEConfig {
|
|
10
|
+
url: string;
|
|
11
|
+
eventSourceInitDict?: EventSource.EventSourceInitDict;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
15
|
+
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
16
|
+
*/
|
|
17
|
+
declare type SSETransportGenerics = TransportGenerics & {
|
|
18
|
+
/**
|
|
19
|
+
* Type details for any provider specific interfaces.
|
|
20
|
+
*/
|
|
21
|
+
Provider: {
|
|
22
|
+
/**
|
|
23
|
+
* Structure of the body of the request that will be sent to the data provider.
|
|
24
|
+
*/
|
|
25
|
+
RequestBody: unknown;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Transport implementation that establishes a long lived connection to a server using the SSE protocol and subcribes to updates.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[SSETransportGenerics]])
|
|
32
|
+
*/
|
|
33
|
+
export declare class SSETransport<T extends SSETransportGenerics> implements Transport<T> {
|
|
34
|
+
private config;
|
|
35
|
+
EventSource: typeof EventSource;
|
|
36
|
+
cache: Cache<AdapterResponse<T['Response']>>;
|
|
37
|
+
eventListeners: {
|
|
38
|
+
type: string;
|
|
39
|
+
parseResponse: (evt: MessageEvent) => ProviderResult<T>;
|
|
40
|
+
}[];
|
|
41
|
+
sseConnection?: EventSource;
|
|
42
|
+
subscriptionSet: SubscriptionSet<T['Request']['Params']>;
|
|
43
|
+
timeOfLastReq: number;
|
|
44
|
+
localSubscriptions: T['Request']['Params'][];
|
|
45
|
+
constructor(config: {
|
|
46
|
+
prepareSSEConnectionConfig: (params: T['Request']['Params'][], context: AdapterContext<T>) => SSEConfig;
|
|
47
|
+
prepareKeepAliveRequest: (context: AdapterContext<T>) => AxiosRequestConfig<T['Provider']['RequestBody']>;
|
|
48
|
+
prepareSubscriptionRequest: (params: T['Request']['Params'][], context: AdapterContext<T>) => AxiosRequestConfig<T['Provider']['RequestBody']>;
|
|
49
|
+
prepareUnsubscriptionRequest: (params: T['Request']['Params'][], context: AdapterContext<T>) => AxiosRequestConfig<T['Provider']['RequestBody']>;
|
|
50
|
+
eventListeners: {
|
|
51
|
+
type: string;
|
|
52
|
+
parseResponse: (evt: MessageEvent) => ProviderResult<T>[];
|
|
53
|
+
}[];
|
|
54
|
+
keepaliveSleepMs?: number;
|
|
55
|
+
pollingSleepMs?: number;
|
|
56
|
+
});
|
|
57
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
58
|
+
registerRequest(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
59
|
+
backgroundExecute(context: AdapterContext<T>): Promise<number>;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
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.SSETransport = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const eventsource_1 = __importDefault(require("eventsource"));
|
|
9
|
+
const util_1 = require("../util");
|
|
10
|
+
const _1 = require("./");
|
|
11
|
+
const logger = (0, util_1.makeLogger)('SSETransport');
|
|
12
|
+
/**
|
|
13
|
+
* Transport implementation that establishes a long lived connection to a server using the SSE protocol and subcribes to updates.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[SSETransportGenerics]])
|
|
16
|
+
*/
|
|
17
|
+
class SSETransport {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.EventSource = eventsource_1.default;
|
|
21
|
+
this.timeOfLastReq = 0;
|
|
22
|
+
// The double sets serve to create a simple polling mechanism instead of needing a subscription
|
|
23
|
+
// This one would not; this is always local state
|
|
24
|
+
this.localSubscriptions = [];
|
|
25
|
+
}
|
|
26
|
+
async initialize(dependencies, config, endpointName) {
|
|
27
|
+
this.cache = dependencies.cache;
|
|
28
|
+
this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
|
|
29
|
+
if (dependencies.eventSource) {
|
|
30
|
+
this.EventSource = dependencies.eventSource;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async registerRequest(req, config) {
|
|
34
|
+
logger.debug(`Adding entry to subscription set (ttl: ${config.SSE_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
35
|
+
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.SSE_SUBSCRIPTION_TTL);
|
|
36
|
+
}
|
|
37
|
+
// Unlike cache warming, this execute will manage subscriptions
|
|
38
|
+
async backgroundExecute(context) {
|
|
39
|
+
logger.debug('Starting background execute, getting subscriptions from sorted set');
|
|
40
|
+
const desiredSubs = await this.subscriptionSet.getAll();
|
|
41
|
+
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
42
|
+
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
|
|
43
|
+
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
|
|
44
|
+
logger.debug(`${subscribeParams.length} new subscriptions; ${unsubscribeParams.length} to unsubscribe`);
|
|
45
|
+
if (subscribeParams.length) {
|
|
46
|
+
logger.trace(`Will subscribe to: ${subscribeParams}`);
|
|
47
|
+
}
|
|
48
|
+
if (unsubscribeParams.length) {
|
|
49
|
+
logger.trace(`Will unsubscribe to: ${unsubscribeParams}`);
|
|
50
|
+
}
|
|
51
|
+
if ((subscribeParams.length || unsubscribeParams.length) &&
|
|
52
|
+
(!this.sseConnection || this.sseConnection.readyState !== this.sseConnection.OPEN)) {
|
|
53
|
+
logger.debug('No established connection and new subscriptions available, connecting to SSE');
|
|
54
|
+
const sseConfig = this.config.prepareSSEConnectionConfig(subscribeParams, context);
|
|
55
|
+
this.sseConnection = new this.EventSource(sseConfig.url, sseConfig.eventSourceInitDict);
|
|
56
|
+
const eventHandlerGenerator = (listener) => {
|
|
57
|
+
return (e) => {
|
|
58
|
+
const providerResponses = listener.parseResponse(e);
|
|
59
|
+
const cacheEntries = (0, _1.buildCacheEntriesFromResults)(providerResponses, context);
|
|
60
|
+
this.cache.setMany(cacheEntries, context.adapterConfig.CACHE_MAX_AGE);
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
this.config.eventListeners.forEach((listener) => {
|
|
64
|
+
this.sseConnection?.addEventListener(listener.type, eventHandlerGenerator(listener));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const makeRequest = async (req) => {
|
|
68
|
+
try {
|
|
69
|
+
const res = await axios_1.default.request(req);
|
|
70
|
+
logger.debug(res.data, `response status ${res.statusText} from keepalive request`);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
logger.error(err, `Error on keepalive request`);
|
|
74
|
+
}
|
|
75
|
+
this.timeOfLastReq = Date.now();
|
|
76
|
+
};
|
|
77
|
+
if (subscribeParams.length) {
|
|
78
|
+
const subscribeRequest = this.config.prepareSubscriptionRequest(subscribeParams, context);
|
|
79
|
+
makeRequest(subscribeRequest);
|
|
80
|
+
}
|
|
81
|
+
if (unsubscribeParams.length) {
|
|
82
|
+
const unsubscribeRequest = this.config.prepareUnsubscriptionRequest(unsubscribeParams, context);
|
|
83
|
+
makeRequest(unsubscribeRequest);
|
|
84
|
+
}
|
|
85
|
+
if (desiredSubs.length &&
|
|
86
|
+
Date.now() - this.timeOfLastReq > context.adapterConfig.SSE_KEEPALIVE_SLEEP) {
|
|
87
|
+
const prepareKeepAliveRequest = this.config.prepareKeepAliveRequest(context);
|
|
88
|
+
makeRequest(prepareKeepAliveRequest);
|
|
89
|
+
}
|
|
90
|
+
logger.debug('Setting local state to cache value');
|
|
91
|
+
this.localSubscriptions = desiredSubs;
|
|
92
|
+
logger.debug('Background execute complete');
|
|
93
|
+
return context.adapterConfig.SSE_SUBSCRIPTION_UPDATE_SLEEP;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.SSETransport = SSETransport;
|
|
97
|
+
//# sourceMappingURL=sse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAiD;AACjD,8DAAqC;AAIrC,kCAAqD;AAErD,yBAA+E;AAE/E,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,cAAc,CAAC,CAAA;AAuBzC;;;;GAIG;AACH,MAAa,YAAY;IAevB,YACU,MAsBP;QAtBO,WAAM,GAAN,MAAM,CAsBb;QArCH,gBAAW,GAAuB,qBAAW,CAAA;QAQ7C,kBAAa,GAAG,CAAC,CAAA;QAE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AAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAA;QAErC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,OAAO,OAAO,CAAC,aAAa,CAAC,6BAA6B,CAAA;IAC5D,CAAC;CACF;AA9ID,oCA8IC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { AdapterConfig, SettingsMap } from '../config';
|
|
3
|
+
/**
|
|
4
|
+
* Performs axios request along with metrics recording and error handling
|
|
5
|
+
*
|
|
6
|
+
* @param request - axios request config
|
|
7
|
+
* @returns axios response for the request
|
|
8
|
+
*/
|
|
9
|
+
export declare function axiosRequest<ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap>(request: AxiosRequestConfig<ProviderRequestBody>, config: AdapterConfig<CustomSettings>): Promise<AxiosResponse<ProviderResponseBody>>;
|
|
@@ -0,0 +1,87 @@
|
|
|
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.axiosRequest = void 0;
|
|
30
|
+
const axios_1 = __importDefault(require("axios"));
|
|
31
|
+
const error_1 = require("../validation/error");
|
|
32
|
+
const transportMetrics = __importStar(require("./metrics"));
|
|
33
|
+
/**
|
|
34
|
+
* Performs axios request along with metrics recording and error handling
|
|
35
|
+
*
|
|
36
|
+
* @param request - axios request config
|
|
37
|
+
* @returns axios response for the request
|
|
38
|
+
*/
|
|
39
|
+
async function axiosRequest(request, config) {
|
|
40
|
+
const responseTimer = transportMetrics.dataProviderRequestDurationSeconds.startTimer();
|
|
41
|
+
let providerResponse;
|
|
42
|
+
try {
|
|
43
|
+
request.timeout = config.API_TIMEOUT;
|
|
44
|
+
providerResponse = await axios_1.default.request(request);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
const error = e;
|
|
48
|
+
// Request error
|
|
49
|
+
let providerStatusCode;
|
|
50
|
+
let adapterError;
|
|
51
|
+
if (error.code === 'ECONNABORTED') {
|
|
52
|
+
adapterError = new error_1.AdapterTimeoutError({});
|
|
53
|
+
providerStatusCode = error?.response?.status ?? 504;
|
|
54
|
+
adapterError.name = 'Data Provider Request Timeout error';
|
|
55
|
+
}
|
|
56
|
+
else if (error?.response?.status) {
|
|
57
|
+
adapterError = new error_1.AdapterDataProviderError({});
|
|
58
|
+
providerStatusCode = error?.response?.status;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
adapterError = new error_1.AdapterConnectionError({});
|
|
62
|
+
providerStatusCode = 0; // 0 -> connection error
|
|
63
|
+
}
|
|
64
|
+
// Record count of failed data provider request
|
|
65
|
+
transportMetrics.dataProviderRequests
|
|
66
|
+
.labels(transportMetrics.dataProviderMetricsLabel(providerStatusCode, request.method))
|
|
67
|
+
.inc();
|
|
68
|
+
adapterError.statusCode = 200;
|
|
69
|
+
adapterError.providerStatusCode = providerStatusCode;
|
|
70
|
+
adapterError.message = error?.message;
|
|
71
|
+
adapterError.cause = error;
|
|
72
|
+
adapterError.errorResponse = error?.response?.data;
|
|
73
|
+
adapterError.url = request.url;
|
|
74
|
+
throw adapterError;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
// Record time taken for data provider request for success or failure
|
|
78
|
+
responseTimer();
|
|
79
|
+
}
|
|
80
|
+
// Record count of successful data provider requests
|
|
81
|
+
transportMetrics.dataProviderRequests
|
|
82
|
+
.labels(transportMetrics.dataProviderMetricsLabel(providerResponse.status, request.method))
|
|
83
|
+
.inc();
|
|
84
|
+
return providerResponse;
|
|
85
|
+
}
|
|
86
|
+
exports.axiosRequest = axiosRequest;
|
|
87
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/transports/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4E;AAE5E,+CAK4B;AAC5B,4DAA6C;AAE7C;;;;;GAKG;AACI,KAAK,UAAU,YAAY,CAKhC,OAAgD,EAChD,MAAqC;IAErC,MAAM,aAAa,GAAG,gBAAgB,CAAC,kCAAkC,CAAC,UAAU,EAAE,CAAA;IACtF,IAAI,gBAAqD,CAAA;IACzD,IAAI;QACF,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAA;QACpC,gBAAgB,GAAG,MAAM,eAAK,CAAC,OAAO,CAAuB,OAAO,CA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gB,CAAC,oBAAoB;SAClC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;SAC1F,GAAG,EAAE,CAAA;IAER,OAAO,gBAAgB,CAAA;AACzB,CAAC;AArDD,oCAqDC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import WebSocket, { ClientOptions, RawData } from 'ws';
|
|
2
|
+
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
3
|
+
import { Cache } from '../cache';
|
|
4
|
+
import { AdapterConfig } from '../config';
|
|
5
|
+
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
6
|
+
import { SubscriptionSet } from '../util';
|
|
7
|
+
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
8
|
+
import { Transport, TransportGenerics } from './';
|
|
9
|
+
export { WebSocket, RawData as WebSocketRawData };
|
|
10
|
+
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined, options?: ClientOptions) => WebSocket;
|
|
11
|
+
export declare class WebSocketClassProvider {
|
|
12
|
+
static ctor: WebSocketClass;
|
|
13
|
+
static set(ctor: WebSocketClass): void;
|
|
14
|
+
static get(): WebSocketClass;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Config object that is provided to the WebSocketTransport constructor.
|
|
18
|
+
*/
|
|
19
|
+
export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics> {
|
|
20
|
+
/** Endpoint to which to open the WS connection*/
|
|
21
|
+
url: (context: AdapterContext<T>) => string;
|
|
22
|
+
/** Optional parameters used when establishing the WebSocket connection */
|
|
23
|
+
options?: (context: AdapterContext<T>) => ClientOptions;
|
|
24
|
+
/** Map of handlers for different WS lifecycle events */
|
|
25
|
+
handlers: {
|
|
26
|
+
/**
|
|
27
|
+
* Handles when the WS is successfully opened
|
|
28
|
+
*
|
|
29
|
+
* @param wsConnection - the WebSocket with an established connection
|
|
30
|
+
* @returns an empty Promise, or void
|
|
31
|
+
*/
|
|
32
|
+
open: (wsConnection: WebSocket, context: AdapterContext<T>) => Promise<void> | void;
|
|
33
|
+
/**
|
|
34
|
+
* Handles when the WS receives a message
|
|
35
|
+
*
|
|
36
|
+
* @param message - the message received by the WS
|
|
37
|
+
* @param context - the background context for the Adapter
|
|
38
|
+
* @returns a list of cache entries of adapter responses to set in the cache
|
|
39
|
+
*/
|
|
40
|
+
message: (message: T['Provider']['WsMessage'], context: AdapterContext<T>) => ProviderResult<T>[] | undefined;
|
|
41
|
+
};
|
|
42
|
+
/** Map of "builders", functions that will be used to prepare specific WS messages */
|
|
43
|
+
builders: {
|
|
44
|
+
/**
|
|
45
|
+
* Builds a WS message that will be sent to subscribe to a specific feed
|
|
46
|
+
*
|
|
47
|
+
* @param params - the body of the adapter request
|
|
48
|
+
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
49
|
+
*/
|
|
50
|
+
subscribeMessage: (params: T['Request']['Params']) => unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Builds a WS message that will be sent to unsubscribe to a specific feed
|
|
53
|
+
*
|
|
54
|
+
* @param params - the body of the adapter request
|
|
55
|
+
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
56
|
+
*/
|
|
57
|
+
unsubscribeMessage: (params: T['Request']['Params']) => unknown;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
62
|
+
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
63
|
+
*/
|
|
64
|
+
declare type WebsocketTransportGenerics = TransportGenerics & {
|
|
65
|
+
/**
|
|
66
|
+
* Type details for any provider specific interfaces.
|
|
67
|
+
*/
|
|
68
|
+
Provider: {
|
|
69
|
+
/**
|
|
70
|
+
* Structure of any message that will come through the websocket connection.
|
|
71
|
+
*/
|
|
72
|
+
WsMessage: unknown;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
77
|
+
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
78
|
+
*
|
|
79
|
+
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[WebsocketTransportGenerics]])
|
|
80
|
+
*/
|
|
81
|
+
export declare class WebSocketTransport<T extends WebsocketTransportGenerics> implements Transport<T> {
|
|
82
|
+
private config;
|
|
83
|
+
cache: Cache<AdapterResponse<T['Response']>>;
|
|
84
|
+
rateLimiter: BackgroundExecuteRateLimiter;
|
|
85
|
+
subscriptionSet: SubscriptionSet<T['Request']['Params']>;
|
|
86
|
+
localSubscriptions: T['Request']['Params'][];
|
|
87
|
+
wsConnection: WebSocket;
|
|
88
|
+
constructor(config: WebSocketTransportConfig<T>);
|
|
89
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
90
|
+
registerRequest(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
91
|
+
serializeMessage(payload: unknown): string;
|
|
92
|
+
deserializeMessage(data: WebSocket.Data): T['Provider']['WsMessage'];
|
|
93
|
+
establishWsConnection(context: AdapterContext<T>): Promise<unknown>;
|
|
94
|
+
backgroundExecute(context: AdapterContext<T>): Promise<number>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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 T - Helper struct type that will be used to pass types to the generic parameters (check [[WebsocketTransportGenerics]])
|
|
51
|
+
*/
|
|
52
|
+
class WebSocketTransport {
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config = config;
|
|
55
|
+
// The double sets serve to create a simple polling mechanism instead of needing a subscription
|
|
56
|
+
// This one would not; this is always local state
|
|
57
|
+
this.localSubscriptions = [];
|
|
58
|
+
}
|
|
59
|
+
async initialize(dependencies, config, endpointName) {
|
|
60
|
+
this.cache = dependencies.cache;
|
|
61
|
+
this.rateLimiter = dependencies.backgroundExecuteRateLimiter;
|
|
62
|
+
this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
|
|
63
|
+
}
|
|
64
|
+
async registerRequest(req, config) {
|
|
65
|
+
logger.debug(`Adding entry to subscription set (ttl: ${config.WS_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
66
|
+
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
|
|
67
|
+
}
|
|
68
|
+
serializeMessage(payload) {
|
|
69
|
+
return typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
70
|
+
}
|
|
71
|
+
deserializeMessage(data) {
|
|
72
|
+
return JSON.parse(data.toString());
|
|
73
|
+
}
|
|
74
|
+
establishWsConnection(context) {
|
|
75
|
+
return new Promise((resolve) => {
|
|
76
|
+
const ctor = WebSocketClassProvider.get();
|
|
77
|
+
const url = context.adapterConfig.WS_API_ENDPOINT || this.config.url(context);
|
|
78
|
+
const options = this.config.options && this.config.options(context);
|
|
79
|
+
this.wsConnection = new ctor(url, undefined, options);
|
|
80
|
+
this.wsConnection.addEventListener('open', async (event) => {
|
|
81
|
+
logger.debug(`Opened websocket connection. (event type ${event.type})`);
|
|
82
|
+
await this.config.handlers.open(this.wsConnection, context);
|
|
83
|
+
logger.debug('Successfully executed connection opened handler');
|
|
84
|
+
// Record active ws connections by incrementing count on open
|
|
85
|
+
transportMetrics.wsConnectionActive.inc();
|
|
86
|
+
resolve(true);
|
|
87
|
+
});
|
|
88
|
+
this.wsConnection.addEventListener('message', async (event) => {
|
|
89
|
+
const parsed = this.deserializeMessage(event.data);
|
|
90
|
+
logger.trace(`Got ws message: ${parsed}`);
|
|
91
|
+
const results = this.config.handlers.message(parsed, context);
|
|
92
|
+
if (Array.isArray(results)) {
|
|
93
|
+
const responses = (0, _1.buildCacheEntriesFromResults)(results, context);
|
|
94
|
+
logger.trace(`Writing ${responses.length} responses to cache`);
|
|
95
|
+
await this.cache.setMany(responses, context.adapterConfig.CACHE_MAX_AGE);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.wsConnection.addEventListener('error', async (event) => {
|
|
99
|
+
logger.debug(`Error occurred in web socket connection. Error: ${event.error} ; Message: ${event.message}`);
|
|
100
|
+
// Record connection error count
|
|
101
|
+
transportMetrics.wsConnectionErrors
|
|
102
|
+
.labels(transportMetrics.connectionErrorLabels(event.message))
|
|
103
|
+
.inc();
|
|
104
|
+
});
|
|
105
|
+
this.wsConnection.addEventListener('close', (event) => {
|
|
106
|
+
logger.debug(`Closed websocket connection. Code: ${event.code} ; reason: ${event.reason?.toString()}`);
|
|
107
|
+
// Record active ws connections by decrementing count on close
|
|
108
|
+
// Using URL in label since connection_key is removed from v3
|
|
109
|
+
transportMetrics.wsConnectionActive.dec();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Unlike cache warming, this execute will manage subscriptions
|
|
114
|
+
async backgroundExecute(context) {
|
|
115
|
+
logger.debug('Starting background execute, getting subscriptions from sorted set');
|
|
116
|
+
const desiredSubs = await this.subscriptionSet.getAll();
|
|
117
|
+
// Keep track of active subscriptions for background execute
|
|
118
|
+
transportMetrics.bgExecuteSubscriptionSetCount
|
|
119
|
+
.labels({ endpoint: context.adapterEndpoint.name, transport_type: 'websocket' })
|
|
120
|
+
.set(desiredSubs.length);
|
|
121
|
+
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
122
|
+
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.map((ls) => JSON.stringify(ls)).includes(JSON.stringify(s)));
|
|
123
|
+
const subscribes = subscribeParams
|
|
124
|
+
.map(this.config.builders.subscribeMessage)
|
|
125
|
+
.map(this.serializeMessage);
|
|
126
|
+
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.map((ds) => JSON.stringify(ds)).includes(JSON.stringify(s)));
|
|
127
|
+
const unsubscribes = unsubscribeParams
|
|
128
|
+
.map(this.config.builders.unsubscribeMessage)
|
|
129
|
+
.map(this.serializeMessage);
|
|
130
|
+
logger.debug(`${subscribes.length} new subscriptions; ${unsubscribes.length} to unsubscribe`);
|
|
131
|
+
if (subscribes.length) {
|
|
132
|
+
logger.trace(`Will subscribe to: ${subscribes}`);
|
|
133
|
+
}
|
|
134
|
+
if (unsubscribes.length) {
|
|
135
|
+
logger.trace(`Will unsubscribe to: ${unsubscribes}`);
|
|
136
|
+
}
|
|
137
|
+
// New subs && no connection -> connect -> add subs
|
|
138
|
+
// No new subs && no connection -> skip
|
|
139
|
+
// New subs && connection -> add subs
|
|
140
|
+
// No new subs && connection -> unsubs only
|
|
141
|
+
if (!subscribes.length && !this.wsConnection) {
|
|
142
|
+
logger.debug('No entries in subscription set and no established connection, skipping');
|
|
143
|
+
return this.rateLimiter.msUntilNextExecution(context.adapterEndpoint.name);
|
|
144
|
+
}
|
|
145
|
+
if (!this.wsConnection && subscribes.length) {
|
|
146
|
+
logger.debug('No established connection and new subscriptions available, connecting to WS');
|
|
147
|
+
await this.establishWsConnection(context);
|
|
148
|
+
}
|
|
149
|
+
logger.debug('Sending subs/unsubs if there are any');
|
|
150
|
+
const messages = unsubscribes.concat(subscribes);
|
|
151
|
+
for (const message of messages) {
|
|
152
|
+
logger.trace(`Sending message: ${JSON.stringify(message)}`);
|
|
153
|
+
this.wsConnection.send(message);
|
|
154
|
+
}
|
|
155
|
+
// Record WS message and subscription metrics
|
|
156
|
+
transportMetrics.recordWsMessageMetrics(context, subscribeParams, unsubscribeParams);
|
|
157
|
+
logger.debug('Setting local state to cache value');
|
|
158
|
+
this.localSubscriptions = desiredSubs;
|
|
159
|
+
logger.debug('Background execute complete');
|
|
160
|
+
return this.rateLimiter.msUntilNextExecution(context.adapterEndpoint.name);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.WebSocketTransport = WebSocketTransport;
|
|
164
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAsD;AAW7C,oBAXF,YAAS,CAWE;AANlB,kCAAqD;AAErD,yBAA+E;AAC/E,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;AAgFzC;;;;;GAKG;AACH,MAAa,kBAAkB;IAW7B,YAAoB,MAAmC;QAAnC,WAAM,GAAN,MAAM,CAA6B;QANvD,+FAA+F;QAC/F,iDAAiD;QACjD,uBAAkB,GAA6B,EAAE,CAAA;IAIS,CAAC;IAE3D,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,MAA0C,EAC1C,YAAoB;QAEpB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAA8C,CAAA;QACxE,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,4BAA4B,CAAA;Q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IAAI,CAAC,YAAY,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;AAxJD,gDAwJC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|