@golemio/pid 2.14.2-dev.1356992619 → 2.14.2-dev.1357024917
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/output-gateway/public/routers/v1/PublicDeparturesRouter.js +1 -1
- package/dist/output-gateway/public/routers/v1/helpers/CustomStopIdGroupValidator.d.ts +1 -0
- package/dist/output-gateway/public/routers/v1/helpers/CustomStopIdGroupValidator.js +38 -16
- package/dist/output-gateway/public/routers/v1/helpers/CustomStopIdGroupValidator.js.map +1 -1
- package/docs/openapi-output.yaml +4 -2
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ class PublicDeparturesRouter {
|
|
|
18
18
|
initRoutes() {
|
|
19
19
|
this.router.get("/", [
|
|
20
20
|
(0, express_validator_1.query)("stopIds").exists().custom(CustomStopIdGroupValidator_1.CustomStopIdGroupValidator.validate),
|
|
21
|
-
(0, express_validator_1.query)("limit").optional().isInt({ min: 1, max:
|
|
21
|
+
(0, express_validator_1.query)("limit").optional().isInt({ min: 1, max: 30 }).not().isArray(),
|
|
22
22
|
(0, express_validator_1.query)("routeShortNames").optional().not().isEmpty({ ignore_whitespace: true }),
|
|
23
23
|
(0, express_validator_1.query)("minutesAfter").optional().isInt({ min: 1, max: 360 }).not().isArray(),
|
|
24
24
|
], Validation_1.checkErrors,
|
|
@@ -2,41 +2,63 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.CustomStopIdGroupValidator = void 0;
|
|
5
|
+
const MAX_STOP_GROUPS = 50;
|
|
6
|
+
const MAX_STOPS_IN_GROUP = 50;
|
|
7
|
+
const MAX_STOPS_TOTAL = 50;
|
|
5
8
|
class CustomStopIdGroupValidator {
|
|
6
|
-
static isStopIdGroupValid(
|
|
9
|
+
static isStopIdGroupValid(stopIds) {
|
|
7
10
|
try {
|
|
8
|
-
const parsed = JSON.parse(value);
|
|
9
|
-
const keys = Object.keys(parsed);
|
|
10
|
-
if (keys.length !== 1) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const priority = Number.parseInt(keys[0]);
|
|
14
|
-
if (Number.isNaN(priority)) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const stopIds = parsed[priority];
|
|
18
11
|
if (!Array.isArray(stopIds) ||
|
|
19
12
|
stopIds.length === 0 ||
|
|
20
|
-
stopIds.length >
|
|
13
|
+
stopIds.length > MAX_STOPS_IN_GROUP ||
|
|
21
14
|
stopIds.some((stopId) => typeof stopId !== "string" || stopId.length === 0 || stopId.length > 30)) {
|
|
22
15
|
return false;
|
|
23
16
|
}
|
|
24
17
|
return true;
|
|
25
18
|
}
|
|
26
|
-
catch (
|
|
19
|
+
catch (_b) {
|
|
27
20
|
return false;
|
|
28
21
|
}
|
|
29
22
|
}
|
|
23
|
+
static parseStopIdsFromGroup(value) {
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(value);
|
|
26
|
+
const keys = Object.keys(parsed);
|
|
27
|
+
if (keys.length !== 1) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const priority = Number.parseInt(keys[0]);
|
|
31
|
+
if (Number.isNaN(priority)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return parsed[priority];
|
|
35
|
+
}
|
|
36
|
+
catch (_b) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
30
40
|
}
|
|
31
41
|
exports.CustomStopIdGroupValidator = CustomStopIdGroupValidator;
|
|
32
42
|
_a = CustomStopIdGroupValidator;
|
|
33
43
|
CustomStopIdGroupValidator.validate = (value, _) => {
|
|
34
44
|
if (value instanceof Array) {
|
|
35
|
-
if (value.length === 0 || value.length >
|
|
45
|
+
if (value.length === 0 || value.length > MAX_STOP_GROUPS) {
|
|
36
46
|
return false;
|
|
37
47
|
}
|
|
38
|
-
|
|
48
|
+
let stopsTotal = 0;
|
|
49
|
+
for (const stopIdGroup of value) {
|
|
50
|
+
const stopIds = _a.parseStopIdsFromGroup(stopIdGroup);
|
|
51
|
+
if (!_a.isStopIdGroupValid(stopIds)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
stopsTotal += stopIds.length;
|
|
55
|
+
if (stopsTotal > MAX_STOPS_TOTAL) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
39
60
|
}
|
|
40
|
-
|
|
61
|
+
const stopIds = _a.parseStopIdsFromGroup(value);
|
|
62
|
+
return _a.isStopIdGroupValid(stopIds);
|
|
41
63
|
};
|
|
42
64
|
//# sourceMappingURL=CustomStopIdGroupValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomStopIdGroupValidator.js","sourceRoot":"","sources":["../../../../../../src/output-gateway/public/routers/v1/helpers/CustomStopIdGroupValidator.ts"],"names":[],"mappings":";;;;AAEA,
|
|
1
|
+
{"version":3,"file":"CustomStopIdGroupValidator.js","sourceRoot":"","sources":["../../../../../../src/output-gateway/public/routers/v1/helpers/CustomStopIdGroupValidator.ts"],"names":[],"mappings":";;;;AAEA,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAa,0BAA0B;IA4B3B,MAAM,CAAC,kBAAkB,CAAC,OAAwB;QACtD,IAAI;YACA,IACI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;gBACvB,OAAO,CAAC,MAAM,KAAK,CAAC;gBACpB,OAAO,CAAC,MAAM,GAAG,kBAAkB;gBACnC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC,EACnG;gBACE,OAAO,KAAK,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AC;KACf;IAED,MAAM,OAAO,GAAG,EAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,EAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC,AAzBqB,CAyBpB"}
|
package/docs/openapi-output.yaml
CHANGED
|
@@ -1305,13 +1305,15 @@ paths:
|
|
|
1305
1305
|
items:
|
|
1306
1306
|
type: string
|
|
1307
1307
|
example: ["{\"0\": [\"U717Z5P\"]}", "{\"1\": [\"U718Z5P\", \"U719Z5P\"]}"]
|
|
1308
|
-
description:
|
|
1308
|
+
description: |
|
|
1309
|
+
Groups of stop IDs formatted as JSON (index/priority -> stop IDs). For example ?stopIds[]={\"0\": [\"U717Z5P\"]}&stopIds[]={\"1\": [\"U718Z5P\", \"U719Z5P\"]}.
|
|
1310
|
+
The maximum number of groups is 50. The maximum number of stops in one group is 50. The maximum number of stops combined is 50.
|
|
1309
1311
|
- in: query
|
|
1310
1312
|
name: limit
|
|
1311
1313
|
required: false
|
|
1312
1314
|
schema:
|
|
1313
1315
|
type: integer
|
|
1314
|
-
description: Limit for each group of departures. Default is 5. Maximum is
|
|
1316
|
+
description: Limit for each group of departures. Default is 5. Maximum is 30.
|
|
1315
1317
|
example: 5
|
|
1316
1318
|
- in: query
|
|
1317
1319
|
name: routeShortNames
|