minotor 11.2.3 → 11.3.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 (70) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +27 -0
  3. package/dist/cli.mjs +300 -98
  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/trips.d.ts +2 -1
  8. package/dist/parser.cjs.js +225 -81
  9. package/dist/parser.cjs.js.map +1 -1
  10. package/dist/parser.d.ts +6 -2
  11. package/dist/parser.esm.js +224 -82
  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.d.ts +4 -3
  16. package/dist/router.esm.js +1 -1
  17. package/dist/router.esm.js.map +1 -1
  18. package/dist/router.umd.js +1 -1
  19. package/dist/router.umd.js.map +1 -1
  20. package/dist/routing/result.d.ts +1 -4
  21. package/dist/routing/route.d.ts +9 -5
  22. package/dist/timetable/route.d.ts +9 -5
  23. package/dist/timetable/timetable.d.ts +24 -3
  24. package/dist/transfers/__tests__/straightLineTransferGenerator.test.d.ts +1 -0
  25. package/dist/transfers/generator.d.ts +40 -0
  26. package/dist/transfers/straightLineTransferGenerator.d.ts +58 -0
  27. package/dist/utils/map.d.ts +10 -0
  28. package/package.json +1 -1
  29. package/src/__e2e__/router.test.ts +6 -2
  30. package/src/cli/minotor.ts +21 -1
  31. package/src/cli/repl.ts +6 -12
  32. package/src/gtfs/__tests__/parser.test.ts +29 -1
  33. package/src/gtfs/__tests__/routes.test.ts +4 -3
  34. package/src/gtfs/__tests__/transfers.test.ts +8 -8
  35. package/src/gtfs/__tests__/trips.test.ts +60 -24
  36. package/src/gtfs/parser.ts +50 -1
  37. package/src/gtfs/profiles/__tests__/extended.test.ts +2 -1
  38. package/src/gtfs/profiles/extended.ts +14 -14
  39. package/src/gtfs/profiles/standard.ts +11 -10
  40. package/src/gtfs/routes.ts +5 -2
  41. package/src/gtfs/transfers.ts +6 -5
  42. package/src/gtfs/trips.ts +7 -14
  43. package/src/parser.ts +20 -2
  44. package/src/router.ts +12 -6
  45. package/src/routing/__tests__/access.test.ts +14 -6
  46. package/src/routing/__tests__/plainRouter.test.ts +25 -23
  47. package/src/routing/__tests__/plotter.test.ts +8 -3
  48. package/src/routing/__tests__/rangeResult.test.ts +6 -2
  49. package/src/routing/__tests__/rangeRouter.test.ts +10 -6
  50. package/src/routing/__tests__/raptor.test.ts +15 -9
  51. package/src/routing/__tests__/result.test.ts +9 -4
  52. package/src/routing/__tests__/route.test.ts +3 -4
  53. package/src/routing/__tests__/router.test.ts +2 -1
  54. package/src/routing/access.ts +7 -4
  55. package/src/routing/plotter.ts +8 -3
  56. package/src/routing/raptor.ts +5 -5
  57. package/src/routing/result.ts +32 -14
  58. package/src/routing/route.ts +13 -10
  59. package/src/routing/state.ts +1 -1
  60. package/src/timetable/__tests__/io.test.ts +22 -10
  61. package/src/timetable/__tests__/route.test.ts +18 -24
  62. package/src/timetable/__tests__/timetable.test.ts +17 -11
  63. package/src/timetable/io.ts +30 -28
  64. package/src/timetable/route.ts +14 -7
  65. package/src/timetable/timetable.ts +77 -28
  66. package/src/transfers/README.md +97 -0
  67. package/src/transfers/__tests__/straightLineTransferGenerator.test.ts +204 -0
  68. package/src/transfers/generator.ts +45 -0
  69. package/src/transfers/straightLineTransferGenerator.ts +143 -0
  70. package/src/utils/map.ts +22 -0
