exodus-framework 2.0.696 → 2.0.699

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.
Files changed (79) hide show
  1. package/lib/app/settings.d.ts.map +1 -1
  2. package/lib/contracts/messaging.d.ts +28 -1
  3. package/lib/contracts/messaging.d.ts.map +1 -1
  4. package/lib/contracts/security.d.ts +11 -0
  5. package/lib/contracts/security.d.ts.map +1 -0
  6. package/lib/contracts/settings.d.ts +6 -0
  7. package/lib/contracts/settings.d.ts.map +1 -1
  8. package/lib/controllers/messaging/database.d.ts +9 -0
  9. package/lib/controllers/messaging/database.d.ts.map +1 -0
  10. package/lib/controllers/messaging/environment.d.ts +10 -0
  11. package/lib/controllers/messaging/environment.d.ts.map +1 -0
  12. package/lib/middlewares/access.d.ts.map +1 -1
  13. package/lib/middlewares/authentication.d.ts +1 -1
  14. package/lib/middlewares/authentication.d.ts.map +1 -1
  15. package/lib/models/Application.d.ts +13 -0
  16. package/lib/models/Application.d.ts.map +1 -0
  17. package/lib/models/Connection.d.ts +1 -0
  18. package/lib/models/Connection.d.ts.map +1 -1
  19. package/lib/models/EnvConnection.d.ts +9 -0
  20. package/lib/models/EnvConnection.d.ts.map +1 -0
  21. package/lib/models/index.d.ts +4 -0
  22. package/lib/models/index.d.ts.map +1 -1
  23. package/lib/routes/index.d.ts +2 -0
  24. package/lib/routes/index.d.ts.map +1 -0
  25. package/lib/routes/messaging/index.d.ts +4 -0
  26. package/lib/routes/messaging/index.d.ts.map +1 -0
  27. package/lib/services/rabitmq.d.ts.map +1 -1
  28. package/lib/services/security.d.ts +29 -0
  29. package/lib/services/security.d.ts.map +1 -0
  30. package/lib/services/sequelize.d.ts.map +1 -1
  31. package/lib/utils/index.d.ts +1 -0
  32. package/lib/utils/index.d.ts.map +1 -1
  33. package/package.json +3 -1
  34. package/lib/app/app.js +0 -84
  35. package/lib/app/controller.js +0 -95
  36. package/lib/app/core.js +0 -66
  37. package/lib/app/index.js +0 -60
  38. package/lib/app/service.js +0 -24
  39. package/lib/app/settings.js +0 -130
  40. package/lib/app/singleton.js +0 -29
  41. package/lib/contracts/console.js +0 -5
  42. package/lib/contracts/entity.js +0 -5
  43. package/lib/contracts/http.js +0 -50
  44. package/lib/contracts/index.js +0 -104
  45. package/lib/contracts/messaging.js +0 -14
  46. package/lib/contracts/service.js +0 -5
  47. package/lib/contracts/session.js +0 -5
  48. package/lib/contracts/settings.js +0 -5
  49. package/lib/contracts/singleton.js +0 -5
  50. package/lib/contracts/socket.js +0 -11
  51. package/lib/contracts/tenant.d.ts +0 -1
  52. package/lib/contracts/tenant.d.ts.map +0 -1
  53. package/lib/contracts/tenant.js +0 -1
  54. package/lib/controllers/api/file.js +0 -24
  55. package/lib/controllers/api/index.js +0 -13
  56. package/lib/controllers/index.js +0 -16
  57. package/lib/express.d.js +0 -5
  58. package/lib/index.js +0 -92
  59. package/lib/middlewares/access.js +0 -35
  60. package/lib/middlewares/authentication.js +0 -27
  61. package/lib/middlewares/file.js +0 -41
  62. package/lib/middlewares/index.js +0 -27
  63. package/lib/models/Connection.js +0 -50
  64. package/lib/models/index.js +0 -16
  65. package/lib/services/error.js +0 -49
  66. package/lib/services/express.js +0 -140
  67. package/lib/services/file.js +0 -65
  68. package/lib/services/index.js +0 -80
  69. package/lib/services/rabitmq.js +0 -87
  70. package/lib/services/redis.js +0 -60
  71. package/lib/services/sequelize.js +0 -238
  72. package/lib/services/socket.js +0 -56
  73. package/lib/services/task.js +0 -162
  74. package/lib/utils/api.js +0 -50
  75. package/lib/utils/database.js +0 -36
  76. package/lib/utils/date.js +0 -28
  77. package/lib/utils/index.js +0 -60
  78. package/lib/utils/logger.js +0 -55
  79. package/lib/utils/session.js +0 -23
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _controller = _interopRequireDefault(require("../app/controller"));
8
- var _multer = _interopRequireDefault(require("multer"));
9
- var fs = _interopRequireWildcard(require("fs"));
10
- var _path = _interopRequireDefault(require("path"));
11
- var _app = require("../app");
12
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- class FileMiddleware extends _controller.default {
16
- storage;
17
- constructor() {
18
- super();
19
- this.initStorage();
20
- }
21
- initStorage() {
22
- this.storage = _multer.default.diskStorage({
23
- destination: async (req, file, cb) => {
24
- !fs.existsSync(_app.Core.settings.getAppication().filePaths.temporary) && fs.mkdirSync(_app.Core.settings.getAppication().filePaths.temporary, {
25
- recursive: true
26
- });
27
- cb(null, _app.Core.settings.getAppication().filePaths.temporary);
28
- },
29
- filename: (req, file, cb) => {
30
- const name = Date.now() + _path.default.extname(file.originalname);
31
- cb(null, name);
32
- }
33
- });
34
- }
35
- upload = field => {
36
- return (0, _multer.default)({
37
- storage: this.storage
38
- }).single(field);
39
- };
40
- }
41
- var _default = exports.default = FileMiddleware;
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "AccessMiddleware", {
7
- enumerable: true,
8
- get: function () {
9
- return _access.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "AuthenticationMiddleware", {
13
- enumerable: true,
14
- get: function () {
15
- return _authentication.default;
16
- }
17
- });
18
- Object.defineProperty(exports, "FileMiddleware", {
19
- enumerable: true,
20
- get: function () {
21
- return _file.default;
22
- }
23
- });
24
- var _access = _interopRequireDefault(require("./access"));
25
- var _authentication = _interopRequireDefault(require("./authentication"));
26
- var _file = _interopRequireDefault(require("./file"));
27
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Connection = void 0;
7
- var _sequelize = require("sequelize");
8
- var _database = require("../utils/database");
9
- class Connection extends _sequelize.Model {}
10
- exports.Connection = Connection;
11
- Connection.init({
12
- uuid: {
13
- type: _sequelize.DataTypes.UUID,
14
- defaultValue: _sequelize.DataTypes.UUIDV4,
15
- primaryKey: true,
16
- allowNull: false,
17
- autoIncrement: false
18
- },
19
- name: {
20
- type: _sequelize.DataTypes.STRING(200),
21
- allowNull: false
22
- },
23
- dialect: {
24
- type: _sequelize.DataTypes.ENUM('mysql', 'postgres', 'sqlite', 'mariadb', 'mssql', 'db2', 'snowflake', 'oracle'),
25
- allowNull: false
26
- },
27
- username: {
28
- type: _sequelize.DataTypes.STRING(100),
29
- allowNull: false
30
- },
31
- password: {
32
- type: _sequelize.DataTypes.STRING(100),
33
- allowNull: false
34
- },
35
- active: {
36
- type: _sequelize.DataTypes.BOOLEAN,
37
- defaultValue: true
38
- },
39
- params: {
40
- type: _sequelize.DataTypes.JSON,
41
- defaultValue: {},
42
- allowNull: true
43
- }
44
- }, {
45
- tableName: 'connections',
46
- sequelize: _database.masterDB,
47
- indexes: [{
48
- fields: ['name']
49
- }]
50
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Connection = require("./Connection");
7
- Object.keys(_Connection).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _Connection[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _Connection[key];
14
- }
15
- });
16
- });
@@ -1,49 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ApplicationHttpException = exports.ApplicationException = void 0;
7
- var _logger = _interopRequireDefault(require("../utils/logger"));
8
- var _http = require("../contracts/http");
9
- var _core = _interopRequireDefault(require("../app/core"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- class ExodusErrorBase extends _core.default {
12
- constructor() {
13
- super();
14
- }
15
- }
16
- class ApplicationHttpException extends ExodusErrorBase {
17
- message;
18
- statusCode;
19
- level;
20
- data;
21
- constructor(message, statusCode = _http.EHttpResponseCode.iternalErro, level = 'error', data) {
22
- super();
23
- this.message = message;
24
- this.statusCode = statusCode;
25
- this.level = level;
26
- this.data = data;
27
- this.handle();
28
- }
29
- handle() {
30
- (0, _logger.default)().warn(this.message, this.statusCode);
31
- (0, _logger.default)().warn(this.data);
32
- }
33
- }
34
- exports.ApplicationHttpException = ApplicationHttpException;
35
- class ApplicationException extends ExodusErrorBase {
36
- message;
37
- error;
38
- constructor(message, error) {
39
- super();
40
- this.message = message;
41
- this.error = error;
42
- this.handle();
43
- }
44
- handle() {
45
- this.log(`${this.message}`, 'danger');
46
- (0, _logger.default)().error(this.error);
47
- }
48
- }
49
- exports.ApplicationException = ApplicationException;
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _service = _interopRequireDefault(require("../app/service"));
8
- var _logger = _interopRequireDefault(require("../utils/logger"));
9
- var _cors = _interopRequireDefault(require("cors"));
10
- var _express = _interopRequireDefault(require("express"));
11
- require("express-async-errors");
12
- var http = _interopRequireWildcard(require("http"));
13
- var _pinoHttp = _interopRequireDefault(require("pino-http"));
14
- var _http2 = require("../contracts/http");
15
- var _error = require("./error");
16
- var _app = require("../app");
17
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
- class ExpressService extends _service.default {
21
- server;
22
- mainRouter;
23
- async init() {
24
- if (!this.mainRouter) throw new _error.ApplicationException('Need router'); //!sem router
25
-
26
- const expss = (0, _express.default)();
27
- const pino = (0, _pinoHttp.default)({
28
- logger: (0, _logger.default)()
29
- });
30
- this.server = http.createServer(expss);
31
- expss.use('/public', _express.default.static(_app.Core.settings.getHttp().publicPath));
32
- expss.use(pino);
33
- expss.use(this.responseTypeMiddleware.bind(this));
34
- expss.use(_express.default.json());
35
- expss.use(_express.default.urlencoded({
36
- extended: false
37
- }));
38
- expss.use((0, _cors.default)({
39
- origin: '*'
40
- }));
41
- expss.use(this.mainRouter);
42
- expss.use(this.handleAuthorizationFailure.bind(this));
43
- expss.use(this.handleNotFoud.bind(this));
44
- expss.use(this.handleRequestProcessFailure.bind(this));
45
- this.server.listen(_app.Core.settings.getAppication().port, () => {
46
- (0, _logger.default)().info(`servidor iniciado na porta: ${_app.Core.settings.getAppication().port}`);
47
- this.log(`🌍 Http Server Listering On: ${_app.Core.settings.getAppication().port}`, 'success');
48
- });
49
- }
50
- getHttpServer() {
51
- return this.server;
52
- }
53
- sendResponse(objResponse, res, next) {
54
- objResponse.timestamp = Date.now();
55
- if (!objResponse.code) objResponse.code = _http2.EHttpResponseCode.successfullyProcessedInformation;
56
- res.status(objResponse.code);
57
- if (objResponse.location) {
58
- res.location(objResponse.location);
59
- delete objResponse.location;
60
- }
61
- let FormulatedResponse;
62
- switch (_app.Core.settings.getHttp().formulation) {
63
- case 'direct':
64
- if (objResponse['data']) {
65
- FormulatedResponse = objResponse.data;
66
- } else {
67
- FormulatedResponse = objResponse;
68
- }
69
- break;
70
- case 'standart':
71
- FormulatedResponse = objResponse;
72
- break;
73
- default:
74
- FormulatedResponse = objResponse;
75
- break;
76
- }
77
- if (next) {
78
- res.write(JSON.stringify(FormulatedResponse));
79
- next();
80
- } else {
81
- res.send(JSON.stringify(FormulatedResponse));
82
- }
83
- }
84
- responseTypeMiddleware(req, res, next) {
85
- res.contentType('application/json');
86
- next();
87
- }
88
-
89
- //* Handlers
90
- handleNotFoud(req, res) {
91
- this.sendResponse({
92
- message: 'Endereço não encontrado',
93
- type: 'warning',
94
- status: false,
95
- code: _http2.EHttpResponseCode.informationNotFound
96
- }, res);
97
- }
98
- handleAuthorizationFailure(err, req, res, next) {
99
- if (err.name === 'UnauthorizedError') {
100
- throw new _error.ApplicationHttpException('Falha na autorização', _http2.EHttpResponseCode.informationUnauthorized);
101
- } else {
102
- next(err);
103
- }
104
- }
105
- handleRequestProcessFailure = async (err, req, res, _) => {
106
- if (err instanceof _error.ApplicationHttpException) {
107
- return this.sendResponse({
108
- message: err.message,
109
- type: err.level,
110
- status: false,
111
- code: err.statusCode,
112
- data: err.data
113
- }, res);
114
- }
115
- this.sendResponse({
116
- message: 'Houve um erro ao acessar este recurso',
117
- type: 'error',
118
- status: false,
119
- code: 500
120
- }, res);
121
- new _error.ApplicationException('Erro não tratado em uma rota.', err);
122
- };
123
- async checkRequest(params) {
124
- let pass = true;
125
- const need = [];
126
- for (const [key, param] of Object.entries(params)) {
127
- if (!param || param === null || param.length < 1 || typeof param === 'string' && param === '' || typeof param === 'object' && Object.values(param).length < 1) {
128
- pass = false;
129
- need.push(key);
130
- }
131
- }
132
- if (!pass) throw new _error.ApplicationHttpException('Requisição incompleta', _http2.EHttpResponseCode.incompleteRequest, 'error', {
133
- need
134
- });
135
- }
136
- registerRouter(router) {
137
- this.mainRouter = router;
138
- }
139
- }
140
- var _default = exports.default = ExpressService;
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _service = _interopRequireDefault(require("../app/service"));
8
- var _logger = _interopRequireDefault(require("../utils/logger"));
9
- var fs = _interopRequireWildcard(require("fs"));
10
- var fsPromisses = _interopRequireWildcard(require("fs/promises"));
11
- var _app = require("../app");
12
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- class FileService extends _service.default {
16
- async init() {
17
- await this.checkPaths();
18
- await this.cleanTemp();
19
- }
20
- async checkPaths() {
21
- for (const path of Object.values(_app.Core.settings.getAppication().filePaths)) {
22
- !fs.existsSync(path) && fs.mkdirSync(path, {
23
- recursive: true
24
- });
25
- }
26
- }
27
- async cleanTemp() {
28
- this.listFiles('temporary', files => {
29
- files.forEach(file => {
30
- const p = _app.Core.settings.getAppication().filePaths.temporary + '/' + file;
31
- fs.rmSync(p, {
32
- recursive: true
33
- });
34
- });
35
- });
36
- }
37
- async save(filename, destiny) {
38
- const p = _app.Core.settings.getAppication().filePaths.temporary + '/' + filename;
39
- const d = _app.Core.settings.getAppication().filePaths[destiny] + '/' + filename;
40
- return await fsPromisses.rename(p, d).then(() => d).catch(e => {
41
- (0, _logger.default)().error({
42
- filename,
43
- destiny,
44
- erro: e
45
- }, 'Não foi possível salvar o arquivo');
46
- return false;
47
- });
48
- }
49
- async delete(filename, destiny) {
50
- const d = _app.Core.settings.getAppication().filePaths[destiny] + '/' + filename;
51
- return await fsPromisses.unlink(d).then(() => true).catch(e => {
52
- (0, _logger.default)().error({
53
- filename,
54
- destiny,
55
- erro: e
56
- }, 'Não foi possível deletar o arquivo');
57
- return false;
58
- });
59
- }
60
- listFiles(origin, cb) {
61
- const p = _app.Core.settings.getAppication().filePaths[origin];
62
- fs.readdir(p, (_, file) => cb(file));
63
- }
64
- }
65
- var _default = exports.default = FileService;
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- ExpressService: true,
8
- FileService: true,
9
- RabbitMQService: true,
10
- RedisService: true,
11
- SequelizeService: true,
12
- SocketIOService: true
13
- };
14
- Object.defineProperty(exports, "ExpressService", {
15
- enumerable: true,
16
- get: function () {
17
- return _express.default;
18
- }
19
- });
20
- Object.defineProperty(exports, "FileService", {
21
- enumerable: true,
22
- get: function () {
23
- return _file.default;
24
- }
25
- });
26
- Object.defineProperty(exports, "RabbitMQService", {
27
- enumerable: true,
28
- get: function () {
29
- return _rabitmq.default;
30
- }
31
- });
32
- Object.defineProperty(exports, "RedisService", {
33
- enumerable: true,
34
- get: function () {
35
- return _redis.default;
36
- }
37
- });
38
- Object.defineProperty(exports, "SequelizeService", {
39
- enumerable: true,
40
- get: function () {
41
- return _sequelize.default;
42
- }
43
- });
44
- Object.defineProperty(exports, "SocketIOService", {
45
- enumerable: true,
46
- get: function () {
47
- return _socket.default;
48
- }
49
- });
50
- var _error = require("./error");
51
- Object.keys(_error).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
54
- if (key in exports && exports[key] === _error[key]) return;
55
- Object.defineProperty(exports, key, {
56
- enumerable: true,
57
- get: function () {
58
- return _error[key];
59
- }
60
- });
61
- });
62
- var _express = _interopRequireDefault(require("./express"));
63
- var _file = _interopRequireDefault(require("./file"));
64
- var _rabitmq = _interopRequireDefault(require("./rabitmq"));
65
- var _redis = _interopRequireDefault(require("./redis"));
66
- var _sequelize = _interopRequireDefault(require("./sequelize"));
67
- var _socket = _interopRequireDefault(require("./socket"));
68
- var _task = require("./task");
69
- Object.keys(_task).forEach(function (key) {
70
- if (key === "default" || key === "__esModule") return;
71
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
72
- if (key in exports && exports[key] === _task[key]) return;
73
- Object.defineProperty(exports, key, {
74
- enumerable: true,
75
- get: function () {
76
- return _task[key];
77
- }
78
- });
79
- });
80
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _service = _interopRequireDefault(require("../app/service"));
8
- var _amqplib = _interopRequireDefault(require("amqplib"));
9
- var _error = require("./error");
10
- var _app = require("../app");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- /**
13
- * Serviço de Mensageria
14
- *
15
- * @class RabbitMQService
16
- * @extends {Service}
17
- * @implements {IService}
18
- */
19
- class RabbitMQService extends _service.default {
20
- connection;
21
- channel;
22
- connected;
23
- mainRouter;
24
-
25
- //# Initialization
26
- constructor() {
27
- super();
28
- }
29
- async init() {
30
- if (!this.mainRouter) throw new _error.ApplicationException('Need router'); //!sem router
31
- await this.connect();
32
- }
33
- registerHandles() {
34
- for (const [queue, handle] of Object.entries(this.mainRouter)) {
35
- this.consumeFromQueue(queue, handle);
36
- }
37
- }
38
- async connect() {
39
- if (this.connected && this.channel) return;else this.connected = true;
40
- try {
41
- this.log(`⌛️ Connecting to Rabbit-MQ Server`);
42
- this.connection = await _amqplib.default.connect(`amqp://${_app.Core.settings.getMessaging().user}:${_app.Core.settings.getMessaging().pass}@${_app.Core.settings.getMessaging().host}:5672`);
43
- this.log(`✅ Rabbit MQ Connection is ready`);
44
- this.channel = await this.connection.createChannel();
45
- this.log(`🛸 Created RabbitMQ Channel successfully`);
46
- this.registerHandles();
47
- } catch (error) {
48
- new _error.ApplicationException(`Not connected to MQ Server`, error);
49
- }
50
- }
51
-
52
- //# Common
53
- async sendToQueue(queue, data) {
54
- try {
55
- if (!this.channel) {
56
- await this.connect();
57
- }
58
- this.channel.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
59
- } catch (error) {
60
- new _error.ApplicationException('Houve um erro no envio de uma mensagem para o rabitmq', error);
61
- }
62
- }
63
- async consumeFromQueue(queue, callBack) {
64
- await this.channel.assertQueue(queue, {
65
- durable: true
66
- });
67
- this.channel.consume(queue, msg => {
68
- {
69
- if (!msg) {
70
- return this.log(`Invalid incoming message in`);
71
- }
72
- try {
73
- callBack(JSON.parse(msg.content.toString()), () => this.channel.ack(msg));
74
- } catch (error) {
75
- this.channel.ack(msg);
76
- new _error.ApplicationException('Error on parsing message from queue', error);
77
- }
78
- }
79
- }, {
80
- noAck: false
81
- });
82
- }
83
- registerRouter(router) {
84
- this.mainRouter = router;
85
- }
86
- }
87
- var _default = exports.default = RabbitMQService;
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _service = _interopRequireDefault(require("../app/service"));
8
- var _redis = require("redis");
9
- var _error = require("./error");
10
- var _app = require("../app");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- /**
13
- * Serviço de cache
14
- *
15
- * @class RedisService
16
- * @extends {Service}
17
- * @implements {IService}
18
- */
19
- class RedisService extends _service.default {
20
- client;
21
-
22
- //* Initialization
23
- async init() {
24
- this.client = (0, _redis.createClient)({
25
- url: `redis://${_app.Core.settings.getCache().host}:${_app.Core.settings.getCache().port}`,
26
- password: _app.Core.settings.getCache().password
27
- });
28
- await this.connect();
29
- }
30
- connect() {
31
- this.client.on('error', this.onClientError.bind(this));
32
- return new Promise(resolve => {
33
- this.client.connect().then(() => {
34
- this.log('Redis client connected.', 'success');
35
- resolve(true);
36
- });
37
- });
38
- }
39
- async disconnect() {
40
- await this.client.quit();
41
- }
42
-
43
- //* Common
44
- async setValue(key, value) {
45
- await this.client.set(key, value);
46
- }
47
- async getValue(key) {
48
- const value = await this.client.get(key);
49
- return value;
50
- }
51
- async deleteValue(key) {
52
- await this.client.del(key);
53
- }
54
-
55
- //* Events
56
- onClientError(err) {
57
- new _error.ApplicationException('Error on init redis client', err);
58
- }
59
- }
60
- var _default = exports.default = RedisService;