badmfck-api-server 2.3.9 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,7 +83,7 @@ async function Initializer(services) {
83
83
  exports.Initializer = Initializer;
84
84
  class APIService extends BaseService_1.BaseService {
85
85
  static nextLogID = 0;
86
- version = "2.3.9";
86
+ version = "2.4.0";
87
87
  options;
88
88
  monitor;
89
89
  monitorIndexFile;
@@ -5,7 +5,6 @@ import * as mysql from "mysql2/promise";
5
5
  import fs from "fs";
6
6
  export declare const S_MYSQL_STARTED: Signal<void>;
7
7
  export declare const REQ_MYSQL_QUERY: Req<MySqlQuery | MySqlQuery[], MysqlResult[]>;
8
- export declare const REQ_MYSQL_TRANSACTION: Req<MySqlQuery[], MysqlResult>;
9
8
  export declare const REQ_MYSQL_TBEGIN: Req<void, number | MysqlError>;
10
9
  export declare const REQ_MYSQL_TQUERY: Req<{
11
10
  query: MySqlQuery;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.MysqlService = exports.executeQuery = exports.REQ_MYSQL_TROLLBACK = exports.REQ_MYSQL_TCOMMIT = exports.REQ_MYSQL_TQUERY = exports.REQ_MYSQL_TBEGIN = exports.REQ_MYSQL_TRANSACTION = exports.REQ_MYSQL_QUERY = exports.S_MYSQL_STARTED = void 0;
29
+ exports.MysqlService = exports.executeQuery = exports.REQ_MYSQL_TROLLBACK = exports.REQ_MYSQL_TCOMMIT = exports.REQ_MYSQL_TQUERY = exports.REQ_MYSQL_TBEGIN = exports.REQ_MYSQL_QUERY = exports.S_MYSQL_STARTED = void 0;
30
30
  const BaseService_1 = require("./BaseService");
31
31
  const badmfck_signal_1 = __importStar(require("badmfck-signal"));
32
32
  const crypto_1 = require("crypto");
@@ -36,7 +36,6 @@ const fs_1 = __importDefault(require("fs"));
36
36
  const path_1 = __importDefault(require("path"));
37
37
  exports.S_MYSQL_STARTED = new badmfck_signal_1.default();
38
38
  exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_QUERY");
39
- exports.REQ_MYSQL_TRANSACTION = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TRANSACTION");
40
39
  exports.REQ_MYSQL_TBEGIN = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TRANSACTION_BEGING");
41
40
  exports.REQ_MYSQL_TQUERY = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TRANSACTION_ADD_OPERATION");
42
41
  exports.REQ_MYSQL_TCOMMIT = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TCOMMIT");
@@ -201,7 +200,7 @@ class MysqlService extends BaseService_1.BaseService {
201
200
  console.log("Query execution status:", err ? err.message : "completed");
202
201
  trx.queries.push({ sql: query, status: err ? err.message : "completed" });
203
202
  return {
204
- data: sqlData,
203
+ data: sqlData ? sqlData[0] : null,
205
204
  error: err,
206
205
  };
207
206
  };
@@ -240,50 +239,6 @@ class MysqlService extends BaseService_1.BaseService {
240
239
  const err = await this.commit(trx);
241
240
  return err;
242
241
  };
243
- exports.REQ_MYSQL_TRANSACTION.listener = async (data) => {
244
- if (!this.pool)
245
- return { error: { code: "NO_POOL", errno: 100000, fatal: true, sql: "", name: "NO_POOL", message: "Mysql pool not created" }, data: null };
246
- const conn = await this.pool.getConnection();
247
- (0, LogService_1.logCrit)("${MysqlService.js}", "REQ_MYSQL_TRANSACTION deprecated, use REQ_MYSQL_TBEGIN, REQ_MYSQL_TQUERY, REQ_MYSQL_TCOMMIT, REQ_MYSQL_TROLLBACK");
248
- if (!conn)
249
- return { error: { code: "NO_CONN", errno: 100001, fatal: true, sql: "", name: "NO_CONN", message: "Mysql pool cant get connection" }, data: null };
250
- const trx = {
251
- id: MysqlService.nextTransactionID++,
252
- timestamp: Date.now(),
253
- conn: conn,
254
- queries: []
255
- };
256
- let income = [];
257
- try {
258
- await conn.query("START TRANSACTION");
259
- }
260
- catch (e) {
261
- const err = this.createMysqlQueryError(e);
262
- this.storeTransactionAsProblem(trx, err.message);
263
- return { error: err, data: null };
264
- }
265
- for (let i of data) {
266
- const query = MysqlService.prepareQuery(i.query, i.fields);
267
- let err = null;
268
- try {
269
- const d = await conn.query(query);
270
- income.push(d[0]);
271
- }
272
- catch (e) {
273
- err = this.createMysqlQueryError(e);
274
- }
275
- trx.queries.push({
276
- sql: query,
277
- status: err ? err.message : "completed"
278
- });
279
- if (err) {
280
- this.storeTransactionAsProblem(trx, err.message);
281
- return { error: err, data: null };
282
- }
283
- }
284
- const err = await this.commit(trx);
285
- return { error: err, data: income };
286
- };
287
242
  }
288
243
  async commit(trx) {
289
244
  try {
@@ -683,16 +638,17 @@ class MysqlService extends BaseService_1.BaseService {
683
638
  });
684
639
  }
685
640
  async queryAsync(conn, query) {
641
+ let result = null;
686
642
  try {
687
- const result = await conn.query(query);
688
- return {
689
- err: null,
690
- results: result[0],
691
- };
643
+ result = await conn.query(query);
692
644
  }
693
645
  catch (e) {
694
646
  return { err: this.createMysqlQueryError(e) };
695
647
  }
648
+ return {
649
+ err: null,
650
+ results: result[0],
651
+ };
696
652
  }
697
653
  createMysqlQueryError(err) {
698
654
  if (err && typeof err === "object" && "code" in err && "errno" in err && "sql" in err && "name" in err && "message" in err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.3.9",
3
+ "version": "2.4.0",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",