minotor 4.0.0 → 5.0.1

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +3 -8
  2. package/dist/cli.mjs +128 -249
  3. package/dist/cli.mjs.map +1 -1
  4. package/dist/gtfs/parser.d.ts +0 -3
  5. package/dist/gtfs/stops.d.ts +1 -2
  6. package/dist/gtfs/trips.d.ts +6 -5
  7. package/dist/parser.cjs.js +127 -248
  8. package/dist/parser.cjs.js.map +1 -1
  9. package/dist/parser.esm.js +127 -248
  10. package/dist/parser.esm.js.map +1 -1
  11. package/dist/router.cjs.js +1 -1
  12. package/dist/router.cjs.js.map +1 -1
  13. package/dist/router.d.ts +2 -2
  14. package/dist/router.esm.js +1 -1
  15. package/dist/router.esm.js.map +1 -1
  16. package/dist/router.umd.js +1 -1
  17. package/dist/router.umd.js.map +1 -1
  18. package/dist/routing/route.d.ts +3 -3
  19. package/dist/timetable/io.d.ts +5 -4
  20. package/dist/timetable/proto/timetable.d.ts +5 -15
  21. package/dist/timetable/route.d.ts +1 -1
  22. package/dist/timetable/timetable.d.ts +7 -5
  23. package/package.json +1 -1
  24. package/src/__e2e__/timetable/stops.bin +2 -2
  25. package/src/__e2e__/timetable/timetable.bin +2 -2
  26. package/src/gtfs/__tests__/parser.test.ts +2 -2
  27. package/src/gtfs/__tests__/routes.test.ts +3 -0
  28. package/src/gtfs/__tests__/stops.test.ts +6 -13
  29. package/src/gtfs/__tests__/trips.test.ts +122 -154
  30. package/src/gtfs/parser.ts +6 -11
  31. package/src/gtfs/profiles/__tests__/ch.test.ts +0 -28
  32. package/src/gtfs/profiles/ch.ts +1 -18
  33. package/src/gtfs/profiles/standard.ts +0 -9
  34. package/src/gtfs/routes.ts +1 -0
  35. package/src/gtfs/stops.ts +2 -12
  36. package/src/gtfs/trips.ts +21 -19
  37. package/src/router.ts +2 -2
  38. package/src/routing/__tests__/route.test.ts +3 -3
  39. package/src/routing/__tests__/router.test.ts +186 -203
  40. package/src/routing/route.ts +3 -3
  41. package/src/routing/router.ts +1 -1
  42. package/src/timetable/__tests__/io.test.ts +52 -64
  43. package/src/timetable/__tests__/timetable.test.ts +9 -13
  44. package/src/timetable/io.ts +20 -19
  45. package/src/timetable/proto/timetable.proto +5 -8
  46. package/src/timetable/proto/timetable.ts +78 -201
  47. package/src/timetable/route.ts +1 -1
  48. package/src/timetable/timetable.ts +20 -16
@@ -12,11 +12,7 @@ import {
12
12
  } from '../io.js';
13
13
  import { REGULAR, Route } from '../route.js';
14
14
  import { Time } from '../time.js';
15
- import {
16
- RoutesAdjacency,
17
- ServiceRoutesMap,
18
- StopsAdjacency,
19
- } from '../timetable.js';
15
+ import { ServiceRoutesMap, StopsAdjacency } from '../timetable.js';
20
16
 
