@imqueue/core 1.15.0 → 2.0.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.
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
- import { JsonObject, IMessageQueue, IMQOptions, IMQMode } from '.';
2
+ import { IMessageQueue, JsonObject, IMQOptions, IMQMode, EventMap } from '.';
4
3
  export declare const DEFAULT_IMQ_OPTIONS: IMQOptions;
5
4
  export declare const IMQ_SHUTDOWN_TIMEOUT: number;
6
5
  /**
@@ -36,7 +35,7 @@ export declare function unpack(data: string): any;
36
35
  * Class RedisQueue
37
36
  * Implements simple messaging queue over redis.
38
37
  */
39
- export declare class RedisQueue extends EventEmitter implements IMessageQueue {
38
+ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessageQueue {
40
39
  name: string;
41
40
  private readonly mode;
42
41
  [name: string]: any;
@@ -69,7 +68,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
69
68
  private reader?;
70
69
  /**
71
70
  * Channel connection associated with this queue instance
72
- * Specially designed for client subscriptions to server emitted events
71
+ * Specially designed for client subscriptions to server-emitted events
73
72
  *
74
73
  * @type {IRedisClient}
75
74
  */
@@ -87,7 +86,13 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
87
86
  */
88
87
  private initialized;
89
88
  /**
90
- * True if current instance owns watcher connection, false otherwise
89
+ * Signals if the queue was destroyed
90
+ *
91
+ * @type {boolean}
92
+ */
93
+ private destroyed;
94
+ /**
95
+ * True if the current instance owns watcher connection, false otherwise
91
96
  *
92
97
  * @type {boolean}
93
98
  */
@@ -134,7 +139,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
134
139
  */
135
140
  constructor(name: string, options?: Partial<IMQOptions>, mode?: IMQMode);
136
141
  /**
137
- * Creates subscription channel over redis and sets up channel
142
+ * Creates a subscription channel over redis and sets up channel
138
143
  * data read handler
139
144
  *
140
145
  * @param {string} channel
@@ -152,9 +157,9 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
152
157
  * Publishes a message to this queue subscription channel for currently
153
158
  * subscribed clients.
154
159
  *
155
- * If toName specified will publish to pubsub with different name. This
160
+ * If toName specified will publish to PubSub with a different name. This
156
161
  * can be used to implement broadcasting some messages to other subscribers
157
- * on other pubsub channels.
162
+ * on other PubSub channels.
158
163
  *
159
164
  * @param {string} [toName]
160
165
  * @param {JsonObject} data
@@ -167,7 +172,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
167
172
  */
168
173
  start(): Promise<RedisQueue>;
169
174
  /**
170
- * Sends given message to a given queue (by name)
175
+ * Sends a given message to a given queue (by name)
171
176
  *
172
177
  * @param {string} toQueue
173
178
  * @param {JsonObject} message
@@ -232,7 +237,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
232
237
  */
233
238
  private set watcher(value);
234
239
  /**
235
- * Logger instance associated with current queue instance
240
+ * Logger instance associated with the current queue instance
236
241
  * @type {ILogger}
237
242
  */
238
243
  private get logger();
@@ -263,50 +268,48 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
263
268
  */
264
269
  private destroyWriter;
265
270
  /**
266
- * Establishes given connection channel by its' name
271
+ * Establishes a given connection channel by its name
267
272
  *
268
273
  * @access private
269
- * @param {"reader"|"writer"|"watcher"|"subscription"} channel
274
+ * @param {RedisConnectionChannel} channel
270
275
  * @param {IMQOptions} options
271
276
  * @param {any} context
272
277
  * @returns {Promise<IRedisClient>}
273
278
  */
274
279
  private connect;
280
+ /**
281
+ * Builds and returns redis reconnection strategy
282
+ *
283
+ * @param {RedisQueue} context
284
+ * @returns {() => (number | void | null)}
285
+ * @private
286
+ */
287
+ private retryStrategy;
275
288
  /**
276
289
  * Builds and returns connection ready state handler
277
290
  *
278
291
  * @access private
279
- * @param {IMQOptions} options
280
- * @param {any} context
281
- * @param {string} channel
292
+ * @param {RedisQueue} context
293
+ * @param {RedisConnectionChannel} channel
282
294
  * @param {(...args: any[]) => void} resolve
283
295
  * @return {() => Promise<void>}
284
296
  */
285
297
  private onReadyHandler;
286
298
  /**
287
- * Sets channel name
299
+ * Generates channel name
288
300
  *
289
- * @param {IRedisClient} channel
290
301
  * @param {string} contextName
291
302
  * @param {string} prefix
292
- * @param {string} name
303
+ * @param {RedisConnectionChannel} name
304
+ * @return {string}
293
305
  */
294
- private setChannelName;
295
- /**
296
- * Builds and returns redis connection reconnect handler
297
- *
298
- * @access private
299
- * @param {any} context
300
- * @param {string} channel
301
- * @return {() => void}
302
- */
303
- private onReconnectHandler;
306
+ private getChannelName;
304
307
  /**
305
308
  * Builds and returns connection error handler
306
309
  *
307
310
  * @access private
308
- * @param context
309
- * @param {string} channel
311
+ * @param {RedisQueue} context
312
+ * @param {RedisConnectionChannel} channel
310
313
  * @param {(...args: any[]) => void} reject
311
314
  * @return {(err: Error) => void}
312
315
  */
@@ -315,8 +318,8 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
315
318
  * Builds and returns redis connection close handler
316
319
  *
317
320
  * @access private
318
- * @param {any} context
319
- * @param {string} channel
321
+ * @param {RedisQueue} context
322
+ * @param {RedisConnectionChannel} channel
320
323
  * @return {(...args: any[]) => any}
321
324
  */
322
325
  private onCloseHandler;
@@ -324,7 +327,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
324
327
  * Processes given redis-queue message
325
328
  *
326
329
  * @access private
327
- * @param {[any , any]} msg
330
+ * @param {[any, any]} msg
328
331
  * @returns {RedisQueue}
329
332
  */
330
333
  private process;
@@ -347,7 +350,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
347
350
  * Watch routine
348
351
  *
349
352
  * @access private
350
- * @return {Promise<any>}
353
+ * @return {Promise<void>}
351
354
  */
352
355
  private processWatch;
353
356
  /**
@@ -374,7 +377,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
374
377
  */
375
378
  private cleanSafeCheckInterval;
376
379
  /**
377
- * Setups watch process on delayed messages
380
+ * Setups watch a process on delayed messages
378
381
  *
379
382
  * @access private
380
383
  * @returns {RedisQueue}
@@ -384,7 +387,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
384
387
  * Cleans up orphaned keys from redis
385
388
  *
386
389
  * @access private
387
- * @returns {RedisQueue}
390
+ * @returns {Promise<RedisQueue | undefined>}
388
391
  */
389
392
  private processCleanup;
390
393
  /**
@@ -396,13 +399,13 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
396
399
  */
397
400
  private readSafe;
398
401
  /**
399
- * Initializes read process on redis message queue
402
+ * Initializes a read process on the redis message queue
400
403
  *
401
404
  * @returns {RedisQueue}
402
405
  */
403
406
  private read;
404
407
  /**
405
- * Checks if watcher connection is locked
408
+ * Checks if the watcher connection is locked
406
409
  *
407
410
  * @access private
408
411
  * @returns {Promise<boolean>}
@@ -432,13 +435,13 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
432
435
  */
433
436
  private emitError;
434
437
  /**
435
- * Acquires owner for watcher connection to this instance of the queue
438
+ * Acquires an owner for watcher connection to this instance of the queue
436
439
  *
437
440
  * @returns {Promise<void>}
438
441
  */
439
442
  private ownWatch;
440
443
  /**
441
- * Returns watcher lock resolver function
444
+ * This method returns watcher lock resolver function
442
445
  *
443
446
  * @access private
444
447
  * @param {(...args: any[]) => void} resolve
@@ -447,7 +450,7 @@ export declare class RedisQueue extends EventEmitter implements IMessageQueue {
447
450
  */
448
451
  private watchLockResolver;
449
452
  /**
450
- * Initializes single watcher connection across all queues with the same
453
+ * Initializes a single watcher connection across all queues with the same
451
454
  * prefix.
452
455
  *
453
456
  * @returns {Promise<void>}