badmfck-api-server 3.4.1 → 3.4.2

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.
@@ -65,7 +65,6 @@ export declare class APIService extends BaseService {
65
65
  private monitor;
66
66
  private started;
67
67
  private requestsCount;
68
- private server;
69
68
  netLog: APIServiceNetworkLogItem[];
70
69
  constructor(options?: APIServiceOptions | null);
71
70
  init(): Promise<void>;
@@ -100,7 +100,6 @@ class APIService extends BaseService_1.BaseService {
100
100
  monitor = null;
101
101
  started = new Date();
102
102
  requestsCount = 0;
103
- server = http_1.default;
104
103
  netLog = [];
105
104
  constructor(options) {
106
105
  super('HTTP Service');
@@ -157,7 +156,7 @@ class APIService extends BaseService_1.BaseService {
157
156
  };
158
157
  const app = (0, express_1.default)();
159
158
  const server = http_1.default.createServer(app);
160
- exports.REQ_HTTP_SERVER.listener = async (ignore) => { return { express: app, http: server }; };
159
+ exports.REQ_HTTP_SERVER.listener = async (_) => { return { express: app, http: server }; };
161
160
  if (this.options.isProductionEnvironment)
162
161
  app.set("env", 'production');
163
162
  app.use(express_1.default.json({ limit: '10mb' }));
@@ -19,6 +19,18 @@ export declare enum ValidationReport {
19
19
  VALUE_TOO_SHORT = 5,
20
20
  VALUE_INCORRECT = 6
21
21
  }
22
+ type ExtractOptionalFieldNames<T> = {
23
+ [K in keyof T as K extends `$__${infer Base}_optinal` ? Base extends keyof T ? T[K] extends true ? Base : never : never : never]: true;
24
+ };
25
+ type OptionalFields<T> = keyof ExtractOptionalFieldNames<T> & string;
26
+ type CleanFields<T> = {
27
+ [K in keyof T as K extends `$__${string}` ? never : K]: T[K];
28
+ };
29
+ export type ValidationModel<T> = {
30
+ [K in keyof CleanFields<T> as K extends OptionalFields<T> ? K : never]?: CleanFields<T>[K];
31
+ } & {
32
+ [K in keyof CleanFields<T> as K extends OptionalFields<T> ? never : K]: CleanFields<T>[K];
33
+ };
22
34
  export declare class Validator {
23
35
  static validateObject(fields: string[], object: any): boolean;
24
36
  static documentStructure(structure: any): Record<string, any> | undefined;
@@ -28,3 +40,4 @@ export declare class Validator {
28
40
  static convertToType<T>(value: any, type: "string" | "number" | "boolean" | "date"): T | null;
29
41
  static validateValue(value: string | number | boolean, opt?: IValidatorOptions): ValidationReport;
30
42
  }
43
+ export {};
@@ -91,11 +91,16 @@ class Validator {
91
91
  }
92
92
  let optional = structure['$__' + i + "_optional"] || false;
93
93
  if (!(i in object)) {
94
- if (!optional)
95
- errors.push("no field '" + i + "'");
94
+ if (structure["$__" + i + "_default"]) {
95
+ object[i] = structure["$__" + i + "_default"];
96
+ }
96
97
  else {
97
- foundKeys.push(i);
98
- continue;
98
+ if (!optional)
99
+ errors.push("no field '" + i + "'");
100
+ else {
101
+ foundKeys.push(i);
102
+ continue;
103
+ }
99
104
  }
100
105
  }
101
106
  if (typeof structure[i] === "number" && typeof object[i] === "string") {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { APIService, Initializer } from "./apiServer/APIService";
2
2
  import { LocalRequest } from "./apiServer/LocalRequest";
3
3
  import { MysqlService } from "./apiServer/MysqlService";
4
- import { Validator } from "./apiServer/helper/Validator";
4
+ import { Validator, ValidationModel } from "./apiServer/helper/Validator";
5
5
  import { LogService } from "./apiServer/LogService";
6
6
  import { ErrorUtils } from "./apiServer/structures/DefaultErrors";
7
7
  import { S_MONITOR_REGISTRATE_ACTION } from "./apiServer/monitor/Monitor";
@@ -9,4 +9,4 @@ import { DataProvider } from "./apiServer/helper/DataProvider";
9
9
  import { UID } from "./apiServer/helper/UID";
10
10
  import { ExternalService } from "./apiServer/external/ExternalService";
11
11
  import { DBService } from "./apiServer/DBService";
12
- export { UID, APIService, Initializer, LocalRequest, MysqlService, Validator, LogService, DataProvider, ErrorUtils, ExternalService, DBService, S_MONITOR_REGISTRATE_ACTION };
12
+ export { UID, APIService, Initializer, LocalRequest, ValidationModel, MysqlService, Validator, LogService, DataProvider, ErrorUtils, ExternalService, DBService, S_MONITOR_REGISTRATE_ACTION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.4.1",
3
+ "version": "3.4.2",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",