badmfck-api-server 4.0.96 → 4.0.98
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.
- package/dist/apiServer/APIService.d.ts +5 -2
- package/dist/apiServer/APIService.js +1 -1
- package/dist/apiServer/DBService.js +9 -10
- package/dist/apiServer/documentation/Documentation.d.ts +1 -1
- package/dist/apiServer/documentation/Documentation.js +22 -3
- package/dist/apiServer/documentation/index.html +56 -42
- package/dist/apiServer/external/MicroserviceClient.js +4 -1
- package/dist/apiServer/helper/DataProvider.js +1 -2
- package/dist/apiServer/helper/Validator.js +38 -20
- package/package.json +2 -2
- package/untitled folder/assets/index-BQHWfl2U.js +0 -40
- package/untitled folder/index.html +0 -12
|
@@ -108,7 +108,10 @@ class MicroserviceClient extends BaseService_1.BaseService {
|
|
|
108
108
|
}
|
|
109
109
|
return { ...DefaultErrors_1.default.EXTERNAL_SERVICE_ERROR, details: "Microservice processing timeout, attempts: " + attempt };
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
if (body && typeof body === "object") {
|
|
112
|
+
return "error" in body ? body.error : (body.data ?? null);
|
|
113
|
+
}
|
|
114
|
+
return body ?? null;
|
|
112
115
|
}
|
|
113
116
|
return { ...DefaultErrors_1.default.EXTERNAL_SERVICE_ERROR, details: "Unknown polling error" };
|
|
114
117
|
}
|
|
@@ -21,8 +21,7 @@ class DataProvider {
|
|
|
21
21
|
this.cacheTime = +cacheTime;
|
|
22
22
|
if (isNaN(this.cacheTime))
|
|
23
23
|
this.cacheTime = 0;
|
|
24
|
-
|
|
25
|
-
this.name = "DataProvider " + (DataProvider.nextID++);
|
|
24
|
+
this.name = name ?? "DataProvider " + (DataProvider.nextID++);
|
|
26
25
|
}
|
|
27
26
|
async forceUpdate() {
|
|
28
27
|
if (this.busy)
|
|
@@ -58,7 +58,7 @@ class Validator {
|
|
|
58
58
|
s_options.min = undefined;
|
|
59
59
|
if (s_options.max == undefined || isNaN(s_options.max)) {
|
|
60
60
|
if (structure[key + "max"] && !isNaN(structure[key + "max"]))
|
|
61
|
-
s_options.
|
|
61
|
+
s_options.max = parseInt(structure[key + "max"]);
|
|
62
62
|
}
|
|
63
63
|
if (s_options.max && isNaN(s_options.max))
|
|
64
64
|
s_options.max = undefined;
|
|
@@ -143,6 +143,13 @@ class Validator {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
if (structureOptions.optional && typeof object[i] === "object" && object[i] !== null) {
|
|
147
|
+
const isEmpty = Array.isArray(object[i]) ? object[i].length === 0 : Object.keys(object[i]).length === 0;
|
|
148
|
+
if (isEmpty) {
|
|
149
|
+
foundKeys.push(i);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
146
153
|
if ((object[i] === null || object[i] === undefined)) {
|
|
147
154
|
if (structure[i] === null || structure[i] === undefined) {
|
|
148
155
|
foundKeys.push(i);
|
|
@@ -210,32 +217,43 @@ class Validator {
|
|
|
210
217
|
if (structure['$__' + i + "_values"])
|
|
211
218
|
structureOptions.values = structure['$__' + i + "_values"];
|
|
212
219
|
if (Array.isArray(structureOptions.values) && structureOptions.values.length) {
|
|
213
|
-
|
|
214
|
-
if (structureOptions.
|
|
215
|
-
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
220
|
+
const checkOneValue = (val) => {
|
|
221
|
+
if (structureOptions.values.includes(val))
|
|
222
|
+
return null;
|
|
218
223
|
let caseValue = null;
|
|
219
|
-
for (
|
|
220
|
-
if (
|
|
224
|
+
for (const av of structureOptions.values) {
|
|
225
|
+
if (av === null || av === undefined)
|
|
221
226
|
continue;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
caseValue = object[i];
|
|
227
|
+
if ((av + "").toLowerCase().trim() === (val + "").toLowerCase().trim()) {
|
|
228
|
+
caseValue = av;
|
|
225
229
|
break;
|
|
226
230
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if ((i[key] + "").toLowerCase().trim() === val) {
|
|
232
|
-
caseValue = i[key];
|
|
231
|
+
if (typeof av === "object") {
|
|
232
|
+
for (const key of Object.keys(av)) {
|
|
233
|
+
if ((av[key] + "").toLowerCase().trim() === (val + "").toLowerCase().trim()) {
|
|
234
|
+
caseValue = av[key];
|
|
233
235
|
break;
|
|
234
236
|
}
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
239
|
}
|
|
238
|
-
|
|
240
|
+
return "wrong value for field '" + parentPath + i + "'" + (caseValue ? ", check case for: " + caseValue : "");
|
|
241
|
+
};
|
|
242
|
+
if (Array.isArray(object[i])) {
|
|
243
|
+
for (const item of object[i]) {
|
|
244
|
+
const err = checkOneValue(item);
|
|
245
|
+
if (err)
|
|
246
|
+
errors.push(err);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
if (structureOptions.default && structureOptions.values.includes(structureOptions.default)) {
|
|
251
|
+
object[i] = structureOptions.default;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const err = checkOneValue(object[i]);
|
|
255
|
+
if (err)
|
|
256
|
+
errors.push(err);
|
|
239
257
|
}
|
|
240
258
|
}
|
|
241
259
|
if (typeof structure[i] === "string" && structureOptions.regex) {
|
|
@@ -257,7 +275,7 @@ class Validator {
|
|
|
257
275
|
}
|
|
258
276
|
if (typeof structure[i] === "number") {
|
|
259
277
|
if (typeof object[i] === "string") {
|
|
260
|
-
if (object[i].indexOf("."))
|
|
278
|
+
if (object[i].indexOf(".") !== -1)
|
|
261
279
|
object[i] = parseFloat(object[i]);
|
|
262
280
|
else
|
|
263
281
|
object[i] = parseInt(object[i]);
|
|
@@ -477,7 +495,7 @@ class Validator {
|
|
|
477
495
|
if (opt.max && value > opt.max)
|
|
478
496
|
return ValidationReport.VALUE_TOO_BIG;
|
|
479
497
|
if (opt.min && value < opt.min)
|
|
480
|
-
return ValidationReport.
|
|
498
|
+
return ValidationReport.VALUE_TOO_SHORT;
|
|
481
499
|
return ValidationReport.OK;
|
|
482
500
|
}
|
|
483
501
|
if (typeof value !== "string")
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "badmfck-api-server",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.98",
|
|
4
4
|
"description": "Simple API http server based on express",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "tsc
|
|
9
|
+
"build": "tsc && cp ./src/apiServer/monitor/index.html ./dist/apiServer/monitor/index.html && cp ./src/apiServer/documentation/index.html ./dist/apiServer/documentation/index.html",
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|