@golemio/pid 2.14.2-dev.1355988562 → 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/db/migrations/postgresql/20240701093122-fix-delay-in-view-v-public-vehiclepositions-past-stop-times.js +53 -0
- package/db/migrations/postgresql/sqls/20240701093122-fix-delay-in-view-v-public-vehiclepositions-past-stop-times-down.sql +31 -0
- package/db/migrations/postgresql/sqls/20240701093122-fix-delay-in-view-v-public-vehiclepositions-past-stop-times-up.sql +38 -0
- 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
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dbm;
|
|
4
|
+
var type;
|
|
5
|
+
var seed;
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var Promise;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* We receive the dbmigrate dependency from dbmigrate initially.
|
|
12
|
+
* This enables us to not have to rely on NODE_PATH.
|
|
13
|
+
*/
|
|
14
|
+
exports.setup = function(options, seedLink) {
|
|
15
|
+
dbm = options.dbmigrate;
|
|
16
|
+
type = dbm.dataType;
|
|
17
|
+
seed = seedLink;
|
|
18
|
+
Promise = options.Promise;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.up = function(db) {
|
|
22
|
+
var filePath = path.join(__dirname, 'sqls', '20240701093122-fix-delay-in-view-v-public-vehiclepositions-past-stop-times-up.sql');
|
|
23
|
+
return new Promise( function( resolve, reject ) {
|
|
24
|
+
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
25
|
+
if (err) return reject(err);
|
|
26
|
+
console.log('received data: ' + data);
|
|
27
|
+
|
|
28
|
+
resolve(data);
|
|
29
|
+
});
|
|
30
|
+
})
|
|
31
|
+
.then(function(data) {
|
|
32
|
+
return db.runSql(data);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.down = function(db) {
|
|
37
|
+
var filePath = path.join(__dirname, 'sqls', '20240701093122-fix-delay-in-view-v-public-vehiclepositions-past-stop-times-down.sql');
|
|
38
|
+
return new Promise( function( resolve, reject ) {
|
|
39
|
+
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
40
|
+
if (err) return reject(err);
|
|
41
|
+
console.log('received data: ' + data);
|
|
42
|
+
|
|
43
|
+
resolve(data);
|
|
44
|
+
});
|
|
45
|
+
})
|
|
46
|
+
.then(function(data) {
|
|
47
|
+
return db.runSql(data);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports._meta = {
|
|
52
|
+
"version": 1
|
|
53
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
CREATE OR REPLACE VIEW v_public_vehiclepositions_past_stop_times AS
|
|
2
|
+
SELECT
|
|
3
|
+
sub.trips_id AS rt_trip_id,
|
|
4
|
+
sub.last_stop_sequence AS stop_sequence,
|
|
5
|
+
sub.stop_arr_delay,
|
|
6
|
+
sub.stop_dep_delay,
|
|
7
|
+
sub.last_stop_id AS stop_id
|
|
8
|
+
FROM (
|
|
9
|
+
SELECT
|
|
10
|
+
rt_position.trips_id,
|
|
11
|
+
rt_position.last_stop_id,
|
|
12
|
+
rt_position.last_stop_sequence,
|
|
13
|
+
rt_position.delay_stop_arrival,
|
|
14
|
+
rt_position.delay_stop_departure,
|
|
15
|
+
max(rt_position.delay_stop_arrival) AS stop_arr_delay,
|
|
16
|
+
min(rt_position.delay_stop_departure) AS stop_dep_delay
|
|
17
|
+
FROM
|
|
18
|
+
vehiclepositions_positions rt_position
|
|
19
|
+
WHERE (rt_position.delay_stop_arrival IS NOT NULL
|
|
20
|
+
OR rt_position.delay_stop_departure IS NOT NULL)
|
|
21
|
+
AND (rt_position.state_position::text = ANY (ARRAY['on_track'::character varying::text, 'at_stop'::character varying::text, 'after_track'::character varying::text]))
|
|
22
|
+
GROUP BY
|
|
23
|
+
rt_position.trips_id,
|
|
24
|
+
rt_position.last_stop_id,
|
|
25
|
+
rt_position.last_stop_sequence,
|
|
26
|
+
rt_position.delay_stop_arrival,
|
|
27
|
+
rt_position.delay_stop_departure) sub
|
|
28
|
+
ORDER BY
|
|
29
|
+
sub.trips_id,
|
|
30
|
+
sub.last_stop_sequence;
|
|
31
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
CREATE OR REPLACE VIEW v_public_vehiclepositions_past_stop_times AS
|
|
2
|
+
SELECT
|
|
3
|
+
sub.trips_id AS rt_trip_id,
|
|
4
|
+
sub.last_stop_sequence AS stop_sequence,
|
|
5
|
+
sub.stop_arr_delay,
|
|
6
|
+
sub.stop_dep_delay,
|
|
7
|
+
sub.last_stop_id AS stop_id
|
|
8
|
+
FROM (
|
|
9
|
+
SELECT
|
|
10
|
+
rt_position.trips_id,
|
|
11
|
+
rt_position.last_stop_id,
|
|
12
|
+
rt_position.last_stop_sequence,
|
|
13
|
+
CASE WHEN (rt_position.last_stop_departure_time::time +(interval '1 second' * min(rt_position.delay_stop_departure)) > rt_position.next_stop_arrival_time::time +(interval '1 second' * max(rt_position.delay_stop_arrival))) THEN
|
|
14
|
+
NULL
|
|
15
|
+
ELSE
|
|
16
|
+
max(rt_position.delay_stop_arrival)
|
|
17
|
+
END AS stop_arr_delay,
|
|
18
|
+
CASE WHEN (rt_position.last_stop_arrival_time::time +(interval '1 second' * max(rt_position.delay_stop_arrival)) > rt_position.last_stop_departure_time::time +(interval '1 second' * min(rt_position.delay_stop_departure))) THEN
|
|
19
|
+
NULL
|
|
20
|
+
ELSE
|
|
21
|
+
min(rt_position.delay_stop_departure)
|
|
22
|
+
END AS stop_dep_delay
|
|
23
|
+
FROM
|
|
24
|
+
vehiclepositions_positions rt_position
|
|
25
|
+
WHERE (rt_position.delay_stop_arrival IS NOT NULL
|
|
26
|
+
OR rt_position.delay_stop_departure IS NOT NULL)
|
|
27
|
+
AND (rt_position.state_position::text = ANY (ARRAY['on_track'::character varying::text, 'at_stop'::character varying::text, 'after_track'::character varying::text]))
|
|
28
|
+
GROUP BY
|
|
29
|
+
rt_position.trips_id,
|
|
30
|
+
rt_position.last_stop_id,
|
|
31
|
+
rt_position.last_stop_sequence,
|
|
32
|
+
rt_position.last_stop_arrival_time,
|
|
33
|
+
rt_position.last_stop_departure_time,
|
|
34
|
+
rt_position.next_stop_arrival_time) sub
|
|
35
|
+
ORDER BY
|
|
36
|
+
sub.trips_id,
|
|
37
|
+
sub.last_stop_sequence;
|
|
38
|
+
|
|
@@ -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,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O,CAAC,EAAE;gBACnC,OAAO,KAAK,CAAC;aAChB;YAED,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;YAC7B,IAAI,UAAU,GAAG,eAAe,EAAE;gBAC9B,OAAO,KAAK,CAAC;aAChB;SACJ;QAED,OAAO,IAAI,CAAC;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
|