minotor 12.0.1 → 13.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 -3
  2. package/README.md +7 -4
  3. package/dist/cli/perf.d.ts +4 -4
  4. package/dist/cli.mjs +1558 -1488
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/gtfs/__tests__/logging.test.d.ts +1 -0
  7. package/dist/gtfs/logging.d.ts +8 -0
  8. package/dist/parser.cjs.js +108 -98
  9. package/dist/parser.cjs.js.map +1 -1
  10. package/dist/parser.d.ts +4 -2
  11. package/dist/parser.esm.js +108 -99
  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 +2 -1
  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/rangeResult.d.ts +34 -25
  21. package/dist/routing/result.d.ts +28 -9
  22. package/dist/routing/resultInternals.d.ts +4 -0
  23. package/dist/routing/routingResult.d.ts +29 -0
  24. package/package.json +1 -1
  25. package/src/cli/minotor.ts +4 -12
  26. package/src/cli/perf.ts +5 -5
  27. package/src/cli/repl.ts +1 -1
  28. package/src/gtfs/__tests__/logging.test.ts +100 -0
  29. package/src/gtfs/frequencies.ts +1 -2
  30. package/src/gtfs/logging.ts +15 -0
  31. package/src/gtfs/parser.ts +1 -2
  32. package/src/gtfs/routes.ts +1 -2
  33. package/src/gtfs/stops.ts +1 -2
  34. package/src/gtfs/transfers.ts +1 -2
  35. package/src/gtfs/trips.ts +1 -2
  36. package/src/parser.ts +4 -0
  37. package/src/router.ts +3 -0
  38. package/src/routing/__tests__/plotter.test.ts +0 -11
  39. package/src/routing/__tests__/rangeResult.test.ts +1470 -46
  40. package/src/routing/__tests__/rangeRouter.test.ts +14 -8
  41. package/src/routing/__tests__/result.test.ts +375 -76
  42. package/src/routing/plainRouter.ts +1 -6
  43. package/src/routing/plotter.ts +6 -5
  44. package/src/routing/rangeResult.ts +67 -52
  45. package/src/routing/rangeRouter.ts +3 -8
  46. package/src/routing/result.ts +95 -36
  47. package/src/routing/resultInternals.ts +5 -0
  48. package/src/routing/routingResult.ts +34 -0
@@ -623,24 +623,30 @@ describe('RangeRouter', () => {
623
623
  assert.strictEqual(result.size, 2);
624
624
  });
625
625
 
