@heritageai/messaging 1.0.3 → 1.0.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.
- package/dist/nats-wrapper.d.ts +1 -1
- package/dist/nats-wrapper.js +7 -5
- package/package.json +1 -1
- package/src/nats-wrapper.ts +10 -7
package/dist/nats-wrapper.d.ts
CHANGED
package/dist/nats-wrapper.js
CHANGED
|
@@ -8,7 +8,7 @@ const node_nats_streaming_1 = __importDefault(require("node-nats-streaming"));
|
|
|
8
8
|
class NatsWrapper {
|
|
9
9
|
get client() {
|
|
10
10
|
if (!this._client) {
|
|
11
|
-
throw new Error(
|
|
11
|
+
throw new Error("Cannot access NATS client before connecting");
|
|
12
12
|
}
|
|
13
13
|
return this._client;
|
|
14
14
|
}
|
|
@@ -18,13 +18,15 @@ class NatsWrapper {
|
|
|
18
18
|
console.log(`🔌 Connecting to NATS (${remaining} retries left)...`);
|
|
19
19
|
this._client = node_nats_streaming_1.default.connect(clusterId, clientId, { url });
|
|
20
20
|
// @ts-ignore
|
|
21
|
-
this._client.on(
|
|
22
|
-
console.log(
|
|
21
|
+
this._client.on("connect", () => {
|
|
22
|
+
console.log("✅ Connected to NATS");
|
|
23
23
|
resolve();
|
|
24
24
|
});
|
|
25
25
|
// @ts-ignore
|
|
26
|
-
this._client.on(
|
|
27
|
-
console.error(
|
|
26
|
+
this._client.on("error", (err) => {
|
|
27
|
+
console.error("❌ NATS connection error:", err.message);
|
|
28
|
+
this._client?.close();
|
|
29
|
+
this._client = undefined;
|
|
28
30
|
if (remaining <= 0) {
|
|
29
31
|
reject(err);
|
|
30
32
|
return;
|
package/package.json
CHANGED
package/src/nats-wrapper.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import nats, { Stan } from
|
|
1
|
+
import nats, { Stan } from "node-nats-streaming";
|
|
2
2
|
|
|
3
3
|
class NatsWrapper {
|
|
4
4
|
private _client?: Stan;
|
|
5
5
|
|
|
6
6
|
get client() {
|
|
7
7
|
if (!this._client) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error("Cannot access NATS client before connecting");
|
|
9
9
|
}
|
|
10
10
|
return this._client;
|
|
11
11
|
}
|
|
@@ -15,7 +15,7 @@ class NatsWrapper {
|
|
|
15
15
|
clientId: string,
|
|
16
16
|
url: string,
|
|
17
17
|
retries = 5,
|
|
18
|
-
delayMs = 3000
|
|
18
|
+
delayMs = 3000,
|
|
19
19
|
): Promise<void> {
|
|
20
20
|
return new Promise((resolve, reject) => {
|
|
21
21
|
const attempt = (remaining: number) => {
|
|
@@ -24,14 +24,17 @@ class NatsWrapper {
|
|
|
24
24
|
this._client = nats.connect(clusterId, clientId, { url });
|
|
25
25
|
|
|
26
26
|
// @ts-ignore
|
|
27
|
-
this._client.on(
|
|
28
|
-
console.log(
|
|
27
|
+
this._client.on("connect", () => {
|
|
28
|
+
console.log("✅ Connected to NATS");
|
|
29
29
|
resolve();
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
// @ts-ignore
|
|
33
|
-
this._client.on(
|
|
34
|
-
console.error(
|
|
33
|
+
this._client.on("error", (err) => {
|
|
34
|
+
console.error("❌ NATS connection error:", err.message);
|
|
35
|
+
|
|
36
|
+
this._client?.close();
|
|
37
|
+
this._client = undefined;
|
|
35
38
|
|
|
36
39
|
if (remaining <= 0) {
|
|
37
40
|
reject(err);
|