exodus-framework 2.0.692 → 2.0.693

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.
@@ -14,8 +14,8 @@ declare class SequelizeService extends Service implements IService {
14
14
  getMasterConnection(): Sequelize;
15
15
  createDB(connection_uuid: string, name: string): Promise<boolean>;
16
16
  deleteDB(connection_uuid: string, name: string): Promise<boolean>;
17
- getDB(tenantId: string): Promise<Sequelize>;
18
- initDB(tenantId: string): Promise<unknown>;
17
+ getDB(tenantId: string): Promise<false | Sequelize>;
18
+ initDB(tenantId: string): Promise<false | Sequelize>;
19
19
  registerModels(models: ModelStatic<any>[]): void;
20
20
  getModel<M extends typeof Model<any, any>>(model: typeof Model<any, any> & {
21
21
  initialize: (connection: Sequelize) => M;
@@ -1 +1 @@
1
- {"version":3,"file":"sequelize.d.ts","sourceRoot":"","sources":["../../src/services/sequelize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAahD,cAAM,gBAAiB,SAAQ,OAAQ,YAAW,QAAQ;IACxD,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3B,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;;IAMjD,IAAI;IAOJ,mBAAmB;IA4BzB,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,SAAI;IAerC,mBAAmB;IAGb,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;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EAAE,MAAM;IA6C9C,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAwC9C,KAAK,CAAC,QAAQ,EAAE,MAAM;IAatB,MAAM,CAAC,QAAQ,EAAE,MAAM;IA4C7B,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE;IAInC,QAAQ,CAAC,CAAC,SAAS,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAC7C,KAAK,EAAE,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG;QAAE,UAAU,EAAE,CAAC,UAAU,EAAE,SAAS,KAAK,CAAC,CAAA;KAAE,EAC5E,QAAQ,EAAE,MAAM;IAwBlB,uBAAuB,CAAC,MAAM,EAAE,MAAM;;;;CAMvC;AAED,eAAe,gBAAgB,CAAC"}
@@ -157,27 +157,27 @@ class SequelizeService extends _service.default {
157
157
  } else if (con_uuid == _app.Core.settings.getDatabase().master.database) {
158
158
  return _database.masterDB;
159
159
  }
160
- const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`;
161
- const queryId = `${con_uuid}@${dbQueryName}`;
162
- return this.connections.get(queryId);
160
+ const dbName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`; //nomeclatura padrão do banco de dados do serviço
161
+ const queryId = `${con_uuid}@${dbName}`;
162
+ return this.connections.get(queryId) || (await this.initDB(tenantId));
163
163
  }
164
164
  async initDB(tenantId) {
165
165
  const {
166
166
  con_uuid,
167
167
  envToken
168
168
  } = this.parseDataInfoByTenantId(tenantId);
169
- const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`;
170
- const queryId = `${con_uuid}@${dbQueryName}`;
169
+ const dbName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`; //nomeclatura padrão do banco de dados do serviço
170
+ const queryId = `${con_uuid}@${dbName}`;
171
171
  if (this.connections.get(queryId)) {
172
- return false;
172
+ return this.connections.get(queryId);
173
173
  }
174
174
  const connData = await _Connection.Connection.findByPk(con_uuid);
175
175
  if (!connData) {
176
- this.log('Connection data not found: ' + con_uuid);
176
+ this.log('Error on init connection, data not found! uuid: ' + con_uuid, 'danger');
177
177
  return false;
178
178
  }
179
179
  const conn = new _sequelize.Sequelize({
180
- database: dbQueryName,
180
+ database: dbName,
181
181
  dialect: connData.dialect,
182
182
  username: connData.username,
183
183
  password: connData.password,
@@ -193,13 +193,13 @@ class SequelizeService extends _service.default {
193
193
  conn.sync({
194
194
  force: false
195
195
  }).then(() => {
196
- this.log(`✅ Connected ${dbQueryName} database sucessfully`, 'success');
196
+ this.log(`✅ Connected ${dbName} database sucessfully`, 'success');
197
197
  this.connections.set(queryId, conn);
198
- resolve(true);
198
+ resolve(conn);
199
199
  }).catch(reason => {
200
- this.log(`error trying to connect: ${dbQueryName}, UUID: ${con_uuid}`);
200
+ this.log(`error trying to connect: ${dbName}, UUID: ${con_uuid}`);
201
201
  reject(reason);
202
- new _error.ApplicationException(`error trying to connect: ${dbQueryName}, UUID: ${con_uuid}`, reason);
202
+ new _error.ApplicationException(`error trying to connect: ${dbName}, UUID: ${con_uuid}`, reason);
203
203
  });
204
204
  });
205
205
  }
@@ -211,18 +211,19 @@ class SequelizeService extends _service.default {
211
211
  con_uuid,
212
212
  envToken
213
213
  } = this.parseDataInfoByTenantId(tenantId);
214
- const query = `${envToken}@${con_uuid}`;
215
- const cache = this.initializedModels.get(query);
214
+ const modelInitID = `${envToken}@${con_uuid}#${model.name}`;
215
+ const cache = this.initializedModels.get(modelInitID);
216
216
  if (cache) {
217
217
  return cache;
218
218
  }
219
219
  const connection = await this.getDB(tenantId);
220
- if (connection) {
221
- const m = model.initialize(connection);
222
- this.initializedModels.set(query, m);
223
- return m;
220
+ if (!connection) {
221
+ throw new _error.ApplicationException('Não foi possível obter o model espeficificado: Conexão não encontrada');
224
222
  }
225
- throw new _error.ApplicationException('Não foi possível obter o model espeficificado');
223
+ const m = model.initialize(connection);
224
+ await m.sync();
225
+ this.initializedModels.set(modelInitID, m);
226
+ return m;
226
227
  }
227
228
  parseDataInfoByTenantId(tenant) {
228
229
  const e = tenant.split('@');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.692",
3
+ "version": "2.0.693",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",