@imqueue/core 2.0.26 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +73 -63
  2. package/index.d.ts +0 -1
  3. package/index.js +8 -9
  4. package/package.json +19 -71
  5. package/src/ClusterManager.d.ts +12 -3
  6. package/src/ClusterManager.js +21 -10
  7. package/src/ClusteredRedisQueue.d.ts +45 -14
  8. package/src/ClusteredRedisQueue.js +186 -168
  9. package/src/IMessageQueue.d.ts +89 -96
  10. package/src/IMessageQueue.js +2 -2
  11. package/src/RedisQueue.d.ts +193 -97
  12. package/src/RedisQueue.js +1328 -1068
  13. package/src/UDPClusterManager.d.ts +100 -26
  14. package/src/UDPClusterManager.js +225 -70
  15. package/src/UDPWorker.d.ts +53 -1
  16. package/src/UDPWorker.js +79 -40
  17. package/src/{promisify.d.ts → helpers/buildOptions.d.ts} +8 -15
  18. package/src/helpers/buildOptions.js +39 -0
  19. package/src/{copyEventEmitter.d.ts → helpers/copyEventEmitter.d.ts} +1 -1
  20. package/src/{copyEventEmitter.js → helpers/copyEventEmitter.js} +3 -4
  21. package/src/helpers/envInt.d.ts +32 -0
  22. package/src/helpers/envInt.js +39 -0
  23. package/src/helpers/escapeRegExp.d.ts +30 -0
  24. package/src/helpers/escapeRegExp.js +36 -0
  25. package/src/helpers/index.d.ts +31 -0
  26. package/src/helpers/index.js +48 -0
  27. package/src/helpers/pack.d.ts +7 -0
  28. package/src/helpers/pack.js +37 -0
  29. package/src/helpers/randomInt.d.ts +31 -0
  30. package/src/helpers/randomInt.js +37 -0
  31. package/src/helpers/sha1.d.ts +7 -0
  32. package/src/helpers/sha1.js +39 -0
  33. package/src/helpers/unpack.d.ts +7 -0
  34. package/src/helpers/unpack.js +37 -0
  35. package/src/index.d.ts +1 -14
  36. package/src/index.js +1 -19
  37. package/src/profile.d.ts +28 -38
  38. package/src/profile.js +100 -95
  39. package/src/redis.d.ts +1 -1
  40. package/src/redis.js +4 -2
  41. package/debug.d.ts +0 -1
  42. package/debug_getter.d.ts +0 -9
  43. package/debug_listener.d.ts +0 -1
  44. package/eslint.config.mjs +0 -98
  45. package/src/promisify.js +0 -106
  46. package/src/uuid.d.ts +0 -6
  47. package/src/uuid.js +0 -65
@@ -21,10 +21,10 @@
21
21
  * purchase a proprietary commercial license. Please contact us at
22
22
  * <support@imqueue.com> to get commercial licensing options.
23
23
  */
24
- import { EventEmitter } from 'events';
24
+ import { EventEmitter } from 'node:events';
25
25
  import { IMQMode } from './IMQMode';
26
26
  import { ClusterManager } from './ClusterManager';
27
- export { EventEmitter } from 'events';
27
+ export { EventEmitter } from 'node:events';
28
28
  /**
29
29
  * Represents any JSON-serializable value
30
30
  */
