woonplan-packages-redishelper 2.0.0 → 2.0.3
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/dist/tsc/classes/Broker.d.ts +42 -0
- package/dist/tsc/classes/Broker.js +185 -0
- package/dist/tsc/classes/Broker.js.map +1 -0
- package/dist/tsc/classes/BrokerClient.d.ts +17 -0
- package/dist/tsc/classes/BrokerClient.js +52 -0
- package/dist/tsc/classes/BrokerClient.js.map +1 -0
- package/dist/tsc/classes/ListListener.d.ts +8 -0
- package/dist/tsc/classes/ListListener.js +18 -0
- package/dist/tsc/classes/ListListener.js.map +1 -0
- package/dist/tsc/classes/ListRunner.d.ts +11 -0
- package/dist/tsc/classes/ListRunner.js +34 -0
- package/dist/tsc/classes/ListRunner.js.map +1 -0
- package/dist/tsc/classes/Listener.d.ts +7 -0
- package/dist/tsc/classes/Listener.js +14 -0
- package/dist/tsc/classes/Listener.js.map +1 -0
- package/dist/tsc/main.d.ts +2 -0
- package/dist/tsc/main.js +7 -0
- package/dist/tsc/main.js.map +1 -0
- package/dist/tsc/services/utils.d.ts +11 -0
- package/dist/tsc/services/utils.js +47 -0
- package/dist/tsc/services/utils.js.map +1 -0
- package/package.json +1 -1
- package/jest.config.js +0 -18
- package/src/__tests__/Broker.test.ts +0 -223
- package/src/__tests__/Listener.test.ts +0 -89
- package/src/classes/Broker.ts +0 -225
- package/src/classes/BrokerClient.ts +0 -64
- package/src/classes/ListListener.ts +0 -20
- package/src/classes/ListRunner.ts +0 -43
- package/src/classes/Listener.ts +0 -14
- package/src/classes/Requester.ts +0 -5
- package/src/services/utils.ts +0 -52
- package/src/types.ts +0 -49
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Redis } from "ioredis";
|
|
3
|
+
import Rollbar from "rollbar";
|
|
4
|
+
import Listener from "./Listener";
|
|
5
|
+
export default class Broker {
|
|
6
|
+
redisConfig: RedisConfig;
|
|
7
|
+
rollbar?: Rollbar;
|
|
8
|
+
consumername: string;
|
|
9
|
+
listeners: Map<string, Listener>;
|
|
10
|
+
writer: Redis;
|
|
11
|
+
reader: Redis;
|
|
12
|
+
listprefix: string;
|
|
13
|
+
service: string;
|
|
14
|
+
subscriptions: string[];
|
|
15
|
+
requestendpoint?: Function;
|
|
16
|
+
constructor(redisConfig: RedisConfig, rollbarConfig: RollbarConfig, service: string, consumer: string);
|
|
17
|
+
get requeststream(): string;
|
|
18
|
+
getRequestStream(service: string): string;
|
|
19
|
+
setRequestEndpoint(callback: Function): this;
|
|
20
|
+
getRequestCallback(callback: Function): (id: string, parameters: DecypheredParameters) => Promise<number | null>;
|
|
21
|
+
publish(channel: string, result: string): Promise<number>;
|
|
22
|
+
addListener(stream: string, callback: Function, group?: string): this;
|
|
23
|
+
addListListener(event: string, callback: Function): this;
|
|
24
|
+
throwError(error: Error): void;
|
|
25
|
+
sendMessage(stream: string, data: Struct): Promise<string | null>;
|
|
26
|
+
getRequest(targetservice: string, key: string, data: Struct): Promise<unknown>;
|
|
27
|
+
requestMessageResponse(resolve: (value?: any) => void, timeout: NodeJS.Timeout): void;
|
|
28
|
+
unsubscribe(channel: string): void;
|
|
29
|
+
setupTimeout(resolve: (value?: any) => void, channel: string, n?: number): NodeJS.Timeout;
|
|
30
|
+
subscribe(channel: string): Promise<unknown>;
|
|
31
|
+
getRequestSubscriptionName(messageid: string): string;
|
|
32
|
+
sendListEvent(event: string, listitems: any[], data?: Struct): Promise<string | null>;
|
|
33
|
+
addToList(listitems: any[], listname?: string): Promise<string>;
|
|
34
|
+
getListChannel(event: string): string;
|
|
35
|
+
sanitizeValue(value: any): any;
|
|
36
|
+
createRedisMessage(struct: Struct): string[];
|
|
37
|
+
getStreamMessages(stream: string): Promise<DecypheredMessage[]>;
|
|
38
|
+
getStreamInfo(stream: string, count?: number): Promise<any[] | null>;
|
|
39
|
+
filterStream(stream: string, key: string, value: any): Promise<DecypheredMessage[]>;
|
|
40
|
+
decypherResponse(...responses: StreamResponse[]): DecypheredResponse[];
|
|
41
|
+
decypherParameters(parameters: string[]): DecypheredParameters;
|
|
42
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const ioredis_1 = tslib_1.__importDefault(require("ioredis"));
|
|
6
|
+
const rollbar_1 = tslib_1.__importDefault(require("rollbar"));
|
|
7
|
+
const types_1 = require("util/types");
|
|
8
|
+
const utils_1 = require("../services/utils");
|
|
9
|
+
const Listener_1 = tslib_1.__importDefault(require("./Listener"));
|
|
10
|
+
const ListListener_1 = tslib_1.__importDefault(require("./ListListener"));
|
|
11
|
+
const uuid_1 = require("uuid");
|
|
12
|
+
class Broker {
|
|
13
|
+
constructor(redisConfig, rollbarConfig, service, consumer) {
|
|
14
|
+
this.consumername = '';
|
|
15
|
+
this.listeners = new Map();
|
|
16
|
+
this.listprefix = 'listUpdated';
|
|
17
|
+
this.subscriptions = [];
|
|
18
|
+
this.redisConfig = redisConfig;
|
|
19
|
+
this.rollbar = new rollbar_1.default({
|
|
20
|
+
accessToken: rollbarConfig.accessToken,
|
|
21
|
+
environment: rollbarConfig.environment,
|
|
22
|
+
});
|
|
23
|
+
this.writer = new ioredis_1.default(redisConfig.REDISURL);
|
|
24
|
+
this.reader = new ioredis_1.default(redisConfig.REDISURL);
|
|
25
|
+
this.consumername = consumer;
|
|
26
|
+
this.service = service;
|
|
27
|
+
}
|
|
28
|
+
get requeststream() {
|
|
29
|
+
return this.getRequestStream(this.service);
|
|
30
|
+
}
|
|
31
|
+
getRequestStream(service) {
|
|
32
|
+
return `keyRequestedFrom${(0, utils_1.capitalizeFirstLetter)(service)}Service`;
|
|
33
|
+
}
|
|
34
|
+
setRequestEndpoint(callback) {
|
|
35
|
+
return this.addListener(this.requeststream, this.getRequestCallback(callback), this.service);
|
|
36
|
+
}
|
|
37
|
+
getRequestCallback(callback) {
|
|
38
|
+
return async (id, parameters) => {
|
|
39
|
+
const result = await callback(id, parameters);
|
|
40
|
+
if (!parameters.messageid)
|
|
41
|
+
return null;
|
|
42
|
+
const channel = this.getRequestSubscriptionName(parameters.messageid);
|
|
43
|
+
return this.publish(channel, result);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
publish(channel, result) {
|
|
47
|
+
return this.writer.publish(channel, result);
|
|
48
|
+
}
|
|
49
|
+
addListener(stream, callback, group) {
|
|
50
|
+
const client = new ioredis_1.default(this.redisConfig.REDISURL);
|
|
51
|
+
this.listeners.set(stream, new Listener_1.default(this, client, stream, callback, group));
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
addListListener(event, callback) {
|
|
55
|
+
const client = new ioredis_1.default(this.redisConfig.REDISURL);
|
|
56
|
+
const channel = this.getListChannel(event);
|
|
57
|
+
this.listeners.set(channel, new ListListener_1.default(this, client, channel, callback));
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
throwError(error) {
|
|
61
|
+
if (!this.rollbar)
|
|
62
|
+
throw new Error('Rollbar not initialized');
|
|
63
|
+
this.rollbar.error(error);
|
|
64
|
+
}
|
|
65
|
+
sendMessage(stream, data) {
|
|
66
|
+
return this.writer.xadd(stream, '*', ...this.createRedisMessage(data));
|
|
67
|
+
}
|
|
68
|
+
async getRequest(targetservice, key, data) {
|
|
69
|
+
// create a message id to subscribe to
|
|
70
|
+
const messageid = (0, uuid_1.v4)();
|
|
71
|
+
//subscribe to message response
|
|
72
|
+
const channel = this.getRequestSubscriptionName(messageid);
|
|
73
|
+
await this.subscribe(channel);
|
|
74
|
+
// send the message to the correct service
|
|
75
|
+
this.sendMessage(this.getRequestStream(targetservice), {
|
|
76
|
+
request: key,
|
|
77
|
+
messageid: messageid,
|
|
78
|
+
data: data
|
|
79
|
+
});
|
|
80
|
+
let resolver;
|
|
81
|
+
// create a promise to be able to pass on to resolve later
|
|
82
|
+
const promise = new Promise((r) => {
|
|
83
|
+
resolver = r;
|
|
84
|
+
});
|
|
85
|
+
if (!resolver)
|
|
86
|
+
return null;
|
|
87
|
+
//setup a timeout
|
|
88
|
+
const timeout = this.setupTimeout(resolver, channel);
|
|
89
|
+
//setup a response
|
|
90
|
+
this.requestMessageResponse(resolver, timeout);
|
|
91
|
+
// return a promise that will resolve when the message returns or times out
|
|
92
|
+
return promise;
|
|
93
|
+
}
|
|
94
|
+
requestMessageResponse(resolve, timeout) {
|
|
95
|
+
this.reader.once('message', (channel, message) => {
|
|
96
|
+
if (message.length)
|
|
97
|
+
resolve(message);
|
|
98
|
+
else
|
|
99
|
+
resolve(null);
|
|
100
|
+
this.unsubscribe(channel);
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
unsubscribe(channel) {
|
|
105
|
+
this.reader.unsubscribe(channel);
|
|
106
|
+
this.subscriptions = this.subscriptions.filter(s => s != channel);
|
|
107
|
+
}
|
|
108
|
+
setupTimeout(resolve, channel, n = 2000) {
|
|
109
|
+
return setTimeout(() => {
|
|
110
|
+
if (!this.subscriptions.includes(channel))
|
|
111
|
+
return;
|
|
112
|
+
console.log(`sub timedout: ${channel}`);
|
|
113
|
+
resolve(null);
|
|
114
|
+
this.unsubscribe(channel);
|
|
115
|
+
}, n);
|
|
116
|
+
}
|
|
117
|
+
subscribe(channel) {
|
|
118
|
+
this.subscriptions.push(channel);
|
|
119
|
+
return this.reader.subscribe(channel);
|
|
120
|
+
}
|
|
121
|
+
getRequestSubscriptionName(messageid) {
|
|
122
|
+
return `messageresponse${messageid}`;
|
|
123
|
+
}
|
|
124
|
+
async sendListEvent(event, listitems, data = {}) {
|
|
125
|
+
const list = await this.addToList.call(this, listitems);
|
|
126
|
+
return this.sendMessage(this.getListChannel(event), {
|
|
127
|
+
...data,
|
|
128
|
+
listname: list
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async addToList(listitems, listname) {
|
|
132
|
+
const list = listname ?? (0, uuid_1.v4)();
|
|
133
|
+
await this.writer.lpush(list, ...listitems.map(this.sanitizeValue));
|
|
134
|
+
return list;
|
|
135
|
+
}
|
|
136
|
+
getListChannel(event) {
|
|
137
|
+
return `${this.listprefix}${event}`;
|
|
138
|
+
}
|
|
139
|
+
sanitizeValue(value) {
|
|
140
|
+
if ((0, types_1.isMap)(value))
|
|
141
|
+
return (0, utils_1.stringifyMap)(value);
|
|
142
|
+
if ((0, class_validator_1.isObject)(value))
|
|
143
|
+
return JSON.stringify(value);
|
|
144
|
+
if ((0, class_validator_1.isArray)(value))
|
|
145
|
+
return JSON.stringify(value);
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
createRedisMessage(struct) {
|
|
149
|
+
return Object.keys(struct).reduce((arr, key) => [...arr, key, this.sanitizeValue(struct[key])], []);
|
|
150
|
+
}
|
|
151
|
+
async getStreamMessages(stream) {
|
|
152
|
+
const streaminfo = await this.getStreamInfo.call(this, stream);
|
|
153
|
+
if (!streaminfo || !(0, class_validator_1.isArray)(streaminfo) || streaminfo.length < 10)
|
|
154
|
+
return [];
|
|
155
|
+
const streamresponses = streaminfo[9];
|
|
156
|
+
return this.decypherResponse(...streamresponses).flatMap(r => r.messages);
|
|
157
|
+
}
|
|
158
|
+
getStreamInfo(stream, count = 0) {
|
|
159
|
+
return this.reader.xinfo('STREAM', stream, 'FULL', 'COUNT', count);
|
|
160
|
+
}
|
|
161
|
+
async filterStream(stream, key, value) {
|
|
162
|
+
const messages = await this.getStreamMessages.call(this, stream);
|
|
163
|
+
return messages.filter(message => message.parameters?.[key] != null && message.parameters[key] == value);
|
|
164
|
+
}
|
|
165
|
+
decypherResponse(...responses) {
|
|
166
|
+
return responses.reduce((resp, response) => [
|
|
167
|
+
...resp,
|
|
168
|
+
{
|
|
169
|
+
stream: response[0],
|
|
170
|
+
messages: response[1].map((message) => ({
|
|
171
|
+
id: message[0],
|
|
172
|
+
parameters: this.decypherParameters(message[1])
|
|
173
|
+
}))
|
|
174
|
+
}
|
|
175
|
+
], []);
|
|
176
|
+
}
|
|
177
|
+
decypherParameters(parameters) {
|
|
178
|
+
return parameters.reduce((params, v, n) => (n == 0 || (n % 2 == 0)) && parameters.length >= n + 1 ? ({
|
|
179
|
+
...params,
|
|
180
|
+
[v]: parameters[n + 1]
|
|
181
|
+
}) : params, {});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.default = Broker;
|
|
185
|
+
//# sourceMappingURL=Broker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Broker.js","sourceRoot":"","sources":["../../../src/classes/Broker.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AACnD,8DAAwC;AACxC,8DAA6B;AAC7B,sCAAkC;AAClC,6CAAuE;AACvE,kEAAiC;AACjC,0EAAyC;AACzC,+BAAmC;AAEnC,MAAqB,MAAM;IAazB,YAAa,WAAuB,EAAE,aAA2B,EAAE,OAAc,EAAE,QAAiB;QAVpG,iBAAY,GAAa,EAAE,CAAA;QAC3B,cAAS,GAAyB,IAAI,GAAG,EAAE,CAAA;QAG3C,eAAU,GAAY,aAAa,CAAA;QAEnC,kBAAa,GAAc,EAAE,CAAA;QAK3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAC;YACzB,WAAW,EAAE,aAAa,CAAC,WAAW;YACtC,WAAW,EAAE,aAAa,CAAC,WAAW;SACvC,CAAC,CAAA;QACF,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAO,CAAE,WAAW,CAAC,QAAkB,CAAE,CAAA;QAC3D,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAO,CAAE,WAAW,CAAC,QAAkB,CAAE,CAAA;QAC3D,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,IAAI,aAAa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,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAE,CAAA;IAC5G,CAAC;IAED,gBAAgB,CAAE,GAAG,SAA0B;QAC7C,OAAO,SAAS,CAAC,MAAM,CAAE,CAAC,IAAyB,EAAE,QAAuB,EAAE,EAAE,CAC9E;YACE,GAAG,IAAI;YACP;gBACE,MAAM,EAAG,QAAQ,CAAC,CAAC,CAAC;gBACpB,QAAQ,EAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBACxC,EAAE,EAAG,OAAO,CAAC,CAAC,CAAC;oBACf,UAAU,EAAG,IAAI,CAAC,kBAAkB,CAAE,OAAO,CAAC,CAAC,CAAC,CAAE;iBACnD,CAAsB,CAAE;aACJ;SACxB,EACD,EAA0B,CAAE,CAAA;IAChC,CAAC;IAGD,kBAAkB,CAAE,UAAmB;QACrC,OAAO,UAAU,CAAC,MAAM,CAAE,CAAE,MAAM,EAAE,CAAQ,EAAE,CAAQ,EAAG,EAAE,CAAC,CAAG,CAAC,IAAI,CAAC,IAAI,CAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,GAAC,CAAC,CAAE,CAAC,CAAC,CAAC;YACtH,GAAG,MAAM;YACT,CAAC,CAAC,CAAC,EAAG,UAAU,CAAC,CAAC,GAAC,CAAC,CAAC;SACtB,CAAC,CAAC,CAAC,CAAC,MAAM,EAAG,EAA0B,CAAC,CAAA;IAC3C,CAAC;CAEF;AApND,yBAoNC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import Broker from "./Broker";
|
|
3
|
+
export default abstract class BrokerClient {
|
|
4
|
+
broker: Broker;
|
|
5
|
+
client: Redis;
|
|
6
|
+
group: string | null;
|
|
7
|
+
stream: string | null;
|
|
8
|
+
list: string | null;
|
|
9
|
+
callback: Function;
|
|
10
|
+
constructor(broker: Broker, client: Redis, callback: Function, list: string | null, stream?: string | null, group?: string | null);
|
|
11
|
+
throwError(error: any): void;
|
|
12
|
+
decypherResponse(...responses: StreamResponse[]): DecypheredResponse[];
|
|
13
|
+
getGroupResponse(): Promise<StreamResponse[] | null>;
|
|
14
|
+
getResponse(lastid: string): Promise<StreamResponse[] | null>;
|
|
15
|
+
listenToStream(lastid?: string): Promise<Function | null>;
|
|
16
|
+
abstract streamCallback(message: DecypheredMessage): Promise<any | null>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class BrokerClient {
|
|
4
|
+
constructor(broker, client, callback, list, stream = null, group = null) {
|
|
5
|
+
this.group = null;
|
|
6
|
+
this.stream = null;
|
|
7
|
+
this.list = null;
|
|
8
|
+
this.broker = broker;
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.list = list;
|
|
11
|
+
this.stream = stream;
|
|
12
|
+
this.group = group;
|
|
13
|
+
this.callback = callback;
|
|
14
|
+
this.listenToStream.call(this);
|
|
15
|
+
}
|
|
16
|
+
throwError(error) {
|
|
17
|
+
return this.broker.throwError(error);
|
|
18
|
+
}
|
|
19
|
+
decypherResponse(...responses) {
|
|
20
|
+
return this.broker.decypherResponse(...responses);
|
|
21
|
+
}
|
|
22
|
+
async getGroupResponse() {
|
|
23
|
+
if (!this.group || !this.stream)
|
|
24
|
+
return null;
|
|
25
|
+
return await this.client.xreadgroup('GROUP', this.group, this.broker.consumername, 'COUNT', 1, 'BLOCK', 0, 'STREAMS', this.stream, '>');
|
|
26
|
+
}
|
|
27
|
+
async getResponse(lastid) {
|
|
28
|
+
if (!this.stream)
|
|
29
|
+
return null;
|
|
30
|
+
return await this.client.xread("BLOCK", 0, "STREAMS", this.stream, lastid);
|
|
31
|
+
}
|
|
32
|
+
async listenToStream(lastid = '$') {
|
|
33
|
+
const responses = await this.getResponse.call(this, lastid);
|
|
34
|
+
if (!responses)
|
|
35
|
+
return null;
|
|
36
|
+
const streamResponses = this.decypherResponse(...responses);
|
|
37
|
+
const messages = streamResponses.flatMap(r => r.messages);
|
|
38
|
+
await Promise.all(messages.map(async (message) => {
|
|
39
|
+
try {
|
|
40
|
+
await this.streamCallback(message);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
this.broker.throwError(e);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
return this.listenToStream.call(this, messages[messages.length - 1]?.id ?? '$');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = BrokerClient;
|
|
52
|
+
//# sourceMappingURL=BrokerClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrokerClient.js","sourceRoot":"","sources":["../../../src/classes/BrokerClient.ts"],"names":[],"mappings":";;AAGA,MAA8B,YAAY;IAQxC,YAAa,MAAa,EAAE,MAAY,EAAE,QAAiB,EAAE,IAAkB,EAAE,SAAuB,IAAI,EAAE,QAAuB,IAAI;QALzI,UAAK,GAAmB,IAAI,CAAA;QAC5B,WAAM,GAAmB,IAAI,CAAA;QAC7B,SAAI,GAAmB,IAAI,CAAA;QAIzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAExB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAE,IAAI,CAAE,CAAA;IAClC,CAAC;IAED,UAAU,CAAE,KAAS;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAE,KAAK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M,IAAI,CAAC,cAAc,CAAE,OAAO,CAAE,CAAA;aAErC;YAAA,OAAO,CAAK,EAAE;gBACb,IAAI,CAAC,MAAM,CAAC,UAAU,CAAE,CAAC,CAAE,CAAA;aAC5B;oBAAO;aAEP;QACH,CAAC,CAAC,CAAE,CAAA;QAEJ,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAC,CAAC,CAAC,EAAE,EAAE,IAAE,GAAG,CAAE,CAAA;IAC/E,CAAC;CAGF;AA3DD,+BA2DC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import Broker from "./Broker";
|
|
3
|
+
import BrokerClient from "./BrokerClient";
|
|
4
|
+
import ListRunner from "./ListRunner";
|
|
5
|
+
export default class Listener extends BrokerClient {
|
|
6
|
+
constructor(broker: Broker, client: Redis, list: string, callback: Function);
|
|
7
|
+
streamCallback(message: DecypheredMessage): Promise<ListRunner | null>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const BrokerClient_1 = tslib_1.__importDefault(require("./BrokerClient"));
|
|
5
|
+
const ListRunner_1 = tslib_1.__importDefault(require("./ListRunner"));
|
|
6
|
+
class Listener extends BrokerClient_1.default {
|
|
7
|
+
constructor(broker, client, list, callback) {
|
|
8
|
+
super(broker, client, callback, list);
|
|
9
|
+
}
|
|
10
|
+
async streamCallback(message) {
|
|
11
|
+
const listrunnercallback = await this.callback(message.id, message.parameters);
|
|
12
|
+
if (message.parameters.listname)
|
|
13
|
+
return new ListRunner_1.default(this.client, message.parameters.listname, listrunnercallback);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = Listener;
|
|
18
|
+
//# sourceMappingURL=ListListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListListener.js","sourceRoot":"","sources":["../../../src/classes/ListListener.ts"],"names":[],"mappings":";;;AAEA,0EAAyC;AACzC,sEAAqC;AAErC,MAAqB,QAAS,SAAQ,sBAAY;IAChD,YAAa,MAAa,EAAE,MAAY,EAAE,IAAW,EAAE,QAAiB;QACtE,KAAK,CAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAE,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,cAAc,CAAE,OAAyB;QAC7C,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAE,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,UAAU,CAAE,CAAA;QAEhF,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ;YAC7B,OAAO,IAAI,oBAAU,CAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAA;QAEtF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAbD,2BAaC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
export default class ListRunner {
|
|
3
|
+
listname: string;
|
|
4
|
+
itemsDone: number;
|
|
5
|
+
itemsPerCall: number;
|
|
6
|
+
callback: Function;
|
|
7
|
+
client: Redis;
|
|
8
|
+
constructor(client: Redis, listname: string, callback: Function, itemsPerCall?: number);
|
|
9
|
+
run(): Promise<Function | void>;
|
|
10
|
+
nextitems(listname: string): Promise<string[] | null>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ListRunner {
|
|
4
|
+
constructor(client, listname, callback, itemsPerCall = 1) {
|
|
5
|
+
this.itemsDone = 0;
|
|
6
|
+
this.client = client;
|
|
7
|
+
this.callback = callback;
|
|
8
|
+
this.listname = listname;
|
|
9
|
+
this.itemsPerCall = itemsPerCall;
|
|
10
|
+
this.run.call(this);
|
|
11
|
+
}
|
|
12
|
+
async run() {
|
|
13
|
+
const items = await this.nextitems.call(this, this.listname);
|
|
14
|
+
if (!items) {
|
|
15
|
+
console.log(`finished with ${this.itemsDone} jobs`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
await this.callback(items);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.log(e);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
this.itemsDone += this.itemsPerCall;
|
|
26
|
+
return this.run.call(this);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async nextitems(listname) {
|
|
30
|
+
return this.client.lpop(listname, this.itemsPerCall);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.default = ListRunner;
|
|
34
|
+
//# sourceMappingURL=ListRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListRunner.js","sourceRoot":"","sources":["../../../src/classes/ListRunner.ts"],"names":[],"mappings":";;AAEA,MAAqB,UAAU;IAQ7B,YAAa,MAAY,EAAE,QAAe,EAAE,QAAiB,EAAE,eAAwB,CAAC;QANxF,cAAS,GAAU,CAAC,CAAA;QAOlB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAEhC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAE,IAAI,CAAE,CAAA;IACvB,CAAC;IAGD,KAAK,CAAC,GAAG;QACP,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAE,CAAA;QAC9D,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,CAAC,GAAG,CAAE,iBAAiB,IAAI,CAAC,SAAS,OAAO,CAAC,CAAA;YACpD,OAAM;SACP;QAED,IAAG;YACD,MAAM,IAAI,CAAC,QAAQ,CAAE,KAAK,CAAE,CAAA;SAC7B;QAAA,OAAO,CAAK,EAAE;YACb,OAAO,CAAC,GAAG,CAAE,CAAC,CAAE,CAAA;SAEjB;gBAAO;YACN,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,YAAY,CAAA;YACnC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAE,IAAI,CAAE,CAAA;SAC7B;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAE,QAAe;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAE,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAE,CAAA;IACxD,CAAC;CAEF;AAxCD,6BAwCC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import Broker from "./Broker";
|
|
3
|
+
import BrokerClient from "./BrokerClient";
|
|
4
|
+
export default class Listener extends BrokerClient {
|
|
5
|
+
constructor(broker: Broker, client: Redis, stream: string, callback: Function, group?: string);
|
|
6
|
+
streamCallback(message: DecypheredMessage): Promise<any>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const BrokerClient_1 = tslib_1.__importDefault(require("./BrokerClient"));
|
|
5
|
+
class Listener extends BrokerClient_1.default {
|
|
6
|
+
constructor(broker, client, stream, callback, group) {
|
|
7
|
+
super(broker, client, callback, null, stream, group);
|
|
8
|
+
}
|
|
9
|
+
streamCallback(message) {
|
|
10
|
+
return this.callback(message.id, message.parameters);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = Listener;
|
|
14
|
+
//# sourceMappingURL=Listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Listener.js","sourceRoot":"","sources":["../../../src/classes/Listener.ts"],"names":[],"mappings":";;;AAEA,0EAAyC;AAEzC,MAAqB,QAAS,SAAQ,sBAAY;IAChD,YAAa,MAAa,EAAE,MAAY,EAAE,MAAa,EAAE,QAAiB,EAAE,KAAe;QACzF,KAAK,CAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAE,CAAA;IACxD,CAAC;IAED,cAAc,CAAC,OAA0B;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAE,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,UAAU,CAAE,CAAA;IACxD,CAAC;CACF;AARD,2BAQC"}
|
package/dist/tsc/main.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Broker = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Broker_1 = tslib_1.__importDefault(require("./classes/Broker"));
|
|
6
|
+
exports.Broker = Broker_1.default;
|
|
7
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":";;;;AAAA,sEAAqC;AAE5B,iBAFF,gBAAM,CAEE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const isJSON: (str: any) => boolean;
|
|
2
|
+
interface ObjectToOmitFrom {
|
|
3
|
+
[index: string]: any;
|
|
4
|
+
}
|
|
5
|
+
declare const omit: (objectToOmitFrom: ObjectToOmitFrom, keys: (keyof ObjectToOmitFrom)[]) => {};
|
|
6
|
+
declare const mapJsonReplacer: (_key: any, value: Map<any, any> | any) => any;
|
|
7
|
+
declare const mapJsonReviver: (_key: any, value: JsonStringifiedMap | any) => any;
|
|
8
|
+
declare const stringifyMap: (map: Map<any, any>) => string;
|
|
9
|
+
declare const parseMap: (json: string) => Map<any, any>;
|
|
10
|
+
declare const capitalizeFirstLetter: (string: string) => string;
|
|
11
|
+
export { isJSON, omit, mapJsonReviver, stringifyMap, parseMap, mapJsonReplacer, capitalizeFirstLetter };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capitalizeFirstLetter = exports.mapJsonReplacer = exports.parseMap = exports.stringifyMap = exports.mapJsonReviver = exports.omit = exports.isJSON = void 0;
|
|
4
|
+
const isJSON = (str) => {
|
|
5
|
+
if (typeof str == 'number')
|
|
6
|
+
return false;
|
|
7
|
+
try {
|
|
8
|
+
JSON.parse(str);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
};
|
|
15
|
+
exports.isJSON = isJSON;
|
|
16
|
+
const omit = (objectToOmitFrom, keys) => Object.keys(objectToOmitFrom)
|
|
17
|
+
.filter(key => keys.indexOf(key) == -1)
|
|
18
|
+
.reduce((struct, key) => Object.assign(struct, { [key]: objectToOmitFrom[key] }), {});
|
|
19
|
+
exports.omit = omit;
|
|
20
|
+
const mapJsonReplacer = (_key, value) => {
|
|
21
|
+
if (value instanceof Map) {
|
|
22
|
+
return {
|
|
23
|
+
dataType: 'Map',
|
|
24
|
+
value: Array.from(value.entries()), // or with spread: value: [...value]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.mapJsonReplacer = mapJsonReplacer;
|
|
32
|
+
const mapJsonReviver = (_key, value) => {
|
|
33
|
+
if (typeof value === 'object' && value !== null) {
|
|
34
|
+
if (value.dataType === 'Map') {
|
|
35
|
+
return new Map(value.value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
exports.mapJsonReviver = mapJsonReviver;
|
|
41
|
+
const stringifyMap = (map) => JSON.stringify(map, exports.mapJsonReplacer);
|
|
42
|
+
exports.stringifyMap = stringifyMap;
|
|
43
|
+
const parseMap = (json) => JSON.parse(json, exports.mapJsonReviver);
|
|
44
|
+
exports.parseMap = parseMap;
|
|
45
|
+
const capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
46
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
47
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/services/utils.ts"],"names":[],"mappings":";;;AACA,MAAM,MAAM,GAAG,CAAE,GAAO,EAAG,EAAE;IAC3B,IAAI,OAAO,GAAG,IAAI,QAAQ;QAAG,OAAO,KAAK,CAAA;IACzC,IAAG;QACD,IAAI,CAAC,KAAK,CAAE,GAAG,CAAE,CAAA;KAClB;IAAA,OAAO,KAAK,EAAE;QACb,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAA;AAyCQ,wBAAM;AAlCf,MAAM,IAAI,GAAG,CAAE,gBAAiC,EAAE,IAA+B,EAAE,EAAE,CACrF,MAAM,CAAC,IAAI,CAAE,gBAAgB,CAAE;KAC9B,MAAM,CAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAE,GAAG,CAAE,IAAI,CAAC,CAAC,CAAE;KAC1C,MAAM,CAAE,CAAC,MAAa,EAAC,GAAG,EAAE,EAAE,CAC7B,MAAM,CAAC,MAAM,CAAE,MAAM,EAAE,EAAC,CAAC,GAAG,CAAC,EAAC,gBAAgB,CAAC,GAAG,CAAC,EAAC,CAAE,EACtD,EAAE,CACH,CAAA;AA4BgB,oBAAI;AAxBrB,MAAM,eAAe,GAAG,CAAE,IAAQ,EAAE,K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(spec|test).+(ts|tsx|js)"
|
|
7
|
-
],
|
|
8
|
-
transform: {
|
|
9
|
-
"^.+\\.(ts|tsx)$": "ts-jest"
|
|
10
|
-
},
|
|
11
|
-
testTimeout: 500,
|
|
12
|
-
globals: {
|
|
13
|
-
'ts-jest': {
|
|
14
|
-
isolatedModules: true
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
preset: 'ts-jest/presets/js-with-ts'
|
|
18
|
-
}
|