exodus-framework 2.0.958 → 2.0.960
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.
| 
         @@ -18,11 +18,14 @@ declare class DatabaseService extends Service { 
     | 
|
| 
       18 
18 
     | 
    
         
             
                    password: string;
         
     | 
| 
       19 
19 
     | 
    
         
             
                    dialect: Dialect;
         
     | 
| 
       20 
20 
     | 
    
         
             
                }): Promise<boolean>;
         
     | 
| 
      
 21 
     | 
    
         
            +
                private createConnectionByHost;
         
     | 
| 
       21 
22 
     | 
    
         
             
                getTenantIds(): Promise<string[]>;
         
     | 
| 
       22 
23 
     | 
    
         
             
                getTenantInformation(tenantId: string): Promise<EnvDBHost>;
         
     | 
| 
       23 
24 
     | 
    
         
             
                private loadEntity;
         
     | 
| 
       24 
25 
     | 
    
         
             
                getEntity<M extends ServiceModel<Model>>(model: StaticServiceModel<M>, tenantId: string): Promise<ModelStatic<M>>;
         
     | 
| 
       25 
26 
     | 
    
         
             
                private normalizeDatabaseName;
         
     | 
| 
      
 27 
     | 
    
         
            +
                createDB(hostId: string, name: string): Promise<boolean>;
         
     | 
| 
      
 28 
     | 
    
         
            +
                deleteDB(hostId: string, name: string): Promise<boolean>;
         
     | 
| 
       26 
29 
     | 
    
         
             
            }
         
     | 
| 
       27 
30 
     | 
    
         
             
            export default DatabaseService;
         
     | 
| 
       28 
31 
     | 
    
         
             
            //# sourceMappingURL=database.d.ts.map
         
     | 
| 
         @@ -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;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;IAO9B,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; 
     | 
| 
      
 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;IAO9B,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;YA2Ba,sBAAsB;IA6BvB,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;IAIhB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IA0BrC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAkBnD;AAED,eAAe,eAAe,CAAC"}
         
     | 
    
        package/lib/services/database.js
    CHANGED
    
    | 
         @@ -115,6 +115,22 @@ class DatabaseService extends _app.Service { 
     | 
|
| 
       115 
115 
     | 
    
         
             
                  });
         
     | 
| 
       116 
116 
     | 
    
         
             
                });
         
     | 
| 
       117 
117 
     | 
    
         
             
              }
         
     | 
| 
      
 118 
     | 
    
         
            +
              async createConnectionByHost(hostId) {
         
     | 
| 
      
 119 
     | 
    
         
            +
                const host = await _models.DatabaseHost.findByPk(hostId);
         
     | 
| 
      
 120 
     | 
    
         
            +
                if (!host) throw new Error(`Host não encontado: ${hostId}`);
         
     | 
| 
      
 121 
     | 
    
         
            +
                const splitedInfo = host.host.split(':');
         
     | 
| 
      
 122 
     | 
    
         
            +
                const address = splitedInfo[0];
         
     | 
| 
      
 123 
     | 
    
         
            +
                const port = Number(splitedInfo[1]);
         
     | 
| 
      
 124 
     | 
    
         
            +
                const key = await _security.default.getService().loadKeyByStr(host.credential);
         
     | 
| 
      
 125 
     | 
    
         
            +
                const data = await _security.default.getService().verifySignature(host.password, key);
         
     | 
| 
      
 126 
     | 
    
         
            +
                if (!data) {
         
     | 
| 
      
 127 
     | 
    
         
            +
                  throw new Error(`Não foi possível descriptografar as credenciais de conexão para host: ${hostId}`);
         
     | 
| 
      
 128 
     | 
    
         
            +
                }
         
     | 
| 
      
 129 
     | 
    
         
            +
                const password = data.payload;
         
     | 
| 
      
 130 
     | 
    
         
            +
                return this.createConnection(address, port, undefined,
         
     | 
| 
      
 131 
     | 
    
         
            +
                //! apenas retornar a conexão
         
     | 
| 
      
 132 
     | 
    
         
            +
                host.username, password, host.dialect);
         
     | 
| 
      
 133 
     | 
    
         
            +
              }
         
     | 
| 
       118 
134 
     | 
    
         | 
| 
       119 
135 
     | 
    
         
             
              //* Environment
         
     | 
| 
       120 
