sim-node-lib 0.0.17 → 0.0.20

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,9 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
3
  export declare class PubSubModel {
4
- readonly value: object;
5
- readonly action: string;
6
- readonly table: string;
4
+ readonly value: any;
5
+ readonly action: PubSubActionEnum;
6
+ readonly table: PubSubTableEnum;
7
7
  constructor(value: object, action: PubSubActionEnum, table: PubSubTableEnum);
8
8
  }
9
9
  export declare class GooglePubSubSubscription {
@@ -19,10 +19,10 @@ export declare class GooglePubSubPublish {
19
19
  export declare abstract class PubSubHandelerAction {
20
20
  constructor(pubsubModel: PubSubModel);
21
21
  protected _pubsubValueModel: PubSubModel;
22
- handlerAction(): boolean;
23
- protected insert(): boolean;
24
- protected update(): boolean;
25
- protected remove(): boolean;
22
+ handlerAction(): Promise<boolean>;
23
+ protected insert(): Promise<boolean>;
24
+ protected update(): Promise<boolean>;
25
+ protected remove(): Promise<boolean>;
26
26
  protected buildData(): Object;
27
27
  }
28
28
  export declare enum PubSubActionEnum {
@@ -13,8 +13,8 @@ const pubsub_1 = require("@google-cloud/pubsub");
13
13
  class PubSubModel {
14
14
  constructor(value, action, table) {
15
15
  this.value = value;
16
- this.action = action.toString();
17
- this.table = table.toString();
16
+ this.action = action;
17
+ this.table = table;
18
18
  }
19
19
  }
20
20
  exports.PubSubModel = PubSubModel;
@@ -25,16 +25,9 @@ class GooglePubSubSubscription {
25
25
  listenMessages(eventEmitter) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
27
  this._subscription.on('message', (message) => {
28
- try {
29
- const data = JSON.parse(message.data.toString());
30
- const pubSubModel = new PubSubModel(data.value, data.action, data.table);
31
- eventEmitter.emit('event', pubSubModel);
32
- message.ack();
33
- }
34
- catch (error) {
35
- console.error(error);
36
- eventEmitter.emit('error', error);
37
- }
28
+ const data = JSON.parse(message.data.toString());
29
+ const pubSubModel = new PubSubModel(data.value, data.action, data.table);
30
+ eventEmitter.emit('event', [pubSubModel, message]);
38
31
  });
39
32
  // Receive callbacks for errors on the subscription
40
33
  this._subscription.on('error', (error) => {
@@ -69,16 +62,18 @@ class PubSubHandelerAction {
69
62
  this._pubsubValueModel = pubsubModel;
70
63
  }
71
64
  handlerAction() {
72
- switch (this._pubsubValueModel.action) {
73
- case 'insert':
74
- return this.insert();
75
- case 'update':
76
- return this.update();
77
- case 'delete':
78
- return this.remove();
79
- default:
80
- throw new Error('PubSub handler action not implemented.');
81
- }
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ switch (this._pubsubValueModel.action) {
67
+ case 'insert':
68
+ return yield this.insert();
69
+ case 'update':
70
+ return yield this.update();
71
+ case 'remove':
72
+ return yield this.remove();
73
+ default:
74
+ throw new Error('PubSub handler action not implemented.');
75
+ }
76
+ });
82
77
  }
83
78
  insert() {
84
79
  throw new Error('Method insert PubSub handler action not implemented.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.0.17",
3
+ "version": "0.0.20",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",