badmfck-api-server 3.9.7 → 3.9.81

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.
@@ -93,7 +93,7 @@ async function Initializer(services) {
93
93
  }
94
94
  exports.Initializer = Initializer;
95
95
  class APIService extends BaseService_1.BaseService {
96
- version = "3.9.7";
96
+ version = "3.9.81";
97
97
  options;
98
98
  monitor = null;
99
99
  started = new Date();
@@ -14,8 +14,8 @@ class UID {
14
14
  + ""
15
15
  + Math.round(Math.random() * 1000)).toString(16), 'hex').toString('base64');
16
16
  uid = uid.replaceAll("=", "");
17
- uid = uid.replaceAll("+", ".");
18
- uid = uid.replaceAll("/", "_");
17
+ uid = uid.replaceAll("+", "pL");
18
+ uid = uid.replaceAll("/", "sl");
19
19
  return uid;
20
20
  }
21
21
  static generateRandomNumberBase(count) {
@@ -282,7 +282,7 @@ class Validator {
282
282
  this.filterStructure(structure[0], i);
283
283
  return;
284
284
  }
285
- for (let key in object) {
285
+ for (let key of Object.keys(object)) {
286
286
  if (!(key in structure)) {
287
287
  delete object[key];
288
288
  continue;
@@ -314,72 +314,71 @@ class Validator {
314
314
  const items = numericKeys.length > 0
315
315
  ? numericKeys.map((i) => node[String(i)])
316
316
  : Object.values(node);
317
- node = items.map((it) => this.syncStructure(tmpl, it));
318
- return node;
317
+ return items.map((it) => this.syncStructure(tmpl, it));
319
318
  }
320
319
  if (!Array.isArray(node))
321
320
  return node;
322
- if (tmpl !== undefined) {
323
- for (let i = 0; i < node.length; i++) {
324
- const item = node[i];
325
- if (item === null || item === undefined) {
326
- node[i] = this.clone(tmpl);
327
- node[i] = this.syncStructure(tmpl, node[i]);
328
- continue;
329
- }
330
- if (this.isPlainObject(tmpl) && this.isPlainObject(item)) {
331
- node[i] = this.syncStructure(tmpl, item);
332
- continue;
333
- }
334
- if (Array.isArray(tmpl) && Array.isArray(item)) {
335
- node[i] = this.syncStructure(tmpl, item);
336
- continue;
337
- }
338
- node[i] = this.clone(tmpl);
339
- node[i] = this.syncStructure(tmpl, node[i]);
321
+ if (tmpl === undefined)
322
+ return node;
323
+ const out = new Array(node.length);
324
+ for (let i = 0; i < node.length; i++) {
325
+ const item = node[i];
326
+ if (item === null || item === undefined) {
327
+ out[i] = this.syncStructure(tmpl, this.clone(tmpl));
328
+ }
329
+ else if (this.isPlainObject(tmpl) && this.isPlainObject(item)) {
330
+ out[i] = this.syncStructure(tmpl, item);
331
+ }
332
+ else if (Array.isArray(tmpl) && Array.isArray(item)) {
333
+ out[i] = this.syncStructure(tmpl, item);
334
+ }
335
+ else {
336
+ out[i] = this.syncStructure(tmpl, this.clone(tmpl));
340
337
  }
341
338
  }
342
- return node;
343
- }
344
- if (!this.isPlainObject(node))
345
- return node;
346
- for (const k of Object.keys(node)) {
347
- if (!(k in structure))
348
- delete node[k];
339
+ return out;
349
340
  }
341
+ const out = {};
342
+ const src = this.isPlainObject(node) ? node : {};
350
343
  for (const k of Object.keys(structure)) {
351
344
  const sv = structure[k];
352
345
  if (k.startsWith("$__")) {
353
- node[k] = this.clone(sv);
346
+ out[k] = this.clone(sv);
354
347
  continue;
355
348
  }
356
- const has = Object.prototype.hasOwnProperty.call(node, k);
357
- const ov = has ? node[k] : undefined;
349
+ const has = Object.prototype.hasOwnProperty.call(src, k);
350
+ const ov = has ? src[k] : undefined;
351
+ const { optional, skip_validation, default: def } = this.parseStructureOptions(k, structure);
358
352
  if (!has) {
359
- node[k] = this.clone(sv);
360
- if (sv && typeof sv === "object")
361
- node[k] = this.syncStructure(sv, node[k]);
353
+ if (sv && typeof sv === "object") {
354
+ out[k] = this.syncStructure(sv, this.clone(sv));
355
+ }
356
+ else {
357
+ out[k] = this.clone(sv);
358
+ }
362
359
  continue;
363
360
  }
364
- const { optional, default: def } = this.parseStructureOptions(k, structure);
365
361
  if (ov === null || ov === undefined) {
366
362
  if (def !== undefined && !optional) {
367
- node[k] = this.clone(def);
368
- continue;
363
+ out[k] = this.clone(def);
369
364
  }
370
- if (!optional) {
371
- node[k] = this.clone(sv);
372
- if (sv && typeof sv === "object")
373
- node[k] = this.syncStructure(sv, node[k]);
374
- continue;
365
+ else if (!optional || skip_validation) {
366
+ out[k] = sv && typeof sv === "object"
367
+ ? this.syncStructure(sv, this.clone(sv))
368
+ : this.clone(sv);
375
369
  }
370
+ else {
371
+ out[k] = ov;
372
+ }
373
+ continue;
376
374
  }
377
375
  if (sv && typeof sv === "object") {
378
- node[k] = this.syncStructure(sv, ov);
376
+ out[k] = this.syncStructure(sv, ov);
379
377
  continue;
380
378
  }
379
+ out[k] = ov;
381
380
  }
382
- return node;
381
+ return out;
383
382
  }
384
383
  static convertToType(value, type) {
385
384
  if (value === null || value === undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.9.7",
3
+ "version": "3.9.81",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",