woonplan-packages-redishelper 2.0.85 → 2.0.87

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.
@@ -1,322 +1,322 @@
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 utils_1 = require("../services/utils");
8
- const Listener_1 = tslib_1.__importDefault(require("./Listener"));
9
- const ListListener_1 = tslib_1.__importDefault(require("./ListListener"));
10
- const uuid_1 = require("uuid");
11
- const lock_1 = require("../services/lock");
12
- const SetWatcher_1 = tslib_1.__importDefault(require("./SetWatcher"));
13
- class Broker {
14
- constructor(redisConfig, rollbarConfig, service, consumer) {
15
- this.consumername = '';
16
- this.listeners = new Map();
17
- this.listprefix = 'listUpdated';
18
- this.subscriptions = [];
19
- this.rejectors = new Map;
20
- this.resolvers = new Map;
21
- this.timeouts = new Map;
22
- this.redisConfig = redisConfig;
23
- this.rollbar = new rollbar_1.default({
24
- accessToken: rollbarConfig.accessToken,
25
- environment: rollbarConfig.environment,
26
- });
27
- this.writer = new ioredis_1.default({
28
- host: redisConfig.REDISURL,
29
- password: redisConfig.REDISPW ?? ''
30
- });
31
- this.reader = new ioredis_1.default({
32
- host: redisConfig.REDISURL,
33
- password: redisConfig.REDISPW ?? ''
34
- });
35
- (0, lock_1.setupLock)(redisConfig);
36
- this.reader.on('message', (channel, message) => this.onMessage.call(this, channel, message));
37
- this.consumername = consumer;
38
- this.service = service;
39
- }
40
- get requeststream() {
41
- return this.getRequestStream(this.service);
42
- }
43
- getRequestStream(service) {
44
- return `keyRequestedFrom${(0, utils_1.capitalizeFirstLetter)(service)}Service`;
45
- }
46
- createClient() {
47
- return new ioredis_1.default({
48
- host: this.redisConfig.REDISURL,
49
- password: this.redisConfig.REDISPW ?? ''
50
- });
51
- }
52
- createSetWatcher(setname, callback, finishedCallback, itemsPerCall = 1) {
53
- new SetWatcher_1.default(this.createClient.call(this), setname, callback, finishedCallback, itemsPerCall);
54
- }
55
- setRequestEndpoint(callback) {
56
- return this.addListener(this.requeststream, this.getRequestCallback(callback), this.service);
57
- }
58
- getRequestCallback(callback) {
59
- return async (id, parameters) => {
60
- let result = null;
61
- try {
62
- result = await callback(id, parameters);
63
- }
64
- catch (error) {
65
- this.throwError(error);
66
- result = JSON.stringify({
67
- rejected: true,
68
- error: {
69
- title: error?.message ?? ''
70
- }
71
- });
72
- }
73
- finally {
74
- if (!parameters.messageid)
75
- return null;
76
- const channel = this.getRequestSubscriptionName(parameters.messageid);
77
- return this.publish(channel, result);
78
- }
79
- };
80
- }
81
- publish(channel, result) {
82
- return this.writer.publish(channel, result);
83
- }
84
- async createGroup(stream, group) {
85
- try {
86
- await this.writer.xgroup('CREATE', stream, group, '$', 'MKSTREAM');
87
- return;
88
- }
89
- catch {
90
- return;
91
- }
92
- }
93
- addListener(stream, callback, group, deleteOnCompletion = false) {
94
- const client = new ioredis_1.default({
95
- host: this.redisConfig.REDISURL,
96
- password: this.redisConfig.REDISPW ?? ''
97
- });
98
- this.createListener.call(this, client, stream, callback, group, deleteOnCompletion);
99
- // dont wait for the result of create listener, just return this so we can chain
100
- return this;
101
- }
102
- async createListener(client, stream, callback, group, deleteOnCompletion = false) {
103
- if (group)
104
- await this.createGroup.call(this, stream, group);
105
- this.listeners.set(stream, new Listener_1.default(this, client, stream, callback, group, deleteOnCompletion));
106
- console.log(`redishelper : listener added for ${stream}`);
107
- }
108
- addListListener(event, callback, finishedevent = '', itemsPerCall = 1) {
109
- const client = new ioredis_1.default({
110
- host: this.redisConfig.REDISURL,
111
- password: this.redisConfig.REDISPW ?? ''
112
- });
113
- const channel = this.getListChannel(event);
114
- this.listeners.set(channel, new ListListener_1.default(this, client, channel, callback, finishedevent, itemsPerCall));
115
- console.log(`redishelper : listlistener added for ${channel}`);
116
- return this;
117
- }
118
- async getList(listname, start = 0, stop = -1) {
119
- const list = await this.reader.lrange(listname, start, stop);
120
- return list;
121
- }
122
- async getSet(listname) {
123
- const set = await this.reader.smembers(listname);
124
- return set;
125
- }
126
- throwError(error) {
127
- if (!this.rollbar)
128
- throw new Error('Rollbar not initialized');
129
- this.rollbar.error(error);
130
- }
131
- sendMessage(stream, data) {
132
- console.log(`sending message to ${stream}`);
133
- return this.writer.xadd(stream, '*', ...(0, utils_1.createRedisMessage)(data));
134
- }
135
- async sendMessageAndSubscribeForResponse(channel, target, messagedata, n = 2000) {
136
- await this.subscribe(channel);
137
- // send the message to the correct service
138
- this.sendMessage(target, messagedata);
139
- let resolver;
140
- let rejecter;
141
- // create a promise to be able to pass on to resolve later
142
- const promise = new Promise((r, rj) => {
143
- resolver = r;
144
- rejecter = rj;
145
- });
146
- if (!resolver || !rejecter)
147
- return null;
148
- //setup a timeout
149
- const timeout = this.setupTimeout(resolver, channel, n);
150
- //setup a response
151
- this.requestMessageResponse(channel, resolver, rejecter, timeout);
152
- // return a promise that will resolve when the message returns or times out
153
- return promise;
154
- }
155
- async getRequest(targetservice, key, data, timeout = 2000) {
156
- // create a message id to subscribe to
157
- const messageid = (0, uuid_1.v4)();
158
- //subscribe to message response
159
- const channel = this.getRequestSubscriptionName(messageid);
160
- return this.sendMessageAndSubscribeForResponse.call(this, channel, this.getRequestStream(targetservice), {
161
- request: key,
162
- messageid: messageid,
163
- data: (0, utils_1.sanitizeValue)(data)
164
- }, timeout);
165
- }
166
- async getApiRequest(endpoint, method, data, jwt = '') {
167
- // create a message id to subscribe to
168
- const messageid = (0, uuid_1.v4)();
169
- //subscribe to message response
170
- const channel = this.getRequestSubscriptionName(messageid);
171
- return this.sendMessageAndSubscribeForResponse.call(this, channel, this.getRequestStream('api'), {
172
- endpoint: endpoint,
173
- method: method,
174
- messageid: messageid,
175
- data: data,
176
- jwt: jwt
177
- });
178
- }
179
- requestMessageResponse(channel, resolver, rejector, timeout) {
180
- this.resolvers.set(channel, resolver);
181
- this.rejectors.set(channel, rejector);
182
- this.timeouts.set(channel, timeout);
183
- }
184
- cleanupMessageReponse(channel) {
185
- this.resolvers.delete(channel);
186
- this.rejectors.delete(channel);
187
- this.timeouts.delete(channel);
188
- }
189
- onMessage(channel, message) {
190
- const rejector = this.rejectors.get(channel);
191
- const resolver = this.resolvers.get(channel);
192
- const timeout = this.timeouts.get(channel);
193
- if (!rejector || !resolver || !timeout) {
194
- this.cleanupMessageReponse.call(this, channel);
195
- return;
196
- }
197
- // check if the request has been rejected
198
- if ((0, class_validator_1.isJSON)(message)) {
199
- const resolvemessage = JSON.parse(message);
200
- if (resolvemessage.rejected && resolvemessage.error && resolvemessage.error?.title) {
201
- rejector(new Error(resolvemessage.error.title));
202
- clearTimeout(timeout);
203
- return;
204
- }
205
- }
206
- if (message.length)
207
- resolver(message);
208
- else
209
- resolver(null);
210
- this.unsubscribe(channel);
211
- clearTimeout(timeout);
212
- }
213
- unsubscribe(channel) {
214
- this.reader.unsubscribe(channel);
215
- this.subscriptions = this.subscriptions.filter(s => s != channel);
216
- }
217
- setupTimeout(resolve, channel, n = 2000) {
218
- return setTimeout(() => {
219
- if (!this.subscriptions.includes(channel))
220
- return;
221
- console.log(`sub timedout: ${channel}`);
222
- resolve(null);
223
- this.unsubscribe(channel);
224
- }, n);
225
- }
226
- subscribe(channel) {
227
- this.subscriptions.push(channel);
228
- return this.reader.subscribe(channel);
229
- }
230
- getRequestSubscriptionName(messageid) {
231
- return `messageresponse${messageid}`;
232
- }
233
- async setKey(key, value) {
234
- try {
235
- return await this.writer.set(key, (0, utils_1.sanitizeValue)(value));
236
- }
237
- catch { }
238
- return;
239
- }
240
- async readKey(key) {
241
- try {
242
- return await this.writer.get(key);
243
- }
244
- catch { }
245
- return null;
246
- }
247
- async deleteKey(key) {
248
- try {
249
- return await this.writer.del(key);
250
- }
251
- catch { }
252
- return;
253
- }
254
- async sendListEvent(event, listitems, data = {}, listname = "") {
255
- if (listitems.length == 0)
256
- return;
257
- // if a listname exist, we first empty it
258
- if (listname.length > 0)
259
- await this.deleteKey.call(this, listname);
260
- const list = await this.addToSet.call(this, listitems, listname.length > 0 ? listname : undefined);
261
- return this.sendMessage(this.getListChannel(event), {
262
- ...data,
263
- listname: list
264
- });
265
- }
266
- async addToSet(listitems, listname) {
267
- const list = listname ?? (0, uuid_1.v4)();
268
- await this.writer.sadd(list, ...listitems.map(utils_1.sanitizeValue));
269
- return list;
270
- }
271
- async addToList(listitems, listname) {
272
- const list = listname ?? (0, uuid_1.v4)();
273
- await this.writer.lpush(list, ...listitems.map(utils_1.sanitizeValue));
274
- return list;
275
- }
276
- getListChannel(event) {
277
- return `${this.listprefix}${event}`;
278
- }
279
- async getStreamMessages(stream) {
280
- const streaminfo = await this.getStreamInfo.call(this, stream);
281
- if (!streaminfo || !(0, class_validator_1.isArray)(streaminfo) || streaminfo.length < 10)
282
- return [];
283
- const params = this.decypherParameters(streaminfo);
284
- if (!params.entries)
285
- return [];
286
- return this.decyperMessages(params.entries);
287
- }
288
- getStreamInfo(stream, count = 0) {
289
- return this.reader.xinfo('STREAM', stream, 'FULL', 'COUNT', count);
290
- }
291
- async filterStream(stream, key, value) {
292
- const messages = await this.getStreamMessages.call(this, stream);
293
- return messages.filter(message => message.parameters?.[key] != null && message.parameters[key] == value);
294
- }
295
- decypherResponse(...responses) {
296
- return responses.reduce((resp, response) => [
297
- ...resp,
298
- {
299
- stream: response[0],
300
- messages: this.decyperMessages(response[1])
301
- }
302
- ], []);
303
- }
304
- decyperMessages(messages) {
305
- return messages.map((message) => ({
306
- id: message[0],
307
- parameters: this.decypherParameters(message[1])
308
- }));
309
- }
310
- decypherParameters(parameters) {
311
- return parameters.reduce((params, v, n) => (n == 0 || (n % 2 == 0)) && parameters.length >= n + 1 ? ({
312
- ...params,
313
- [v]: parameters[n + 1]
314
- }) : params, {});
315
- }
316
- async isSetPickedUp(setname) {
317
- const pickedup = await this.reader.get((0, utils_1.getSetPickedUpName)(setname));
318
- return pickedup !== null;
319
- }
320
- }
321
- exports.default = Broker;
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 utils_1 = require("../services/utils");
8
+ const Listener_1 = tslib_1.__importDefault(require("./Listener"));
9
+ const ListListener_1 = tslib_1.__importDefault(require("./ListListener"));
10
+ const uuid_1 = require("uuid");
11
+ const lock_1 = require("../services/lock");
12
+ const SetWatcher_1 = tslib_1.__importDefault(require("./SetWatcher"));
13
+ class Broker {
14
+ constructor(redisConfig, rollbarConfig, service, consumer) {
15
+ this.consumername = '';
16
+ this.listeners = new Map();
17
+ this.listprefix = 'listUpdated';
18
+ this.subscriptions = [];
19
+ this.rejectors = new Map;
20
+ this.resolvers = new Map;
21
+ this.timeouts = new Map;
22
+ this.redisConfig = redisConfig;
23
+ this.rollbar = new rollbar_1.default({
24
+ accessToken: rollbarConfig.accessToken,
25
+ environment: rollbarConfig.environment,
26
+ });
27
+ this.writer = new ioredis_1.default({
28
+ host: redisConfig.REDISURL,
29
+ password: redisConfig.REDISPW ?? ''
30
+ });
31
+ this.reader = new ioredis_1.default({
32
+ host: redisConfig.REDISURL,
33
+ password: redisConfig.REDISPW ?? ''
34
+ });
35
+ (0, lock_1.setupLock)(redisConfig);
36
+ this.reader.on('message', (channel, message) => this.onMessage.call(this, channel, message));
37
+ this.consumername = consumer;
38
+ this.service = service;
39
+ }
40
+ get requeststream() {
41
+ return this.getRequestStream(this.service);
42
+ }
43
+ getRequestStream(service) {
44
+ return `keyRequestedFrom${(0, utils_1.capitalizeFirstLetter)(service)}Service`;
45
+ }
46
+ createClient() {
47
+ return new ioredis_1.default({
48
+ host: this.redisConfig.REDISURL,
49
+ password: this.redisConfig.REDISPW ?? ''
50
+ });
51
+ }
52
+ createSetWatcher(setname, callback, finishedCallback, itemsPerCall = 1) {
53
+ new SetWatcher_1.default(this.createClient.call(this), setname, callback, finishedCallback, itemsPerCall);
54
+ }
55
+ setRequestEndpoint(callback) {
56
+ return this.addListener(this.requeststream, this.getRequestCallback(callback), this.service);
57
+ }
58
+ getRequestCallback(callback) {
59
+ return async (id, parameters) => {
60
+ let result = null;
61
+ try {
62
+ result = await callback(id, parameters);
63
+ }
64
+ catch (error) {
65
+ this.throwError(error);
66
+ result = JSON.stringify({
67
+ rejected: true,
68
+ error: {
69
+ title: error?.message ?? ''
70
+ }
71
+ });
72
+ }
73
+ finally {
74
+ if (!parameters.messageid)
75
+ return null;
76
+ const channel = this.getRequestSubscriptionName(parameters.messageid);
77
+ return this.publish(channel, result);
78
+ }
79
+ };
80
+ }
81
+ publish(channel, result) {
82
+ return this.writer.publish(channel, result);
83
+ }
84
+ async createGroup(stream, group) {
85
+ try {
86
+ await this.writer.xgroup('CREATE', stream, group, '$', 'MKSTREAM');
87
+ return;
88
+ }
89
+ catch {
90
+ return;
91
+ }
92
+ }
93
+ addListener(stream, callback, group, deleteOnCompletion = false) {
94
+ const client = new ioredis_1.default({
95
+ host: this.redisConfig.REDISURL,
96
+ password: this.redisConfig.REDISPW ?? ''
97
+ });
98
+ this.createListener.call(this, client, stream, callback, group, deleteOnCompletion);
99
+ // dont wait for the result of create listener, just return this so we can chain
100
+ return this;
101
+ }
102
+ async createListener(client, stream, callback, group, deleteOnCompletion = false) {
103
+ if (group)
104
+ await this.createGroup.call(this, stream, group);
105
+ this.listeners.set(stream, new Listener_1.default(this, client, stream, callback, group, deleteOnCompletion));
106
+ console.log(`redishelper : listener added for ${stream}`);
107
+ }
108
+ addListListener(event, callback, finishedevent = '', itemsPerCall = 1) {
109
+ const client = new ioredis_1.default({
110
+ host: this.redisConfig.REDISURL,
111
+ password: this.redisConfig.REDISPW ?? ''
112
+ });
113
+ const channel = this.getListChannel(event);
114
+ this.listeners.set(channel, new ListListener_1.default(this, client, channel, callback, finishedevent, itemsPerCall));
115
+ console.log(`redishelper : listlistener added for ${channel}`);
116
+ return this;
117
+ }
118
+ async getList(listname, start = 0, stop = -1) {
119
+ const list = await this.reader.lrange(listname, start, stop);
120
+ return list;
121
+ }
122
+ async getSet(listname) {
123
+ const set = await this.reader.smembers(listname);
124
+ return set;
125
+ }
126
+ throwError(error) {
127
+ if (!this.rollbar)
128
+ throw new Error('Rollbar not initialized');
129
+ this.rollbar.error(error);
130
+ }
131
+ sendMessage(stream, data) {
132
+ console.log(`sending message to ${stream}`);
133
+ return this.writer.xadd(stream, '*', ...(0, utils_1.createRedisMessage)(data));
134
+ }
135
+ async sendMessageAndSubscribeForResponse(channel, target, messagedata, n = 2000) {
136
+ await this.subscribe(channel);
137
+ // send the message to the correct service
138
+ this.sendMessage(target, messagedata);
139
+ let resolver;
140
+ let rejecter;
141
+ // create a promise to be able to pass on to resolve later
142
+ const promise = new Promise((r, rj) => {
143
+ resolver = r;
144
+ rejecter = rj;
145
+ });
146
+ if (!resolver || !rejecter)
147
+ return null;
148
+ //setup a timeout
149
+ const timeout = this.setupTimeout(resolver, channel, n);
150
+ //setup a response
151
+ this.requestMessageResponse(channel, resolver, rejecter, timeout);
152
+ // return a promise that will resolve when the message returns or times out
153
+ return promise;
154
+ }
155
+ async getRequest(targetservice, key, data, timeout = 2000) {
156
+ // create a message id to subscribe to
157
+ const messageid = (0, uuid_1.v4)();
158
+ //subscribe to message response
159
+ const channel = this.getRequestSubscriptionName(messageid);
160
+ return this.sendMessageAndSubscribeForResponse.call(this, channel, this.getRequestStream(targetservice), {
161
+ request: key,
162
+ messageid: messageid,
163
+ data: (0, utils_1.sanitizeValue)(data)
164
+ }, timeout);
165
+ }
166
+ async getApiRequest(endpoint, method, data, jwt = '') {
167
+ // create a message id to subscribe to
168
+ const messageid = (0, uuid_1.v4)();
169
+ //subscribe to message response
170
+ const channel = this.getRequestSubscriptionName(messageid);
171
+ return this.sendMessageAndSubscribeForResponse.call(this, channel, this.getRequestStream('api'), {
172
+ endpoint: endpoint,
173
+ method: method,
174
+ messageid: messageid,
175
+ data: data,
176
+ jwt: jwt
177
+ });
178
+ }
179
+ requestMessageResponse(channel, resolver, rejector, timeout) {
180
+ this.resolvers.set(channel, resolver);
181
+ this.rejectors.set(channel, rejector);
182
+ this.timeouts.set(channel, timeout);
183
+ }
184
+ cleanupMessageReponse(channel) {
185
+ this.resolvers.delete(channel);
186
+ this.rejectors.delete(channel);
187
+ this.timeouts.delete(channel);
188
+ }
189
+ onMessage(channel, message) {
190
+ const rejector = this.rejectors.get(channel);
191
+ const resolver = this.resolvers.get(channel);
192
+ const timeout = this.timeouts.get(channel);
193
+ if (!rejector || !resolver || !timeout) {
194
+ this.cleanupMessageReponse.call(this, channel);
195
+ return;
196
+ }
197
+ // check if the request has been rejected
198
+ if ((0, class_validator_1.isJSON)(message)) {
199
+ const resolvemessage = JSON.parse(message);
200
+ if (resolvemessage.rejected && resolvemessage.error) {
201
+ rejector(new Error(resolvemessage.error?.title ?? 'unknown-reason'));
202
+ clearTimeout(timeout);
203
+ return;
204
+ }
205
+ }
206
+ if (message.length)
207
+ resolver(message);
208
+ else
209
+ resolver(null);
210
+ this.unsubscribe(channel);
211
+ clearTimeout(timeout);
212
+ }
213
+ unsubscribe(channel) {
214
+ this.reader.unsubscribe(channel);
215
+ this.subscriptions = this.subscriptions.filter(s => s != channel);
216
+ }
217
+ setupTimeout(resolve, channel, n = 2000) {
218
+ return setTimeout(() => {
219
+ if (!this.subscriptions.includes(channel))
220
+ return;
221
+ console.log(`sub timedout: ${channel}`);
222
+ resolve(null);
223
+ this.unsubscribe(channel);
224
+ }, n);
225
+ }
226
+ subscribe(channel) {
227
+ this.subscriptions.push(channel);
228
+ return this.reader.subscribe(channel);
229
+ }
230
+ getRequestSubscriptionName(messageid) {
231
+ return `messageresponse${messageid}`;
232
+ }
233
+ async setKey(key, value) {
234
+ try {
235
+ return await this.writer.set(key, (0, utils_1.sanitizeValue)(value));
236
+ }
237
+ catch { }
238
+ return;
239
+ }
240
+ async readKey(key) {
241
+ try {
242
+ return await this.writer.get(key);
243
+ }
244
+ catch { }
245
+ return null;
246
+ }
247
+ async deleteKey(key) {
248
+ try {
249
+ return await this.writer.del(key);
250
+ }
251
+ catch { }
252
+ return;
253
+ }
254
+ async sendListEvent(event, listitems, data = {}, listname = "") {
255
+ if (listitems.length == 0)
256
+ return;
257
+ // if a listname exist, we first empty it
258
+ if (listname.length > 0)
259
+ await this.deleteKey.call(this, listname);
260
+ const list = await this.addToSet.call(this, listitems, listname.length > 0 ? listname : undefined);
261
+ return this.sendMessage(this.getListChannel(event), {
262
+ ...data,
263
+ listname: list
264
+ });
265
+ }
266
+ async addToSet(listitems, listname) {
267
+ const list = listname ?? (0, uuid_1.v4)();
268
+ await this.writer.sadd(list, ...listitems.map(utils_1.sanitizeValue));
269
+ return list;
270
+ }
271
+ async addToList(listitems, listname) {
272
+ const list = listname ?? (0, uuid_1.v4)();
273
+ await this.writer.lpush(list, ...listitems.map(utils_1.sanitizeValue));
274
+ return list;
275
+ }
276
+ getListChannel(event) {
277
+ return `${this.listprefix}${event}`;
278
+ }
279
+ async getStreamMessages(stream) {
280
+ const streaminfo = await this.getStreamInfo.call(this, stream);
281
+ if (!streaminfo || !(0, class_validator_1.isArray)(streaminfo) || streaminfo.length < 10)
282
+ return [];
283
+ const params = this.decypherParameters(streaminfo);
284
+ if (!params.entries)
285
+ return [];
286
+ return this.decyperMessages(params.entries);
287
+ }
288
+ getStreamInfo(stream, count = 0) {
289
+ return this.reader.xinfo('STREAM', stream, 'FULL', 'COUNT', count);
290
+ }
291
+ async filterStream(stream, key, value) {
292
+ const messages = await this.getStreamMessages.call(this, stream);
293
+ return messages.filter(message => message.parameters?.[key] != null && message.parameters[key] == value);
294
+ }
295
+ decypherResponse(...responses) {
296
+ return responses.reduce((resp, response) => [
297
+ ...resp,
298
+ {
299
+ stream: response[0],
300
+ messages: this.decyperMessages(response[1])
301
+ }
302
+ ], []);
303
+ }
304
+ decyperMessages(messages) {
305
+ return messages.map((message) => ({
306
+ id: message[0],
307
+ parameters: this.decypherParameters(message[1])
308
+ }));
309
+ }
310
+ decypherParameters(parameters) {
311
+ return parameters.reduce((params, v, n) => (n == 0 || (n % 2 == 0)) && parameters.length >= n + 1 ? ({
312
+ ...params,
313
+ [v]: parameters[n + 1]
314
+ }) : params, {});
315
+ }
316
+ async isSetPickedUp(setname) {
317
+ const pickedup = await this.reader.get((0, utils_1.getSetPickedUpName)(setname));
318
+ return pickedup !== null;
319
+ }
320
+ }
321
+ exports.default = Broker;
322
322
  //# sourceMappingURL=Broker.js.map