21
17
  describe('Timetable IO', () => {
22
18
  const stopsAdjacency: StopsAdjacency = new Map([
@@ -24,7 +20,7 @@ describe('Timetable IO', () => {
24
20
  1,
25
21
  {
26
22
  transfers: [{ destination: 2, type: 'RECOMMENDED' }],
27
- routes: ['route1'],
23
+ routes: [0],
28
24
  },
29
25
  ],
30
26
  [
@@ -37,45 +33,39 @@ describe('Timetable IO', () => {
37
33
  minTransferTime: Duration.fromMinutes(3),
38
34
  },
39
35
  ],
40
- routes: ['route2'],
36
+ routes: [1],
41
37
  },
42
38
  ],
43
39
  ]);
44
- const routesAdjacency: RoutesAdjacency = new Map([
45
- [
46
- 'route1',
47
- new Route(
48
- new Uint16Array([
49
- Time.fromHMS(16, 40, 0).toMinutes(),
50
- Time.fromHMS(16, 50, 0).toMinutes(),
51
- ]),
52
- new Uint8Array([REGULAR, REGULAR]),
53
- new Uint32Array([1, 2]),
54
- 'gtfs1',
55
- ),
56
- ],
57
- [
58
- 'route2',
59
- new Route(
60
- new Uint16Array([
61
- Time.fromHMS(15, 20, 0).toMinutes(),
62
- Time.fromHMS(15, 30, 0).toMinutes(),
63
- ]),
64
- new Uint8Array([REGULAR, REGULAR]),
65
- new Uint32Array([2, 1]),
66
- 'gtfs2',
67
- ),
68
- ],
69
- ]);
40
+ const routesAdjacency = [
41
+ new Route(
42
+ new Uint16Array([
43
+ Time.fromHMS(16, 40, 0).toMinutes(),
44
+ Time.fromHMS(16, 50, 0).toMinutes(),
45
+ ]),
46
+ new Uint8Array([REGULAR, REGULAR]),
47
+ new Uint32Array([1, 2]),
48
+ 'gtfs1',
49
+ ),
50
+ new Route(
51
+ new Uint16Array([
52
+ Time.fromHMS(15, 20, 0).toMinutes(),
53
+ Time.fromHMS(15, 30, 0).toMinutes(),
54
+ ]),
55
+ new Uint8Array([REGULAR, REGULAR]),
56
+ new Uint32Array([2, 1]),
57
+ 'gtfs2',
58
+ ),
59
+ ];
70
60
  const routes: ServiceRoutesMap = new Map([
71
- ['gtfs1', { type: 'RAIL', name: 'Route 1' }],
72
- ['gtfs2', { type: 'RAIL', name: 'Route 2' }],
61
+ ['gtfs1', { type: 'RAIL', name: 'Route 1', routes: [0] }],
62
+ ['gtfs2', { type: 'RAIL', name: 'Route 2', routes: [1] }],
73
63
  ]);
74
64
  const stopsAdjacencyProto = {
75
65
  stops: {
76
66
  '1': {
77
67
  transfers: [{ destination: 2, type: 0 }],
78
- routes: ['route1'],
68
+ routes: [0],
79
69
  },
80
70
  '2': {
81
71
  transfers: [
@@ -85,42 +75,40 @@ describe('Timetable IO', () => {
85
75
  minTransferTime: 180,
86
76
  },
87
77
  ],
88
- routes: ['route2'],
78
+ routes: [1],
89
79
  },
90
80
  },
91
81
  };
92
82
 
93
- const routesAdjacencyProto = {
94
- routes: {
95
- route1: {
96
- stopTimes: new Uint8Array(
97
- new Uint16Array([
98
- Time.fromHMS(16, 40, 0).toMinutes(),
99
- Time.fromHMS(16, 50, 0).toMinutes(),
100
- ]).buffer,
101
- ),
102
- pickUpDropOffTypes: new Uint8Array([REGULAR, REGULAR]),
103
- stops: new Uint8Array(new Uint32Array([1, 2]).buffer),
104
- serviceRouteId: 'gtfs1',
105
- },
106
- route2: {
107
- stopTimes: new Uint8Array(
108
- new Uint16Array([
109
- Time.fromHMS(15, 20, 0).toMinutes(),
110
- Time.fromHMS(15, 30, 0).toMinutes(),
111
- ]).buffer,
112
- ),
113
- pickUpDropOffTypes: new Uint8Array([REGULAR, REGULAR]),
114
- stops: new Uint8Array(new Uint32Array([2, 1]).buffer),
115
- serviceRouteId: 'gtfs2',
116
- },
83
+ const routesAdjacencyProto = [
84
+ {
85
+ stopTimes: new Uint8Array(
86
+ new Uint16Array([
87
+ Time.fromHMS(16, 40, 0).toMinutes(),
88
+ Time.fromHMS(16, 50, 0).toMinutes(),
89
+ ]).buffer,
90
+ ),
91
+ pickUpDropOffTypes: new Uint8Array([REGULAR, REGULAR]),
92
+ stops: new Uint8Array(new Uint32Array([1, 2]).buffer),
93
+ serviceRouteId: 'gtfs1',
117
94
  },
118
- };
95
+ {
96
+ stopTimes: new Uint8Array(
97
+ new Uint16Array([
98
+ Time.fromHMS(15, 20, 0).toMinutes(),
99
+ Time.fromHMS(15, 30, 0).toMinutes(),
100
+ ]).buffer,
101
+ ),
102
+ pickUpDropOffTypes: new Uint8Array([REGULAR, REGULAR]),
103
+ stops: new Uint8Array(new Uint32Array([2, 1]).buffer),
104
+ serviceRouteId: 'gtfs2',
105
+ },
106
+ ];
119
107
 
120
108
  const routesProto = {
121
109
  routes: {
122
- gtfs1: { type: 2, name: 'Route 1' },
123
- gtfs2: { type: 2, name: 'Route 2' },
110
+ gtfs1: { type: 2, name: 'Route 1', routes: [0] },
111
+ gtfs2: { type: 2, name: 'Route 2', routes: [1] },
124
112
  },
125
113
  };
126
114
 
@@ -6,7 +6,6 @@ import { Duration } from '../duration.js';
6
6
  import { NOT_AVAILABLE, REGULAR, Route } from '../route.js';
7
7
  import { Time } from '../time.js';
8
8
  import {
9
- RoutesAdjacency,
10
9
  RouteType,
11
10
  ServiceRoutesMap,
12
11
  StopsAdjacency,
@@ -19,7 +18,7 @@ describe('Timetable', () => {
19
18
  1,
20
19
  {
21
20
  transfers: [{ destination: 2, type: 'RECOMMENDED' }],
22
- routes: ['route1', 'route2'],
21
+ routes: [0, 1],
23
22
  },
24
23
  ],
25
24
  [
@@ -32,7 +31,7 @@ describe('Timetable', () => {
32
31
  minTransferTime: Duration.fromMinutes(3),
33
32
  },
34
33
  ],
35
- routes: ['route2', 'route1'],
34
+ routes: [1, 0],
36
35
  },
37
36
  ],
38
37
  [
@@ -73,13 +72,10 @@ describe('Timetable', () => {
73
72
  new Uint32Array([2, 1]),
74
73
  'gtfs2',
75
74
  );
76
- const routesAdjacency: RoutesAdjacency = new Map([
77
- ['route1', route1],
78
- ['route2', route2],
79
- ]);
75
+ const routesAdjacency = [route1, route2];
80
76
  const routes: ServiceRoutesMap = new Map([
81
- ['gtfs1', { type: 'RAIL', name: 'Route 1' }],
82
- ['gtfs2', { type: 'RAIL', name: 'Route 2' }],
77
+ ['gtfs1', { type: 'RAIL', name: 'Route 1', routes: [0] }],
78
+ ['gtfs2', { type: 'RAIL', name: 'Route 2', routes: [1] }],
83
79
  ]);
84
80
 
85
81
  const sampleTimetable: Timetable = new Timetable(
@@ -101,14 +97,14 @@ describe('Timetable', () => {
101
97
 
102
98
  it('should find the earliest trip for stop1 on route1', () => {
103
99
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
104
- const route = sampleTimetable.getRoute('route1')!;
100
+ const route = sampleTimetable.getRoute(0)!;
105
101
  const tripIndex = route.findEarliestTrip(1);
106
102
  assert.strictEqual(tripIndex, 0);
107
103
  });
108
104
 
109
105
  it('should find the earliest trip for stop1 on route1 after a specific time', () => {
110
106
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
111
- const route = sampleTimetable.getRoute('route1')!;
107
+ const route = sampleTimetable.getRoute(0)!;
112
108
  const afterTime = Time.fromHMS(17, 0, 0);
113
109
  const tripIndex = route.findEarliestTrip(1, afterTime);
114
110
  assert.strictEqual(tripIndex, 1);
@@ -116,14 +112,14 @@ describe('Timetable', () => {
116
112
 
117
113
  it('should return undefined if no valid trip exists after a specific time', () => {
118
114
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119
- const route = sampleTimetable.getRoute('route1')!;
115
+ const route = sampleTimetable.getRoute(0)!;
120
116
  const afterTime = Time.fromHMS(23, 40, 0);
121
117
  const tripIndex = route.findEarliestTrip(1, afterTime);
122
118
  assert.strictEqual(tripIndex, undefined);
123
119
  });
124
120
  it('should return undefined if the stop on a trip has pick up not available', () => {
125
121
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
- const route = sampleTimetable.getRoute('route1')!;
122
+ const route = sampleTimetable.getRoute(0)!;
127
123
  const tripIndex = route.findEarliestTrip(2);
128
124
  assert.strictEqual(tripIndex, 1);
129
125
  });
@@ -1,15 +1,14 @@
1
1
  import { Duration } from './duration.js';
2
2
  import {
3
- RoutesAdjacency as ProtoRoutesAdjacency,
3
+ Route as ProtoRoute,
4
4
  RouteType as ProtoRouteType,
5
5
  ServiceRoutesMap as ProtoServiceRoutesMap,
6
6
  StopsAdjacency as ProtoStopsAdjacency,
7
7
  Transfer as ProtoTransfer,
8
8
  TransferType as ProtoTransferType,
9
9
  } from './proto/timetable.js';
10
- import { Route } from './route.js';
10
+ import { Route, RouteId } from './route.js';
11
11
  import {
12
- RoutesAdjacency,
13
12
  RouteType,
14
13
  ServiceRouteId,
15
14
  ServiceRoutesMap,
@@ -130,7 +129,7 @@ export const serializeStopsAdjacency = (
130
129
  };
131
130
 
132
131
  stopsAdjacency.forEach(
133
- (value: { transfers: Transfer[]; routes: string[] }, key: number) => {
132
+ (value: { transfers: Transfer[]; routes: number[] }, key: number) => {
134
133
  protoStopsAdjacency.stops[key] = {
135
134
  transfers: value.transfers.map((transfer) => ({
136
135
  destination: transfer.destination,
@@ -148,20 +147,18 @@ export const serializeStopsAdjacency = (
148
147
  };
149
148
 
150
149
  export const serializeRoutesAdjacency = (
151
- routesAdjacency: RoutesAdjacency,
152
- ): ProtoRoutesAdjacency => {
153
- const protoRoutesAdjacency: ProtoRoutesAdjacency = {
154
- routes: {},
155
- };
150
+ routesAdjacency: Route[],
151
+ ): ProtoRoute[] => {
152
+ const protoRoutesAdjacency: ProtoRoute[] = [];
156
153
 
157
- routesAdjacency.forEach((route: Route, key: string) => {
154
+ routesAdjacency.forEach((route: Route) => {
158
155
  const routeData = route.serialize();
159
- protoRoutesAdjacency.routes[key] = {
156
+ protoRoutesAdjacency.push({
160
157
  stopTimes: uint16ArrayToBytes(routeData.stopTimes),
161
158
  pickUpDropOffTypes: routeData.pickUpDropOffTypes,
162
159
  stops: uint32ArrayToBytes(routeData.stops),
163
160
  serviceRouteId: routeData.serviceRouteId,
164
- };
161
+ });
165
162
  });
166
163
 
167
164
  return protoRoutesAdjacency;
@@ -175,10 +172,14 @@ export const serializeServiceRoutesMap = (
175
172
  };
176
173
 
177
174
  serviceRoutesMap.forEach(
178
- (value: { type: RouteType; name: string }, key: string) => {
175
+ (
176
+ value: { type: RouteType; name: string; routes: RouteId[] },
177
+ key: string,
178
+ ) => {
179
179
  protoServiceRoutesMap.routes[key] = {
180
180
  type: serializeRouteType(value.type),
181
181
  name: value.name,
182
+ routes: value.routes,
182
183
  };
183
184
  },
184
185
  );
@@ -211,14 +212,13 @@ export const deserializeStopsAdjacency = (
211
212
  };
212
213
 
213
214
  export const deserializeRoutesAdjacency = (
214
- protoRoutesAdjacency: ProtoRoutesAdjacency,
215
- ): RoutesAdjacency => {
216
- const routesAdjacency: RoutesAdjacency = new Map();
215
+ protoRoutesAdjacency: ProtoRoute[],
216
+ ): Route[] => {
217
+ const routesAdjacency: Route[] = [];
217
218
 
218
- Object.entries(protoRoutesAdjacency.routes).forEach(([key, value]) => {
219
+ protoRoutesAdjacency.forEach((value) => {
219
220
  const stops = bytesToUint32Array(value.stops);
220
- routesAdjacency.set(
221
- key,
221
+ routesAdjacency.push(
222
222
  new Route(
223
223
  bytesToUint16Array(value.stopTimes),
224
224
  value.pickUpDropOffTypes,
@@ -240,6 +240,7 @@ export const deserializeServiceRoutesMap = (
240
240
  serviceRoutesMap.set(key, {
241
241
  type: parseRouteType(value.type),
242
242
  name: value.name,
243
+ routes: value.routes,
243
244
  });
244
245
  });
245
246
 
@@ -27,10 +27,6 @@ message Route {
27
27
  string serviceRouteId = 4;
28
28
  }
29
29
 
30
- message RoutesAdjacency {
31
- map<string, Route> routes = 1;
32
- }
33
-
34
30
  enum TransferType {
35
31
  RECOMMENDED_TRANSFER_POINT = 0;
36
32
  TIMED_TRANSFER = 1;
@@ -41,15 +37,15 @@ enum TransferType {
41
37
  message Transfer {
42
38
  uint32 destination = 1;
43
39
  TransferType type = 2;
44
- optional int32 minTransferTime = 3;
40
+ optional uint32 minTransferTime = 3;
45
41
  }
46
42
 
47
43
  message StopsAdjacency {
48
44
  message StopAdjacency {
49
45
  repeated Transfer transfers = 1;
50
- repeated string routes = 2;
46
+ repeated int32 routes = 2;
51
47
  }
52
- map<string, StopAdjacency> stops = 1;
48
+ map<uint32, StopAdjacency> stops = 1;
53
49
  }
54
50
 
55
51
  enum RouteType {
@@ -68,6 +64,7 @@ enum RouteType {
68
64
  message ServiceRoute {
69
65
  RouteType type = 1;
70
66
  string name = 2;
67
+ repeated int32 routes = 3;
71
68
  }
72
69
 
73
70
  message ServiceRoutesMap {
@@ -77,6 +74,6 @@ message ServiceRoutesMap {
77
74
  message Timetable {
78
75
  string version = 1;
79
76
  StopsAdjacency stopsAdjacency = 2;
80
- RoutesAdjacency routesAdjacency = 3;
77
+ repeated Route routesAdjacency = 3;
81
78
  ServiceRoutesMap routes = 4;
82
79
  }