136 
     | 
    
         
             
              async getTenantIds() {
         
     | 
| 
         @@ -154,5 +170,46 @@ class DatabaseService extends _app.Service { 
     | 
|
| 
       154 
170 
     | 
    
         
             
              normalizeDatabaseName(envToken) {
         
     | 
| 
       155 
171 
     | 
    
         
             
                return `${_app.Core.settings.getDatabase().main.database}_${envToken}`;
         
     | 
| 
       156 
172 
     | 
    
         
             
              }
         
     | 
| 
      
 173 
     | 
    
         
            +
              async createDB(hostId, name) {
         
     | 
| 
      
 174 
     | 
    
         
            +
                try {
         
     | 
| 
      
 175 
     | 
    
         
            +
                  const connection = await this.createConnectionByHost(hostId);
         
     | 
| 
      
 176 
     | 
    
         
            +
                  try {
         
     | 
| 
      
 177 
     | 
    
         
            +
                    const dbQueryName = `${_app.Core.settings.getDatabase().main.database}_${name}`;
         
     | 
| 
      
 178 
     | 
    
         
            +
                    const [results] = await connection.query(`SHOW DATABASES LIKE '${dbQueryName}';`);
         
     | 
| 
      
 179 
     | 
    
         
            +
                    if (results.length === 0) {
         
     | 
| 
      
 180 
     | 
    
         
            +
                      // Se o banco de dados não existir, cria-o
         
     | 
| 
      
 181 
     | 
    
         
            +
                      await connection.query(`CREATE DATABASE ${dbQueryName};`);
         
     | 
| 
      
 182 
     | 
    
         
            +
                      this.log(`Database "${dbQueryName}" has been created.`);
         
     | 
| 
      
 183 
     | 
    
         
            +
                      return true;
         
     | 
| 
      
 184 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 185 
     | 
    
         
            +
                      this.log(`Database "${dbQueryName}" already exists.`);
         
     | 
| 
      
 186 
     | 
    
         
            +
                      return false;
         
     | 
| 
      
 187 
     | 
    
         
            +
                    }
         
     | 
| 
      
 188 
     | 
    
         
            +
                  } catch (error) {
         
     | 
| 
      
 189 
     | 
    
         
            +
                    new _app.ErrorHandler('Erro on creating database', error);
         
     | 
| 
      
 190 
     | 
    
         
            +
                  } finally {
         
     | 
| 
      
 191 
     | 
    
         
            +
                    connection.close();
         
     | 
| 
      
 192 
     | 
    
         
            +
                  }
         
     | 
| 
      
 193 
     | 
    
         
            +
                } catch (error) {
         
     | 
| 
      
 194 
     | 
    
         
            +
                  return false;
         
     | 
| 
      
 195 
     | 
    
         
            +
                }
         
     | 
| 
      
 196 
     | 
    
         
            +
              }
         
     | 
| 
      
 197 
     | 
    
         
            +
              async deleteDB(hostId, name) {
         
     | 
| 
      
 198 
     | 
    
         
            +
                try {
         
     | 
| 
      
 199 
     | 
    
         
            +
                  const connection = await this.createConnectionByHost(hostId);
         
     | 
| 
      
 200 
     | 
    
         
            +
                  try {
         
     | 
| 
      
 201 
     | 
    
         
            +
                    const dbQueryName = `${_app.Core.settings.getDatabase().main.database}_${name}`;
         
     | 
| 
      
 202 
     | 
    
         
            +
                    await connection.query(`DROP DATABASE IF EXISTS ${dbQueryName};`);
         
     | 
| 
      
 203 
     | 
    
         
            +
                    this.log(`Database "${dbQueryName}" has been deleted.`);
         
     | 
| 
      
 204 
     | 
    
         
            +
                    return true;
         
     | 
| 
      
 205 
     | 
    
         
            +
                  } catch (error) {
         
     | 
| 
      
 206 
     | 
    
         
            +
                    return false;
         
     | 
| 
      
 207 
     | 
    
         
            +
                  } finally {
         
     | 
| 
      
 208 
     | 
    
         
            +
                    connection.close();
         
     | 
| 
      
 209 
     | 
    
         
            +
                  }
         
     | 
| 
      
 210 
     | 
    
         
            +
                } catch (error) {
         
     | 
| 
      
 211 
     | 
    
         
            +
                  return false;
         
     | 
| 
      
 212 
     | 
    
         
            +
                }
         
     | 
| 
      
 213 
     | 
    
         
            +
              }
         
     | 
| 
       157 
214 
     | 
    
         
             
            }
         
     | 
| 
       158 
215 
     | 
    
         
             
            var _default = exports.default = DatabaseService;
         
     |