badmfck-api-server 3.8.7 → 3.8.9

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.
@@ -93,7 +93,7 @@ async function Initializer(services) {
93
93
  }
94
94
  exports.Initializer = Initializer;
95
95
  class APIService extends BaseService_1.BaseService {
96
- version = "3.8.7";
96
+ version = "3.8.9";
97
97
  options;
98
98
  monitor = null;
99
99
  started = new Date();
@@ -242,7 +242,6 @@ class MysqlAdapter {
242
242
  }
243
243
  if (this.options.debug)
244
244
  (0, LogService_1.logDB)("Commit transaction:", trx.id);
245
- this.transactions = this.transactions.filter(i => i.id !== trxid);
246
245
  if (this.options.debug)
247
246
  (0, LogService_1.logDB)("Transaction pool:", this.transactions);
248
247
  const err = await this.commit(trx);
@@ -439,15 +438,20 @@ class MysqlAdapter {
439
438
  };
440
439
  }
441
440
  }
441
+ let trx = null;
442
+ if (request.transactionID)
443
+ trx = this.transactions.find(i => i.id === request.transactionID);
442
444
  try {
443
445
  let result = null;
444
446
  if (this.options.maxQueryTimeout && this.options.maxQueryTimeout > 0)
445
- result = await this.withTimeout(conn.query(query), this.options.maxQueryTimeout ?? 1000 * 25, query);
447
+ result = await this.withTimeout(conn.query(query), this.options.maxQueryTimeout, query);
446
448
  else
447
449
  result = await conn.query(query);
448
450
  this.lastSuccessQueryTime = +new Date();
449
451
  if (!request.transactionID && doCloseConnection)
450
452
  this.finalizeConnection(conn);
453
+ if (trx)
454
+ trx.queries.push({ sql: query, status: "ok" });
451
455
  return {
452
456
  data: result[0],
453
457
  error: null,
@@ -469,10 +473,14 @@ class MysqlAdapter {
469
473
  this.finalizeConnection(conn);
470
474
  }
471
475
  const error = this.createMysqlQueryError(e);
476
+ if (trx)
477
+ trx.queries.push({ sql: query, status: error.code });
472
478
  if (`${e}`.indexOf('ECONNREFUSED') !== -1 || `${e}`.indexOf("PROTOCOL_") !== -1 || error.message.includes("closed state")) {
473
479
  (0, LogService_1.logError)("Connection looks dead, recreating pool 1");
474
480
  this.recreatePool();
475
481
  }
482
+ if (trx)
483
+ this.storeTransactionAsProblem(trx, "error:" + error.errno);
476
484
  if (request.throwable)
477
485
  throw { ...DefaultErrors_1.default.DB_ERROR, details: error.message, stack: error };
478
486
  return {
@@ -636,10 +644,14 @@ class MysqlAdapter {
636
644
  await trx.conn.commit();
637
645
  trx.conn.removeAllListeners();
638
646
  trx.conn.release();
647
+ const trxIndex = this.transactions.indexOf(trx);
648
+ this.transactions.splice(trxIndex, 1);
639
649
  }
640
650
  catch (e) {
651
+ const err = this.createMysqlQueryError(e);
652
+ trx.queries.push({ sql: "COMMIT", status: err.code });
641
653
  await this.rollbackTransaction(trx);
642
- return this.createMysqlQueryError(e);
654
+ return err;
643
655
  }
644
656
  return null;
645
657
  }
@@ -648,7 +660,6 @@ class MysqlAdapter {
648
660
  try {
649
661
  (0, LogService_1.logDB)("Rollback started", trx.conn.threadId);
650
662
  await trx.conn.rollback();
651
- await trx.conn.commit();
652
663
  trx.conn.removeAllListeners();
653
664
  trx.conn.release();
654
665
  (0, LogService_1.logDB)("Rollback connection released", trx.conn.threadId);
@@ -656,12 +667,13 @@ class MysqlAdapter {
656
667
  this.transactions = this.transactions.filter(i => trx && i && i.id !== trx.id);
657
668
  if (this.options.debug)
658
669
  (0, LogService_1.logDB)("Rollback complete", trx.conn.threadId);
670
+ trx.queries.push({ sql: "ROLLBACK", status: "ok" });
659
671
  }
660
672
  catch (e) {
661
673
  (0, LogService_1.logCrit)("MysqlAdapter", "Can't rollback transaction", trx.queries);
662
674
  err = this.createMysqlQueryError(e);
675
+ trx.queries.push({ sql: "ROLLBACK", status: "fail" });
663
676
  }
664
- this.storeTransactionAsProblem(trx, "rollback");
665
677
  return err;
666
678
  }
667
679
  async finish() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.8.7",
3
+ "version": "3.8.9",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",