badmfck-api-server 2.9.2 → 2.9.4

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.
@@ -89,7 +89,7 @@ async function Initializer(services) {
89
89
  exports.Initializer = Initializer;
90
90
  class APIService extends BaseService_1.BaseService {
91
91
  static nextLogID = 0;
92
- version = "2.9.2";
92
+ version = "2.9.3";
93
93
  options;
94
94
  monitor = null;
95
95
  monitorIndexFile;
@@ -1,7 +1,7 @@
1
1
  import { Req } from "badmfck-signal";
2
2
  import { BaseService } from "./BaseService";
3
3
  import { IDBAdapter } from "./db/IDBAdapter";
4
- export interface IDBQueryField extends Record<string, string | number | boolean | null | undefined | {
4
+ export interface IDBQueryField {
5
5
  name?: string | null;
6
6
  value: string | number | boolean | null | undefined;
7
7
  system?: boolean;
@@ -9,12 +9,13 @@ export interface IDBQueryField extends Record<string, string | number | boolean
9
9
  ignoreInUpdate?: boolean;
10
10
  useInReplace?: boolean;
11
11
  __parsedValue?: string | number | boolean | null | undefined;
12
- }> {
13
12
  }
14
13
  export interface IDBQuery {
15
14
  dbid?: string;
16
15
  query: string;
17
- fields?: IDBQueryField;
16
+ fields?: {
17
+ [key: string]: IDBQueryField | null | string | number | boolean;
18
+ };
18
19
  throwable?: boolean;
19
20
  transactionID?: number;
20
21
  calculateCount?: boolean;
@@ -20,9 +20,9 @@ class MysqlAdapter {
20
20
  queries = [];
21
21
  static nextTransactionID = 1;
22
22
  transactions = [];
23
- maxTransactionWaitTime = 1000 * 60 * 1;
23
+ maxTransactionWaitTime = 1000 * 60 * 2;
24
24
  lastSuccessQueryTime = 0;
25
- pingInterval = 1000 * 60 * 2;
25
+ pingInterval = 1000 * 60 * 5;
26
26
  failReportFileStream = null;
27
27
  failReportFileStreamName = null;
28
28
  failReportLastAccessTime = 0;
@@ -79,8 +79,9 @@ class MysqlAdapter {
79
79
  if (Date.now() - this.lastSuccessQueryTime > this.pingInterval) {
80
80
  if (!this.pool)
81
81
  return;
82
- for (let i = 0; i < this.options.connectionLimit; i++)
82
+ for (let i = 0; i < this.options.connectionLimit; i++) {
83
83
  this.query({ query: "SELECT 1 @NOLIMIT" });
84
+ }
84
85
  }
85
86
  }, 1000 * 30);
86
87
  setInterval(() => {
@@ -210,6 +211,7 @@ class MysqlAdapter {
210
211
  if (this.options.debug)
211
212
  (0, LogService_1.logInfo)("Execute query:", query);
212
213
  const result = await conn.query(query);
214
+ this.lastSuccessQueryTime = +new Date();
213
215
  if (!request.transactionID)
214
216
  this.finalizeConnection(conn);
215
217
  return {
@@ -270,13 +272,16 @@ class MysqlAdapter {
270
272
  if (fields) {
271
273
  for (let i in fields) {
272
274
  const name = i;
273
- const value = fields[i];
274
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean")
275
- fields[i] = { value: value, system: false };
276
- if (value === undefined)
275
+ let queryField = fields[i];
276
+ if (queryField === undefined)
277
277
  continue;
278
- if (value === null)
279
- fields[i] = { value: null, system: true };
278
+ if (typeof queryField === "string" || typeof queryField === "number" || typeof queryField === "boolean")
279
+ queryField = { value: queryField, system: false };
280
+ if (queryField === null)
281
+ queryField = { value: null, system: true };
282
+ if (!queryField.name)
283
+ queryField.name = name.replaceAll("`", '').replaceAll('\"', "").replaceAll('\'', "");
284
+ fields[i] = queryField;
280
285
  const parsed = MysqlAdapter.prepareQueryFieldValue(fields[i]);
281
286
  query = query.replaceAll("@" + name, parsed + "");
282
287
  }
@@ -292,11 +297,8 @@ class MysqlAdapter {
292
297
  let f = fields[i];
293
298
  if (f.ignoreInInsert)
294
299
  continue;
295
- let name = f.name;
296
- if (!name)
297
- name = i.replaceAll("`", '').replaceAll('\"', "").replaceAll('\'', "");
298
- insertFieldNames.push('`' + (name + "").replaceAll("`", '').replaceAll('\"', "").replaceAll('\'', "") + '`');
299
- insertFieldValues.push(f._parsedValue);
300
+ insertFieldNames.push('`' + f.name + '`');
301
+ insertFieldValues.push(f.__parsedValue);
300
302
  }
301
303
  query = query
302
304
  .replaceAll('@fields', insertFieldNames.join(","))
@@ -309,11 +311,8 @@ class MysqlAdapter {
309
311
  let f = fields[i];
310
312
  if (f.ignoreInInsert)
311
313
  continue;
312
- let name = f.name;
313
- if (!name)
314
- name = i.replaceAll("`", '').replaceAll('\"', "").replaceAll('\'', "");
315
- oninsertNames.push(name);
316
- oninsertValues.push(f._parsedValue);
314
+ oninsertNames.push(f.name);
315
+ oninsertValues.push(f.__parsedValue);
317
316
  }
318
317
  query = query.replaceAll("@insert", `(${oninsertNames.join(",")}) VALUES (${oninsertValues.join(",")})`);
319
318
  }
@@ -323,10 +322,7 @@ class MysqlAdapter {
323
322
  let f = fields[i];
324
323
  if (f.ignoreInUpdate)
325
324
  continue;
326
- let name = f.name;
327
- if (!name)
328
- name = i.replaceAll("`", '').replaceAll('\"', "").replaceAll('\'', "");
329
- onUpdate.push('`' + (name + "") + '` = ' + f._parsedValue);
325
+ onUpdate.push('`' + f.name + '` = ' + f.__parsedValue);
330
326
  }
331
327
  query = query.replaceAll("@onupdate", onUpdate.join(" , "));
332
328
  }
@@ -336,10 +332,7 @@ class MysqlAdapter {
336
332
  let f = fields[i];
337
333
  if (!f.useInReplace)
338
334
  continue;
339
- let name = f.name;
340
- if (!name)
341
- name = i.replaceAll("`", '').replaceAll('\"', "").replaceAll('\'', "");
342
- onDuplicate.push('`' + (name + "") + f._parsedValue);
335
+ onDuplicate.push('`' + f.name + f.__parsedValue);
343
336
  }
344
337
  query = query.replaceAll("@onduplicate", onDuplicate.join(" , "));
345
338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",