minotor 11.2.3 → 11.4.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 (71) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +27 -0
  3. package/dist/cli.mjs +310 -102
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/gtfs/parser.d.ts +3 -1
  6. package/dist/gtfs/routes.d.ts +1 -2
  7. package/dist/gtfs/transfers.d.ts +7 -3
  8. package/dist/gtfs/trips.d.ts +2 -1
  9. package/dist/parser.cjs.js +235 -85
  10. package/dist/parser.cjs.js.map +1 -1
  11. package/dist/parser.d.ts +6 -2
  12. package/dist/parser.esm.js +234 -86
  13. package/dist/parser.esm.js.map +1 -1
  14. package/dist/router.cjs.js +1 -1
  15. package/dist/router.cjs.js.map +1 -1
  16. package/dist/router.d.ts +4 -3
  17. package/dist/router.esm.js +1 -1
  18. package/dist/router.esm.js.map +1 -1
  19. package/dist/router.umd.js +1 -1
  20. package/dist/router.umd.js.map +1 -1
  21. package/dist/routing/result.d.ts +1 -4
  22. package/dist/routing/route.d.ts +9 -5
  23. package/dist/timetable/route.d.ts +9 -5
  24. package/dist/timetable/timetable.d.ts +24 -3
  25. package/dist/transfers/__tests__/straightLineTransferGenerator.test.d.ts +1 -0
  26. package/dist/transfers/generator.d.ts +40 -0
  27. package/dist/transfers/straightLineTransferGenerator.d.ts +58 -0
  28. package/dist/utils/map.d.ts +10 -0
  29. package/package.json +1 -1
  30. package/src/__e2e__/router.test.ts +6 -2
  31. package/src/cli/minotor.ts +21 -1
  32. package/src/cli/repl.ts +6 -12
  33. package/src/gtfs/__tests__/parser.test.ts +29 -1
  34. package/src/gtfs/__tests__/routes.test.ts +4 -3
  35. package/src/gtfs/__tests__/transfers.test.ts +108 -21
  36. package/src/gtfs/__tests__/trips.test.ts +60 -24
  37. package/src/gtfs/parser.ts +51 -2
  38. package/src/gtfs/profiles/__tests__/extended.test.ts +2 -1
  39. package/src/gtfs/profiles/extended.ts +14 -14
  40. package/src/gtfs/profiles/standard.ts +11 -10
  41. package/src/gtfs/routes.ts +5 -2
  42. package/src/gtfs/transfers.ts +20 -7
  43. package/src/gtfs/trips.ts +7 -14
  44. package/src/parser.ts +20 -2
  45. package/src/router.ts +12 -6
  46. package/src/routing/__tests__/access.test.ts +14 -6
  47. package/src/routing/__tests__/plainRouter.test.ts +25 -23
  48. package/src/routing/__tests__/plotter.test.ts +8 -3
  49. package/src/routing/__tests__/rangeResult.test.ts +6 -2
  50. package/src/routing/__tests__/rangeRouter.test.ts +10 -6
  51. package/src/routing/__tests__/raptor.test.ts +15 -9
  52. package/src/routing/__tests__/result.test.ts +9 -4
  53. package/src/routing/__tests__/route.test.ts +3 -4
  54. package/src/routing/__tests__/router.test.ts +2 -1
  55. package/src/routing/access.ts +7 -4
  56. package/src/routing/plotter.ts +8 -3
  57. package/src/routing/raptor.ts +5 -5
  58. package/src/routing/result.ts +32 -14
  59. package/src/routing/route.ts +13 -10
  60. package/src/routing/state.ts +1 -1
  61. package/src/timetable/__tests__/io.test.ts +22 -10
  62. package/src/timetable/__tests__/route.test.ts +18 -24
  63. package/src/timetable/__tests__/timetable.test.ts +17 -11
  64. package/src/timetable/io.ts +30 -28
  65. package/src/timetable/route.ts +14 -7
  66. package/src/timetable/timetable.ts +77 -28
  67. package/src/transfers/README.md +97 -0
  68. package/src/transfers/__tests__/straightLineTransferGenerator.test.ts +204 -0
  69. package/src/transfers/generator.ts +45 -0
  70. package/src/transfers/straightLineTransferGenerator.ts +143 -0
  71. package/src/utils/map.ts +22 -0
