badmfck-api-server 1.6.7 → 1.6.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.
@@ -47,7 +47,7 @@ async function Initializer(services) {
47
47
  exports.Initializer = Initializer;
48
48
  class APIService extends BaseService_1.BaseService {
49
49
  static nextLogID = 0;
50
- version = "1.6.6";
50
+ version = "1.6.8";
51
51
  options;
52
52
  monitor;
53
53
  monitorIndexFile;
@@ -140,8 +140,6 @@ class APIService extends BaseService_1.BaseService {
140
140
  params: req.params
141
141
  };
142
142
  }
143
- if (this.options.onNetworkLog && log)
144
- this.options.onNetworkLog(log);
145
143
  const execute = async () => {
146
144
  const body = req.body;
147
145
  if (req.query && typeof req.query === "object") {
@@ -150,7 +150,7 @@ class MysqlService extends BaseService_1.BaseService {
150
150
  else
151
151
  value = "NULL";
152
152
  }
153
- if (!value)
153
+ if (value === null || value === undefined)
154
154
  return "NULL";
155
155
  return value;
156
156
  }
@@ -14,5 +14,6 @@ export declare enum ValidationReport {
14
14
  }
15
15
  export declare class Validator {
16
16
  static validateObject(fields: string[], object: any): boolean;
17
+ static convertToType<T>(value: any, type: "string" | "number" | "boolean" | "date"): T | null;
17
18
  static validateValue(value: string | number | boolean, opt?: IValidatorOptions): ValidationReport;
18
19
  }
@@ -20,6 +20,43 @@ class Validator {
20
20
  }
21
21
  return true;
22
22
  }
23
+ static convertToType(value, type) {
24
+ if (value === null || value === undefined)
25
+ return null;
26
+ if (type === "string") {
27
+ if (typeof value === "object") {
28
+ let result = null;
29
+ try {
30
+ result = JSON.stringify(value);
31
+ }
32
+ catch (e) { }
33
+ if (result !== null)
34
+ return result;
35
+ }
36
+ return value + "";
37
+ }
38
+ if (type === "boolean") {
39
+ if (typeof value === "boolean")
40
+ return value;
41
+ if (typeof value === "number")
42
+ return value > 0;
43
+ if (typeof value === "object")
44
+ return false;
45
+ if (typeof value === "string")
46
+ return (value.toLowerCase() === "true");
47
+ }
48
+ if (type === "date") {
49
+ if (typeof value === "string" || typeof value === "number")
50
+ return new Date(value);
51
+ return null;
52
+ }
53
+ if (typeof value === "number")
54
+ return value;
55
+ if (typeof value === "object")
56
+ return 0;
57
+ const num = parseInt(value + "");
58
+ return num;
59
+ }
23
60
  static validateValue(value, opt) {
24
61
  if (value === undefined || value === null)
25
62
  return ValidationReport.VALUE_IS_NULL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",