@fedify/amqp 2.5.0-dev.2664 → 2.5.0-dev.2687

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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/amqp",
3
- "version": "2.5.0-dev.2664+4790a72e",
3
+ "version": "2.5.0-dev.2687+924da5ce",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./src/mod.ts",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "tasks": {
26
26
  "build": "pnpm build",
27
- "check": "deno fmt --check && deno check *.ts",
27
+ "check": "deno check *.ts",
28
28
  "test": "deno test --allow-net --allow-env",
29
29
  "test:node": {
30
30
  "dependencies": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/amqp",
3
- "version": "2.5.0-dev.2664+4790a72e",
3
+ "version": "2.5.0-dev.2687+924da5ce",
4
4
  "description": "AMQP/RabbitMQ driver for Fedify",
5
5
  "keywords": [
6
6
  "fedify",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "peerDependencies": {
54
54
  "amqplib": "^0.10.9",
55
- "@fedify/fedify": "^2.5.0-dev.2664+4790a72e"
55
+ "@fedify/fedify": "^2.5.0-dev.2687+924da5ce"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@alinea/suite": "^0.6.3",
@@ -60,7 +60,7 @@
60
60
  "@types/amqplib": "^0.10.8",
61
61
  "tsdown": "^0.22.0",
62
62
  "typescript": "^6.0.3",
63
- "@fedify/testing": "^2.5.0-dev.2664+4790a72e"
63
+ "@fedify/testing": "^2.5.0-dev.2687+924da5ce"
64
64
  },
65
65
  "scripts": {
66
66
  "build:self": "tsdown",
package/src/mq.test.ts CHANGED
@@ -16,22 +16,17 @@ const test = AMQP_URL ? unitTest : unitTest.skip;
16
16
 
17
17
  unitTest("AmqpMessageQueue declares non-atomic batch enqueueing", () => {
18
18
  const mq = new AmqpMessageQueue({} as ChannelModel);
19
- ok(!(mq.atomicEnqueueMany));
19
+ ok(!mq.atomicEnqueueMany);
20
20
  });
21
21
 
22
22
  class FakeDepthChannel {
23
23
  #closed = false;
24
24
 
25
- constructor(private readonly connection: FakeDepthConnection) {
26
- }
25
+ constructor(private readonly connection: FakeDepthConnection) {}
27
26
 
28
- on(): void {
29
- }
27
+ on(): void {}
30
28
 
31
- assertQueue(
32
- queue: string,
33
- options?: { expires?: number },
34
- ): Promise<void> {
29
+ assertQueue(queue: string, options?: { expires?: number }): Promise<void> {
35
30
  if (this.#closed) {
36
31
  return Promise.reject(new Error("Channel is closed"));
37
32
  }
@@ -93,8 +88,7 @@ class FakeDepthConnection {
93
88
  channelCount = 0;
94
89
  maxActiveChecks = 0;
95
90
 
96
- constructor(readonly checkDelayMs: number = 25) {
97
- }
91
+ constructor(readonly checkDelayMs: number = 25) {}
98
92
 
99
93
  createChannel(): Promise<Channel> {
100
94
  this.channelCount++;
@@ -126,7 +120,7 @@ unitTest(
126
120
  ready: 0,
127
121
  delayed: 3,
128
122
  });
129
- ok((conn.maxActiveChecks) > (1));
123
+ ok(conn.maxActiveChecks > 1);
130
124
  },
131
125
  );
132
126
 
@@ -160,7 +154,7 @@ unitTest(
160
154
 
161
155
  deepStrictEqual(conn.messageCounts.get("delayed_1000"), 1);
162
156
  deepStrictEqual(conn.queueExpires.get("delayed_1000"), undefined);
163
- ok((conn.channelCount) > (1));
157
+ ok(conn.channelCount > 1);
164
158
  },
165
159
  );
166
160
 
@@ -303,8 +297,9 @@ test(
303
297
  const channel = await conn.createChannel().catch(() => undefined);
304
298
  try {
305
299
  await channel?.deleteQueue(queue).catch(() => {});
306
- await channel?.deleteQueue(`${delayedQueuePrefix}60000`).catch(() => {
307
- });
300
+ await channel
301
+ ?.deleteQueue(`${delayedQueuePrefix}60000`)
302
+ .catch(() => {});
308
303
  } finally {
309
304
  await channel?.close().catch(() => {});
310
305
  await conn.close().catch(() => {});
@@ -363,16 +358,19 @@ test(
363
358
  const queue = `fedify_queue_${randomSuffix}`;
364
359
  const delayedQueuePrefix = `fedify_delayed_${randomSuffix}_`;
365
360
  const mq = new AmqpMessageQueue(conn, { queue, delayedQueuePrefix });
366
- ok(!(mq.nativeRetrial));
361
+ ok(!mq.nativeRetrial);
367
362
 
368
363
  const controller = new AbortController();
369
364
  let i = 0;
370
- const listening = mq.listen((message: string) => {
371
- if (message !== "Hello, world!") return;
372
- if (i++ < 1) {
373
- throw new Error("Test error to check native retrial");
374
- }
375
- }, { signal: controller.signal });
365
+ const listening = mq.listen(
366
+ (message: string) => {
367
+ if (message !== "Hello, world!") return;
368
+ if (i++ < 1) {
369
+ throw new Error("Test error to check native retrial");
370
+ }
371
+ },
372
+ { signal: controller.signal },
373
+ );
376
374
 
377
375
  await mq.enqueue("Hello, world!");
378
376
 
@@ -405,12 +403,15 @@ test(
405
403
 
406
404
  const controller = new AbortController();
407
405
  let i = 0;
408
- const listening = mq.listen((message: string) => {
409
- if (message !== "Hello, world!") return;
410
- if (i++ < 1) {
411
- throw new Error("Test error to check native retrial");
412
- }
413
- }, { signal: controller.signal });
406
+ const listening = mq.listen(
407
+ (message: string) => {
408
+ if (message !== "Hello, world!") return;
409
+ if (i++ < 1) {
410
+ throw new Error("Test error to check native retrial");
411
+ }
412
+ },
413
+ { signal: controller.signal },
414
+ );
414
415
 
415
416
  await mq.enqueue("Hello, world!");
416
417
 
@@ -420,6 +421,6 @@ test(
420
421
  await listening;
421
422
  await conn.close();
422
423
 
423
- ok(i > (1));
424
+ ok(i > 1);
424
425
  },
425
426
  );
package/src/mq.ts CHANGED
@@ -9,13 +9,21 @@ import type { Channel, ChannelModel, ConsumeMessage } from "amqplib";
9
9
  import { Buffer } from "node:buffer";
10
10
 
11
11
  function isQueueNotFoundError(error: unknown): boolean {
12
- return typeof error === "object" && error != null &&
13
- "code" in error && error.code === 404;
12
+ return (
13
+ typeof error === "object" &&
14
+ error != null &&
15
+ "code" in error &&
16
+ error.code === 404
17
+ );
14
18
  }
15
19
 
16
20
  function isPreconditionFailedError(error: unknown): boolean {
17
- return typeof error === "object" && error != null &&
18
- "code" in error && error.code === 406;
21
+ return (
22
+ typeof error === "object" &&
23
+ error != null &&
24
+ "code" in error &&
25
+ error.code === 406
26
+ );
19
27
  }
20
28
 
21
29
  const depthProbeConcurrency = 8;
@@ -155,10 +163,7 @@ export class AmqpMessageQueue implements MessageQueue {
155
163
  * @param connection A connection to the AMQP server.
156
164
  * @param options Options for the message queue.
157
165
  */
158
- constructor(
159
- connection: ChannelModel,
160
- options: AmqpMessageQueueOptions = {},
161
- ) {
166
+ constructor(connection: ChannelModel, options: AmqpMessageQueueOptions = {}) {
162
167
  this.#connection = connection;
163
168
  this.#queue = options.queue ?? "fedify_queue";
164
169
  this.#delayedQueuePrefix = options.delayedQueuePrefix ?? "fedify_delayed_";
@@ -291,14 +296,10 @@ export class AmqpMessageQueue implements MessageQueue {
291
296
  });
292
297
  this.#trackDelayedQueue(queue);
293
298
  }
294
- channel.sendToQueue(
295
- queue,
296
- Buffer.from(JSON.stringify(message), "utf-8"),
297
- {
298
- persistent: this.#durable,
299
- contentType: "application/json",
300
- },
301
- );
299
+ channel.sendToQueue(queue, Buffer.from(JSON.stringify(message), "utf-8"), {
300
+ persistent: this.#durable,
301
+ contentType: "application/json",
302
+ });
302
303
  }
303
304
 
304
305
  /**
@@ -456,9 +457,7 @@ export class AmqpMessageQueue implements MessageQueue {
456
457
  // The channel can already be closed by a failed passive queue check.
457
458
  }
458
459
  };
459
- const checkQueue = async (
460
- queue: string,
461
- ): Promise<number | undefined> => {
460
+ const checkQueue = async (queue: string): Promise<number | undefined> => {
462
461
  channel ??= await this.#createDepthChannel();
463
462
  try {
464
463
  return (await channel.checkQueue(queue)).messageCount;
@@ -488,9 +487,9 @@ export class AmqpMessageQueue implements MessageQueue {
488
487
 
489
488
  async #pruneMissingDelayedQueues(): Promise<void> {
490
489
  const delayedQueues = [...this.#delayedQueues];
491
- for (
492
- const [queue, messageCount] of await this.#checkQueueDepths(delayedQueues)
493
- ) {
490
+ for (const [queue, messageCount] of await this.#checkQueueDepths(
491
+ delayedQueues,
492
+ )) {
494
493
  if (messageCount == null) this.#delayedQueues.delete(queue);
495
494
  }
496
495
  }
@@ -510,9 +509,9 @@ export class AmqpMessageQueue implements MessageQueue {
510
509
 
511
510
  let delayed = 0;
512
511
  const delayedQueues = [...this.#delayedQueues];
513
- for (
514
- const [queue, messageCount] of await this.#checkQueueDepths(delayedQueues)
515
- ) {
512
+ for (const [queue, messageCount] of await this.#checkQueueDepths(
513
+ delayedQueues,
514
+ )) {
516
515
  if (messageCount == null) {
517
516
  this.#delayedQueues.delete(queue);
518
517
  } else {
@@ -575,11 +574,9 @@ export class AmqpMessageQueue implements MessageQueue {
575
574
  if (this.#ordering != null) {
576
575
  for (let i = 0; i < this.#ordering.partitions; i++) {
577
576
  const queueName = this.#getOrderingQueueName(i);
578
- const orderingReply = await channel.consume(
579
- queueName,
580
- messageHandler,
581
- { noAck: false },
582
- );
577
+ const orderingReply = await channel.consume(queueName, messageHandler, {
578
+ noAck: false,
579
+ });
583
580
  consumerTags.push(orderingReply.consumerTag);
584
581
  }
585
582
  }
@@ -1,9 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
3
  "include": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
4
- "exclude": [
5
- "dist",
6
- "dist-tests",
7
- "node_modules"
8
- ]
4
+ "exclude": ["dist", "dist-tests", "node_modules"]
9
5
  }