exodus-framework 2.0.952 → 2.0.954
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/lib/services/database.d.ts +2 -0
- package/lib/services/database.d.ts.map +1 -1
- package/lib/services/database.js +25 -3
- package/lib/services/sequelize.d.ts +0 -1
- package/lib/services/sequelize.d.ts.map +1 -1
- package/lib/services/sequelize.js +3 -13
- package/lib/utils/database.d.ts +0 -1
- package/lib/utils/database.d.ts.map +1 -1
- package/lib/utils/database.js +11 -9
- package/package.json +1 -1
@@ -6,6 +6,8 @@ declare class DatabaseService extends Service {
|
|
6
6
|
private entities;
|
7
7
|
private connections;
|
8
8
|
onServiceInit(): Promise<void>;
|
9
|
+
onStart(): Promise<boolean>;
|
10
|
+
onStartFail(): Promise<void>;
|
9
11
|
private initConnection;
|
10
12
|
createConnection(host: string, port: number, database: string, username: string, password: string, dialect: Dialect): Promise<Sequelize>;
|
11
13
|
getConnection(tenantId: string): Promise<Sequelize>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/services/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACnE,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;AAIpD,cAAM,eAAgB,SAAQ,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,WAAW,CAAyB;IAE/B,aAAa;
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/services/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACnE,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;AAIpD,cAAM,eAAgB,SAAQ,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,WAAW,CAAyB;IAE/B,aAAa;IAWb,OAAO;IAgBP,WAAW;YAMV,cAAc;IA0Cf,gBAAgB,CAC3B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO;IAwBL,aAAa,CAAC,QAAQ,EAAE,MAAM;IAQ9B,YAAY;IAKZ,oBAAoB,CAAC,QAAQ,EAAE,MAAM;YAMpC,UAAU;IASX,SAAS,CAAC,CAAC,SAAS,YAAY,CAAC,KAAK,CAAC,EAClD,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC5B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAU1B,OAAO,CAAC,qBAAqB;CAG9B;AAED,eAAe,eAAe,CAAC"}
|
package/lib/services/database.js
CHANGED
@@ -19,7 +19,26 @@ class DatabaseService extends _app.Service {
|
|
19
19
|
|
20
20
|
// para busca rápidas
|
21
21
|
this.connections.set(_app.Core.settings.getDatabase().service.database, _utils.serviceDB);
|
22
|
-
this.
|
22
|
+
this.startAttemptDelay = 5 * 1000;
|
23
|
+
this.maxStartAttempts = 3;
|
24
|
+
}
|
25
|
+
async onStart() {
|
26
|
+
this.log(`⌛️ Connecting Sequelize to database: ${this.currentStartAttempts}/${this.maxStartAttempts}`);
|
27
|
+
try {
|
28
|
+
await _utils.serviceDB.authenticate();
|
29
|
+
await _utils.serviceDB.sync({
|
30
|
+
alter: true
|
31
|
+
});
|
32
|
+
this.log('✅ Connected service database sucessfully', 'success');
|
33
|
+
return true;
|
34
|
+
} catch (error) {
|
35
|
+
(0, _utils.logger)().error(error, `Not connected Sequelize to database`);
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
async onStartFail() {
|
40
|
+
await super.onStartFail();
|
41
|
+
this.log(`Not possible to connect database`, 'danger');
|
23
42
|
}
|
24
43
|
|
25
44
|
//* Connection
|
@@ -57,7 +76,8 @@ class DatabaseService extends _app.Service {
|
|
57
76
|
timestamps: true
|
58
77
|
},
|
59
78
|
timezone: '-03:00',
|
60
|
-
logging: _app.Core.settings.getDatabase().service.log
|
79
|
+
logging: _app.Core.settings.getDatabase().service.log,
|
80
|
+
pool: _app.Core.settings.getDatabase().service.pool
|
61
81
|
});
|
62
82
|
try {
|
63
83
|
await sequelize.authenticate();
|
@@ -95,7 +115,9 @@ class DatabaseService extends _app.Service {
|
|
95
115
|
const k = `${tenantId}#${entity.name}`;
|
96
116
|
const connection = await this.getConnection(tenantId);
|
97
117
|
const loadedEntity = entity.initialize(connection);
|
98
|
-
await loadedEntity.sync(
|
118
|
+
await loadedEntity.sync({
|
119
|
+
alter: true
|
120
|
+
});
|
99
121
|
this.entities.set(k, loadedEntity);
|
100
122
|
}
|
101
123
|
async getEntity(model, tenantId) {
|
@@ -5,7 +5,6 @@ import { EnvDBHost } from '../models';
|
|
5
5
|
import { StaticServiceModel } from '../contracts';
|
6
6
|
declare class SequelizeService extends Service {
|
7
7
|
serviceDB: Sequelize;
|
8
|
-
masterDB: Sequelize;
|
9
8
|
models: StaticServiceModel<any>[];
|
10
9
|
connections: Map<string, Sequelize>;
|
11
10
|
initializedModels: Map<string, ModelStatic<any>>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sequelize.d.ts","sourceRoot":"","sources":["../../src/services/sequelize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EA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QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAiBvC,MAAM,CAAC,QAAQ,EAAE,MAAM;IA2BvB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS;IAkBpE,SAAS,CAAC,QAAQ,EAAE,MAAM;IAK1B,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,SAAI;IAe/B,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;IA2CpD,cAAc,CAAC,IAAI,EAAE;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;KAClB;IA4BY,WAAW,CAAC,QAAQ,EAAE,MAAM;IAe5B,QAAQ,CAAC,CAAC,SAAS,YAAY,CAAC,KAAK,CAAC,EACjD,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC5B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;WAWZ,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE;IAGjD,UAAU;CAOxB;AAED,eAAe,gBAAgB,CAAC"}
|
@@ -13,16 +13,18 @@ var _database = require("../utils/database");
|
|
13
13
|
var _logger = _interopRequireDefault(require("../utils/logger"));
|
14
14
|
var _security = _interopRequireDefault(require("./security"));
|
15
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
17
|
+
|
16
18
|
/**
|
17
19
|
* Serviço de gerênciamento do banco de dados
|
18
20
|
*
|
19
21
|
* @class SequelizeService
|
20
22
|
* @extends {Service}
|
23
|
+
* @deprecated Use {@link DatabaseService}
|
21
24
|
* @implements {IService}
|
22
25
|
*/
|
23
26
|
class SequelizeService extends _service.default {
|
24
27
|
serviceDB;
|
25
|
-
masterDB;
|
26
28
|
models;
|
27
29
|
connections;
|
28
30
|
initializedModels;
|
@@ -37,7 +39,6 @@ class SequelizeService extends _service.default {
|
|
37
39
|
await super.onServiceInit();
|
38
40
|
if (!this.models) throw new Error('Models are requireds! Call registerModels(modelsArray)');
|
39
41
|
this.serviceDB = _database.serviceDB;
|
40
|
-
this.masterDB = _database.masterDB;
|
41
42
|
this.connections = new Map();
|
42
43
|
this.initializedModels = new Map();
|
43
44
|
this.initializingdModels = new Map();
|
@@ -65,13 +66,6 @@ class SequelizeService extends _service.default {
|
|
65
66
|
if (this.isReconnecting) return false;
|
66
67
|
this.log(`⌛️ Connecting Sequelize to database: ${this.currentStartAttempts}/${this.maxStartAttempts}`);
|
67
68
|
try {
|
68
|
-
if (!this.isMasterConnected) {
|
69
|
-
await this.masterDB.sync({
|
70
|
-
force: false
|
71
|
-
});
|
72
|
-
this.isMasterConnected = true;
|
73
|
-
this.log('✅ Connected master database sucessfully', 'success');
|
74
|
-
}
|
75
69
|
if (!this.isServiceConnected) {
|
76
70
|
await this.serviceDB.sync({
|
77
71
|
force: false
|
@@ -93,8 +87,6 @@ class SequelizeService extends _service.default {
|
|
93
87
|
/* master or service */
|
94
88
|
if (tenantId == _app.Core.settings.getDatabase().service.database) {
|
95
89
|
return _database.serviceDB;
|
96
|
-
} else if (tenantId == _app.Core.settings.getDatabase().master.database) {
|
97
|
-
return _database.masterDB;
|
98
90
|
}
|
99
91
|
const relation = await this.getRelation(tenantId);
|
100
92
|
if (!relation) return false;
|
@@ -169,8 +161,6 @@ class SequelizeService extends _service.default {
|
|
169
161
|
let connection = false;
|
170
162
|
if (tenantId == _app.Core.settings.getDatabase().service.database) {
|
171
163
|
connection = _database.serviceDB;
|
172
|
-
} else if (tenantId == _app.Core.settings.getDatabase().master.database) {
|
173
|
-
connection = _database.masterDB;
|
174
164
|
} else {
|
175
165
|
const relation = await this.getRelation(tenantId);
|
176
166
|
if (!relation) return false;
|
package/lib/utils/database.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { Sequelize, WhereOptions } from 'sequelize';
|
2
2
|
import { IRequestFilterCondition, LogicalCondition } from '../contracts';
|
3
3
|
export declare const serviceDB: Sequelize;
|
4
|
-
export declare const masterDB: Sequelize;
|
5
4
|
export declare function processFilters<D>(filters?: Partial<Record<keyof D, IRequestFilterCondition<D>> | LogicalCondition<D>>): WhereOptions<D>;
|
6
5
|
//# sourceMappingURL=database.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEzE,eAAO,MAAM,SAAS,
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEzE,eAAO,MAAM,SAAS,WASpB,CAAC;AA8FH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACnF,YAAY,CAAC,CAAC,CAAC,CAwCjB"}
|
package/lib/utils/database.js
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.masterDB = void 0;
|
7
6
|
exports.processFilters = processFilters;
|
8
7
|
exports.serviceDB = void 0;
|
9
8
|
var _sequelize = require("sequelize");
|
@@ -21,18 +20,21 @@ const serviceDB = exports.serviceDB = new _sequelize.Sequelize({
|
|
21
20
|
timezone: '-03:00',
|
22
21
|
logging: _core.default.settings.getDatabase().service.log
|
23
22
|
});
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
|
24
|
+
//!nunca foi usado
|
25
|
+
/* export const masterDB = new Sequelize({
|
26
|
+
database: Core.settings.getDatabase().master.database,
|
27
|
+
dialect: Core.settings.getDatabase().master.dialect,
|
28
|
+
username: Core.settings.getDatabase().master.username,
|
29
|
+
password: Core.settings.getDatabase().master.password,
|
30
|
+
pool: Core.settings.getDatabase().master.pool,
|
30
31
|
define: {
|
31
32
|
timestamps: true
|
32
33
|
},
|
33
34
|
timezone: '-03:00',
|
34
|
-
logging:
|
35
|
-
});
|
35
|
+
logging: Core.settings.getDatabase().service.log
|
36
|
+
}); */
|
37
|
+
|
36
38
|
function processCondition(cond) {
|
37
39
|
if ('or' in cond) {
|
38
40
|
return {
|