badmfck-api-server 3.7.6 → 3.7.8

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.
@@ -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.7.6";
98
+ version = "3.7.8";
99
99
  options;
100
100
  monitor = null;
101
101
  started = new Date();
@@ -47,7 +47,7 @@ export type ValidationModel<T> = DeepMutable<{
47
47
  export declare class Validator {
48
48
  static validateObject(fields: string[], object: any): boolean;
49
49
  static documentStructure(structure: any): Record<string, any> | undefined;
50
- static validateStructure(structure: any, object: any, level?: number): Promise<string[] | undefined>;
50
+ static validateStructure(structure: any, object: any, level?: number, parentPath?: string): Promise<string[] | undefined>;
51
51
  static filterStructure(structure: any, object: any): void;
52
52
  static syncStructure(structure: any, object: any): any;
53
53
  static convertToType<T>(value: any, type: "string" | "number" | "boolean" | "date"): T | null;
@@ -60,7 +60,7 @@ class Validator {
60
60
  }
61
61
  return params;
62
62
  }
63
- static async validateStructure(structure, object, level = 0) {
63
+ static async validateStructure(structure, object, level = 0, parentPath = "") {
64
64
  if (!structure)
65
65
  return;
66
66
  if (!object)
@@ -98,7 +98,7 @@ class Validator {
98
98
  }
99
99
  else {
100
100
  if (!optional) {
101
- errors.push("no field '" + i + "'");
101
+ errors.push("no field '" + parentPath + i + "'");
102
102
  continue;
103
103
  }
104
104
  else {
@@ -109,7 +109,7 @@ class Validator {
109
109
  }
110
110
  if (object[i] === null || object[i] === undefined) {
111
111
  if (!optional)
112
- errors.push("no value for field '" + i + "'");
112
+ errors.push("no value for field '" + parentPath + i + "'");
113
113
  else {
114
114
  foundKeys.push(i);
115
115
  continue;
@@ -120,7 +120,7 @@ class Validator {
120
120
  if (object[i].includes(","))
121
121
  num = parseFloat(object[i]);
122
122
  if (isNaN(num))
123
- errors.push("wrong value for field '" + i + "', expected number got " + object[i]);
123
+ errors.push("wrong value for field '" + parentPath + i + "', expected number got " + object[i]);
124
124
  else
125
125
  object[i] = num;
126
126
  }
@@ -128,14 +128,14 @@ class Validator {
128
128
  errors.push("wrong datatype for field '" + i + "' expected " + typeof structure[i] + " got " + typeof object[i]);
129
129
  if (typeof structure[i] === "object" || typeof structure[i] === "function") {
130
130
  if (typeof object[i] !== "object") {
131
- errors.push("wrong type for: " + i);
131
+ errors.push("wrong type for: " + parentPath + i);
132
132
  }
133
133
  else {
134
134
  if (Array.isArray(structure[i]) && !Array.isArray(object[i])) {
135
- errors.push("array expected for " + i);
135
+ errors.push("array expected for " + parentPath + i);
136
136
  }
137
137
  else {
138
- const result = await this.validateStructure(structure[i], object[i], level++);
138
+ const result = await this.validateStructure(structure[i], object[i], level++, parentPath + i + ".");
139
139
  if (result) {
140
140
  for (let j of result)
141
141
  errors.push(j);
@@ -148,9 +148,9 @@ class Validator {
148
148
  if (expected.length) {
149
149
  const value = object[i].toString().toLowerCase().trim();
150
150
  if (value.length === 0)
151
- errors.push("empty value for field '" + i + "'");
151
+ errors.push("empty value for field '" + parentPath + i + "'");
152
152
  else if (expected.indexOf(value) === -1)
153
- errors.push("wrong value for field '" + i + "', expected " + expected.join(", ") + " got: " + value);
153
+ errors.push("wrong value for field '" + parentPath + i + "', expected " + expected.join(", ") + " got: " + value);
154
154
  }
155
155
  }
156
156
  if (structure['$__' + i + "_values"]) {
@@ -165,7 +165,7 @@ class Validator {
165
165
  break;
166
166
  }
167
167
  }
168
- errors.push("Wrong value for field '" + i + "'" + (caseValue ? ", check case for: " + caseValue : ""));
168
+ errors.push("wrong value for field '" + parentPath + i + "'" + (caseValue ? ", check case for: " + caseValue : ""));
169
169
  }
170
170
  }
171
171
  }
@@ -173,12 +173,12 @@ class Validator {
173
173
  const regex = structure["$__" + i + "_regex"];
174
174
  const reg = new RegExp(regex);
175
175
  if (reg.test(object[i]) === false)
176
- errors.push("wrong value for field '" + i + "', false mask for: >" + object[i] + "<");
176
+ errors.push("wrong value for field '" + parentPath + i + "', false mask for: >" + object[i] + "<");
177
177
  }
178
178
  if (typeof structure[i] === "string" && (structure[i] === "@" || structure[i] === "email")) {
179
179
  const value = object[i].toString().toLowerCase().trim();
180
180
  if (value.replaceAll(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$/g, "").length !== 0)
181
- errors.push("wrong value for field '" + i + "', expected email got: " + object[i]);
181
+ errors.push("wrong value for field '" + parentPath + i + "', expected email got: " + object[i]);
182
182
  const domain = value.split("@")[1];
183
183
  try {
184
184
  await dns_1.default.promises.resolveMx(domain);
@@ -195,39 +195,39 @@ class Validator {
195
195
  object[i] = parseInt(object[i]);
196
196
  }
197
197
  if (isNaN(object[i]))
198
- errors.push("wrong value for field '" + i + "', expected number got " + object[i]);
198
+ errors.push("wrong value for field '" + parentPath + i + "', expected number got " + object[i]);
199
199
  if (structure[i] != 0) {
200
200
  if (structure[i] > 0) {
201
201
  const max = structure[i];
202
202
  if (object[i] > max)
203
- errors.push("value for field '" + i + "' is too big, expected less than " + max + " got: " + object[i]);
203
+ errors.push("value for field '" + parentPath + i + "' is too big, expected less than " + max + " got: " + object[i]);
204
204
  }
205
205
  else {
206
206
  const min = structure[i] * -1;
207
207
  if (object[i] < min)
208
- errors.push("value for field '" + i + "' is too small, expected more than " + min + " got: " + object[i]);
208
+ errors.push("value for field '" + parentPath + i + "' is too small, expected more than " + min + " got: " + object[i]);
209
209
  }
210
210
  }
211
211
  }
212
212
  if (typeof structure[i] === "number" && structure["$__" + i + "_min"]) {
213
213
  const min = structure["$__" + i + "_min"];
214
214
  if (object[i] < min)
215
- errors.push("value for field '" + i + "' is too small, expected more than " + min + " got: " + object[i]);
215
+ errors.push("value for field '" + parentPath + i + "' is too small, expected more than " + min + " got: " + object[i]);
216
216
  }
217
217
  if (typeof structure[i] === "number" && structure["$__" + i + "_max"]) {
218
218
  const max = structure["$__" + i + "_max"];
219
219
  if (object[i] > max)
220
- errors.push("value for field '" + i + "' is too big, expected less than " + max + " got: " + object[i]);
220
+ errors.push("value for field '" + parentPath + i + "' is too big, expected less than " + max + " got: " + object[i]);
221
221
  }
222
222
  if (typeof object[i] === "string" && structure["$__" + i + "_min"]) {
223
223
  const min = structure["$__" + i + "_min"];
224
224
  if (object[i].length < min)
225
- errors.push("value length for field '" + i + "' is too small, expected more than " + min + " got: " + object[i].length);
225
+ errors.push("value length for field '" + parentPath + i + "' is too small, expected more than " + min + " got: " + object[i].length);
226
226
  }
227
227
  if (typeof object[i] === "string" && structure["$__" + i + "_max"]) {
228
228
  const max = structure["$__" + i + "_max"];
229
229
  if (object[i].length > max)
230
- errors.push("value length for field '" + i + "' is too big, expected less than " + max + " got: " + object[i].length);
230
+ errors.push("value length for field '" + parentPath + i + "' is too big, expected less than " + max + " got: " + object[i].length);
231
231
  }
232
232
  foundKeys.push(i);
233
233
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.7.6",
3
+ "version": "3.7.8",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",