minotor 3.0.2 → 5.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 (43) hide show
  1. package/CHANGELOG.md +9 -3
  2. package/README.md +1 -0
  3. package/dist/cli.mjs +294 -307
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/gtfs/trips.d.ts +12 -6
  6. package/dist/parser.cjs.js +290 -302
  7. package/dist/parser.cjs.js.map +1 -1
  8. package/dist/parser.esm.js +290 -302
  9. package/dist/parser.esm.js.map +1 -1
  10. package/dist/router.cjs.js +1 -1
  11. package/dist/router.cjs.js.map +1 -1
  12. package/dist/router.d.ts +2 -2
  13. package/dist/router.esm.js +1 -1
  14. package/dist/router.esm.js.map +1 -1
  15. package/dist/router.umd.js +1 -1
  16. package/dist/router.umd.js.map +1 -1
  17. package/dist/routing/route.d.ts +3 -3
  18. package/dist/timetable/io.d.ts +5 -4
  19. package/dist/timetable/proto/timetable.d.ts +7 -16
  20. package/dist/timetable/route.d.ts +7 -5
  21. package/dist/timetable/timetable.d.ts +7 -5
  22. package/package.json +1 -1
  23. package/src/__e2e__/timetable/timetable.bin +2 -2
  24. package/src/cli/repl.ts +0 -1
  25. package/src/gtfs/__tests__/parser.test.ts +2 -2
  26. package/src/gtfs/__tests__/routes.test.ts +3 -0
  27. package/src/gtfs/__tests__/trips.test.ts +123 -166
  28. package/src/gtfs/parser.ts +50 -9
  29. package/src/gtfs/routes.ts +1 -0
  30. package/src/gtfs/trips.ts +195 -112
  31. package/src/router.ts +2 -2
  32. package/src/routing/__tests__/route.test.ts +3 -3
  33. package/src/routing/__tests__/router.test.ts +186 -203
  34. package/src/routing/route.ts +3 -3
  35. package/src/routing/router.ts +1 -1
  36. package/src/timetable/__tests__/io.test.ts +52 -64
  37. package/src/timetable/__tests__/route.test.ts +25 -17
  38. package/src/timetable/__tests__/timetable.test.ts +16 -24
  39. package/src/timetable/io.ts +20 -19
  40. package/src/timetable/proto/timetable.proto +7 -9
  41. package/src/timetable/proto/timetable.ts +80 -202
  42. package/src/timetable/route.ts +27 -13
  43. package/src/timetable/timetable.ts +20 -16
@@ -7,7 +7,6 @@ import { Duration } from '../../timetable/duration.js';
7
7
  import { REGULAR, Route } from '../../timetable/route.js';
8
8
  import { Time } from '../../timetable/time.js';
