qrusty-client 0.17.3 → 0.17.4

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 (2) hide show
  1. package/index.js +123 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -27,12 +27,22 @@ class QrustyClient {
27
27
  * @param {string} name
28
28
  * @param {string} [ordering="MaxFirst"] - One of: Fifo | MinFirst | MaxFirst
29
29
  * @param {boolean} [allowDuplicates=true]
30
+ * @param {string} [priorityKind="Numeric"] - One of: Numeric | Text
30
31
  * @returns {Promise<void>}
31
32
  */
32
- async createQueue(name, ordering = "MaxFirst", allowDuplicates = true) {
33
+ async createQueue(
34
+ name,
35
+ ordering = "MaxFirst",
36
+ allowDuplicates = true,
37
+ priorityKind = "Numeric",
38
+ ) {
33
39
  const data = {
34
40
  name,
35
- config: { ordering, allow_duplicates: allowDuplicates },
41
+ config: {
42
+ ordering,
43
+ allow_duplicates: allowDuplicates,
44
+ priority_kind: priorityKind,
45
+ },
36
46
  };
37
47
  await axios.post(`${this.baseUrl}/create-queue`, data);
38
48
  }
@@ -187,6 +197,50 @@ class QrustyClient {
187
197
  const resp = await axios.get(`${this.baseUrl}/queues`);
188
198
  return resp.data;
189
199
  }
200
+
201
+ /**
202
+ * Purge all messages from all queues
203
+ * @returns {Promise<object>}
204
+ */
205
+ async purgeAll() {
206
+ const resp = await axios.post(`${this.baseUrl}/purge-all`);
207
+ return resp.data;
208
+ }
209
+
210
+ /**
211
+ * Delete all queues and their messages
212
+ * @returns {Promise<object>}
213
+ */
214
+ async deleteAll() {
215
+ const resp = await axios.post(`${this.baseUrl}/delete-all`);
216
+ return resp.data;
217
+ }
218
+
219
+ /**
220
+ * Batch-acknowledge multiple messages
221
+ * @param {string} queue
222
+ * @param {string} consumerId
223
+ * @param {string[]} messageIds
224
+ * @returns {Promise<object>}
225
+ */
226
+ async ackBatch(queue, consumerId, messageIds) {
227
+ const data = { consumer_id: consumerId, message_ids: messageIds };
228
+ const resp = await axios.post(`${this.baseUrl}/ack-batch/${queue}`, data);
229
+ return resp.data;
230
+ }
231
+
232
+ /**
233
+ * Batch-negative-acknowledge multiple messages
234
+ * @param {string} queue
235
+ * @param {string} consumerId
236
+ * @param {string[]} messageIds
237
+ * @returns {Promise<object>}
238
+ */
239
+ async nackBatch(queue, consumerId, messageIds) {
240
+ const data = { consumer_id: consumerId, message_ids: messageIds };
241
+ const resp = await axios.post(`${this.baseUrl}/nack-batch/${queue}`, data);
242
+ return resp.data;
243
+ }
190
244
  }
191
245
 
192
246
  // ---------------------------------------------------------------------------
@@ -235,6 +289,7 @@ class WsSession {
235
289
  this._reqCounter = 0;
236
290
  this._pending = new Map(); // req_id → { resolve, reject }
237
291
  this._deliverQueues = new Map(); // queue → Array of waiting resolvers
292
+ this._logWaiters = []; // Array of { resolve, reject } for log entries
238
293
  }
239
294
 
240
295
  // -------------------------------------------------------------------------
@@ -267,6 +322,11 @@ class WsSession {
267
322
  }
268
323
  }
269
324
  this._deliverQueues.clear();
325
+
326
+ // Reject all log waiters.
327
+ for (const { reject } of this._logWaiters.splice(0)) {
328
+ reject(new Error("connection closed"));
329
+ }
270
330
  }
271
331
 
272
332
  /** Close the connection gracefully. */
@@ -320,6 +380,18 @@ class WsSession {
320
380
  });
321
381
  }
322
382
  }
383
+ return;
384
+ }
385
+
386
+ if (frame.type === "log") {
387
+ const { resolve } = this._logWaiters.shift() || {};
388
+ if (resolve) {
389
+ resolve({
390
+ timestamp: frame.timestamp,
391
+ level: frame.level,
392
+ message: frame.message,
393
+ });
394
+ }
323
395
  }
324
396
  }
325
397
 
@@ -345,7 +417,7 @@ class WsSession {
345
417
  * Publish a message to a queue.
346
418
  * @param {string} queue
347
419
  * @param {string} payload
348
- * @param {number} [priority=0]
420
+ * @param {number|string} [priority=0]
349
421
  * @returns {Promise<string>} The assigned message id.
350
422
  */
351
423
  async publish(queue, payload, priority = 0) {
@@ -448,6 +520,54 @@ class WsSession {
448
520
  return { unlocked: resp.unlocked, dropped: resp.dropped };
449
521
  }
450
522
 
523
+ /**
524
+ * Replenish credits for a subscription on a queue.
525
+ * @param {string} queue
526
+ * @param {number} credits
527
+ * @returns {Promise<void>}
528
+ */
529
+ async grantCredits(queue, credits) {
530
+ await this._request({ type: "credit", queue, credits });
531
+ }
532
+
533
+ /**
534
+ * Subscribe to the server's log stream.
535
+ * Returns an AsyncIterable that yields log entry objects
536
+ * with timestamp, level, and message properties.
537
+ * @returns {AsyncIterable<{timestamp: string, level: string, message: string}>}
538
+ */
539
+ subscribeLogs() {
540
+ this._request({ type: "subscribe-logs" }).catch(() => {});
541
+
542
+ const self = this;
543
+ return {
544
+ [Symbol.asyncIterator]() {
545
+ return {
546
+ next() {
547
+ return new Promise((resolve, reject) => {
548
+ self._logWaiters.push({
549
+ resolve: (entry) => resolve({ value: entry, done: false }),
550
+ reject,
551
+ });
552
+ });
553
+ },
554
+ return() {
555
+ return Promise.resolve({ value: undefined, done: true });
556
+ },
557
+ };
558
+ },
559
+ };
560
+ }
561
+
562
+ /**
563
+ * Unsubscribe from the server's log stream.
564
+ * @returns {Promise<void>}
565
+ */
566
+ async unsubscribeLogs() {
567
+ await this._request({ type: "unsubscribe-logs" });
568
+ this._logWaiters.splice(0);
569
+ }
570
+
451
571
  /**
452
572
  * Renew (extend) the lock on a message by 30 seconds.
453
573
  * Implements: WS-0020
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qrusty-client",
3
- "version": "0.17.3",
3
+ "version": "0.17.4",
4
4
  "description": "Node.js client for the qrusty priority queue server API.",
5
5
  "main": "index.js",
6
6
  "author": "Gordon Greene <greeng3@obscure-reference.com>",