@@ -6,9 +6,11 @@ import { StopsIndex } from '../../stops/stopsIndex.js';
6
6
  import { Route } from '../../timetable/route.js';
7
7
  import { durationFromSeconds, timeFromHM } from '../../timetable/time.js';
8
8
  import {
9
+ RouteTypes,
9
10
  ServiceRoute,
10
11
  StopAdjacency,
11
12
  Timetable,
13
+ TransferTypes,
12
14
  TripTransfers,
13
15
  } from '../../timetable/timetable.js';
14
16
  import { encode } from '../../timetable/tripStopId.js';
@@ -63,7 +65,7 @@ describe('PlainRouter', () => {
63
65
 
64
66
  const routes: ServiceRoute[] = [
65
67
  {
66
- type: 'BUS',
68
+ type: RouteTypes.BUS,
67
69
  name: 'Line 1',
68
70
  routes: [0],
69
71
  },
@@ -246,12 +248,12 @@ describe('PlainRouter', () => {
246
248
 
247
249
  const routes: ServiceRoute[] = [
248
250
  {
249
- type: 'BUS',
251
+ type: RouteTypes.BUS,
250
252
  name: 'Line 1',
251
253
  routes: [0],
252
254
  },
253
255
  {
254
- type: 'RAIL',
256
+ type: RouteTypes.RAIL,
255
257
  name: 'Line 2',
256
258
  routes: [1],
257
259
  },
@@ -360,7 +362,7 @@ describe('PlainRouter', () => {
360
362
  transfers: [
361
363
  {
362
364
  destination: 4,
363
- type: 'REQUIRES_MINIMAL_TIME',
365
+ type: TransferTypes.REQUIRES_MINIMAL_TIME,
364
366
  minTransferTime: durationFromSeconds(300), // 5 minutes walking
365
367
  },
366
368
  ],
@@ -429,12 +431,12 @@ describe('PlainRouter', () => {
429
431
 
430
432
  const routes: ServiceRoute[] = [
431
433
  {
432
- type: 'BUS',
434
+ type: RouteTypes.BUS,
433
435
  name: 'Line 1',
434
436
  routes: [0],
435
437
  },
436
438
  {
437
- type: 'RAIL',
439
+ type: RouteTypes.RAIL,
438
440
  name: 'Line 2',
439
441
  routes: [1],
440
442
  },
@@ -633,17 +635,17 @@ describe('PlainRouter', () => {
633
635
 
634
636
  const routes: ServiceRoute[] = [
635
637
  {
636
- type: 'BUS',
638
+ type: RouteTypes.BUS,
637
639
  name: 'Line 1',
638
640
  routes: [0],
639
641
  },
640
642
  {
641
- type: 'RAIL',
643
+ type: RouteTypes.RAIL,
642
644
  name: 'Line 2',
643
645
  routes: [1],
644
646
  },
645
647
  {
646
- type: 'FERRY',
648
+ type: RouteTypes.FERRY,
647
649
  name: 'Line 3',
648
650
  routes: [2],
649
651
  },
@@ -795,12 +797,12 @@ describe('PlainRouter', () => {
795
797
 
796
798
  const routes: ServiceRoute[] = [
797
799
  {
798
- type: 'BUS',
800
+ type: RouteTypes.BUS,
799
801
  name: 'Line 1',
800
802
  routes: [0],
801
803
  },
802
804
  {
803
- type: 'BUS',
805
+ type: RouteTypes.BUS,
804
806
  name: 'Line 2',
805
807
  routes: [1],
806
808
  },
@@ -959,12 +961,12 @@ describe('PlainRouter', () => {
959
961
 
960
962
  const routes: ServiceRoute[] = [
961
963
  {
962
- type: 'BUS',
964
+ type: RouteTypes.BUS,
963
965
  name: 'Line 1',
964
966
  routes: [0],
965
967
  },
966
968
  {
967
- type: 'BUS',
969
+ type: RouteTypes.BUS,
968
970
  name: 'Line 2',
969
971
  routes: [1],
970
972
  },
@@ -1123,12 +1125,12 @@ describe('PlainRouter', () => {
1123
1125
 
1124
1126
  const routes: ServiceRoute[] = [
1125
1127
  {
1126
- type: 'BUS',
1128
+ type: RouteTypes.BUS,
1127
1129
  name: 'Line 1',
1128
1130
  routes: [0],
1129
1131
  },
1130
1132
  {
1131
- type: 'BUS',
1133
+ type: RouteTypes.BUS,
1132
1134
  name: 'Line 2',
1133
1135
  routes: [1],
1134
1136
  },
@@ -1281,9 +1283,9 @@ describe('PlainRouter', () => {
1281
1283
  ];
1282
1284
 
1283
1285
  const routes: ServiceRoute[] = [
1284
- { type: 'BUS', name: 'Line 1', routes: [0] },
1285
- { type: 'BUS', name: 'Line 2', routes: [1] },
1286
- { type: 'BUS', name: 'Line 3', routes: [2] },
1286
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
1287
+ { type: RouteTypes.BUS, name: 'Line 2', routes: [1] },
1288
+ { type: RouteTypes.BUS, name: 'Line 3', routes: [2] },
1287
1289
  ];
1288
1290
 
1289
1291
  timetable = new Timetable(stopsAdjacency, routesAdjacency, routes);
@@ -1440,8 +1442,8 @@ describe('PlainRouter', () => {
1440
1442
  ];
1441
1443
 
1442
1444
  const routes: ServiceRoute[] = [
1443
- { type: 'BUS', name: 'Bus Line', routes: [0] },
1444
- { type: 'RAIL', name: 'Rail Line', routes: [1] },
1445
+ { type: RouteTypes.BUS, name: 'Bus Line', routes: [0] },
1446
+ { type: RouteTypes.RAIL, name: 'Rail Line', routes: [1] },
1445
1447
  ];
1446
1448
 
1447
1449
  timetable = new Timetable(stopsAdjacency, routesAdjacency, routes);
@@ -1491,7 +1493,7 @@ describe('PlainRouter', () => {
1491
1493
  .from(0)
1492
1494
  .to(1)
1493
1495
  .departureTime(timeFromHM(8, 0))
1494
- .transportModes(new Set(['BUS'] as const))
1496
+ .transportModes(new Set([RouteTypes.BUS] as const))
1495
1497
  .build();
1496
1498
 
1497
1499
  const result: Result = router.route(query);
@@ -1505,7 +1507,7 @@ describe('PlainRouter', () => {
1505
1507
  .from(0)
1506
1508
  .to(1)
1507
1509
  .departureTime(timeFromHM(8, 0))
1508
- .transportModes(new Set(['FERRY'] as const)) // Neither route is a ferry
1510
+ .transportModes(new Set([RouteTypes.FERRY] as const)) // Neither route is a ferry
1509
1511
  .build();
1510
1512
 
1511
1513
  const result: Result = router.route(query);
@@ -1567,7 +1569,7 @@ describe('PlainRouter', () => {
1567
1569
  ];
1568
1570
 
1569
1571
  const routes: ServiceRoute[] = [
1570
- { type: 'BUS', name: 'Line 1', routes: [0] },
1572
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
1571
1573
  ];
1572
1574
 
1573
1575
  timetable = new Timetable(stopsAdjacency, routesAdjacency, routes);
@@ -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 { Plotter } from '../plotter.js';
11
16
  import { Query } from '../query.js';
12
17
  import { Result } from '../result.js';
@@ -58,7 +63,7 @@ describe('Plotter', () => {
58
63
 
59
64
  const routes: ServiceRoute[] = [
60
65
  {
61
- type: 'RAIL',
66
+ type: RouteTypes.RAIL,
62
67
  name: 'IC 1',
63
68
  routes: [0],
64
69
  },
@@ -192,7 +197,7 @@ describe('Plotter', () => {
192
197
  from: 0,
193
198
  to: 1,
194
199
  arrival: timeFromHMS(8, 45, 0),
195
- type: 'RECOMMENDED',
200
+ type: TransferTypes.RECOMMENDED,
196
201
  minTransferTime: 5,
197
202
  },
198
203
  ],
@@ -6,7 +6,11 @@ import { Stop, StopId } from '../../stops/stops.js';
6
6
  import { StopsIndex } from '../../stops/stopsIndex.js';
7
7
  import { Route } from '../../timetable/route.js';
8
8
  import { timeFromHM } from '../../timetable/time.js';
9
- import { ServiceRoute, StopAdjacency } from '../../timetable/timetable.js';
9
+ import {
10
+ RouteTypes,
11
+ ServiceRoute,
12
+ StopAdjacency,
13
+ } from '../../timetable/timetable.js';
10
14
  import { ParetoRun, RangeResult } from '../rangeResult.js';
11
15
  import { Result } from '../result.js';
12
16
  import { RoutingState, VehicleEdge } from '../router.js';
@@ -74,7 +78,7 @@ const routesAdjacency = [
74
78
  }),
75
79
  ];
76
80
  const serviceRoutes: ServiceRoute[] = [
77
- { type: 'BUS', name: 'Line 1', routes: [0] },
81
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
78
82
  ];
79
83
  const timetable = new Timetable(stopsAdjacency, routesAdjacency, serviceRoutes);
80
84
 
@@ -6,9 +6,11 @@ import { StopsIndex } from '../../stops/stopsIndex.js';
6
6
  import { Route } from '../../timetable/route.js';
7
7
  import { durationFromSeconds, timeFromHM } from '../../timetable/time.js';
8
8
  import {
9
+ RouteTypes,
9
10
  ServiceRoute,
10
11
  StopAdjacency,
11
12
  Timetable,
13
+ TransferTypes,
12
14
  } from '../../timetable/timetable.js';
13
15
  import { AccessFinder } from '../access.js';
14
16
  import { RangeQuery } from '../query.js';
@@ -24,7 +26,9 @@ describe('RangeRouter', () => {
24
26
  const stopsAdjacency: StopAdjacency[] = [
25
27
  {
26
28
  routes: [],
27
- transfers: [{ destination: 1, type: 'REQUIRES_MINIMAL_TIME' }],
29
+ transfers: [
30
+ { destination: 1, type: TransferTypes.REQUIRES_MINIMAL_TIME },
31
+ ],
28
32
  },
29
33
  { routes: [0] },
30
34
  { routes: [0] },
@@ -54,7 +58,7 @@ describe('RangeRouter', () => {
54
58
  ];
55
59
 
56
60
  const serviceRoutes: ServiceRoute[] = [
57
- { type: 'BUS', name: 'Line 1', routes: [0] },
61
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
58
62
  ];
59
63
 
60
64
  const timetable = new Timetable(
@@ -174,7 +178,7 @@ describe('RangeRouter', () => {
174
178
  ];
175
179
 
176
180
  const serviceRoutes: ServiceRoute[] = [
177
- { type: 'BUS', name: 'Line 1', routes: [0] },
181
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
178
182
  ];
179
183
 
180
184
  timetable = new Timetable(stopsAdjacency, routesAdjacency, serviceRoutes);
@@ -276,7 +280,7 @@ describe('RangeRouter', () => {
276
280
  ];
277
281
 
278
282
  const serviceRoutes: ServiceRoute[] = [
279
- { type: 'BUS', name: 'Line 1', routes: [0] },
283
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
280
284
  ];
281
285
 
282
286
  const dominatingTimetable = new Timetable(
@@ -423,7 +427,7 @@ describe('RangeRouter', () => {
423
427
  ];
424
428
 
425
429
  const serviceRoutes: ServiceRoute[] = [
426
- { type: 'BUS', name: 'Line 1', routes: [0] },
430
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
427
431
  ];
428
432
 
429
433
  const timetable = new Timetable(
@@ -544,7 +548,7 @@ describe('RangeRouter', () => {
544
548
  ];
545
549
 
546
550
  const serviceRoutes: ServiceRoute[] = [
547
- { type: 'BUS', name: 'Line 1', routes: [0] },
551
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
548
552
  ];
549
553
 
550
554
  const timetable = new Timetable(
@@ -6,9 +6,11 @@ import { Route } from '../../timetable/route.js';
6
6
  import { timeFromHM } from '../../timetable/time.js';
7
7
  import {
8
8
  ALL_TRANSPORT_MODES,
9
+ RouteTypes,
9
10
  ServiceRoute,
10
11
  StopAdjacency,
11
12
  Timetable,
13
+ TransferTypes,
12
14
  TripTransfers,
13
15
  } from '../../timetable/timetable.js';
14
16
  import { encode } from '../../timetable/tripStopId.js';
@@ -73,8 +75,8 @@ const stopsAdjacency: StopAdjacency[] = [
73
75
  ];
74
76
 
75
77
  const serviceRoutes: ServiceRoute[] = [
76
- { type: 'BUS', name: 'Route 0', routes: [0] },
77
- { type: 'BUS', name: 'Route 1', routes: [1] },
78
+ { type: RouteTypes.BUS, name: 'Route 0', routes: [0] },
79
+ { type: RouteTypes.BUS, name: 'Route 1', routes: [1] },
78
80
  ];
79
81
 
80
82
  // ─── Extended fixture: slower direct route 0→2 ────────────────────────────────
@@ -108,9 +110,9 @@ const stopsAdjacencyWithDirectRoute: StopAdjacency[] = [
108
110
  ];
109
111
 
110
112
  const serviceRoutesWithDirectRoute: ServiceRoute[] = [
111
- { type: 'BUS', name: 'Route 0', routes: [0] },
112
- { type: 'BUS', name: 'Route 1', routes: [1] },
113
- { type: 'BUS', name: 'Route 2', routes: [2] },
113
+ { type: RouteTypes.BUS, name: 'Route 0', routes: [0] },
114
+ { type: RouteTypes.BUS, name: 'Route 1', routes: [1] },
115
+ { type: RouteTypes.BUS, name: 'Route 2', routes: [2] },
114
116
  ];
115
117
 
116
118
  // ─── Extended fixture: walking transfer from stop 1 to stop 2 ─────────────────
@@ -121,7 +123,11 @@ const stopsAdjacencyWithTransfer: StopAdjacency[] = [
121
123
  {
122
124
  routes: [0],
123
125
  transfers: [
124
- { destination: 2, type: 'REQUIRES_MINIMAL_TIME', minTransferTime: 5 },
126
+ {
127
+ destination: 2,
128
+ type: TransferTypes.REQUIRES_MINIMAL_TIME,
129
+ minTransferTime: 5,
130
+ },
125
131
  ],
126
132
  },
127
133
  { routes: [] },
@@ -131,8 +137,8 @@ const stopsAdjacencyWithTransfer: StopAdjacency[] = [
131
137
  // Route 0 is BUS, route 1 is RAIL — used to verify mode filtering.
132
138
 
133
139
  const mixedModeServiceRoutes: ServiceRoute[] = [
134
- { type: 'BUS', name: 'Route 0', routes: [0] },
135
- { type: 'RAIL', name: 'Route 1', routes: [1] },
140
+ { type: RouteTypes.BUS, name: 'Route 0', routes: [0] },
141
+ { type: RouteTypes.RAIL, name: 'Route 1', routes: [1] },
136
142
  ];
137
143
 
138
144
  // ─── Extended fixture: in-seat trip continuation ──────────────────────────────
@@ -468,7 +474,7 @@ describe('Raptor', () => {
468
474
  const options: QueryOptions = {
469
475
  maxTransfers: 5,
470
476
  minTransferTime: 2,
471
- transportModes: new Set(['RAIL']),
477
+ transportModes: new Set([RouteTypes.RAIL]),
472
478
  };
473
479
  raptor.run(options, state);
474
480
  assert.strictEqual(state.getArrival(1), undefined);
@@ -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