9
9
  import {
10
- RoutesAdjacency,
11
10
  ServiceRoutesMap,
12
11
  StopsAdjacency,
13
12
  Timetable,
@@ -23,36 +22,33 @@ describe('Router', () => {
23
22
 
24
23
  beforeEach(() => {
25
24
  const stopsAdjacency: StopsAdjacency = new Map([
26
- [0, { transfers: [], routes: ['route1'] }],
27
- [1, { transfers: [], routes: ['route1'] }],
28
- [2, { transfers: [], routes: ['route1'] }],
25
+ [0, { transfers: [], routes: [0] }],
26
+ [1, { transfers: [], routes: [0] }],
27
+ [2, { transfers: [], routes: [0] }],
29
28
  ]);
30
29
 
31
- const routesAdjacency: RoutesAdjacency = new Map([
32
- [
33
- 'route1',
34
- new Route(
35
- new Uint16Array([
36
- Time.fromString('08:00:00').toMinutes(),
37
- Time.fromString('08:10:00').toMinutes(),
38
- Time.fromString('08:15:00').toMinutes(),
39
- Time.fromString('08:25:00').toMinutes(),
40
- Time.fromString('08:35:00').toMinutes(),
41
- Time.fromString('08:45:00').toMinutes(),
42
- ]),
43
- new Uint8Array([
44
- REGULAR,
45
- REGULAR,
46
- REGULAR,
47
- REGULAR,
48
- REGULAR,
49
- REGULAR,
50
- ]),
51
- new Uint32Array([0, 1, 2]),
52
- 'service_route1',
53
- ),
54
- ],
55
- ]);
30
+ const routesAdjacency = [
31
+ new Route(
32
+ new Uint16Array([
33
+ Time.fromString('08:00:00').toMinutes(),
34
+ Time.fromString('08:10:00').toMinutes(),
35
+ Time.fromString('08:15:00').toMinutes(),
36
+ Time.fromString('08:25:00').toMinutes(),
37
+ Time.fromString('08:35:00').toMinutes(),
38
+ Time.fromString('08:45:00').toMinutes(),
39
+ ]),
40
+ new Uint8Array([
41
+ REGULAR,
42
+ REGULAR,
43
+ REGULAR,
44
+ REGULAR,
45
+ REGULAR,
46
+ REGULAR,
47
+ ]),
48
+ new Uint32Array([0, 1, 2]),
49
+ 'service_route1',
50
+ ),
51
+ ];
56
52
 
57
53
  const routes: ServiceRoutesMap = new Map([
58
54
  [
@@ -60,6 +56,7 @@ describe('Router', () => {
60
56
  {
61
57
  type: 'BUS',
62
58
  name: 'Line 1',
59
+ routes: [0],
63
60
  },
64
61
  ],
65
62
  ]);
@@ -154,60 +151,54 @@ describe('Router', () => {
154
151
 
155
152
  beforeEach(() => {
156
153
  const stopsAdjacency: StopsAdjacency = new Map([
157
- [0, { transfers: [], routes: ['route1'] }],
158
- [1, { transfers: [], routes: ['route1', 'route2'] }],
159
- [2, { transfers: [], routes: ['route1'] }],
160
- [3, { transfers: [], routes: ['route2'] }],
161
- [4, { transfers: [], routes: ['route2'] }],
162
- ]);
163
- const routesAdjacency: RoutesAdjacency = new Map([
164
- [
165
- 'route1',
166
- new Route(
167
- new Uint16Array([
168
- Time.fromString('08:00:00').toMinutes(),
169
- Time.fromString('08:15:00').toMinutes(),
170
- Time.fromString('08:30:00').toMinutes(),
171
- Time.fromString('08:45:00').toMinutes(),
172
- Time.fromString('09:00:00').toMinutes(),
173
- Time.fromString('09:10:00').toMinutes(),
174
- ]),
175
- new Uint8Array([
176
- REGULAR,
177
- REGULAR,
178
- REGULAR,
179
- REGULAR,
180
- REGULAR,
181
- REGULAR,
182
- ]),
183
- new Uint32Array([0, 1, 2]),
184
- 'service_route1',
185
- ),
186
- ],
187
- [
188
- 'route2',
189
- new Route(
190
- new Uint16Array([
191
- Time.fromString('08:05:00').toMinutes(),
192
- Time.fromString('08:20:00').toMinutes(),
193
- Time.fromString('09:00:00').toMinutes(),
194
- Time.fromString('09:15:00').toMinutes(),
195
- Time.fromString('09:20:00').toMinutes(),
196
- Time.fromString('09:35:00').toMinutes(),
197
- ]),
198
- new Uint8Array([
199
- REGULAR,
200
- REGULAR,
201
- REGULAR,
202
- REGULAR,
203
- REGULAR,
204
- REGULAR,
205
- ]),
206
- new Uint32Array([3, 1, 4]),
207
- 'service_route2',
208
- ),
209
- ],
154
+ [0, { transfers: [], routes: [0] }],
155
+ [1, { transfers: [], routes: [0, 1] }],
156
+ [2, { transfers: [], routes: [0] }],
157
+ [3, { transfers: [], routes: [1] }],
158
+ [4, { transfers: [], routes: [1] }],
210
159
  ]);
160
+ const routesAdjacency = [
161
+ new Route(
162
+ new Uint16Array([
163
+ Time.fromString('08:00:00').toMinutes(),
164
+ Time.fromString('08:15:00').toMinutes(),
165
+ Time.fromString('08:30:00').toMinutes(),
166
+ Time.fromString('08:45:00').toMinutes(),
167
+ Time.fromString('09:00:00').toMinutes(),
168
+ Time.fromString('09:10:00').toMinutes(),
169
+ ]),
170
+ new Uint8Array([
171
+ REGULAR,
172
+ REGULAR,
173
+ REGULAR,
174
+ REGULAR,
175
+ REGULAR,
176
+ REGULAR,
177
+ ]),
178
+ new Uint32Array([0, 1, 2]),
179
+ 'service_route1',
180
+ ),
181
+ new Route(
182
+ new Uint16Array([
183
+ Time.fromString('08:05:00').toMinutes(),
184
+ Time.fromString('08:20:00').toMinutes(),
185
+ Time.fromString('09:00:00').toMinutes(),
186
+ Time.fromString('09:15:00').toMinutes(),
187
+ Time.fromString('09:20:00').toMinutes(),
188
+ Time.fromString('09:35:00').toMinutes(),
189
+ ]),
190
+ new Uint8Array([
191
+ REGULAR,
192
+ REGULAR,
193
+ REGULAR,
194
+ REGULAR,
195
+ REGULAR,
196
+ REGULAR,
197
+ ]),
198
+ new Uint32Array([3, 1, 4]),
199
+ 'service_route2',
200
+ ),
201
+ ];
211
202
 
212
203
  const routes: ServiceRoutesMap = new Map([
213
204
  [
@@ -215,6 +206,7 @@ describe('Router', () => {
215
206
  {
216
207
  type: 'BUS',
217
208
  name: 'Line 1',
209
+ routes: [0],
218
210
  },
219
211
  ],
220
212
  [
@@ -222,6 +214,7 @@ describe('Router', () => {
222
214
  {
223
215
  type: 'RAIL',
224
216
  name: 'Line 2',
217
+ routes: [1],
225
218
  },
226
219
  ],
227
220
  ]);
@@ -330,7 +323,7 @@ describe('Router', () => {
330
323
 
331
324
  beforeEach(() => {
332
325
  const stopsAdjacency: StopsAdjacency = new Map([
333
- [0, { transfers: [], routes: ['route1'] }],
326
+ [0, { transfers: [], routes: [0] }],
334
327
  [
335
328
  1,
336
329
  {
@@ -341,63 +334,57 @@ describe('Router', () => {
341
334
  minTransferTime: Duration.fromSeconds(300),
342
335
  },
343
336
  ],
344
- routes: ['route1'],
337
+ routes: [0],
345
338
  },
346
339
  ],
347
- [2, { transfers: [], routes: ['route1'] }],
348
- [3, { transfers: [], routes: ['route2'] }],
349
- [4, { transfers: [], routes: ['route2'] }],
350
- [5, { transfers: [], routes: ['route2'] }],
340
+ [2, { transfers: [], routes: [0] }],
341
+ [3, { transfers: [], routes: [1] }],
342
+ [4, { transfers: [], routes: [1] }],
343
+ [5, { transfers: [], routes: [1] }],
351
344
  ]);
352
345
 
353
- const routesAdjacency: RoutesAdjacency = new Map([
354
- [
355
- 'route1',
356
- new Route(
357
- new Uint16Array([
358
- Time.fromString('08:00:00').toMinutes(),
359
- Time.fromString('08:15:00').toMinutes(),
360
- Time.fromString('08:25:00').toMinutes(),
361
- Time.fromString('08:35:00').toMinutes(),
362
- Time.fromString('08:45:00').toMinutes(),
363
- Time.fromString('08:55:00').toMinutes(),
364
- ]),
365
- new Uint8Array([
366
- REGULAR,
367
- REGULAR,
368
- REGULAR,
369
- REGULAR,
370
- REGULAR,
371
- REGULAR,
372
- ]),
373
- new Uint32Array([0, 1, 2]),
374
- 'service_route1',
375
- ),
376
- ],
377
- [
378
- 'route2',
379
- new Route(
380
- new Uint16Array([
381
- Time.fromString('08:10:00').toMinutes(),
382
- Time.fromString('08:20:00').toMinutes(),
383
- Time.fromString('08:40:00').toMinutes(),
384
- Time.fromString('08:50:00').toMinutes(),
385
- Time.fromString('09:00:00').toMinutes(),
386
- Time.fromString('09:10:00').toMinutes(),
387
- ]),
388
- new Uint8Array([
389
- REGULAR,
390
- REGULAR,
391
- REGULAR,
392
- REGULAR,
393
- REGULAR,
394
- REGULAR,
395
- ]),
396
- new Uint32Array([3, 4, 5]),
397
- 'service_route2',
398
- ),
399
- ],
400
- ]);
346
+ const routesAdjacency = [
347
+ new Route(
348
+ new Uint16Array([
349
+ Time.fromString('08:00:00').toMinutes(),
350
+ Time.fromString('08:15:00').toMinutes(),
351
+ Time.fromString('08:25:00').toMinutes(),
352
+ Time.fromString('08:35:00').toMinutes(),
353
+ Time.fromString('08:45:00').toMinutes(),
354
+ Time.fromString('08:55:00').toMinutes(),
355
+ ]),
356
+ new Uint8Array([
357
+ REGULAR,
358
+ REGULAR,
359
+ REGULAR,
360
+ REGULAR,
361
+ REGULAR,
362
+ REGULAR,
363
+ ]),
364
+ new Uint32Array([0, 1, 2]),
365
+ 'service_route1',
366
+ ),
367
+ new Route(
368
+ new Uint16Array([
369
+ Time.fromString('08:10:00').toMinutes(),
370
+ Time.fromString('08:20:00').toMinutes(),
371
+ Time.fromString('08:40:00').toMinutes(),
372
+ Time.fromString('08:50:00').toMinutes(),
373
+ Time.fromString('09:00:00').toMinutes(),
374
+ Time.fromString('09:10:00').toMinutes(),
375
+ ]),
376
+ new Uint8Array([
377
+ REGULAR,
378
+ REGULAR,
379
+ REGULAR,
380
+ REGULAR,
381
+ REGULAR,
382
+ REGULAR,
383
+ ]),
384
+ new Uint32Array([3, 4, 5]),
385
+ 'service_route2',
386
+ ),
387
+ ];
401
388
 
402
389
  const routes: ServiceRoutesMap = new Map([
403
390
  [
@@ -405,6 +392,7 @@ describe('Router', () => {
405
392
  {
406
393
  type: 'BUS',
407
394
  name: 'Line 1',
395
+ routes: [0],
408
396
  },
409
397
  ],
410
398
  [
@@ -412,6 +400,7 @@ describe('Router', () => {
412
400
  {
413
401
  type: 'RAIL',
414
402
  name: 'Line 2',
403
+ routes: [1],
415
404
  },
416
405
  ],
417
406
  ]);
@@ -530,75 +519,66 @@ describe('Router', () => {
530
519
 
531
520
  beforeEach(() => {
532
521
  const stopsAdjacency: StopsAdjacency = new Map([
533
- [0, { transfers: [], routes: ['route1'] }],
534
- [1, { transfers: [], routes: ['route1', 'route2'] }],
535
- [2, { transfers: [], routes: ['route1'] }],
536
- [3, { transfers: [], routes: ['route2'] }],
537
- [4, { transfers: [], routes: ['route2'] }],
522
+ [0, { transfers: [], routes: [0] }],
523
+ [1, { transfers: [], routes: [0, 1] }],
524
+ [2, { transfers: [], routes: [0] }],
525
+ [3, { transfers: [], routes: [1] }],
526
+ [4, { transfers: [], routes: [1] }],
538
527
  ]);
539
528
 
540
- const routesAdjacency: RoutesAdjacency = new Map([
541
- [
542
- 'route1',
543
- new Route(
544
- new Uint16Array([
545
- Time.fromString('08:00:00').toMinutes(),
546
- Time.fromString('08:15:00').toMinutes(),
547
- Time.fromString('08:30:00').toMinutes(),
548
- Time.fromString('08:45:00').toMinutes(),
549
- Time.fromString('09:00:00').toMinutes(),
550
- Time.fromString('09:15:00').toMinutes(),
551
- ]),
552
- new Uint8Array([
553
- REGULAR,
554
- REGULAR,
555
- REGULAR,
556
- REGULAR,
557
- REGULAR,
558
- REGULAR,
559
- ]),
560
- new Uint32Array([0, 1, 2]),
561
- 'service_route1',
562
- ),
563
- ],
564
- [
565
- 'route2',
566
- new Route(
567
- new Uint16Array([
568
- Time.fromString('08:10:00').toMinutes(),
569
- Time.fromString('08:25:00').toMinutes(),
570
- Time.fromString('08:50:00').toMinutes(),
571
- Time.fromString('09:05:00').toMinutes(),
572
- Time.fromString('09:10:00').toMinutes(),
573
- Time.fromString('09:25:00').toMinutes(),
574
- ]),
575
- new Uint8Array([
576
- REGULAR,
577
- REGULAR,
578
- REGULAR,
579
- REGULAR,
580
- REGULAR,
581
- REGULAR,
582
- ]),
583
- new Uint32Array([3, 1, 4]),
584
- 'service_route2',
585
- ),
586
- ],
587
- [
588
- 'route3',
589
- new Route(
590
- new Uint16Array([
591
- Time.fromString('08:00:00').toMinutes(),
592
- Time.fromString('08:15:00').toMinutes(),
593
- Time.fromString('09:45:00').toMinutes(),
594
- Time.fromString('10:00:00').toMinutes(),
595
- ]),
596
- new Uint8Array([REGULAR, REGULAR, REGULAR, REGULAR]),
597
- new Uint32Array([0, 4]),
598
- 'service_route3',
599
- ),
600
- ],
601
- ]);
529
+ const routesAdjacency = [
530
+ new Route(
531
+ new Uint16Array([
532
+ Time.fromString('08:00:00').toMinutes(),
533
+ Time.fromString('08:15:00').toMinutes(),
534
+ Time.fromString('08:30:00').toMinutes(),
535
+ Time.fromString('08:45:00').toMinutes(),
536
+ Time.fromString('09:00:00').toMinutes(),
537
+ Time.fromString('09:15:00').toMinutes(),
538
+ ]),
539
+ new Uint8Array([
540
+ REGULAR,
541
+ REGULAR,
542
+ REGULAR,
543
+ REGULAR,
544
+ REGULAR,
545
+ REGULAR,
546
+ ]),
547
+ new Uint32Array([0, 1, 2]),
548
+ 'service_route1',
549
+ ),
550
+ new Route(
551
+ new Uint16Array([
552
+ Time.fromString('08:10:00').toMinutes(),
553
+ Time.fromString('08:25:00').toMinutes(),
554
+ Time.fromString('08:50:00').toMinutes(),
555
+ Time.fromString('09:05:00').toMinutes(),
556
+ Time.fromString('09:10:00').toMinutes(),
557
+ Time.fromString('09:25:00').toMinutes(),
558
+ ]),
559
+ new Uint8Array([
560
+ REGULAR,
561
+ REGULAR,
562
+ REGULAR,
563
+ REGULAR,
564
+ REGULAR,
565
+ REGULAR,
566
+ ]),
567
+ new Uint32Array([3, 1, 4]),
568
+ 'service_route2',
569
+ ),
570
+ new Route(
571
+ new Uint16Array([
572
+ Time.fromString('08:00:00').toMinutes(),
573
+ Time.fromString('08:15:00').toMinutes(),
574
+ Time.fromString('09:45:00').toMinutes(),
575
+ Time.fromString('10:00:00').toMinutes(),
576
+ ]),
577
+ new Uint8Array([REGULAR, REGULAR, REGULAR, REGULAR]),
578
+ new Uint32Array([0, 4]),
579
+ 'service_route3',
580
+ ),
581
+ ];
602
582
 
603
583
  const routes: ServiceRoutesMap = new Map([
604
584
  [
@@ -606,6 +586,7 @@ describe('Router', () => {
606
586
  {
607
587
  type: 'BUS',
608
588
  name: 'Line 1',
589
+ routes: [0],
609
590
  },
610
591
  ],
611
592
  [
@@ -613,6 +594,7 @@ describe('Router', () => {
613
594
  {
614
595
  type: 'RAIL',
615
596
  name: 'Line 2',
597
+ routes: [1],
616
598
  },
617
599
  ],
618
600
  [
@@ -620,6 +602,7 @@ describe('Router', () => {
620
602
  {
621
603
  type: 'FERRY',
622
604
  name: 'Line 3',
605
+ routes: [2],
623
606
  },
624
607
  ],
625
608
  ]);
@@ -1,7 +1,7 @@
1
1
  import { SourceStopId, Stop } from '../stops/stops.js';
2
2
  import { Duration } from '../timetable/duration.js';
3
3
  import { Time } from '../timetable/time.js';
4
- import { ServiceRoute, TransferType } from '../timetable/timetable.js';
4
+ import { ServiceRouteInfo, TransferType } from '../timetable/timetable.js';
5
5
 
6
6
  export type JsonLeg = {
7
7
  from: SourceStopId;
@@ -10,7 +10,7 @@ export type JsonLeg = {
10
10
  | {
11
11
  departure: string;
12
12
  arrival: string;
13
- route: ServiceRoute;
13
+ route: ServiceRouteInfo;
14
14
  }
15
15
  | {
16
16
  type: TransferType;
@@ -35,7 +35,7 @@ export type Transfer = BaseLeg & {
35
35
  };
36
36
 
37
37
  export type VehicleLeg = BaseLeg & {
38
- route: ServiceRoute;
38
+ route: ServiceRouteInfo;
39
39
  departureTime: Time;
40
40
  arrivalTime: Time;
41
41
  // TODO support pick up and drop off types
@@ -219,7 +219,7 @@ export class Router {
219
219
  to: this.stopsIndex.findStopById(currentStop)!,
220
220
  departureTime: bestHopOnDepartureTime,
221
221
  arrivalTime: currentArrivalTime,
222
- route: this.timetable.getServiceRoute(route),
222
+ route: this.timetable.getServiceRouteInfo(route),
223
223
  },
224
224
  });
225
225
  earliestArrivals.set(currentStop, {