minotor 5.0.1 → 6.0.0

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 (56) hide show
  1. package/CHANGELOG.md +8 -3
  2. package/dist/cli.mjs +207 -596
  3. package/dist/cli.mjs.map +1 -1
  4. package/dist/gtfs/parser.d.ts +4 -10
  5. package/dist/gtfs/routes.d.ts +16 -2
  6. package/dist/gtfs/stops.d.ts +3 -13
  7. package/dist/gtfs/transfers.d.ts +2 -2
  8. package/dist/gtfs/trips.d.ts +12 -8
  9. package/dist/parser.cjs.js +201 -593
  10. package/dist/parser.cjs.js.map +1 -1
  11. package/dist/parser.esm.js +201 -593
  12. package/dist/parser.esm.js.map +1 -1
  13. package/dist/router.cjs.js +1 -1
  14. package/dist/router.cjs.js.map +1 -1
  15. package/dist/router.esm.js +1 -1
  16. package/dist/router.esm.js.map +1 -1
  17. package/dist/router.umd.js +1 -1
  18. package/dist/router.umd.js.map +1 -1
  19. package/dist/stops/io.d.ts +3 -3
  20. package/dist/stops/proto/stops.d.ts +1 -8
  21. package/dist/stops/stops.d.ts +0 -4
  22. package/dist/stops/stopsIndex.d.ts +3 -3
  23. package/dist/timetable/io.d.ts +6 -6
  24. package/dist/timetable/proto/timetable.d.ts +5 -27
  25. package/dist/timetable/timetable.d.ts +17 -9
  26. package/package.json +1 -1
  27. package/src/__e2e__/timetable/stops.bin +2 -2
  28. package/src/__e2e__/timetable/timetable.bin +2 -2
  29. package/src/cli/minotor.ts +3 -4
  30. package/src/gtfs/__tests__/parser.test.ts +5 -6
  31. package/src/gtfs/__tests__/routes.test.ts +0 -3
  32. package/src/gtfs/__tests__/stops.test.ts +1 -124
  33. package/src/gtfs/__tests__/transfers.test.ts +7 -7
  34. package/src/gtfs/__tests__/trips.test.ts +74 -45
  35. package/src/gtfs/parser.ts +32 -49
  36. package/src/gtfs/routes.ts +43 -5
  37. package/src/gtfs/stops.ts +2 -44
  38. package/src/gtfs/transfers.ts +2 -2
  39. package/src/gtfs/trips.ts +57 -40
  40. package/src/routing/__tests__/result.test.ts +48 -48
  41. package/src/routing/__tests__/router.test.ts +279 -363
  42. package/src/routing/router.ts +3 -1
  43. package/src/stops/__tests__/io.test.ts +25 -31
  44. package/src/stops/__tests__/stopFinder.test.ts +82 -103
  45. package/src/stops/io.ts +8 -17
  46. package/src/stops/proto/stops.proto +3 -3
  47. package/src/stops/proto/stops.ts +16 -120
  48. package/src/stops/stops.ts +0 -4
  49. package/src/stops/stopsIndex.ts +20 -26
  50. package/src/timetable/__tests__/io.test.ts +44 -54
  51. package/src/timetable/__tests__/route.test.ts +11 -11
  52. package/src/timetable/__tests__/timetable.test.ts +29 -37
  53. package/src/timetable/io.ts +38 -66
  54. package/src/timetable/proto/timetable.proto +6 -13
  55. package/src/timetable/proto/timetable.ts +43 -385
  56. package/src/timetable/timetable.ts +43 -28
@@ -25,15 +25,12 @@ export type Transfer = {
25
25
  minTransferTime?: Duration;
26
26
  };
27
27
 
28
- export type StopsAdjacency = Map<
29
- StopId,
30
- {
31
- transfers: Transfer[];
32
- routes: RouteId[];
33
- }
34
- >;
28
+ export type StopAdjacency = {
29
+ transfers: Transfer[];
30
+ routes: RouteId[];
31
+ };
35
32
 
36
- export type ServiceRouteId = string;
33
+ export type ServiceRouteId = number;
37
34
 
38
35
  export type RouteType =
39
36
  | 'TRAM'
@@ -47,18 +44,16 @@ export type RouteType =
47
44
  | 'TROLLEYBUS'
48
45
  | 'MONORAIL';
49
46
 
