sim-node-lib 0.0.52 → 0.0.53

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,6 @@
1
1
  export declare enum PubSubTableEnum {
2
2
  agrupador = "agrupador",
3
+ autosystem_plate = "autosystema-pessoa_frota",
3
4
  bandeira = "bandeira",
4
5
  cargo = "cargo",
5
6
  cliente = "cliente",
@@ -4,6 +4,7 @@ exports.PubSubTableEnum = void 0;
4
4
  var PubSubTableEnum;
5
5
  (function (PubSubTableEnum) {
6
6
  PubSubTableEnum["agrupador"] = "agrupador";
7
+ PubSubTableEnum["autosystem_plate"] = "autosystema-pessoa_frota";
7
8
  PubSubTableEnum["bandeira"] = "bandeira";
8
9
  PubSubTableEnum["cargo"] = "cargo";
9
10
  PubSubTableEnum["cliente"] = "cliente";
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ export declare class PubSubModel {
4
+ readonly value: object;
5
+ readonly action: string;
6
+ readonly table: string;
7
+ constructor(value: object, action: PubSubActionEnum, table: string);
8
+ }
9
+ export declare class GooglePubSubSubscription {
10
+ constructor(subscriptionName: string);
11
+ private _subscription;
12
+ listenMessages(eventEmitter: EventEmitter): Promise<void>;
13
+ }
14
+ export declare class GooglePubSubPublish {
15
+ constructor(topicName: string);
16
+ private _topicName;
17
+ createMessages(message: object, action: PubSubActionEnum, table: string): Promise<void>;
18
+ }
19
+ export declare abstract class PubSubHandelerAction {
20
+ constructor(pubsubModel: PubSubModel);
21
+ protected _pubsubValueModel: any;
22
+ protected handlerAction(action: string): void;
23
+ protected insert(): void;
24
+ protected update(): void;
25
+ protected remove(): void;
26
+ protected buildData(): Object;
27
+ }
28
+ export declare enum PubSubActionEnum {
29
+ insert = "insert",
30
+ update = "update",
31
+ remove = "remove"
32
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const pubsub_1 = require("@google-cloud/pubsub");
13
+ class PubSubModel {
14
+ constructor(value, action, table) {
15
+ this.value = value;
16
+ this.action = action.toString();
17
+ this.table = table;
18
+ }
19
+ }
20
+ exports.PubSubModel = PubSubModel;
21
+ class GooglePubSubSubscription {
22
+ constructor(subscriptionName) {
23
+ this._subscription = new pubsub_1.PubSub().subscription(subscriptionName);
24
+ }
25
+ listenMessages(eventEmitter) {
26
+ return __awaiter(this, void 0, void 0, function* () {
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, message]);
32
+ }
33
+ catch (error) {
34
+ console.error(error);
35
+ throw Error(error);
36
+ }
37
+ });
38
+ // Receive callbacks for errors on the subscription
39
+ this._subscription.on('error', (error) => {
40
+ console.error('Received error:', error);
41
+ throw Error(error);
42
+ });
43
+ });
44
+ }
45
+ }
46
+ exports.GooglePubSubSubscription = GooglePubSubSubscription;
47
+ class GooglePubSubPublish {
48
+ constructor(topicName) {
49
+ this._topicName = topicName;
50
+ }
51
+ createMessages(message, action, table) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const pubSubClient = new pubsub_1.PubSub();
54
+ const send = new PubSubModel(message, action, table);
55
+ // Creates a new topic
56
+ const topic = pubSubClient.topic(this._topicName);
57
+ console.log(`Topic ${topic.name} created.`);
58
+ const dataSend = JSON.stringify(send);
59
+ //Create message
60
+ const data = Buffer.from(dataSend);
61
+ // Send a message to the topic
62
+ yield topic.publishMessage({ data });
63
+ });
64
+ }
65
+ }
66
+ exports.GooglePubSubPublish = GooglePubSubPublish;
67
+ class PubSubHandelerAction {
68
+ constructor(pubsubModel) {
69
+ this._pubsubValueModel = pubsubModel.value;
70
+ this.handlerAction(pubsubModel.action);
71
+ }
72
+ handlerAction(action) {
73
+ switch (action) {
74
+ case 'insert':
75
+ this.insert();
76
+ break;
77
+ case 'update':
78
+ this.update();
79
+ break;
80
+ case 'delete':
81
+ this.remove();
82
+ break;
83
+ default:
84
+ this.insert();
85
+ //throw new Error('PubSub handler action not implemented.')
86
+ }
87
+ }
88
+ insert() {
89
+ throw new Error('Method insert PubSub handler action not implemented.');
90
+ }
91
+ update() {
92
+ throw new Error('Method update PubSub handler action not implemented.');
93
+ }
94
+ remove() {
95
+ throw new Error('Method remove PubSub handler action not implemented.');
96
+ }
97
+ buildData() {
98
+ throw new Error('Method buildData PubSub handler action not implemented.');
99
+ }
100
+ }
101
+ exports.PubSubHandelerAction = PubSubHandelerAction;
102
+ var PubSubActionEnum;
103
+ (function (PubSubActionEnum) {
104
+ PubSubActionEnum["insert"] = "insert";
105
+ PubSubActionEnum["update"] = "update";
106
+ PubSubActionEnum["remove"] = "remove";
107
+ })(PubSubActionEnum = exports.PubSubActionEnum || (exports.PubSubActionEnum = {}));
@@ -0,0 +1,2 @@
1
+ export declare function sayHello(): void;
2
+ export declare function sayGoodbye(): void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("dotenv").config();
4
+ function sayHello() {
5
+ console.log("hi my friend, the NODE PORT is: ", process.env.PORT);
6
+ }
7
+ exports.sayHello = sayHello;
8
+ function sayGoodbye() {
9
+ console.log("goodbye");
10
+ }
11
+ exports.sayGoodbye = sayGoodbye;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",