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.
@@ -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
|
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
|
-
|
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
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
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
|
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
|
-
|
346
|
+
out[k] = this.clone(sv);
|
354
347
|
continue;
|
355
348
|
}
|
356
|
-
const has = Object.prototype.hasOwnProperty.call(
|
357
|
-
const ov = has ?
|
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
|
-
|
360
|
-
|
361
|
-
|
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
|
-
|
368
|
-
continue;
|
363
|
+
out[k] = this.clone(def);
|
369
364
|
}
|
370
|
-
if (!optional) {
|
371
|
-
|
372
|
-
|
373
|
-
|
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
|
-
|
376
|
+
out[k] = this.syncStructure(sv, ov);
|
379
377
|
continue;
|
380
378
|
}
|
379
|
+
out[k] = ov;
|
381
380
|
}
|
382
|
-
return
|
381
|
+
return out;
|
383
382
|
}
|
384
383
|
static convertToType(value, type) {
|
385
384
|
if (value === null || value === undefined)
|