@heritageai/messaging 1.0.0 → 1.0.2

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.
@@ -1,5 +1,5 @@
1
- import { Stan, Message } from 'node-nats-streaming';
2
- export declare abstract class BaseListener<T> {
1
+ import { Stan, Message } from "node-nats-streaming";
2
+ export declare abstract class Listener<T> {
3
3
  abstract subject: string;
4
4
  abstract queueGroupName: string;
5
5
  abstract onMessage(data: T, msg: Message): void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseListener = void 0;
4
- class BaseListener {
3
+ exports.Listener = void 0;
4
+ class Listener {
5
5
  constructor(client) {
6
6
  this.client = client;
7
7
  }
@@ -14,11 +14,13 @@ class BaseListener {
14
14
  }
15
15
  listen() {
16
16
  const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
17
- // @ts-ignore
18
- subscription.on('message', (msg) => {
19
- const parsedData = JSON.parse(msg.getData());
20
- this.onMessage(parsedData, msg);
17
+ // @ts-ignore (node-nats-streaming typing bug)
18
+ subscription.on("message", (msg) => {
19
+ const data = typeof msg.getData() === "string"
20
+ ? JSON.parse(msg.getData())
21
+ : JSON.parse(msg.getData().toString("utf8"));
22
+ this.onMessage(data, msg);
21
23
  });
22
24
  }
23
25
  }
24
- exports.BaseListener = BaseListener;
26
+ exports.Listener = Listener;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "future_platform",
3
3
  "name": "@heritageai/messaging",
4
4
  "license": "ISC",
5
- "version": "1.0.0",
5
+ "version": "1.0.2",
6
6
  "description": "",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -1,9 +1,10 @@
1
- import { Stan, Message } from 'node-nats-streaming';
1
+ import { Stan, Message } from "node-nats-streaming";
2
2
 
3
- export abstract class BaseListener<T> {
3
+ export abstract class Listener<T> {
4
4
  abstract subject: string;
5
5
  abstract queueGroupName: string;
6
6
  abstract onMessage(data: T, msg: Message): void;
7
+
7
8
  protected client: Stan;
8
9
 
9
10
  constructor(client: Stan) {
@@ -25,10 +26,14 @@ export abstract class BaseListener<T> {
25
26
  this.subscriptionOptions()
26
27
  );
27
28
 
28
- // @ts-ignore
29
- subscription.on('message', (msg: Message) => {
30
- const parsedData = JSON.parse(msg.getData() as string);
31
- this.onMessage(parsedData, msg);
29
+ // @ts-ignore (node-nats-streaming typing bug)
30
+ subscription.on("message", (msg: Message) => {
31
+ const data =
32
+ typeof msg.getData() === "string"
33
+ ? JSON.parse(msg.getData())
34
+ : JSON.parse(msg.getData().toString("utf8"));
35
+
36
+ this.onMessage(data, msg);
32
37
  });
33
38
  }
34
39
  }