@@ -6,7 +6,12 @@ import { Stop } from '../../stops/stops.js';
6
6
  import { StopsIndex } from '../../stops/stopsIndex.js';
7
7
  import { Route } from '../../timetable/route.js';
8
8
  import { timeFromHMS, timeFromString } from '../../timetable/time.js';
9
- import { ServiceRoute, StopAdjacency } from '../../timetable/timetable.js';
9
+ import {
10
+ RouteTypes,
11
+ ServiceRoute,
12
+ StopAdjacency,
13
+ TransferTypes,
14
+ } from '../../timetable/timetable.js';
10
15
  import { Query } from '../query.js';
11
16
  import { Result } from '../result.js';
12
17
  import { RoutingState, TransferEdge, VehicleEdge } from '../router.js';
@@ -155,8 +160,8 @@ describe('Result', () => {
155
160
  ];
156
161
 
157
162
  const routes: ServiceRoute[] = [
158
- { type: 'RAIL', name: 'Line 1', routes: [0] },
159
- { type: 'RAIL', name: 'Line 2', routes: [1] },
163
+ { type: RouteTypes.RAIL, name: 'Line 1', routes: [0] },
164
+ { type: RouteTypes.RAIL, name: 'Line 2', routes: [1] },
160
165
  ];
161
166
 
162
167
  const mockStopsIndex = new StopsIndex([
@@ -569,7 +574,7 @@ describe('Result', () => {
569
574
  arrival: timeFromHMS(8, 35, 0),
570
575
  from: 1,
571
576
  to: 2,
572
- type: 'RECOMMENDED',
577
+ type: TransferTypes.RECOMMENDED,
573
578
  minTransferTime: 5,
574
579
  };
575
580
  const secondVehicleEdge: VehicleEdge = {
@@ -3,8 +3,7 @@ import { describe, it } from 'node:test';
3
3
 
4
4
  import { Stop } from '../../stops/stops.js';
5
5
  import { timeFromHMS } from '../../timetable/time.js';
6
- import { ServiceRouteInfo, TransferType } from '../../timetable/timetable.js';
7
- import { Route, VehicleLeg } from '../route.js';
6
+ import { Route, ServiceRouteInfo, Transfer, VehicleLeg } from '../route.js';
8
7
 
9
8
  describe('Route', () => {
10
9
  const stopA: Stop = {
@@ -59,10 +58,10 @@ describe('Route', () => {
59
58
  dropOffType: 'REGULAR',
60
59
  };
61
60
 
62
- const transferLeg = {
61
+ const transferLeg: Transfer = {
63
62
  from: stopB,
64
63
  to: stopC,
65
- type: 'RECOMMENDED' as TransferType,
64
+ type: 'RECOMMENDED',
66
65
  minTransferTime: 5,
67
66
  };
68
67
 
@@ -6,6 +6,7 @@ import { StopsIndex } from '../../stops/stopsIndex.js';
6
6
  import { Route } from '../../timetable/route.js';
7
7
  import { timeFromHM } from '../../timetable/time.js';
8
8
  import {
9
+ RouteTypes,
9
10
  ServiceRoute,
10
11
  StopAdjacency,
11
12
  Timetable,
@@ -40,7 +41,7 @@ const routesAdjacency = [
40
41
  }),
41
42
  ];
42
43
  const serviceRoutes: ServiceRoute[] = [
43
- { type: 'BUS', name: 'Line 1', routes: [0] },
44
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
44
45
  ];
45
46
  const stops: Stop[] = [
46
47
  {
@@ -1,8 +1,8 @@
1
1
  import { StopId } from '../stops/stops.js';
2
2
  import { StopsIndex } from '../stops/stopsIndex.js';
3
- import { NOT_AVAILABLE } from '../timetable/route.js';
3
+ import { PickUpDropOffTypes } from '../timetable/route.js';
4
4
  import { Duration, Time } from '../timetable/time.js';
5
- import { Timetable } from '../timetable/timetable.js';
5
+ import { Timetable, TransferTypes } from '../timetable/timetable.js';
6
6
 
7
7
  /**
8
8
  * An access path from the query origin to an initial boarding stop.
@@ -58,7 +58,7 @@ export class AccessFinder {
58
58
  });
59
59
  }
60
60
  for (const transfer of this.timetable.getTransfers(origin)) {
61
- if (transfer.type === 'REQUIRES_MINIMAL_TIME') {
61
+ if (transfer.type === TransferTypes.REQUIRES_MINIMAL_TIME) {
62
62
  const duration = transfer.minTransferTime ?? fallbackMinTransferTime;
63
63
  const existingAccess = accessPaths.get(transfer.destination);
64
64
  // Keep the shortest walk to maximize the set of reachable trips.
@@ -117,7 +117,10 @@ export class AccessFinder {
117
117
  while (tripIndex < nbTrips) {
118
118
  const dep = route.departureFrom(stopIndex, tripIndex);
119
119
  if (dep > searchTo) break;
120
- if (route.pickUpTypeFrom(stopIndex, tripIndex) !== NOT_AVAILABLE) {
120
+ if (
121
+ route.pickUpTypeFrom(stopIndex, tripIndex) !==
122
+ PickUpDropOffTypes.NOT_AVAILABLE
123
+ ) {
121
124
  const t = dep - path.duration;
122
125
  let paths = slotMap.get(t);
123
126
  if (paths === undefined) {
@@ -1,5 +1,6 @@
1
1
  import { StopId } from '../stops/stops.js';
2
2
  import { durationToString, timeToString } from '../timetable/time.js';
3
+ import { routeTypeToString } from '../timetable/timetable.js';
3
4
  import { Result } from './result.js';
4
5
  import {
5
6
  AccessEdge,
@@ -326,7 +327,7 @@ export class Plotter {
326
327
 
327
328
  const serviceRouteInfo = this.result.timetable.getServiceRouteInfo(route);
328
329
  const routeName = serviceRouteInfo.name;
329
- const routeType = serviceRouteInfo.type;
330
+ const routeType = routeTypeToString(serviceRouteInfo.type);
330
331
 
331
332
  const departureTime = timeToString(
332
333
  route.departureFrom(edge.stopIndex, edge.tripIndex),
@@ -424,8 +425,12 @@ export class Plotter {
424
425
  const toRouteName =
425
426
  toServiceRouteInfo?.name ?? `Route ${String(toEdge.routeId)}`;
426
427
 
427
- const fromRouteType = fromServiceRouteInfo?.type || 'UNKNOWN';
428
- const toRouteType = toServiceRouteInfo?.type || 'UNKNOWN';
428
+ const fromRouteType = fromServiceRouteInfo
429
+ ? routeTypeToString(fromServiceRouteInfo.type)
430
+ : 'UNKNOWN';
431
+ const toRouteType = toServiceRouteInfo
432
+ ? routeTypeToString(toServiceRouteInfo.type)
433
+ : 'UNKNOWN';
429
434
 
430
435
  const fromArrivalTime = timeToString(fromEdge.arrival);
431
436
  const toDepartureTime = toRoute
@@ -1,13 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
  import { StopId } from '../stops/stops.js';
3
3
  import {
4
- NOT_AVAILABLE,
4
+ PickUpDropOffTypes,
5
5
  Route,
6
6
  StopRouteIndex,
7
7
  TripRouteIndex,
8
8
  } from '../timetable/route.js';
9
9
  import { Duration, DURATION_ZERO, Time } from '../timetable/time.js';
10
- import { Timetable, TripStop } from '../timetable/timetable.js';
10
+ import { Timetable, TransferTypes, TripStop } from '../timetable/timetable.js';
11
11
  import { QueryOptions } from './query.js';
12
12
  import { RoutingEdge, TransferEdge, VehicleEdge } from './state.js';
13
13
 
@@ -214,7 +214,7 @@ export class Raptor {
214
214
  );
215
215
 
216
216
  if (
217
- dropOffType !== NOT_AVAILABLE &&
217
+ dropOffType !== PickUpDropOffTypes.NOT_AVAILABLE &&
218
218
  arrivalTime <= state.maxArrivalTime &&
219
219
  arrivalTime < state.improvementBound(round, currentStop) &&
220
220
  arrivalTime < state.destinationBest
@@ -285,7 +285,7 @@ export class Raptor {
285
285
  );
286
286
 
287
287
  if (
288
- dropOffType !== NOT_AVAILABLE &&
288
+ dropOffType !== PickUpDropOffTypes.NOT_AVAILABLE &&
289
289
  arrivalTime <= state.maxArrivalTime &&
290
290
  arrivalTime < state.improvementBound(round, currentStop) &&
291
291
  arrivalTime < state.destinationBest
@@ -392,7 +392,7 @@ export class Raptor {
392
392
  let transferTime: Duration;
393
393
  if (transfer.minTransferTime) {
394
394
  transferTime = transfer.minTransferTime;
395
- } else if (transfer.type === 'IN_SEAT') {
395
+ } else if (transfer.type === TransferTypes.IN_SEAT) {
396
396
  transferTime = DURATION_ZERO;
397
397
  } else {
398
398
  transferTime = options.minTransferTime;
@@ -1,22 +1,32 @@
1
1
  import { Timetable } from '../router.js';
2
2
  import { SourceStopId, StopId } from '../stops/stops.js';
3
3
  import { StopsIndex } from '../stops/stopsIndex.js';
4
- import { RawPickUpDropOffType } from '../timetable/route.js';
4
+ import {
5
+ PickUpDropOffTypeString,
6
+ RawPickUpDropOffType,
7
+ Route as TimetableRoute,
8
+ } from '../timetable/route.js';
5
9
  import { Time } from '../timetable/time.js';
6
- import { Access, Leg, Route, Transfer, VehicleLeg } from './route.js';
10
+ import {
11
+ routeTypeToString,
12
+ TransferTypes,
13
+ transferTypeToString,
14
+ } from '../timetable/timetable.js';
15
+ import {
16
+ Access,
17
+ Leg,
18
+ Route,
19
+ ServiceRouteInfo,
20
+ Transfer,
21
+ VehicleLeg,
22
+ } from './route.js';
7
23
  import { Arrival, RoutingState, TransferEdge, VehicleEdge } from './router.js';
8
24
  import { AccessEdge } from './state.js';
9
25
 
10
26
  /**
11
27
  * Details about the pickup and drop-off modalities at each stop in each trip of a route.
12
28
  */
13
- export type PickUpDropOffType =
14
- | 'REGULAR'
15
- | 'NOT_AVAILABLE'
16
- | 'MUST_PHONE_AGENCY'
17
- | 'MUST_COORDINATE_WITH_DRIVER';
18
-
19
- const pickUpDropOffTypeMap: PickUpDropOffType[] = [
29
+ const pickUpDropOffTypeMap: PickUpDropOffTypeString[] = [
20
30
  'REGULAR',
21
31
  'NOT_AVAILABLE',
22
32
  'MUST_PHONE_AGENCY',
@@ -28,12 +38,12 @@ const pickUpDropOffTypeMap: PickUpDropOffType[] = [
28
38
  * into its corresponding string representation.
29
39
  *
30
40
  * @param numericalType - The numerical value representing the pick-up/drop-off type.
31
- * @returns The corresponding PickUpDropOffType as a string.
41
+ * @returns The corresponding PickUpDropOffTypeString as a string.
32
42
  * @throws An error if the numerical type is invalid.
33
43
  */
34
44
  const toPickupDropOffType = (
35
45
  rawType: RawPickUpDropOffType,
36
- ): PickUpDropOffType => {
46
+ ): PickUpDropOffTypeString => {
37
47
  const type = pickUpDropOffTypeMap[rawType];
38
48
  if (!type) {
39
49
  throw new Error(`Invalid pickup/drop-off type ${rawType}`);
@@ -212,6 +222,14 @@ export class Result {
212
222
  return new Route(route.reverse());
213
223
  }
214
224
 
225
+ private buildServiceRouteInfo(route: TimetableRoute): ServiceRouteInfo {
226
+ const serviceRouteInfo = this.timetable.getServiceRouteInfo(route);
227
+ return {
228
+ type: routeTypeToString(serviceRouteInfo.type),
229
+ name: serviceRouteInfo.name,
230
+ };
231
+ }
232
+
215
233
  /**
216
234
  * Builds a vehicle leg from a chain of vehicle edges.
217
235
  *
@@ -243,7 +261,7 @@ export class Result {
243
261
  lastRoute.stopId(lastEdge.hopOffStopIndex),
244
262
  )!,
245
263
  // The route info comes from the first boarded route in case of continuous trips
246
- route: this.timetable.getServiceRouteInfo(firstRoute),
264
+ route: this.buildServiceRouteInfo(firstRoute),
247
265
  departureTime: firstRoute.departureFrom(
248
266
  firstEdge.stopIndex,
249
267
  firstEdge.tripIndex,
@@ -271,7 +289,7 @@ export class Result {
271
289
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
272
290
  to: this.stopsIndex.findStopById(edge.to)!,
273
291
  minTransferTime: edge.minTransferTime,
274
- type: edge.type,
292
+ type: transferTypeToString(edge.type),
275
293
  };
276
294
  }
277
295
 
@@ -314,7 +332,7 @@ export class Result {
314
332
  from: this.stopsIndex.findStopById(fromStopId)!,
315
333
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
316
334
  to: this.stopsIndex.findStopById(toStopId)!,
317
- type: 'GUARANTEED',
335
+ type: transferTypeToString(TransferTypes.GUARANTEED),
318
336
  };
319
337
  }
320
338
 
@@ -1,4 +1,5 @@
1
1
  import { Stop } from '../stops/stops.js';
2
+ import type { PickUpDropOffTypeString } from '../timetable/route.js';
2
3
  import {
3
4
  Duration,
4
5
  DURATION_ZERO,
@@ -7,13 +8,15 @@ import {
7
8
  TIME_ORIGIN,
8
9
  timeToString,
9
10
  } from '../timetable/time.js';
10
- import { ServiceRouteInfo, TransferType } from '../timetable/timetable.js';
11
-
12
- export type PickUpDropOffType =
13
- | 'REGULAR'
14
- | 'NOT_AVAILABLE'
15
- | 'MUST_PHONE_AGENCY'
16
- | 'MUST_COORDINATE_WITH_DRIVER';
11
+ import type {
12
+ RouteTypeString,
13
+ TransferTypeString,
14
+ } from '../timetable/timetable.js';
15
+
16
+ export type ServiceRouteInfo = {
17
+ type: RouteTypeString;
18
+ name: string;
19
+ };
17
20
 
18
21
  export type BaseLeg = {
19
22
  from: Stop;
@@ -26,15 +29,15 @@ export type Access = BaseLeg & {
26
29
 
27
30
  export type Transfer = BaseLeg & {
28
31
  minTransferTime?: Duration;
29
- type: TransferType;
32
+ type: TransferTypeString;
30
33
  };
31
34
 
32
35
  export type VehicleLeg = BaseLeg & {
33
36
  route: ServiceRouteInfo;
34
37
  departureTime: Time;
35
38
  arrivalTime: Time;
36
- pickUpType: PickUpDropOffType;
37
- dropOffType: PickUpDropOffType;
39
+ pickUpType: PickUpDropOffTypeString;
40
+ dropOffType: PickUpDropOffTypeString;
38
41
  };
39
42
 
40
43
  export type Leg = Transfer | Access | VehicleLeg;
@@ -33,7 +33,7 @@ export type VehicleEdge = TripStop & {
33
33
  export type TransferEdge = {
34
34
  arrival: Time;
35
35
  from: StopId;
36
- to: StopId; // TODO remove
36
+ to: StopId;
37
37
  type: TransferType;
38
38
  minTransferTime?: Duration;
39
39
  };
@@ -11,22 +11,28 @@ import {
11
11
  serializeStopsAdjacency,
12
12
  serializeTripTransfers,
13
13
  } from '../io.js';
14
- import { REGULAR, Route } from '../route.js';
14
+ import { PickUpDropOffTypes, Route } from '../route.js';
15
15
  import { timeFromHMS } from '../time.js';
16
- import { ServiceRoute, StopAdjacency, TripStop } from '../timetable.js';
16
+ import {
17
+ RouteTypes,
18
+ ServiceRoute,
19
+ StopAdjacency,
20
+ TransferTypes,
21
+ TripStop,
22
+ } from '../timetable.js';
17
23
  import { encode } from '../tripStopId.js';
18
24
 
19
25
  describe('Timetable IO', () => {
20
26
  const stopsAdjacency: StopAdjacency[] = [
21
27
  {
22
- transfers: [{ destination: 2, type: 'RECOMMENDED' }],
28
+ transfers: [{ destination: 2, type: TransferTypes.RECOMMENDED }],
23
29
  routes: [0],
24
30
  },
25
31
  {
26
32
  transfers: [
27
33
  {
28
34
  destination: 1,
29
- type: 'GUARANTEED',
35
+ type: TransferTypes.GUARANTEED,
30
36
  minTransferTime: 3,
31
37
  },
32
38
  ],
@@ -37,21 +43,21 @@ describe('Timetable IO', () => {
37
43
  new Route(
38
44
  0,
39
45
  new Uint16Array([timeFromHMS(16, 40, 0), timeFromHMS(16, 50, 0)]),
40
- new Uint8Array([REGULAR, REGULAR]),
46
+ new Uint8Array([PickUpDropOffTypes.REGULAR, PickUpDropOffTypes.REGULAR]),
41
47
  new Uint32Array([1, 2]),
42
48
  0,
43
49
  ),
44
50
  new Route(
45
51
  1,
46
52
  new Uint16Array([timeFromHMS(15, 20, 0), timeFromHMS(15, 30, 0)]),
47
- new Uint8Array([REGULAR, REGULAR]),
53
+ new Uint8Array([PickUpDropOffTypes.REGULAR, PickUpDropOffTypes.REGULAR]),
48
54
  new Uint32Array([2, 1]),
49
55
  1,
50
56
  ),
51
57
  ];
52
58
  const routes: ServiceRoute[] = [
53
- { type: 'RAIL', name: 'Route 1', routes: [0] },
54
- { type: 'RAIL', name: 'Route 2', routes: [1] },
59
+ { type: RouteTypes.RAIL, name: 'Route 1', routes: [0] },
60
+ { type: RouteTypes.RAIL, name: 'Route 2', routes: [1] },
55
61
  ];
56
62
  const stopsAdjacencyProto = [
57
63
  {
@@ -76,7 +82,10 @@ describe('Timetable IO', () => {
76
82
  new Uint16Array([timeFromHMS(16, 40, 0), timeFromHMS(16, 50, 0)])
77
83
  .buffer,
78
84
  ),
79
- pickupDropOffTypes: new Uint8Array([REGULAR, REGULAR]),
85
+ pickupDropOffTypes: new Uint8Array([
86
+ PickUpDropOffTypes.REGULAR,
87
+ PickUpDropOffTypes.REGULAR,
88
+ ]),
80
89
  stops: new Uint8Array(new Uint32Array([1, 2]).buffer),
81
90
  serviceRouteId: 0,
82
91
  },
@@ -85,7 +94,10 @@ describe('Timetable IO', () => {
85
94
  new Uint16Array([timeFromHMS(15, 20, 0), timeFromHMS(15, 30, 0)])
86
95
  .buffer,
87
96
  ),
88
- pickupDropOffTypes: new Uint8Array([REGULAR, REGULAR]),
97
+ pickupDropOffTypes: new Uint8Array([
98
+ PickUpDropOffTypes.REGULAR,
99
+ PickUpDropOffTypes.REGULAR,
100
+ ]),
89
101
  stops: new Uint8Array(new Uint32Array([2, 1]).buffer),
90
102
  serviceRouteId: 1,
91
103
  },
@@ -2,13 +2,7 @@ import assert from 'node:assert';
2
2
  import { describe, it } from 'node:test';
3
3
 
4
4
  import { encodePickUpDropOffTypes } from '../../gtfs/trips.js';
5
- import {
6
- MUST_COORDINATE_WITH_DRIVER,
7
- MUST_PHONE_AGENCY,
8
- NOT_AVAILABLE,
9
- REGULAR,
10
- Route,
11
- } from '../route.js';
5
+ import { PickUpDropOffTypes, Route } from '../route.js';
12
6
  import { TIME_ORIGIN, timeFromHMS } from '../time.js';
13
7
 
14
8
  describe('Route', () => {
@@ -33,25 +27,25 @@ describe('Route', () => {
33
27
  const pickupDropOffTypes = encodePickUpDropOffTypes(
34
28
  [
35
29
  // Trip 0
36
- REGULAR,
37
- NOT_AVAILABLE,
30
+ PickUpDropOffTypes.REGULAR,
31
+ PickUpDropOffTypes.NOT_AVAILABLE,
38
32
  // Trip 1
39
- REGULAR,
40
- REGULAR,
33
+ PickUpDropOffTypes.REGULAR,
34
+ PickUpDropOffTypes.REGULAR,
41
35
  // Trip 2
42
- MUST_PHONE_AGENCY,
43
- MUST_COORDINATE_WITH_DRIVER,
36
+ PickUpDropOffTypes.MUST_PHONE_AGENCY,
37
+ PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER,
44
38
  ],
45
39
  [
46
40
  // Trip 0
47
- REGULAR,
48
- REGULAR,
41
+ PickUpDropOffTypes.REGULAR,
42
+ PickUpDropOffTypes.REGULAR,
49
43
  // Trip 1
50
- REGULAR,
51
- REGULAR,
44
+ PickUpDropOffTypes.REGULAR,
45
+ PickUpDropOffTypes.REGULAR,
52
46
  // Trip 2
53
- REGULAR,
54
- REGULAR,
47
+ PickUpDropOffTypes.REGULAR,
48
+ PickUpDropOffTypes.REGULAR,
55
49
  ],
56
50
  );
57
51
 
@@ -159,17 +153,17 @@ describe('Route', () => {
159
153
  describe('pickUpTypeFrom', () => {
160
154
  it('should return REGULAR pickup type for trip 0 at stop index 0', () => {
161
155
  const pickUpType = route.pickUpTypeFrom(0, 0);
162
- assert.strictEqual(pickUpType, REGULAR);
156
+ assert.strictEqual(pickUpType, PickUpDropOffTypes.REGULAR);
163
157
  });
164
158
 
165
159
  it('should return NOT_AVAILABLE pickup type for trip 0 at stop index 1', () => {
166
160
  const pickUpType = route.pickUpTypeFrom(1, 0);
167
- assert.strictEqual(pickUpType, NOT_AVAILABLE);
161
+ assert.strictEqual(pickUpType, PickUpDropOffTypes.NOT_AVAILABLE);
168
162
  });
169
163
 
170
164
  it('should return MUST_PHONE_AGENCY pickup type for trip 2 at stop index 0', () => {
171
165
  const pickUpType = route.pickUpTypeFrom(0, 2);
172
- assert.strictEqual(pickUpType, MUST_PHONE_AGENCY);
166
+ assert.strictEqual(pickUpType, PickUpDropOffTypes.MUST_PHONE_AGENCY);
173
167
  });
174
168
 
175
169
  it('should throw error for invalid stop index', () => {
@@ -190,12 +184,12 @@ describe('Route', () => {
190
184
  describe('dropOffTypeAt', () => {
191
185
  it('should return REGULAR drop off type for trip 0 at stop index 0', () => {
192
186
  const dropOffType = route.dropOffTypeAt(0, 0);
193
- assert.strictEqual(dropOffType, REGULAR);
187
+ assert.strictEqual(dropOffType, PickUpDropOffTypes.REGULAR);
194
188
  });
195
189
 
196
190
  it('should return REGULAR drop off type for trip 1 at stop index 1', () => {
197
191
  const dropOffType = route.dropOffTypeAt(1, 1);
198
- assert.strictEqual(dropOffType, REGULAR);
192
+ assert.strictEqual(dropOffType, PickUpDropOffTypes.REGULAR);
199
193
  });
200
194
 
201
195
  it('should throw error for invalid stop index', () => {
@@ -1,13 +1,15 @@
1
1
  import assert from 'node:assert';
2
2
  import { describe, it } from 'node:test';
3
3
 
4
- import { NOT_AVAILABLE, Route } from '../route.js';
4
+ import { PickUpDropOffTypes, Route } from '../route.js';
5
5
  import { timeFromHMS } from '../time.js';
6
6
  import {
7
7
  RouteType,
8
+ RouteTypes,
8
9
  ServiceRoute,
9
10
  StopAdjacency,
10
11
  Timetable,
12
+ TransferTypes,
11
13
  TripStop,
12
14
  TripTransfers,
13
15
  } from '../timetable.js';
@@ -17,14 +19,14 @@ describe('Timetable', () => {
17
19
  const stopsAdjacency: StopAdjacency[] = [
18
20
  { routes: [] },
19
21
  {
20
- transfers: [{ destination: 2, type: 'RECOMMENDED' }],
22
+ transfers: [{ destination: 2, type: TransferTypes.RECOMMENDED }],
21
23
  routes: [0, 1],
22
24
  },
23
25
  {
24
26
  transfers: [
25
27
  {
26
28
  destination: 1,
27
- type: 'GUARANTEED',
29
+ type: TransferTypes.GUARANTEED,
28
30
  minTransferTime: 3,
29
31
  },
30
32
  ],
@@ -50,7 +52,7 @@ describe('Timetable', () => {
50
52
  id: 2,
51
53
  arrivalTime: timeFromHMS(17, 20, 0),
52
54
  departureTime: timeFromHMS(17, 30, 0),
53
- pickUpType: NOT_AVAILABLE,
55
+ pickUpType: PickUpDropOffTypes.NOT_AVAILABLE,
54
56
  },
55
57
  ],
56
58
  },
@@ -92,8 +94,8 @@ describe('Timetable', () => {
92
94
  });
93
95
  const routesAdjacency = [route1, route2];
94
96
  const routes: ServiceRoute[] = [
95
- { type: 'RAIL', name: 'Route 1', routes: [0] },
96
- { type: 'RAIL', name: 'Route 2', routes: [1] },
97
+ { type: RouteTypes.RAIL, name: 'Route 1', routes: [0] },
98
+ { type: RouteTypes.RAIL, name: 'Route 2', routes: [1] },
97
99
  ];
98
100
 
99
101
  const sampleTimetable: Timetable = new Timetable(
@@ -191,7 +193,7 @@ describe('Timetable', () => {
191
193
 
192
194
  const railRoutes = sampleTimetable.findReachableRoutes(
193
195
  fromStops,
194
- new Set<RouteType>(['RAIL']),
196
+ new Set<RouteType>([RouteTypes.RAIL]),
195
197
  );
196
198
  assert.strictEqual(railRoutes.size, 2);
197
199
  assert.deepStrictEqual(
@@ -204,14 +206,18 @@ describe('Timetable', () => {
204
206
 
205
207
  const busRoutes = sampleTimetable.findReachableRoutes(
206
208
  fromStops,
207
- new Set<RouteType>(['BUS']),
209
+ new Set<RouteType>([RouteTypes.BUS]),
208
210
  );
209
211
  assert.strictEqual(busRoutes.size, 0);
210
212
  assert.deepStrictEqual(busRoutes, new Map());
211
213
 
212
214
  const multiModeRoutes = sampleTimetable.findReachableRoutes(
213
215
  fromStops,
214
- new Set<RouteType>(['RAIL', 'BUS', 'SUBWAY']),
216
+ new Set<RouteType>([
217
+ RouteTypes.RAIL,
218
+ RouteTypes.BUS,
219
+ RouteTypes.SUBWAY,
220
+ ]),
215
221
  );
216
222
  assert.strictEqual(multiModeRoutes.size, 2);
217
223
  });
@@ -685,7 +691,7 @@ describe('Timetable', () => {
685
691
  id: 0,
686
692
  arrivalTime: timeFromHMS(9, 0, 0),
687
693
  departureTime: timeFromHMS(9, 0, 0),
688
- pickUpType: NOT_AVAILABLE,
694
+ pickUpType: PickUpDropOffTypes.NOT_AVAILABLE,
689
695
  },
690
696
  {
691
697
  id: 1,
@@ -731,7 +737,7 @@ describe('Timetable', () => {
731
737
  ];
732
738
 
733
739
  const ffbtServiceRoutes = [
734
- { type: 'BUS' as const, name: 'Route 2', routes: [FFBT_ROUTE_ID] },
740
+ { type: RouteTypes.BUS, name: 'Route 2', routes: [FFBT_ROUTE_ID] },
735
741
  ];
736
742
 
737
743
  const ffbtTimetable = new Timetable(