exodus-framework 2.1.1007 → 2.1.1009
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.
@@ -27,9 +27,9 @@ declare class DatabaseService extends Service {
|
|
27
27
|
createDB(hostId: string, name: string): Promise<boolean>;
|
28
28
|
deleteDB(hostId: string, name: string): Promise<boolean>;
|
29
29
|
hasDB(hostId: string, name: string): Promise<boolean>;
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
execTenantMigrates(connection: Sequelize): Promise<void>;
|
31
|
+
execCoreMigrates(connection: Sequelize): Promise<void>;
|
32
|
+
execServiceMigrate(): Promise<void>;
|
33
33
|
}
|
34
34
|
export default DatabaseService;
|
35
35
|
//# sourceMappingURL=database.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/services/database.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEnE,OAAO,EAAsB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAgB,SAAS,EAAE,MAAM,WAAW,CAAC;AAKpD,cAAM,eAAgB,SAAQ,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,WAAW,CAAyB;IAE/B,aAAa;IAWb,OAAO;
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/services/database.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEnE,OAAO,EAAsB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAg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Service {
|
|
33
33
|
await _utils.mainDb.sync({
|
34
34
|
alter: true
|
35
35
|
});
|
36
|
-
await this.
|
37
|
-
await this.
|
36
|
+
await this.execServiceMigrate(); // migrar atualizações do serviço
|
37
|
+
await this.execTenantMigrates(_utils.mainDb); //migrar atualizações do tenant para o serviço principal (este ainda é usado como serviço/tenant para supersu)
|
38
38
|
this.log('✅ Connected service database sucessfully', 'success');
|
39
|
+
if (process.env.DB_INIT_WITH_MIGRATE === 'true') {
|
40
|
+
this.log('⌚ Migrando entidades do serviço...', 'warning');
|
41
|
+
const tenants = await this.getTenantIds();
|
42
|
+
for (const tenantId of tenants) {
|
43
|
+
const sequelize = await this.getConnection(tenantId);
|
44
|
+
if (sequelize) {
|
45
|
+
this.log(`⌚ Migrando entidades do tenant ${tenantId}...`, 'warning');
|
46
|
+
await this.execTenantMigrates(sequelize);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
39
50
|
return true;
|
40
51
|
} catch (error) {
|
41
52
|
_logger.default.logger().error(error, `Not connected Sequelize to database`);
|
@@ -68,8 +79,8 @@ class DatabaseService extends _app.Service {
|
|
68
79
|
}
|
69
80
|
const password = data.payload;
|
70
81
|
const connection = await this.createConnection(address, port, database, dbHost.username, password, dbHost.dialect);
|
71
|
-
await this.
|
72
|
-
await this.
|
82
|
+
await this.execCoreMigrates(connection);
|
83
|
+
await this.execTenantMigrates(connection);
|
73
84
|
this.connections.set(tenantId, connection);
|
74
85
|
this.log(`Conexão para o tenant ${tenantId} foi criada com sucesso`, 'success');
|
75
86
|
}
|
@@ -188,8 +199,8 @@ class DatabaseService extends _app.Service {
|
|
188
199
|
await connection.query(`CREATE DATABASE ${dbQueryName};`);
|
189
200
|
this.log(`Database "${dbQueryName}" has been created.`);
|
190
201
|
await connection.query(`USE ${dbQueryName};`);
|
191
|
-
await this.
|
192
|
-
await this.
|
202
|
+
await this.execCoreMigrates(connection);
|
203
|
+
await this.execTenantMigrates(connection);
|
193
204
|
return true;
|
194
205
|
} else {
|
195
206
|
this.log(`Database "${dbQueryName}" already exists.`);
|
@@ -244,7 +255,7 @@ class DatabaseService extends _app.Service {
|
|
244
255
|
* @param {Sequelize} connection
|
245
256
|
* @memberof DatabaseService
|
246
257
|
*/
|
247
|
-
async
|
258
|
+
async execTenantMigrates(connection) {
|
248
259
|
const migrations = _app.Core.settings.getDatabase().migrationsPath;
|
249
260
|
const umzung = new _umzug.Umzug({
|
250
261
|
migrations: {
|
@@ -265,7 +276,7 @@ class DatabaseService extends _app.Service {
|
|
265
276
|
* @param {Sequelize} connection
|
266
277
|
* @memberof DatabaseService
|
267
278
|
*/
|
268
|
-
async
|
279
|
+
async execCoreMigrates(connection) {
|
269
280
|
const migrations = _path.default.resolve(__dirname, '../models/migrations');
|
270
281
|
const umzung = new _umzug.Umzug({
|
271
282
|
migrations: {
|
@@ -285,7 +296,7 @@ class DatabaseService extends _app.Service {
|
|
285
296
|
*
|
286
297
|
* @memberof DatabaseService
|
287
298
|
*/
|
288
|
-
async
|
299
|
+
async execServiceMigrate() {
|
289
300
|
const path = `${_app.Core.settings.getDatabase().migrationsPath}/main`;
|
290
301
|
(0, _fs.mkdirSync)(path, {
|
291
302
|
recursive: true
|
package/lib/services/logger.d.ts
CHANGED
@@ -2,17 +2,17 @@ import { Logger } from 'pino';
|
|
2
2
|
import Managed from '../app/classes/managed';
|
3
3
|
declare class LoggerService extends Managed {
|
4
4
|
private static loggerInstance;
|
5
|
-
private path;
|
5
|
+
private static path;
|
6
6
|
onInit(): Promise<void>;
|
7
7
|
onMasterInit(): Promise<void>;
|
8
8
|
private createLogger;
|
9
|
-
reservedFileLog(title: string, filename: string, ...args: any[]): Promise<void>;
|
9
|
+
static reservedFileLog(title: string, filename: string, ...args: any[]): Promise<void>;
|
10
10
|
static logger(): Logger<never>;
|
11
11
|
private compressLogFolder;
|
12
12
|
private backupLogs;
|
13
13
|
private cleanBackupLogs;
|
14
|
-
private toObject;
|
15
|
-
private writeToLog;
|
14
|
+
private static toObject;
|
15
|
+
private static writeToLog;
|
16
16
|
}
|
17
17
|
export default LoggerService;
|
18
18
|
//# sourceMappingURL=logger.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/services/logger.ts"],"names":[],"mappings":"AAEA,OAAa,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAQ7C,cAAM,aAAc,SAAQ,OAAO;IACjC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAgB;IAC7C,OAAO,CAAC,IAAI,CAAS;
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/services/logger.ts"],"names":[],"mappings":"AAEA,OAAa,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAQ7C,cAAM,aAAc,SAAQ,OAAO;IACjC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAgB;IAC7C,OAAO,CAAC,MAAM,CAAC,IAAI,CAAS;IAEf,MAAM;IAON,YAAY;YAOX,YAAY;WA2DN,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;WAOrE,MAAM;YAIN,iBAAiB;YA2BjB,UAAU;YA2BV,eAAe;IAyB7B,OAAO,CAAC,MAAM,CAAC,QAAQ;IAIvB,OAAO,CAAC,MAAM,CAAC,UAAU;CAO1B;AACD,eAAe,aAAa,CAAC"}
|
package/lib/services/logger.js
CHANGED
@@ -18,7 +18,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
19
19
|
class LoggerService extends _managed.default {
|
20
20
|
static loggerInstance;
|
21
|
-
path;
|
21
|
+
static path;
|
22
22
|
async onInit() {
|
23
23
|
super.onInit();
|
24
24
|
if (!LoggerService.loggerInstance) {
|
@@ -34,8 +34,8 @@ class LoggerService extends _managed.default {
|
|
34
34
|
await this.cleanBackupLogs();
|
35
35
|
}
|
36
36
|
async createLogger() {
|
37
|
-
|
38
|
-
await (0, _promises.mkdir)(
|
37
|
+
LoggerService.path = _path.default.resolve(_core.default.settings.getLogger().path, (0, _dateFns.format)(_exodus.default.getStartedAt(), 'dd-MM-yyyy'), (0, _dateFns.format)(_exodus.default.getStartedAt(), 'HH_mm'));
|
38
|
+
await (0, _promises.mkdir)(LoggerService.path, {
|
39
39
|
recursive: true
|
40
40
|
});
|
41
41
|
const isDev = process.argv.includes('--dev');
|
@@ -43,42 +43,42 @@ class LoggerService extends _managed.default {
|
|
43
43
|
level: 'info',
|
44
44
|
target: '../utils/logger-transport' + (isDev ? '.ts' : '.js'),
|
45
45
|
options: {
|
46
|
-
destination: _path.default.join(
|
46
|
+
destination: _path.default.join(LoggerService.path, 'info.json'),
|
47
47
|
level: 'info'
|
48
48
|
}
|
49
49
|
}, {
|
50
50
|
level: 'error',
|
51
51
|
target: '../utils/logger-transport' + (isDev ? '.ts' : '.js'),
|
52
52
|
options: {
|
53
|
-
destination: _path.default.join(
|
53
|
+
destination: _path.default.join(LoggerService.path, 'error.json'),
|
54
54
|
level: 'error'
|
55
55
|
}
|
56
56
|
}, {
|
57
57
|
level: 'debug',
|
58
58
|
target: '../utils/logger-transport' + (isDev ? '.ts' : '.js'),
|
59
59
|
options: {
|
60
|
-
destination: _path.default.join(
|
60
|
+
destination: _path.default.join(LoggerService.path, 'debug.json'),
|
61
61
|
level: 'debug'
|
62
62
|
}
|
63
63
|
}, {
|
64
64
|
level: 'warn',
|
65
65
|
target: '../utils/logger-transport' + (isDev ? '.ts' : '.js'),
|
66
66
|
options: {
|
67
|
-
destination: _path.default.join(
|
67
|
+
destination: _path.default.join(LoggerService.path, 'warn.json'),
|
68
68
|
level: 'warn'
|
69
69
|
}
|
70
70
|
}, {
|
71
71
|
level: 'fatal',
|
72
72
|
target: '../utils/logger-transport' + (isDev ? '.ts' : '.js'),
|
73
73
|
options: {
|
74
|
-
destination: _path.default.join(
|
74
|
+
destination: _path.default.join(LoggerService.path, 'fatal.json'),
|
75
75
|
level: 'fatal'
|
76
76
|
}
|
77
77
|
}, {
|
78
78
|
level: 'trace',
|
79
79
|
target: '../utils/logger-transport' + (isDev ? '.ts' : '.js'),
|
80
80
|
options: {
|
81
|
-
destination: _path.default.join(
|
81
|
+
destination: _path.default.join(LoggerService.path, 'trace.json'),
|
82
82
|
level: 'trace'
|
83
83
|
}
|
84
84
|
}];
|
@@ -99,10 +99,10 @@ class LoggerService extends _managed.default {
|
|
99
99
|
targets
|
100
100
|
}));
|
101
101
|
}
|
102
|
-
async reservedFileLog(title, filename, ...args) {
|
102
|
+
static async reservedFileLog(title, filename, ...args) {
|
103
103
|
if (args.length < 1) return;
|
104
|
-
const obj =
|
105
|
-
|
104
|
+
const obj = LoggerService.toObject(args);
|
105
|
+
LoggerService.writeToLog(filename, title, JSON.stringify(obj, null, 2));
|
106
106
|
}
|
107
107
|
static logger() {
|
108
108
|
return LoggerService.loggerInstance;
|
@@ -180,14 +180,14 @@ class LoggerService extends _managed.default {
|
|
180
180
|
}
|
181
181
|
this.log(`🗑️ Limpeza de ${count} backups concluída`, 'success');
|
182
182
|
}
|
183
|
-
toObject(data) {
|
183
|
+
static toObject(data) {
|
184
184
|
return JSON.parse(JSON.stringify(data, null, 2));
|
185
185
|
}
|
186
|
-
writeToLog(filename, message, data) {
|
186
|
+
static writeToLog(filename, message, data) {
|
187
187
|
const date = new Date();
|
188
188
|
const logMessage = `[${(0, _dateFns.format)(date, 'HH:mm:ss')}][${message}]: ${data}\n`;
|
189
|
-
console.log('salvando', `${
|
190
|
-
fs.appendFileSync(`${
|
189
|
+
console.log('salvando', `${LoggerService.path}/${filename}.log`);
|
190
|
+
fs.appendFileSync(`${LoggerService.path}/${filename}.log`, logMessage);
|
191
191
|
}
|
192
192
|
}
|
193
193
|
var _default = exports.default = LoggerService;
|