626
- it('allEarliestArrivals covers all reachable stops', () => {
627
- const arrivals = result.allEarliestArrivals();
626
+ it('arrivals covers all reachable stops', () => {
627
+ const arrivals = [...result.arrivals()];
628
628
  // Stop 1 is first reached by trip 0 (depart 08:00, arrive 08:30).
629
- assert.strictEqual(arrivals.get(1)?.arrival, timeFromHM(8, 30));
629
+ assert.strictEqual(
630
+ arrivals.find(({ stop }) => stop === 1)?.arrival,
631
+ timeFromHM(8, 30),
632
+ );
630
633
  });
631
634
 
632
- it('allShortestDurations covers all reachable stops', () => {
633
- const durations = result.allShortestDurations();
635
+ it('shortestDurations covers all reachable stops', () => {
636
+ const durations = [...result.shortestDurations()];
634
637
  // Both trips take 30 min; shortest duration to stop 1 is 30 min.
635
- assert.strictEqual(durations.get(1)?.duration, 30);
638
+ assert.strictEqual(
639
+ durations.find(({ stop }) => stop === 1)?.duration,
640
+ 30,
641
+ );
636
642
  });
637
643
 
638
644
  it('bestRoute without an explicit stop returns undefined', () => {
639
645
  assert.strictEqual(result.bestRoute(), undefined);
640
646
  });
641
647
 
642
- it('getRoutes returns an empty array', () => {
643
- assert.deepStrictEqual(result.getRoutes(), []);
648
+ it('routes yields nothing', () => {
649
+ assert.deepStrictEqual([...result.routes()], []);
644
650
  });
645
651
  });
646
652
  });
@@ -12,7 +12,6 @@ import {
12
12
  StopAdjacency,
13
13
  TransferTypes,
14
14
  } from '../../timetable/timetable.js';
15
- import { Query } from '../query.js';
16
15
  import { Result } from '../result.js';
17
16
  import { RoutingState, TransferEdge, VehicleEdge } from '../router.js';
18
17
 
@@ -175,16 +174,45 @@ describe('Result', () => {
175
174
  ]);
176
175
  const mockTimetable = new Timetable(stopsAdjacency, routesAdjacency, routes);
177
176
 
178
- const mockQuery = new Query.Builder()
179
- .from(0)
180
- .to(new Set([2, 3]))
181
- .departureTime(timeFromHMS(8, 0, 0))
182
- .build();
177
+ describe('arrivals', () => {
178
+ it('yields reached stops including origins', () => {
179
+ const result = new Result(
180
+ RoutingState.fromTestData({
181
+ nbStops: NB_STOPS,
182
+ origins: [0],
183
+ arrivals: [
184
+ [0, 480, 0],
185
+ [2, 510, 1],
186
+ [5, 540, 2],
187
+ ],
188
+ }),
189
+ mockStopsIndex,
190
+ mockTimetable,
191
+ );
192
+
193
+ const expected = [
194
+ { stop: 0, arrival: 480, legNumber: 0 },
195
+ { stop: 2, arrival: 510, legNumber: 1 },
196
+ { stop: 5, arrival: 540, legNumber: 2 },
197
+ ];
198
+ assert.deepStrictEqual([...result.arrivals()], expected);
199
+ assert.deepStrictEqual([...result.arrivals()], expected);
200
+ });
201
+
202
+ it('yields nothing when no stops were reached', () => {
203
+ const result = new Result(
204
+ RoutingState.fromTestData({ nbStops: NB_STOPS }),
205
+ mockStopsIndex,
206
+ mockTimetable,
207
+ );
208
+
209
+ assert.deepStrictEqual([...result.arrivals()], []);
210
+ });
211
+ });
183
212
 
184
213
  describe('bestRoute', () => {
185
214
  it('should return undefined when no route exists', () => {
186
215
  const result = new Result(
187
- mockQuery.to,
188
216
  RoutingState.fromTestData({ nbStops: NB_STOPS, destinations: [2, 3] }),
189
217
  mockStopsIndex,
190
218
  mockTimetable,
@@ -196,7 +224,6 @@ describe('Result', () => {
196
224
 
197
225
  it('should return undefined for unreachable destination', () => {
198
226
  const result = new Result(
199
- mockQuery.to,
200
227
  RoutingState.fromTestData({
201
228
  nbStops: NB_STOPS,
202
229
  origins: [0],
@@ -222,7 +249,6 @@ describe('Result', () => {
222
249
  };
223
250
 
224
251
  const result = new Result(
225
- mockQuery.to,
226
252
  RoutingState.fromTestData({
227
253
  nbStops: NB_STOPS,
228
254
  origins: [0],
@@ -260,7 +286,6 @@ describe('Result', () => {
260
286
  };
261
287
 
262
288
  const result = new Result(
263
- mockQuery.to,
264
289
  RoutingState.fromTestData({
265
290
  nbStops: NB_STOPS,
266
291
  origins: [2],
@@ -309,7 +334,6 @@ describe('Result', () => {
309
334
  };
310
335
 
311
336
  const result = new Result(
312
- mockQuery.to,
313
337
  RoutingState.fromTestData({
314
338
  nbStops: NB_STOPS,
315
339
  origins: [0],
@@ -354,7 +378,6 @@ describe('Result', () => {
354
378
  };
355
379
 
356
380
  const result = new Result(
357
- mockQuery.to,
358
381
  RoutingState.fromTestData({
359
382
  nbStops: NB_STOPS,
360
383
  origins: [0],
@@ -399,7 +422,6 @@ describe('Result', () => {
399
422
  };
400
423
 
401
424
  const result = new Result(
402
- mockQuery.to,
403
425
  RoutingState.fromTestData({
404
426
  nbStops: NB_STOPS,
405
427
  origins: [0],
@@ -436,7 +458,6 @@ describe('Result', () => {
436
458
  };
437
459
 
438
460
  const result = new Result(
439
- mockQuery.to,
440
461
  RoutingState.fromTestData({
441
462
  nbStops: NB_STOPS,
442
463
  origins: [0],
@@ -485,7 +506,6 @@ describe('Result', () => {
485
506
  };
486
507
 
487
508
  const result = new Result(
488
- mockQuery.to,
489
509
  RoutingState.fromTestData({
490
510
  nbStops: NB_STOPS,
491
511
  origins: [0],
@@ -535,7 +555,6 @@ describe('Result', () => {
535
555
  };
536
556
 
537
557
  const result = new Result(
538
- mockQuery.to,
539
558
  RoutingState.fromTestData({
540
559
  nbStops: NB_STOPS,
541
560
  origins: [0],
@@ -605,12 +624,7 @@ describe('Result', () => {
605
624
  ],
606
625
  });
607
626
 
608
- const result = new Result(
609
- mockQuery.to,
610
- state,
611
- mockStopsIndex,
612
- mockTimetable,
613
- );
627
+ const result = new Result(state, mockStopsIndex, mockTimetable);
614
628
  const route = result.bestRoute(3);
615
629
  assert(route);
616
630
  assert.strictEqual(
@@ -654,7 +668,6 @@ describe('Result', () => {
654
668
  const arrivalTime = { arrival: timeFromHMS(9, 0, 0), legNumber: 1 };
655
669
 
656
670
  const result = new Result(
657
- mockQuery.to,
658
671
  RoutingState.fromTestData({
659
672
  nbStops: NB_STOPS,
660
673
  destinations: [2],
@@ -670,7 +683,6 @@ describe('Result', () => {
670
683
 
671
684
  it('should return undefined for unreachable stop', () => {
672
685
  const result = new Result(
673
- mockQuery.to,
674
686
  RoutingState.fromTestData({
675
687
  nbStops: NB_STOPS,
676
688
  destinations: [2],
@@ -688,7 +700,6 @@ describe('Result', () => {
688
700
  const earlierArrival = { arrival: timeFromHMS(9, 0, 0), legNumber: 1 };
689
701
 
690
702
  const result = new Result(
691
- mockQuery.to,
692
703
  RoutingState.fromTestData({
693
704
  nbStops: NB_STOPS,
694
705
  destinations: [4],
@@ -705,59 +716,8 @@ describe('Result', () => {
705
716
  assert.deepStrictEqual(arrival, earlierArrival);
706
717
  });
707
718
 
708
- it('should respect maxTransfers constraint', () => {
709
- const directArrival = { arrival: timeFromHMS(9, 30, 0), legNumber: 1 };
710
- const transferArrival = { arrival: timeFromHMS(9, 0, 0), legNumber: 2 };
711
-
712
- const vehicleEdge1: VehicleEdge = {
713
- arrival: timeFromHMS(9, 30, 0),
714
- stopIndex: 0,
715
- hopOffStopIndex: 2,
716
- routeId: 0,
717
- tripIndex: 0,
718
- };
719
-
720
- const vehicleEdge2: VehicleEdge = {
721
- arrival: timeFromHMS(9, 45, 0),
722
- stopIndex: 0,
723
- hopOffStopIndex: 1,
724
- routeId: 1,
725
- tripIndex: 0,
726
- };
727
-
728
- const result = new Result(
729
- mockQuery.to,
730
- RoutingState.fromTestData({
731
- nbStops: NB_STOPS,
732
- origins: [0],
733
- destinations: [2],
734
- // The best overall arrival at stop 2 is 9:00 (leg 2), coming from a
735
- // route with a transfer — even though the graph edges themselves arrive
736
- // later. This tests that arrivalAt respects the maxTransfers limit by
737
- // falling back to the graph rather than the global best.
738
- arrivals: [[2, timeFromHMS(9, 0, 0), 2]],
739
- graph: [
740
- [[0, { stopId: 0, arrival: timeFromHMS(8, 0, 0) }]], // round 0 – origins
741
- [[2, vehicleEdge1]], // round 1 – direct (9:30)
742
- [[2, vehicleEdge2]], // round 2 – with transfer
743
- ],
744
- }),
745
- mockStopsIndex,
746
- mockTimetable,
747
- );
748
-
749
- // With maxTransfers = 0, only round 1 is considered → direct arrival.
750
- const arrivalWithLimit = result.arrivalAt(2, 0);
751
- assert.deepStrictEqual(arrivalWithLimit, directArrival);
752
-
753
- // Without a limit, the global best is returned.
754
- const arrivalWithoutLimit = result.arrivalAt(2);
755
- assert.deepStrictEqual(arrivalWithoutLimit, transferArrival);
756
- });
757
-
758
719
  it('should handle non-existent stops', () => {
759
720
  const result = new Result(
760
- mockQuery.to,
761
721
  RoutingState.fromTestData({
762
722
  nbStops: NB_STOPS,
763
723
  destinations: [2],
@@ -771,4 +731,343 @@ describe('Result', () => {
771
731
  assert.strictEqual(arrival, undefined);
772
732
  });
773
733
  });
734
+
735
+ describe('with transfer limits', () => {
736
+ const ORIGIN = 0;
737
+ const INTERCHANGE = 1;
738
+ const DESTINATION = 2;
739
+ const TRANSFER_ONLY = 3;
740
+ const WALK_ONLY = 4;
741
+ const UNREACHABLE = 5;
742
+ const DESTINATION_STATION = 6;
743
+ const DIRECT = 0;
744
+ const TO_INTERCHANGE = 1;
745
+ const FROM_INTERCHANGE = 2;
746
+ const TO_TRANSFER_ONLY = 3;
747
+
748
+ const stops: Stop[] = [
749
+ {
750
+ id: ORIGIN,
751
+ sourceStopId: 'stop0',
752
+ name: 'Origin',
753
+ locationType: 'SIMPLE_STOP_OR_PLATFORM',
754
+ children: [],
755
+ },
756
+ {
757
+ id: INTERCHANGE,
758
+ sourceStopId: 'stop1',
759
+ name: 'Interchange',
760
+ locationType: 'SIMPLE_STOP_OR_PLATFORM',
761
+ children: [],
762
+ },
763
+ {
764
+ id: DESTINATION,
765
+ sourceStopId: 'stop2',
766
+ name: 'Destination',
767
+ locationType: 'SIMPLE_STOP_OR_PLATFORM',
768
+ children: [],
769
+ parent: DESTINATION_STATION,
770
+ },
771
+ {
772
+ id: TRANSFER_ONLY,
773
+ sourceStopId: 'stop3',
774
+ name: 'Transfer-only destination',
775
+ locationType: 'SIMPLE_STOP_OR_PLATFORM',
776
+ children: [],
777
+ },
778
+ {
779
+ id: WALK_ONLY,
780
+ sourceStopId: 'stop4',
781
+ name: 'Walk-only destination',
782
+ locationType: 'SIMPLE_STOP_OR_PLATFORM',
783
+ children: [],
784
+ },
785
+ {
786
+ id: UNREACHABLE,
787
+ sourceStopId: 'stop5',
788
+ name: 'Unreachable stop',
789
+ locationType: 'SIMPLE_STOP_OR_PLATFORM',
790
+ children: [],
791
+ },
792
+ {
793
+ id: DESTINATION_STATION,
794
+ sourceStopId: 'stop6',
795
+ name: 'Destination station',
796
+ locationType: 'SIMPLE_STOP_OR_PLATFORM',
797
+ children: [DESTINATION],
798
+ },
799
+ ];
800
+ const stopsIndex = new StopsIndex(stops);
801
+
802
+ const departureTime = timeFromHMS(8, 0, 0);
803
+ const directArrival = timeFromHMS(9, 10, 0);
804
+ const viaArrival = timeFromHMS(8, 40, 0);
805
+ const timetable = new Timetable(
806
+ [
807
+ { routes: [DIRECT, TO_INTERCHANGE] }, // Origin
808
+ { routes: [TO_INTERCHANGE, FROM_INTERCHANGE, TO_TRANSFER_ONLY] }, // Interchange
809
+ { routes: [DIRECT, FROM_INTERCHANGE] }, // Destination
810
+ { routes: [TO_TRANSFER_ONLY] }, // Transfer-only destination
811
+ { routes: [] }, // Walk-only destination
812
+ { routes: [] }, // Unreachable stop
813
+ { routes: [] }, // Destination station
814
+ ],
815
+ [
816
+ Route.of({
817
+ id: DIRECT,
818
+ serviceRouteId: DIRECT,
819
+ trips: [
820
+ {
821
+ stops: [
822
+ {
823
+ id: ORIGIN,
824
+ arrivalTime: departureTime,
825
+ departureTime: departureTime,
826
+ },
827
+ {
828
+ id: DESTINATION,
829
+ arrivalTime: directArrival,
830
+ departureTime: directArrival,
831
+ },
832
+ ],
833
+ },
834
+ ],
835
+ }),
836
+ Route.of({
837
+ id: TO_INTERCHANGE,
838
+ serviceRouteId: TO_INTERCHANGE,
839
+ trips: [
840
+ {
841
+ stops: [
842
+ {
843
+ id: ORIGIN,
844
+ arrivalTime: departureTime,
845
+ departureTime: departureTime,
846
+ },
847
+ {
848
+ id: INTERCHANGE,
849
+ arrivalTime: departureTime + 5,
850
+ departureTime: departureTime + 5,
851
+ },
852
+ ],
853
+ },
854
+ ],
855
+ }),
856
+ Route.of({
857
+ id: FROM_INTERCHANGE,
858
+ serviceRouteId: FROM_INTERCHANGE,
859
+ trips: [
860
+ {
861
+ stops: [
862
+ {
863
+ id: INTERCHANGE,
864
+ arrivalTime: departureTime + 7,
865
+ departureTime: departureTime + 7,
866
+ },
867
+ {
868
+ id: DESTINATION,
869
+ arrivalTime: viaArrival,
870
+ departureTime: viaArrival,
871
+ },
872
+ ],
873
+ },
874
+ ],
875
+ }),
876
+ Route.of({
877
+ id: TO_TRANSFER_ONLY,
878
+ serviceRouteId: TO_TRANSFER_ONLY,
879
+ trips: [
880
+ {
881
+ stops: [
882
+ {
883
+ id: INTERCHANGE,
884
+ arrivalTime: departureTime + 7,
885
+ departureTime: departureTime + 7,
886
+ },
887
+ {
888
+ id: TRANSFER_ONLY,
889
+ arrivalTime: viaArrival,
890
+ departureTime: viaArrival,
891
+ },
892
+ ],
893
+ },
894
+ ],
895
+ }),
896
+ ],
897
+ [
898
+ { type: RouteTypes.BUS, name: 'Line 0', routes: [DIRECT] },
899
+ { type: RouteTypes.BUS, name: 'Line 1', routes: [TO_INTERCHANGE] },
900
+ { type: RouteTypes.BUS, name: 'Line 2', routes: [FROM_INTERCHANGE] },
901
+ { type: RouteTypes.BUS, name: 'Line 3', routes: [TO_TRANSFER_ONLY] },
902
+ ],
903
+ );
904
+ const result = new Result(
905
+ RoutingState.fromTestData({
906
+ nbStops: stops.length,
907
+ origins: [ORIGIN],
908
+ destinations: [DESTINATION],
909
+ arrivals: [
910
+ [ORIGIN, departureTime, 0],
911
+ [INTERCHANGE, departureTime + 5, 1],
912
+ [DESTINATION, viaArrival, 2],
913
+ [TRANSFER_ONLY, viaArrival, 2],
914
+ [WALK_ONLY, departureTime + 2, 0],
915
+ ],
916
+ graph: [
917
+ [
918
+ [ORIGIN, { stopId: ORIGIN, arrival: departureTime }],
919
+ [
920
+ WALK_ONLY,
921
+ {
922
+ from: ORIGIN,
923
+ to: WALK_ONLY,
924
+ duration: 2,
925
+ arrival: departureTime + 2,
926
+ },
927
+ ],
928
+ ],
929
+ [
930
+ [
931
+ INTERCHANGE,
932
+ {
933
+ routeId: TO_INTERCHANGE,
934
+ arrival: departureTime + 5,
935
+ tripIndex: 0,
936
+ stopIndex: 0,
937
+ hopOffStopIndex: 1,
938
+ },
939
+ ],
940
+ [
941
+ DESTINATION,
942
+ {
943
+ routeId: DIRECT,
944
+ arrival: directArrival,
945
+ tripIndex: 0,
946
+ stopIndex: 0,
947
+ hopOffStopIndex: 1,
948
+ },
949
+ ],
950
+ ],
951
+ [
952
+ [
953
+ DESTINATION,
954
+ {
955
+ routeId: FROM_INTERCHANGE,
956
+ arrival: viaArrival,
957
+ tripIndex: 0,
958
+ stopIndex: 0,
959
+ hopOffStopIndex: 1,
960
+ },
961
+ ],
962
+ [
963
+ TRANSFER_ONLY,
964
+ {
965
+ routeId: TO_TRANSFER_ONLY,
966
+ arrival: viaArrival,
967
+ tripIndex: 0,
968
+ stopIndex: 0,
969
+ hopOffStopIndex: 1,
970
+ },
971
+ ],
972
+ ],
973
+ ],
974
+ }),
975
+ stopsIndex,
976
+ timetable,
977
+ );
978
+ describe('arrivals', () => {
979
+ it('should retain direct and access journeys with zero transfers', () => {
980
+ assert.deepStrictEqual(
981
+ [...result.arrivals(0)],
982
+ [
983
+ { stop: ORIGIN, arrival: departureTime, legNumber: 0 },
984
+ { stop: INTERCHANGE, arrival: departureTime + 5, legNumber: 1 },
985
+ { stop: DESTINATION, arrival: directArrival, legNumber: 1 },
986
+ { stop: WALK_ONLY, arrival: departureTime + 2, legNumber: 0 },
987
+ ],
988
+ );
989
+ });
990
+ });
991
+
992
+ describe('arrivalAt', () => {
993
+ it('should select a slower direct arrival at an equivalent stop', () => {
994
+ assert.deepStrictEqual(result.arrivalAt(DESTINATION_STATION, 0), {
995
+ arrival: directArrival,
996
+ legNumber: 1,
997
+ });
998
+ assert.deepStrictEqual(result.arrivalAt(DESTINATION_STATION, 1), {
999
+ arrival: viaArrival,
1000
+ legNumber: 2,
1001
+ });
1002
+ assert.deepStrictEqual(result.arrivalAt(DESTINATION_STATION), {
1003
+ arrival: viaArrival,
1004
+ legNumber: 2,
1005
+ });
1006
+ assert.deepStrictEqual(result.arrivalAt(DESTINATION_STATION, 100), {
1007
+ arrival: viaArrival,
1008
+ legNumber: 2,
1009
+ });
1010
+ assert.strictEqual(result.arrivalAt(TRANSFER_ONLY, 0), undefined);
1011
+ });
1012
+ });
1013
+
1014
+ describe('bestRoute', () => {
1015
+ for (const [name, target] of [
1016
+ ['default destinations', undefined],
1017
+ ['a stop', DESTINATION],
1018
+ ['an equivalent stop', DESTINATION_STATION],
1019
+ ['a stop set', new Set([TRANSFER_ONLY, DESTINATION_STATION])],
1020
+ ] as const) {
1021
+ it(`should apply transfer limits to ${name}`, () => {
1022
+ const route = result.bestRoute(target, 0);
1023
+ assert(route);
1024
+ assert.strictEqual(route.arrivalTime(), directArrival);
1025
+ assert.strictEqual(
1026
+ route.legs.filter((leg) => 'route' in leg).length,
1027
+ 1,
1028
+ );
1029
+ assert.strictEqual(
1030
+ result.bestRoute(target, 1)?.arrivalTime(),
1031
+ viaArrival,
1032
+ );
1033
+ });
1034
+ }
1035
+
1036
+ it('should return undefined when a destination requires a transfer', () => {
1037
+ assert.strictEqual(result.bestRoute(TRANSFER_ONLY, 0), undefined);
1038
+ });
1039
+
1040
+ it('should reconstruct an access-only journey with zero transfers', () => {
1041
+ const route = result.bestRoute(WALK_ONLY, 0);
1042
+ assert(route);
1043
+ assert.deepStrictEqual(route.legs, [
1044
+ { from: stops[ORIGIN], to: stops[WALK_ONLY], duration: 2 },
1045
+ ]);
1046
+ });
1047
+ });
1048
+
1049
+ describe('bestRouteToSourceStopId', () => {
1050
+ it('should apply transfer limits to source IDs and equivalent stops', () => {
1051
+ assert.strictEqual(
1052
+ result
1053
+ .bestRouteToSourceStopId(`stop${DESTINATION_STATION}`, 0)
1054
+ ?.arrivalTime(),
1055
+ directArrival,
1056
+ );
1057
+ assert.strictEqual(
1058
+ result
1059
+ .bestRouteToSourceStopId(
1060
+ new Set([`stop${TRANSFER_ONLY}`, `stop${DESTINATION_STATION}`]),
1061
+ 0,
1062
+ )
1063
+ ?.arrivalTime(),
1064
+ directArrival,
1065
+ );
1066
+ assert.strictEqual(
1067
+ result.bestRouteToSourceStopId(`stop${TRANSFER_ONLY}`, 0),
1068
+ undefined,
1069
+ );
1070
+ });
1071
+ });
1072
+ });
774
1073
  });
@@ -51,11 +51,6 @@ export class PlainRouter {
51
51
  );
52
52
 
53
53
  this.raptor.run(query.options, routingState);
54
- return new Result(
55
- new Set(destinations),
56
- routingState,
57
- this.stopsIndex,
58
- this.timetable,
59
- );
54
+ return new Result(routingState, this.stopsIndex, this.timetable);
60
55
  }
61
56
  }
@@ -2,6 +2,7 @@ import { StopId } from '../stops/stops.js';
2
2
  import { durationToString, timeToString } from '../timetable/time.js';
3
3
  import { routeTypeToString } from '../timetable/timetable.js';
4
4
  import { Result } from './result.js';
5
+ import { resultGraph } from './resultInternals.js';
5
6
  import {
6
7
  AccessEdge,
7
8
  RoutingEdge,
@@ -261,9 +262,9 @@ export class Plotter {
261
262
  isOrigin: boolean;
262
263
  isDestination: boolean;
263
264
  } {
264
- const isOrigin = this.result.routingState.graph[0]?.[stopId] !== undefined;
265
- const isDestination =
266
- this.result.routingState.destinations.includes(stopId);
265
+ const { graph, destinations } = this.result[resultGraph]();
266
+ const isOrigin = graph[0]?.[stopId] !== undefined;
267
+ const isDestination = destinations.includes(stopId);
267
268
  return { isOrigin, isDestination };
268
269
  }
269
270
 
@@ -463,7 +464,7 @@ export class Plotter {
463
464
  */
464
465
  private collectStations(): Set<StopId> {
465
466
  const stations = new Set<StopId>();
466
- const graph = this.result.routingState.graph;
467
+ const graph = this.result[resultGraph]().graph;
467
468
 
468
469
  for (const roundEdges of graph) {
469
470
  for (let stopId = 0; stopId < roundEdges.length; stopId++) {
@@ -516,7 +517,7 @@ export class Plotter {
516
517
  private collectEdges(): string[] {
517
518
  const edges: string[] = [];
518
519
  const continuationEdges: string[] = [];
519
- const graph = this.result.routingState.graph;
520
+ const graph = this.result[resultGraph]().graph;
520
521
 
521
522
  for (let round = 0; round < graph.length; round++) {
522
523
  const roundEdges = graph[round];