sim-node-lib 0.0.31 → 0.0.34
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/Class/GooglePubSubPublish.d.ts +7 -0
- package/dist/Class/GooglePubSubPublish.js +30 -0
- package/dist/Class/GooglePubSubSubscription.d.ts +7 -0
- package/dist/Class/GooglePubSubSubscription.js +33 -0
- package/dist/Enums/PubSubActionEnum.d.ts +7 -0
- package/dist/Enums/PubSubActionEnum.js +11 -0
- package/dist/Enums/PubSubTableEnum.d.ts +30 -0
- package/dist/Enums/PubSubTableEnum.js +34 -0
- package/dist/Handlers/PubSubHandlerAction.d.ts +12 -0
- package/dist/Handlers/PubSubHandlerAction.js +54 -0
- package/dist/Helpers/CryptHelper.d.ts +4 -0
- package/dist/Helpers/CryptHelper.js +19 -0
- package/dist/Helpers/HashHelper.d.ts +3 -0
- package/dist/Helpers/HashHelper.js +10 -0
- package/dist/Helpers/NumberHelper.d.ts +5 -0
- package/dist/Helpers/NumberHelper.js +15 -0
- package/dist/Helpers/PromiseHelper.d.ts +3 -0
- package/dist/Helpers/PromiseHelper.js +14 -0
- package/dist/Helpers/StringHelper.d.ts +5 -0
- package/dist/Helpers/StringHelper.js +27 -0
- package/dist/Models/PubSubModel.d.ts +8 -0
- package/dist/Models/PubSubModel.js +11 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -6
- package/package.json +5 -1
- package/dist/google-pub-sub.d.ts +0 -32
- package/dist/google-pub-sub.js +0 -107
- package/dist/hello-world.d.ts +0 -2
- package/dist/hello-world.js +0 -11
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
|
|
2
|
+
import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
|
|
3
|
+
export declare class GooglePubSubPublish {
|
|
4
|
+
constructor(topicName: string);
|
|
5
|
+
private _topicName;
|
|
6
|
+
createMessages(message: object, action: PubSubActionEnum, table: PubSubTableEnum): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
exports.GooglePubSubPublish = void 0;
|
|
13
|
+
const pubsub_1 = require("@google-cloud/pubsub");
|
|
14
|
+
const PubSubModel_1 = require("../Models/PubSubModel");
|
|
15
|
+
class GooglePubSubPublish {
|
|
16
|
+
constructor(topicName) {
|
|
17
|
+
this._topicName = topicName;
|
|
18
|
+
}
|
|
19
|
+
createMessages(message, action, table) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const pubSubClient = new pubsub_1.PubSub();
|
|
22
|
+
const send = new PubSubModel_1.PubSubModel(message, action, table);
|
|
23
|
+
const topic = pubSubClient.topic(this._topicName);
|
|
24
|
+
const dataSend = JSON.stringify(send);
|
|
25
|
+
const data = Buffer.from(dataSend);
|
|
26
|
+
yield topic.publishMessage({ data });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.GooglePubSubPublish = GooglePubSubPublish;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
exports.GooglePubSubSubscription = void 0;
|
|
13
|
+
const pubsub_1 = require("@google-cloud/pubsub");
|
|
14
|
+
const PubSubModel_1 = require("../Models/PubSubModel");
|
|
15
|
+
class GooglePubSubSubscription {
|
|
16
|
+
constructor(subscriptionName) {
|
|
17
|
+
this._subscription = new pubsub_1.PubSub().subscription(subscriptionName);
|
|
18
|
+
}
|
|
19
|
+
listenMessages(eventEmitter) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
this._subscription.on('message', (message) => {
|
|
22
|
+
const data = JSON.parse(message.data.toString());
|
|
23
|
+
const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table);
|
|
24
|
+
eventEmitter.emit('event', [pubSubModel, message]);
|
|
25
|
+
});
|
|
26
|
+
this._subscription.on('error', (error) => {
|
|
27
|
+
console.error('Received error:', error);
|
|
28
|
+
eventEmitter.emit('error', error);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.GooglePubSubSubscription = GooglePubSubSubscription;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PubSubActionEnum = void 0;
|
|
4
|
+
var PubSubActionEnum;
|
|
5
|
+
(function (PubSubActionEnum) {
|
|
6
|
+
PubSubActionEnum["insert"] = "insert";
|
|
7
|
+
PubSubActionEnum["insertMany"] = "insert_many";
|
|
8
|
+
PubSubActionEnum["update"] = "update";
|
|
9
|
+
PubSubActionEnum["updateMany"] = "update_many";
|
|
10
|
+
PubSubActionEnum["delete"] = "delete";
|
|
11
|
+
})(PubSubActionEnum = exports.PubSubActionEnum || (exports.PubSubActionEnum = {}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare enum PubSubTableEnum {
|
|
2
|
+
bandeira = "bandeira",
|
|
3
|
+
cliente = "cliente",
|
|
4
|
+
clienteEndereco = "cliente_endereco",
|
|
5
|
+
clientePendente = "cliente_pendente",
|
|
6
|
+
configuracao = "configuracao",
|
|
7
|
+
concorrentes = "concorrentes",
|
|
8
|
+
empresa = "empresa",
|
|
9
|
+
empresaHorario = "empresa_horario",
|
|
10
|
+
empresaServico = "empresa_servico",
|
|
11
|
+
grupoDesconto = "grupo_desconto",
|
|
12
|
+
grupoDescontoLimite = "grupo_desconto_limite",
|
|
13
|
+
grupoPromocao = "grupo_promocao",
|
|
14
|
+
grupoEmpresa = "grupo_empresa",
|
|
15
|
+
item = "item",
|
|
16
|
+
itemTag = "item_tag",
|
|
17
|
+
promocao = "promocao",
|
|
18
|
+
promocaoCombo = "promocao_combo",
|
|
19
|
+
promocaoComboItem = "promocao_combo_item",
|
|
20
|
+
promocaoEmpresa = "promocao_empresa",
|
|
21
|
+
promocaoGrupoDesconto = "promocao_grupo_desconto",
|
|
22
|
+
promocaoRecorrencia = "promocao_recorrencia",
|
|
23
|
+
rede = "rede",
|
|
24
|
+
servico = "servico",
|
|
25
|
+
tag = "tag",
|
|
26
|
+
voucherDesconto = "voucher_desconto",
|
|
27
|
+
voucherDescontoLote = "voucher_desconto_lote",
|
|
28
|
+
voucherMigracao = "voucher_migracao",
|
|
29
|
+
voucherMigracaoLote = "voucher_migracao_lote"
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PubSubTableEnum = void 0;
|
|
4
|
+
var PubSubTableEnum;
|
|
5
|
+
(function (PubSubTableEnum) {
|
|
6
|
+
PubSubTableEnum["bandeira"] = "bandeira";
|
|
7
|
+
PubSubTableEnum["cliente"] = "cliente";
|
|
8
|
+
PubSubTableEnum["clienteEndereco"] = "cliente_endereco";
|
|
9
|
+
PubSubTableEnum["clientePendente"] = "cliente_pendente";
|
|
10
|
+
PubSubTableEnum["configuracao"] = "configuracao";
|
|
11
|
+
PubSubTableEnum["concorrentes"] = "concorrentes";
|
|
12
|
+
PubSubTableEnum["empresa"] = "empresa";
|
|
13
|
+
PubSubTableEnum["empresaHorario"] = "empresa_horario";
|
|
14
|
+
PubSubTableEnum["empresaServico"] = "empresa_servico";
|
|
15
|
+
PubSubTableEnum["grupoDesconto"] = "grupo_desconto";
|
|
16
|
+
PubSubTableEnum["grupoDescontoLimite"] = "grupo_desconto_limite";
|
|
17
|
+
PubSubTableEnum["grupoPromocao"] = "grupo_promocao";
|
|
18
|
+
PubSubTableEnum["grupoEmpresa"] = "grupo_empresa";
|
|
19
|
+
PubSubTableEnum["item"] = "item";
|
|
20
|
+
PubSubTableEnum["itemTag"] = "item_tag";
|
|
21
|
+
PubSubTableEnum["promocao"] = "promocao";
|
|
22
|
+
PubSubTableEnum["promocaoCombo"] = "promocao_combo";
|
|
23
|
+
PubSubTableEnum["promocaoComboItem"] = "promocao_combo_item";
|
|
24
|
+
PubSubTableEnum["promocaoEmpresa"] = "promocao_empresa";
|
|
25
|
+
PubSubTableEnum["promocaoGrupoDesconto"] = "promocao_grupo_desconto";
|
|
26
|
+
PubSubTableEnum["promocaoRecorrencia"] = "promocao_recorrencia";
|
|
27
|
+
PubSubTableEnum["rede"] = "rede";
|
|
28
|
+
PubSubTableEnum["servico"] = "servico";
|
|
29
|
+
PubSubTableEnum["tag"] = "tag";
|
|
30
|
+
PubSubTableEnum["voucherDesconto"] = "voucher_desconto";
|
|
31
|
+
PubSubTableEnum["voucherDescontoLote"] = "voucher_desconto_lote";
|
|
32
|
+
PubSubTableEnum["voucherMigracao"] = "voucher_migracao";
|
|
33
|
+
PubSubTableEnum["voucherMigracaoLote"] = "voucher_migracao_lote";
|
|
34
|
+
})(PubSubTableEnum = exports.PubSubTableEnum || (exports.PubSubTableEnum = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PubSubModel } from './../Models/PubSubModel';
|
|
2
|
+
export declare abstract class PubSubHandlerAction {
|
|
3
|
+
constructor(pubsubModel: PubSubModel);
|
|
4
|
+
protected _pubsubValueModel: PubSubModel;
|
|
5
|
+
handlerAction(): Promise<boolean>;
|
|
6
|
+
protected insert(): Promise<boolean>;
|
|
7
|
+
protected insertMany(): Promise<boolean>;
|
|
8
|
+
protected update(): Promise<boolean>;
|
|
9
|
+
protected updateMany(): Promise<boolean>;
|
|
10
|
+
protected delete(): Promise<boolean>;
|
|
11
|
+
protected buildData(): Object;
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
exports.PubSubHandlerAction = void 0;
|
|
13
|
+
class PubSubHandlerAction {
|
|
14
|
+
constructor(pubsubModel) {
|
|
15
|
+
this._pubsubValueModel = pubsubModel;
|
|
16
|
+
}
|
|
17
|
+
handlerAction() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
switch (this._pubsubValueModel.action) {
|
|
20
|
+
case 'insert':
|
|
21
|
+
return yield this.insert();
|
|
22
|
+
case 'insert_many':
|
|
23
|
+
return yield this.insertMany();
|
|
24
|
+
case 'update':
|
|
25
|
+
return yield this.update();
|
|
26
|
+
case 'update_many':
|
|
27
|
+
return yield this.updateMany();
|
|
28
|
+
case 'delete':
|
|
29
|
+
return yield this.delete();
|
|
30
|
+
default:
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
insert() {
|
|
36
|
+
throw new Error('Method insert PubSub handler action not implemented.');
|
|
37
|
+
}
|
|
38
|
+
insertMany() {
|
|
39
|
+
throw new Error('Method insert PubSub handler action not implemented.');
|
|
40
|
+
}
|
|
41
|
+
update() {
|
|
42
|
+
throw new Error('Method update PubSub handler action not implemented.');
|
|
43
|
+
}
|
|
44
|
+
updateMany() {
|
|
45
|
+
throw new Error('Method update PubSub handler action not implemented.');
|
|
46
|
+
}
|
|
47
|
+
delete() {
|
|
48
|
+
throw new Error('Method delete PubSub handler action not implemented.');
|
|
49
|
+
}
|
|
50
|
+
buildData() {
|
|
51
|
+
throw new Error('Method buildData PubSub handler action not implemented.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.PubSubHandlerAction = PubSubHandlerAction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CryptHelper = void 0;
|
|
4
|
+
const crypto = require('crypto');
|
|
5
|
+
const alg = 'aes-256-ctr';
|
|
6
|
+
const pwd = 'Macaco';
|
|
7
|
+
class CryptHelper {
|
|
8
|
+
static encrypt(mensagem) {
|
|
9
|
+
const cipher = crypto.createCipher(alg, pwd);
|
|
10
|
+
const crypted = cipher.update(mensagem, 'utf8', 'hex');
|
|
11
|
+
return crypted;
|
|
12
|
+
}
|
|
13
|
+
static decrypt(mensagem) {
|
|
14
|
+
const decipher = crypto.createDecipher(alg, pwd);
|
|
15
|
+
const plain = decipher.update(mensagem, 'hex', 'utf8');
|
|
16
|
+
return plain;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CryptHelper = CryptHelper;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HashHelper = void 0;
|
|
4
|
+
class HashHelper {
|
|
5
|
+
static criarHash(forceUppercase, length) {
|
|
6
|
+
const keygen = require('keygenerator');
|
|
7
|
+
return keygen._({ forceUppercase: forceUppercase, length: length });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.HashHelper = HashHelper;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberHelper = void 0;
|
|
4
|
+
class NumberHelper {
|
|
5
|
+
static convertBase(num, baseFrom, baseTo) {
|
|
6
|
+
return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
|
|
7
|
+
}
|
|
8
|
+
static convertBase10to36(num) {
|
|
9
|
+
return parseInt(num.toString(), 10).toString(36).toUpperCase();
|
|
10
|
+
}
|
|
11
|
+
static convertBase10to36WithZeroFill(num, size) {
|
|
12
|
+
return this.convertBase10to36(num).padStart(size, '0');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NumberHelper = NumberHelper;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromiseUtil = void 0;
|
|
4
|
+
class PromiseUtil {
|
|
5
|
+
static PromiseHelper(ms = Number(process.env.REQUEST_TIMEOUT)) {
|
|
6
|
+
return new Promise((reject) => {
|
|
7
|
+
const id = setTimeout(() => {
|
|
8
|
+
clearTimeout(id);
|
|
9
|
+
reject('Timeout in ' + ms + ' ms');
|
|
10
|
+
}, ms);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.PromiseUtil = PromiseUtil;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringHelper = void 0;
|
|
4
|
+
class StringHelper {
|
|
5
|
+
static removeSpecialCharactersFromString(str) {
|
|
6
|
+
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
7
|
+
}
|
|
8
|
+
static convertBooleanToString(string) {
|
|
9
|
+
switch (string.toLowerCase().trim()) {
|
|
10
|
+
case 'true':
|
|
11
|
+
case 'yes':
|
|
12
|
+
case '1':
|
|
13
|
+
return true;
|
|
14
|
+
case 'false':
|
|
15
|
+
case 'no':
|
|
16
|
+
case '0':
|
|
17
|
+
case null:
|
|
18
|
+
return false;
|
|
19
|
+
default:
|
|
20
|
+
return Boolean(string);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static camelToSnakeCase(string) {
|
|
24
|
+
return string.replace(/([A-Z])/g, (char) => `_${char.toLowerCase()}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.StringHelper = StringHelper;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
|
|
2
|
+
import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
|
|
3
|
+
export declare class PubSubModel {
|
|
4
|
+
readonly value: any;
|
|
5
|
+
readonly action: PubSubActionEnum;
|
|
6
|
+
readonly table: PubSubTableEnum;
|
|
7
|
+
constructor(value: object, action: PubSubActionEnum, table: PubSubTableEnum);
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PubSubModel = void 0;
|
|
4
|
+
class PubSubModel {
|
|
5
|
+
constructor(value, action, table) {
|
|
6
|
+
this.value = value;
|
|
7
|
+
this.action = action;
|
|
8
|
+
this.table = table;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.PubSubModel = PubSubModel;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { GooglePubSubSubscription
|
|
1
|
+
export { PubSubHandlerAction } from "./Handlers/PubSubHandlerAction";
|
|
2
|
+
export { GooglePubSubSubscription } from "./Class/GooglePubSubSubscription";
|
|
3
|
+
export { GooglePubSubPublish } from "./Class/GooglePubSubPublish";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports
|
|
6
|
-
var
|
|
7
|
-
exports
|
|
8
|
-
|
|
3
|
+
exports.GooglePubSubPublish = exports.GooglePubSubSubscription = exports.PubSubHandlerAction = void 0;
|
|
4
|
+
var PubSubHandlerAction_1 = require("./Handlers/PubSubHandlerAction");
|
|
5
|
+
Object.defineProperty(exports, "PubSubHandlerAction", { enumerable: true, get: function () { return PubSubHandlerAction_1.PubSubHandlerAction; } });
|
|
6
|
+
var GooglePubSubSubscription_1 = require("./Class/GooglePubSubSubscription");
|
|
7
|
+
Object.defineProperty(exports, "GooglePubSubSubscription", { enumerable: true, get: function () { return GooglePubSubSubscription_1.GooglePubSubSubscription; } });
|
|
8
|
+
var GooglePubSubPublish_1 = require("./Class/GooglePubSubPublish");
|
|
9
|
+
Object.defineProperty(exports, "GooglePubSubPublish", { enumerable: true, get: function () { return GooglePubSubPublish_1.GooglePubSubPublish; } });
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sim-node-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "Library from SIMLabs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"/dist"
|
|
9
9
|
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"tsc": "tsc",
|
|
12
|
+
"pub": "tsc && yarn publish"
|
|
13
|
+
},
|
|
10
14
|
"license": "ISC",
|
|
11
15
|
"dependencies": {
|
|
12
16
|
"@google-cloud/pubsub": "^3.0.1",
|
package/dist/google-pub-sub.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/google-pub-sub.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
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 = {}));
|
package/dist/hello-world.d.ts
DELETED
package/dist/hello-world.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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;
|