50
- type ServiceRoute = {
47
+ // A service refers to a collection of trips that are displayed to riders as a single service.
48
+ // As opposed to a route which consists of the subset of trips from a service which shares the same list of stops.
49
+ // Service is here a synonym for route in the GTFS sense.
50
+ export type ServiceRoute = {
51
51
  type: RouteType;
52
52
  name: string;
53
53
  routes: RouteId[];
54
54
  };
55
55
  export type ServiceRouteInfo = Omit<ServiceRoute, 'routes'>;
56
56
 
57
- // A service refers to a collection of trips that are displayed to riders as a single service.
58
- // As opposed to a route which consists of the subset of trips from a service which shares the same list of stops.
59
- // Service is here a synonym for route in the GTFS sense.
60
- export type ServiceRoutesMap = Map<ServiceRouteId, ServiceRoute>;
61
-
62
57
  export const ALL_TRANSPORT_MODES: Set<RouteType> = new Set([
63
58
  'TRAM',
64
59
  'SUBWAY',
@@ -72,24 +67,33 @@ export const ALL_TRANSPORT_MODES: Set<RouteType> = new Set([
72
67
  'MONORAIL',
73
68
  ]);
74
69
 
75
- export const CURRENT_VERSION = '0.0.5';
70
+ export const CURRENT_VERSION = '0.0.6';
76
71
 
77
72
  /**
78
73
  * The internal transit timetable format.
79
74
  */
80
75
  export class Timetable {
81
- private readonly stopsAdjacency: StopsAdjacency;
76
+ private readonly stopsAdjacency: StopAdjacency[];
82
77
  private readonly routesAdjacency: Route[];
83
- private readonly routes: ServiceRoutesMap;
78
+ private readonly serviceRoutes: ServiceRoute[];
79
+ private readonly activeStops: Set<StopId>;
84
80
 
85
81
  constructor(
86
- stopsAdjacency: StopsAdjacency,
82
+ stopsAdjacency: StopAdjacency[],
87
83
  routesAdjacency: Route[],
88
- routes: ServiceRoutesMap,
84
+ routes: ServiceRoute[],
89
85
  ) {
90
86
  this.stopsAdjacency = stopsAdjacency;
91
87
  this.routesAdjacency = routesAdjacency;
92
- this.routes = routes;
88
+ this.serviceRoutes = routes;
89
+ this.activeStops = new Set<StopId>();
90
+ for (let i = 0; i < stopsAdjacency.length; i++) {
91
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
+ const stop = stopsAdjacency[i]!;
93
+ if (stop.routes.length > 0 || stop.transfers.length > 0) {
94
+ this.activeStops.add(i);
95
+ }
96
+ }
93
97
  }
94
98
 
95
99
  /**
@@ -102,7 +106,7 @@ export class Timetable {
102
106
  version: CURRENT_VERSION,
103
107
  stopsAdjacency: serializeStopsAdjacency(this.stopsAdjacency),
104
108
  routesAdjacency: serializeRoutesAdjacency(this.routesAdjacency),
105
- routes: serializeServiceRoutesMap(this.routes),
109
+ serviceRoutes: serializeServiceRoutesMap(this.serviceRoutes),
106
110
  };
107
111
  const writer = new BinaryWriter();
108
112
  ProtoTimetable.encode(protoTimetable, writer);
@@ -124,14 +128,25 @@ export class Timetable {
124
128
  );
125
129
  }
126
130
  return new Timetable(
127
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
128
- deserializeStopsAdjacency(protoTimetable.stopsAdjacency!),
131
+ deserializeStopsAdjacency(protoTimetable.stopsAdjacency),
129
132
  deserializeRoutesAdjacency(protoTimetable.routesAdjacency),
130
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
131
- deserializeServiceRoutesMap(protoTimetable.routes!),
133
+
134
+ deserializeServiceRoutesMap(protoTimetable.serviceRoutes),
132
135
  );
133
136
  }
134
137
 
138
+ /**
139
+ * Checks if the given stop is active on the timetable.
140
+ * An active stop is a stop reached by a route that is active on the timetable
141
+ * or by a transfer reachable from an active route.
142
+ *
143
+ * @param stopId - The ID of the stop to check.
144
+ * @returns True if the stop is active, false otherwise.
145
+ */
146
+ isActive(stopId: StopId): boolean {
147
+ return this.activeStops.has(stopId);
148
+ }
149
+
135
150
  /**
136
151
  * Retrieves the route associated with the given route ID.
137
152
  *
@@ -150,7 +165,7 @@ export class Timetable {
150
165
  * @returns An array of transfer options available at the stop.
151
166
  */
152
167
  getTransfers(stopId: StopId): Transfer[] {
153
- return this.stopsAdjacency.get(stopId)?.transfers ?? [];
168
+ return this.stopsAdjacency[stopId]?.transfers ?? [];
154
169
  }
155
170
 
156
171
  /**
@@ -162,7 +177,7 @@ export class Timetable {
162
177
  * @returns The service route corresponding to the provided route.
163
178
  */
164
179
  getServiceRouteInfo(route: Route): ServiceRouteInfo {
165
- const serviceRoute = this.routes.get(route.serviceRoute());
180
+ const serviceRoute = this.serviceRoutes[route.serviceRoute()];
166
181
  if (!serviceRoute) {
167
182
  throw new Error(
168
183
  `Service route not found for route ID: ${route.serviceRoute()}`,
@@ -180,7 +195,7 @@ export class Timetable {
180
195
  * @returns An array of routes passing through the specified stop.
181
196
  */
182
197
  routesPassingThrough(stopId: StopId): Route[] {
183
- const stopData = this.stopsAdjacency.get(stopId);
198
+ const stopData = this.stopsAdjacency[stopId];
184
199
  if (!stopData) {
185
200
  return [];
186
201
  }