@@ -40,13 +40,6 @@ export interface JsonObject {
40
40
  */
41
41
  export interface JsonArray extends Array<AnyJson> {
42
42
  }
43
- /**
44
- * Alias for JsonObject, legacy, outdated, deprecated, try to avoid using.
45
- * Stands here for backward-compatibility only
46
- *
47
- * @deprecated
48
- */
49
- export type IJson = JsonObject;
50
43
  /**
51
44
  * Logger interface
52
45
  */
@@ -54,30 +47,30 @@ export interface ILogger {
54
47
  /**
55
48
  * Log level function
56
49
  *
57
- * @param {...any[]} args
50
+ * @param {...unknown[]} args
58
51
  */
59
- log(...args: any[]): void;
52
+ log(...args: unknown[]): void;
60
53
  /**
61
54
  * Info level function
62
55
  *
63
- * @param {...any[]} args
56
+ * @param {...unknown[]} args
64
57
  */
65
- info(...args: any[]): void;
58
+ info(...args: unknown[]): void;
66
59
  /**
67
60
  * Warning level function
68
61
  *
69
- * @param {...any[]} args
62
+ * @param {...unknown[]} args
70
63
  */
71
- warn(...args: any[]): void;
64
+ warn(...args: unknown[]): void;
72
65
  /**
73
66
  * Error level function
74
67
  *
75
- * @param {...any[]} args
68
+ * @param {...unknown[]} args
76
69
  */
77
- error(...args: any[]): void;
70
+ error(...args: unknown[]): void;
78
71
  }
79
72
  /**
80
- * Defines message format.
73
+ * Defines a message format.
81
74
  *
82
75
  * @type {IMessage}
83
76
  */
@@ -172,8 +165,7 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
172
165
  */
173
166
  cleanup: boolean;
174
167
  /**
175
- * Defines cleanup pattern for the name of the queue
176
- * which should be removed during cleanup processing
168
+ * Cleanup pattern for queue names that should be removed during cleanup
177
169
  *
178
170
  * @type {string}
179
171
  */
@@ -191,41 +183,38 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
191
183
  */
192
184
  prefix?: string;
193
185
  /**
194
- * Logger defined to be used within message queue in runtime
186
+ * Logger instance to use for message queue logging at runtime
195
187
  *
196
188
  * @type {ILogger}
197
189
  */
198
190
  logger?: ILogger;
199
191
  /**
200
- * Watcher check delay period. This is used by a queue watcher
201
- * agent to make sure at least one watcher is available for
202
- * queue operations.
192
+ * Delay period (in milliseconds) between watcher availability checks.
193
+ * Used to ensure at least one watcher is available for queue operations.
203
194
  *
204
195
  * @type {number}
205
196
  */
206
197
  watcherCheckDelay?: number;
207
198
  /**
208
- * A way to serialize message using compression. Will increase
209
- * load to worker process but can decrease network traffic between worker
210
- * and queue host application
199
+ * Enable message compression for serialization. Increases a worker CPU load
200
+ * but decreases network traffic between workers and the queue host.
211
201
  *
212
202
  * @type {boolean}
213
203
  */
214
204
  useGzip?: boolean;
215
205
  /**
216
- * Enables/disables safe message delivery. When safe message delivery
217
- * is turned on it will use more complex algorithm for message handling
218
- * by a worker process, guaranteeing that if worker fails the message will
219
- * be delivered to another possible worker anyway. In most cases it
220
- * is not required unless it is required by a system design.
206
+ * Enable guaranteed message delivery. When enabled, uses a more complex
207
+ * algorithm for message handling, ensuring that if a worker fails, the
208
+ * message will be delivered to another worker. Required only for systems
209
+ * that demand guaranteed delivery semantics.
221
210
  *
222
211
  * @type {boolean}
223
212
  */
224
213
  safeDelivery?: boolean;
225
214
  /**
226
- * Time-to-live of worker queues (after this time messages are back to
227
- * main queue for handling if worker died). Only works if safeDelivery
228
- * option enabled.
215
+ * Time-to-live (in milliseconds) for messages in worker queues. After this
216
+ * period, unacknowledged messages return to the main queue for reprocessing
217
+ * if the worker died. Only effective when safeDelivery is enabled.
229
218
  *
230
219
  * @type {number}
231
220
  */
@@ -243,6 +232,15 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
243
232
  * @type {ClusterManager[]}
244
233
  */
245
234
  clusterManagers?: ClusterManager[];
235
+ /**
236
+ * Enable process signal handling (SIGTERM, SIGINT, SIGABRT) by the queue.
237
+ * When enabled, the queue releases its watcher lock and exits gracefully
238
+ * on these signals. Disable if the host application manages shutdown.
239
+ *
240
+ * @default true
241
+ * @type {boolean}
242
+ */
243
+ handleSignals?: boolean;
246
244
  /**
247
245
  * Enables/disables verbose logging
248
246
  *
@@ -261,7 +259,7 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
261
259
  verboseExtended?: boolean;
262
260
  }
263
261
  export interface EventMap {
264
- message: [data: any, id: string, from: string];
262
+ message: [data: JsonObject, id: string, from: string];
265
263
  error: [error: Error, eventName: string];
266
264
  }
267
265
  export type IMessageQueueConstructor = new (name: string, options?: Partial<IMQOptions>, mode?: IMQMode) => IMessageQueue;
@@ -270,117 +268,112 @@ export type IMessageQueueConstructor = new (name: string, options?: Partial<IMQO
270
268
  *
271
269
  * @example
272
270
  * ~~~typescript
273
- * import { IMessageQueue, EventEmitter, uuid } from '@imqueue/core';
271
+ * import { IMessageQueue, EventEmitter } from '@imqueue/core';
272
+ * import { randomUUID } from 'node:crypto';
274
273
  *
275
- * class SomeMQAdapter implements IMessageQueue extends EventEmitter {
276
- * public async start(): Promise<SomeMQAdapter> {
277
- * // ... implementation goes here
278
- * return this;
279
- * }
280
- * public async stop(): Promise<SomeMQAdapter> {
281
- * // ... implementation goes here
282
- * return this;
283
- * }
284
- * public async send(
285
- * toQueue: string,
286
- * message: JsonObject,
287
- * delay?: number
288
- * ): Promise<string> {
289
- * const messageId = uuid();
290
- * // ... implementation goes here
291
- * return messageId;
292
- * }
293
- * public async destroy(): Promise<void> {
294
- * // ... implementation goes here
295
- * }
296
- * public async clear(): Promise<SomeMQAdapter> {
297
- * // ... implementation goes here
298
- * return this;
299
- * }
274
+ * class SomeMQAdapter extends EventEmitter implements IMessageQueue {
275
+ * public async start(): Promise<SomeMQAdapter> {
276
+ * // ... implementation goes here
277
+ * return this;
278
+ * }
279
+ * public async stop(): Promise<SomeMQAdapter> {
280
+ * // ... implementation goes here
281
+ * return this;
282
+ * }
283
+ * public async send(
284
+ * toQueue: string,
285
+ * message: JsonObject,
286
+ * delay?: number,
287
+ * ): Promise<string> {
288
+ * const messageId = randomUUID();
289
+ * // ... implementation goes here
290
+ * return messageId;
291
+ * }
292
+ * public async destroy(): Promise<void> {
293
+ * // ... implementation goes here
294
+ * }
295
+ * public async clear(): Promise<SomeMQAdapter> {
296
+ * // ... implementation goes here
297
+ * return this;
298
+ * }
300
299
  * }
301
300
  * ~~~
302
301
  */
303
302
  export interface IMessageQueue extends EventEmitter<EventMap> {
304
303
  /**
305
- * Message event. Occurs every time queue got a message.
304
+ * Message event. Occurs every time the queue receives a message.
306
305
  *
307
306
  * @event IMessageQueue#message
308
307
  * @type {JsonObject} message - message data
309
308
  * @type {string} id - message identifier
310
- * @type {string} from - source queue produced the message
309
+ * @type {string} from - source queue that produced the message
311
310
  */
312
311
  /**
313
- * Error event. Occurs every time queue caught an error.
312
+ * Error event. Occurs every time the queue encounters an error.
314
313
  *
315
314
  * @event IMessageQueue#error
316
- * @type {Error} err - error caught by message queue
315
+ * @type {Error} err - error caught by the message queue
317
316
  * @type {string} code - message queue error code
318
317
  */
319
318
  /**
320
319
  * Starts the messaging queue.
321
- * Supposed to be an async function.
322
320
  *
323
321
  * @returns {Promise<IMessageQueue>}
324
322
  */
325
323
  start(): Promise<IMessageQueue>;
326
324
  /**
327
- * Stops the queue (should stop handle queue messages).
328
- * Supposed to be an async function.
325
+ * Stops the queue from handling messages.
329
326
  *
330
327
  * @returns {Promise<IMessageQueue>}
331
328
  */
332
329
  stop(): Promise<IMessageQueue>;
333
330
  /**
334
- * Sends a message to given queue name with the given data.
335
- * Supposed to be an async function.
331
+ * Sends a message to the specified queue with the given data.
336
332
  *
337
- * @param {string} toQueue - queue name to which message should be sent to
338
- * @param {JsonObject} message - message data
339
- * @param {number} [delay] - if specified, message will be handled in the
340
- * target queue after specified period of time in milliseconds.
341
- * @param {(err: Error) => void} [errorHandler] - callback called only when
342
- * internal error occurs during message send execution.
343
- * @returns {Promise<string>} - message identifier
333
+ * @param {string} toQueue - name of the destination queue
334
+ * @param {JsonObject} message - message data to send
335
+ * @param {number} [delay] - if specified, the message will be handled in
336
+ * the target queue after the specified delay in milliseconds
337
+ * @param {(err: Error) => void} [errorHandler] - callback invoked only
338
+ * when an internal error occurs during message send execution
339
+ * @returns {Promise<string>} - the message identifier
344
340
  */
345
341
  send(toQueue: string, message: JsonObject, delay?: number, errorHandler?: (err: Error) => void): Promise<string>;
346
342
  /**
347
- * Creates or uses subscription channel with the given name and sets
343
+ * Creates or uses a subscription channel with the given name and sets
348
344
  * message handler on data receive
349
345
  *
350
346
  * @param {string} channel - channel name
351
- * @param {(data: JsonObject) => any} handler
347
+ * @param {(data: JsonObject) => void} handler
352
348
  */
353
- subscribe(channel: string, handler: (data: JsonObject) => any): Promise<void>;
349
+ subscribe(channel: string, handler: (data: JsonObject) => void): Promise<void>;
354
350
  /**
355
- * Closes subscription channel
351
+ * Closes the subscription channel
356
352
  *
357
- * @return {Promise<void>}
353
+ * @returns {Promise<void>}
358
354
  */
359
355
  unsubscribe(): Promise<void>;
360
356
  /**
361
- * Publishes data to current queue channel
357
+ * Publishes data to the current queue channel
362
358
  *
363
- * If toName specified will publish to pubsub with different name. This
364
- * can be used to implement broadcasting some messages to other subscribers
365
- * on other pubsub channels. Different name should be in the same namespace
366
- * (same imq prefix)
359
+ * If toName is specified, publishes to a pubsub with a different name. This
360
+ * can be used to broadcast messages to other subscribers on different pubsub
361
+ * channels. Different names must be in the same namespace (same imq prefix).
367
362
  *
368
- * @param {JsonObject} data - data to publish as channel message
369
- * @param {string} [toName] - different name of the pubsub to publish to
370
- * @return {Promise<void>}
363
+ * @param {JsonObject} data - data to publish as a channel message
364
+ * @param {string} [toName] - optional different pubsub name to publish to
365
+ * @returns {Promise<void>}
371
366
  */
372
367
  publish(data: JsonObject, toName?: string): Promise<void>;
373
368
  /**
374
- * Safely destroys current queue, unregistered all set event
375
- * listeners and connections.
376
- * Supposed to be an async function.
369
+ * Safely destroys the current queue, unregistering all event listeners
370
+ * and closing connections.
377
371
  *
378
372
  * @returns {Promise<void>}
379
373
  */
380
374
  destroy(): Promise<void>;
381
375
  /**
382
- * Clears queue data in queue host application.
383
- * Supposed to be an async function.
376
+ * Clears all queue data from the queue host application.
384
377
  *
385
378
  * @returns {Promise<IMessageQueue>}
386
379
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventEmitter = void 0;
4
- var events_1 = require("events");
5
- Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return events_1.EventEmitter; } });
4
+ var node_events_1 = require("node:events");
5
+ Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return node_events_1.EventEmitter; } });
6
6
  //# sourceMappingURL=IMessageQueue.js.map