badmfck-api-server 2.3.9 → 2.4.1

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.1";
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;
@@ -70,6 +69,7 @@ export interface ITransaction {
70
69
  }[];
71
70
  }
72
71
  export interface MysqlQueryFieldObject extends Record<string, string | number | boolean | null | undefined | {
72
+ name?: string | null;
73
73
  value: string | number | boolean | null | undefined;
74
74
  system?: boolean;
75
75
  ignoreInInsert?: boolean;
@@ -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 {
@@ -443,7 +398,8 @@ class MysqlService extends BaseService_1.BaseService {
443
398
  system: i.system,
444
399
  ignoreInInsert: i.ignoreInInsert,
445
400
  ignoreInUpdate: i.ignoreInUpdate,
446
- useInReplace: i.useInReplace
401
+ useInReplace: i.useInReplace,
402
+ name: i.name
447
403
  };
448
404
  }
449
405
  else
@@ -470,7 +426,7 @@ class MysqlService extends BaseService_1.BaseService {
470
426
  };
471
427
  }
472
428
  fields.push({
473
- name: i,
429
+ name: mo.name ?? i,
474
430
  value: mo.value,
475
431
  system: mo.system,
476
432
  ignoreInInsert: mo.system,
@@ -683,16 +639,17 @@ class MysqlService extends BaseService_1.BaseService {
683
639
  });
684
640
  }
685
641
  async queryAsync(conn, query) {
642
+ let result = null;
686
643
  try {
687
- const result = await conn.query(query);
688
- return {
689
- err: null,
690
- results: result[0],
691
- };
644
+ result = await conn.query(query);
692
645
  }
693
646
  catch (e) {
694
647
  return { err: this.createMysqlQueryError(e) };
695
648
  }
649
+ return {
650
+ err: null,
651
+ results: result[0],
652
+ };
696
653
  }
697
654
  createMysqlQueryError(err) {
698
655
  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.1",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",