badmfck-api-server 3.2.7 → 3.3.0

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.
@@ -5,6 +5,7 @@ import { IBaseEndpoint } from './BaseEndpoint';
5
5
  import { HTTPRequestVO, IError, TransferPacketVO } from './structures/Interfaces';
6
6
  import { Req } from "badmfck-signal";
7
7
  import http from 'http';
8
+ import { IWebsocket } from './Websocket';
8
9
  export interface IMonitorUser {
9
10
  login: string;
10
11
  password: string;
@@ -39,6 +40,7 @@ export interface APIServiceOptions {
39
40
  monitor?: IMonitorUser[];
40
41
  documentation?: IMonitorUser[];
41
42
  };
43
+ websocket?: IWebsocket[];
42
44
  monitor?: IMonitorUser[];
43
45
  appVersion?: string;
44
46
  fileTempDir: string;
@@ -95,7 +95,7 @@ async function Initializer(services) {
95
95
  exports.Initializer = Initializer;
96
96
  class APIService extends BaseService_1.BaseService {
97
97
  static nextLogID = 0;
98
- version = "3.2.7";
98
+ version = "3.3.0";
99
99
  options;
100
100
  monitor = null;
101
101
  monitorIndexFile;
@@ -0,0 +1,8 @@
1
+ export interface IWebsocket {
2
+ }
3
+ export interface IWebSocketServiceOptions {
4
+ }
5
+ export declare class Websocket implements IWebsocket {
6
+ options: IWebSocketServiceOptions;
7
+ constructor(opt?: IWebSocketServiceOptions);
8
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Websocket = void 0;
4
+ const getDefaultWebSocketServiceOptions = () => {
5
+ return {
6
+ endpoint: "/ws"
7
+ };
8
+ };
9
+ class Websocket {
10
+ options;
11
+ constructor(opt) {
12
+ this.options = { ...getDefaultWebSocketServiceOptions(), opt };
13
+ }
14
+ }
15
+ exports.Websocket = Websocket;
@@ -34,7 +34,10 @@ class Validator {
34
34
  let type = typeof structure[i];
35
35
  let description = structure['$__' + i] || "";
36
36
  let childs = undefined;
37
- let optional = structure['$__optional_' + i] || "";
37
+ let optional = structure['$__' + i + "_optional"] || "";
38
+ let regex = structure['$__' + i + '_regex'] || undefined;
39
+ let min = structure['$__' + i + "_min"] || undefined;
40
+ let max = structure['$__' + i + "_max"] || undefined;
38
41
  if (optional === undefined)
39
42
  optional = structure[i] === null || structure[i] === undefined;
40
43
  if (type === "object" && Array.isArray(structure[i]))
@@ -47,6 +50,9 @@ class Validator {
47
50
  type: type,
48
51
  description: description,
49
52
  optional: optional,
53
+ regex: regex,
54
+ min: min,
55
+ max: max,
50
56
  childs: childs
51
57
  };
52
58
  }
@@ -83,7 +89,7 @@ class Validator {
83
89
  foundKeys.push(i);
84
90
  continue;
85
91
  }
86
- let optional = structure['$__optional_' + i] || false;
92
+ let optional = structure['$__' + i + "optional"] || false;
87
93
  if (!(i in object)) {
88
94
  if (!optional)
89
95
  errors.push("no field '" + i + "'");
@@ -120,8 +126,8 @@ class Validator {
120
126
  errors.push("wrong value for field '" + i + "', expected " + expected.join(", ") + " got: " + value);
121
127
  }
122
128
  }
123
- if (typeof structure[i] === "string" && structure["$__regex_" + i]) {
124
- const regex = structure["$__regex_" + i];
129
+ if (typeof structure[i] === "string" && structure["$__" + i + "_regex"]) {
130
+ const regex = structure["$__" + i + "_regex"];
125
131
  const reg = new RegExp(regex);
126
132
  if (reg.test(object[i]) === false)
127
133
  errors.push("wrong value for field '" + i + "', false mask for: " + object[i]);
@@ -154,13 +160,13 @@ class Validator {
154
160
  }
155
161
  }
156
162
  }
157
- if (typeof structure[i] === "number" && structure["$__min_" + i]) {
158
- const min = structure["$__min_" + i];
163
+ if (typeof structure[i] === "number" && structure["$__" + i + "_min"]) {
164
+ const min = structure["$__" + i + "_min"];
159
165
  if (object[i] < min)
160
166
  errors.push("value for field '" + i + "' is too small, expected more than " + min + " got: " + object[i]);
161
167
  }
162
- if (typeof structure[i] === "number" && structure["$__max_" + i]) {
163
- const max = structure["$__max_" + i];
168
+ if (typeof structure[i] === "number" && structure["$__" + i + "_max"]) {
169
+ const max = structure["$__" + i + "_max"];
164
170
  if (object[i] > max)
165
171
  errors.push("value for field '" + i + "' is too big, expected less than " + max + " got: " + object[i]);
166
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.2.7",
3
+ "version": "3.3.0",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",