badmfck-api-server 3.3.3 → 3.3.5

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.3.2";
98
+ version = "3.3.5";
99
99
  options;
100
100
  monitor = null;
101
101
  started = new Date();
@@ -181,8 +181,15 @@ class Validator {
181
181
  return;
182
182
  if (typeof structure !== "object" || typeof object !== "object")
183
183
  return;
184
- if (Array.isArray(structure))
184
+ if (Array.isArray(structure)) {
185
+ if (!Array.isArray(object))
186
+ return;
187
+ if (structure.length < 1)
188
+ return;
189
+ for (let i of object)
190
+ this.filterStructure(structure[0], i);
185
191
  return;
192
+ }
186
193
  for (let key in object) {
187
194
  if (!(key in structure)) {
188
195
  delete object[key];
@@ -196,26 +203,38 @@ class Validator {
196
203
  static syncStructure(structure, object) {
197
204
  if (typeof structure !== "object")
198
205
  return;
199
- if (typeof object !== "object")
200
- return;
201
206
  for (const key in object) {
202
207
  if (!(key in structure)) {
203
208
  delete object[key];
204
209
  }
205
210
  }
206
211
  for (const key in structure) {
207
- const tVal = structure[key];
208
- const bVal = object[key];
212
+ const structureValue = structure[key];
213
+ const objectValue = object[key];
209
214
  if (!(key in object)) {
210
- object[key] = tVal;
215
+ object[key] = structureValue;
216
+ continue;
217
+ }
218
+ if (objectValue === null && structureValue !== null) {
219
+ if (!structure["$__" + key + "_optional"])
220
+ object[key] = structureValue;
221
+ continue;
222
+ }
223
+ if (key.startsWith("$__")) {
224
+ object[key] = structure[key];
225
+ continue;
211
226
  }
212
- else if (typeof tVal === "object" &&
213
- tVal !== null &&
214
- !Array.isArray(tVal) &&
215
- typeof bVal === "object" &&
216
- bVal !== null &&
217
- !Array.isArray(bVal)) {
218
- this.syncStructure(bVal, tVal);
227
+ if (objectValue && typeof objectValue === "object") {
228
+ if (Array.isArray(objectValue) && Array.isArray(structureValue) && structureValue.length > 0) {
229
+ for (let i of objectValue) {
230
+ if (typeof i === "object")
231
+ this.syncStructure(structureValue[0], i);
232
+ }
233
+ }
234
+ else {
235
+ this.syncStructure(structureValue, objectValue);
236
+ }
237
+ continue;
219
238
  }
220
239
  }
221
240
  return object;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.3.3",
3
+ "version": "3.3.5",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",