@onebun/nats 0.1.1 → 0.1.3
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/package.json +2 -2
- package/src/jetstream.adapter.ts +6 -4
- package/src/nats-client.ts +3 -1
- package/src/nats.adapter.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onebun/nats",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "NATS and JetStream integration for OneBun framework",
|
|
5
5
|
"license": "LGPL-3.0",
|
|
6
6
|
"author": "RemRyahirev",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test": "bun test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@onebun/core": "
|
|
41
|
+
"@onebun/core": "^0.1.9",
|
|
42
42
|
"@nats-io/transport-node": "^3.0.0-31",
|
|
43
43
|
"@nats-io/jetstream": "^3.0.0-31",
|
|
44
44
|
"effect": "^3.13.10"
|
package/src/jetstream.adapter.ts
CHANGED
|
@@ -30,6 +30,9 @@ import {
|
|
|
30
30
|
|
|
31
31
|
import { NatsClient } from './nats-client';
|
|
32
32
|
|
|
33
|
+
const DEFAULT_ACK_WAIT_NANOSECONDS = 30_000_000_000; // 30 seconds in nanoseconds
|
|
34
|
+
const DEFAULT_MAX_DELIVER = 3;
|
|
35
|
+
|
|
33
36
|
// Import JetStream types dynamically
|
|
34
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
38
|
let jetstreamModule: any = null;
|
|
@@ -345,9 +348,8 @@ export class JetStreamQueueAdapter implements QueueAdapter {
|
|
|
345
348
|
ack_policy: ackPolicy,
|
|
346
349
|
filter_subject: filterSubject,
|
|
347
350
|
max_ack_pending: options?.prefetch ?? 100,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
max_deliver: options?.retry?.attempts ?? this.options.consumerConfig?.maxDeliver ?? 3,
|
|
351
|
+
ack_wait: this.options.consumerConfig?.ackWait ?? DEFAULT_ACK_WAIT_NANOSECONDS,
|
|
352
|
+
max_deliver: options?.retry?.attempts ?? this.options.consumerConfig?.maxDeliver ?? DEFAULT_MAX_DELIVER,
|
|
351
353
|
});
|
|
352
354
|
} catch {
|
|
353
355
|
// Consumer might already exist, try to get it
|
|
@@ -469,7 +471,7 @@ export class JetStreamQueueAdapter implements QueueAdapter {
|
|
|
469
471
|
}
|
|
470
472
|
|
|
471
473
|
private generateMessageId(): string {
|
|
472
|
-
// eslint-disable-next-line no-magic-numbers
|
|
474
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
473
475
|
return `js-${++this.messageIdCounter}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
474
476
|
}
|
|
475
477
|
|
package/src/nats-client.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import type { NatsConnectionOptions } from './types';
|
|
8
8
|
|
|
9
|
+
const DEFAULT_TIMEOUT = 5_000; // 5 seconds
|
|
10
|
+
|
|
9
11
|
// Import NATS types dynamically to handle potential import issues
|
|
10
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
13
|
let natsModule: any = null;
|
|
@@ -170,7 +172,7 @@ export class NatsClient {
|
|
|
170
172
|
|
|
171
173
|
|
|
172
174
|
const response = await this.nc.request(subject, encoder.encode(data), {
|
|
173
|
-
timeout: options?.timeout ??
|
|
175
|
+
timeout: options?.timeout ?? DEFAULT_TIMEOUT,
|
|
174
176
|
});
|
|
175
177
|
|
|
176
178
|
return {
|
package/src/nats.adapter.ts
CHANGED
|
@@ -406,7 +406,7 @@ export class NatsQueueAdapter implements QueueAdapter {
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
private generateMessageId(): string {
|
|
409
|
-
// eslint-disable-next-line no-magic-numbers
|
|
409
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
410
410
|
return `nats-${++this.messageIdCounter}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
411
411
|
}
|
|
412
412
|
|