badmfck-api-server 3.3.0 → 3.3.2
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,10 +95,9 @@ 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.
|
98
|
+
version = "3.3.2";
|
99
99
|
options;
|
100
100
|
monitor = null;
|
101
|
-
monitorIndexFile;
|
102
101
|
started = new Date();
|
103
102
|
requestsCount = 0;
|
104
103
|
server = http_1.default;
|
@@ -24,6 +24,7 @@ export declare class Validator {
|
|
24
24
|
static documentStructure(structure: any): Record<string, any> | undefined;
|
25
25
|
static validateStructure(structure: any, object: any, level?: number): Promise<string[] | undefined>;
|
26
26
|
static filterStructure(structure: any, object: any): void;
|
27
|
+
static syncStructure(structure: any, object: any): any;
|
27
28
|
static convertToType<T>(value: any, type: "string" | "number" | "boolean" | "date"): T | null;
|
28
29
|
static validateValue(value: string | number | boolean, opt?: IValidatorOptions): ValidationReport;
|
29
30
|
}
|
@@ -89,7 +89,7 @@ class Validator {
|
|
89
89
|
foundKeys.push(i);
|
90
90
|
continue;
|
91
91
|
}
|
92
|
-
let optional = structure['$__' + i + "
|
92
|
+
let optional = structure['$__' + i + "_optional"] || false;
|
93
93
|
if (!(i in object)) {
|
94
94
|
if (!optional)
|
95
95
|
errors.push("no field '" + i + "'");
|
@@ -193,6 +193,33 @@ class Validator {
|
|
193
193
|
this.filterStructure(structure[key], object[key]);
|
194
194
|
}
|
195
195
|
}
|
196
|
+
static syncStructure(structure, object) {
|
197
|
+
if (typeof structure !== "object")
|
198
|
+
return;
|
199
|
+
if (typeof object !== "object")
|
200
|
+
return;
|
201
|
+
for (const key in object) {
|
202
|
+
if (!(key in structure)) {
|
203
|
+
delete object[key];
|
204
|
+
}
|
205
|
+
}
|
206
|
+
for (const key in structure) {
|
207
|
+
const tVal = structure[key];
|
208
|
+
const bVal = object[key];
|
209
|
+
if (!(key in object)) {
|
210
|
+
object[key] = tVal;
|
211
|
+
}
|
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);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
return object;
|
222
|
+
}
|
196
223
|
static convertToType(value, type) {
|
197
224
|
if (value === null || value === undefined)
|
198
225
|
return null;
|