minotor 1.0.6 → 2.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 (60) hide show
  1. package/CHANGELOG.md +9 -3
  2. package/README.md +3 -2
  3. package/dist/cli.mjs +604 -531
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/gtfs/stops.d.ts +19 -5
  6. package/dist/gtfs/transfers.d.ts +5 -4
  7. package/dist/gtfs/trips.d.ts +7 -5
  8. package/dist/gtfs/utils.d.ts +7 -8
  9. package/dist/parser.cjs.js +569 -501
  10. package/dist/parser.cjs.js.map +1 -1
  11. package/dist/parser.esm.js +569 -501
  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 +3 -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/__tests__/route.test.d.ts +1 -0
  21. package/dist/routing/query.d.ts +7 -7
  22. package/dist/routing/result.d.ts +3 -3
  23. package/dist/routing/route.d.ts +1 -0
  24. package/dist/stops/proto/stops.d.ts +5 -4
  25. package/dist/stops/stops.d.ts +10 -1
  26. package/dist/stops/stopsIndex.d.ts +21 -4
  27. package/dist/timetable/proto/timetable.d.ts +21 -18
  28. package/dist/timetable/timetable.d.ts +38 -14
  29. package/package.json +4 -3
  30. package/src/cli/repl.ts +13 -10
  31. package/src/gtfs/__tests__/parser.test.ts +50 -579
  32. package/src/gtfs/__tests__/stops.test.ts +181 -112
  33. package/src/gtfs/__tests__/transfers.test.ts +170 -12
  34. package/src/gtfs/__tests__/trips.test.ts +212 -141
  35. package/src/gtfs/__tests__/utils.test.ts +4 -4
  36. package/src/gtfs/parser.ts +22 -13
  37. package/src/gtfs/stops.ts +63 -28
  38. package/src/gtfs/transfers.ts +14 -6
  39. package/src/gtfs/trips.ts +110 -47
  40. package/src/gtfs/utils.ts +11 -11
  41. package/src/router.ts +2 -4
  42. package/src/routing/__tests__/route.test.ts +112 -0
  43. package/src/routing/__tests__/router.test.ts +234 -244
  44. package/src/routing/query.ts +7 -7
  45. package/src/routing/result.ts +9 -6
  46. package/src/routing/route.ts +11 -0
  47. package/src/routing/router.ts +26 -24
  48. package/src/stops/__tests__/io.test.ts +9 -8
  49. package/src/stops/__tests__/stopFinder.test.ts +45 -36
  50. package/src/stops/io.ts +8 -5
  51. package/src/stops/proto/stops.proto +8 -7
  52. package/src/stops/proto/stops.ts +68 -38
  53. package/src/stops/stops.ts +13 -1
  54. package/src/stops/stopsIndex.ts +50 -7
  55. package/src/timetable/__tests__/io.test.ts +40 -49
  56. package/src/timetable/__tests__/timetable.test.ts +50 -58
  57. package/src/timetable/io.ts +69 -56
  58. package/src/timetable/proto/timetable.proto +22 -17
  59. package/src/timetable/proto/timetable.ts +94 -184
  60. package/src/timetable/timetable.ts +62 -29
@@ -1,20 +1,34 @@
1
- import { Latitude, Longitude, Platform, StopId, StopsMap } from '../stops/stops.js';
1
+ import { Latitude, Longitude, Platform, SourceStopId, Stop, StopId, StopsMap } from '../stops/stops.js';
2
2
  import { Maybe } from './utils.js';
3
- export type StopIds = Set<StopId>;
4
3
  export type GtfsLocationType = 0 | 1 | 2 | 3 | 4;
5
4
  export type StopEntry = {
6
- stop_id: StopId;
5
+ stop_id: SourceStopId;
7
6
  stop_name: string;
8
7
  stop_lat?: Latitude;
9
8
  stop_lon?: Longitude;
10
9
  location_type?: GtfsLocationType;
11
- parent_station?: StopId;
10
+ parent_station?: SourceStopId;
12
11
  platform_code?: Platform;
13
12
  };
13
+ type ParsedStop = Stop & {
14
+ parentSourceId?: SourceStopId;
15
+ };
16
+ export type ParsedStopsMap = Map<SourceStopId, ParsedStop>;
14
17
  /**
15
18
  * Parses the stops.txt file from a GTFS feed.
16
19
  *
17
20
  * @param stopsStream The readable stream containing the stops data.
18
21
  * @return A mapping of stop IDs to corresponding stop details.
19
22
  */
20
- export declare const parseStops: (stopsStream: NodeJS.ReadableStream, platformParser?: (stopEntry: StopEntry) => Maybe<Platform>, validStops?: StopIds) => Promise<StopsMap>;
23
+ export declare const parseStops: (stopsStream: NodeJS.ReadableStream, platformParser?: (stopEntry: StopEntry) => Maybe<Platform>) => Promise<ParsedStopsMap>;
24
+ /**
25
+ * Builds the final stop map indexed by internal IDs.
26
+ * Excludes all stops that do not have at least one valid stopId
27
+ * as a child, a parent, or being valid itself.
28
+ *
29
+ * @param parsedStops - The map of parsed stops.
30
+ * @param validStops - A set of valid stop IDs.
31
+ * @returns A map of stops indexed by internal IDs.
32
+ */
33
+ export declare const indexStops: (parsedStops: ParsedStopsMap, validStops?: Set<StopId>) => StopsMap;
34
+ export {};
@@ -1,11 +1,12 @@
1
- import { StopId } from '../stops/stops.js';
1
+ import { SourceStopId, StopId } from '../stops/stops.js';
2
2
  import { ServiceRouteId, Transfer } from '../timetable/timetable.js';
3
+ import { ParsedStopsMap } from './stops.js';
3
4
  import { TripId } from './trips.js';
4
5
  export type GtfsTransferType = 0 | 1 | 2 | 3 | 4 | 5;
5
6
  export type TransfersMap = Map<StopId, Transfer[]>;
6
7
  export type TransferEntry = {
7
- from_stop_id?: StopId;
8
- to_stop_id?: StopId;
8
+ from_stop_id?: SourceStopId;
9
+ to_stop_id?: SourceStopId;
9
10
  from_trip_id?: TripId;
10
11
  to_trip_id?: TripId;
11
12
  from_route_id?: ServiceRouteId;
@@ -19,4 +20,4 @@ export type TransferEntry = {
19
20
  * @param stopsStream The readable stream containing the stops data.
20
21
  * @return A mapping of stop IDs to corresponding stop details.
21
22
  */
22
- export declare const parseTransfers: (transfersStream: NodeJS.ReadableStream) => Promise<TransfersMap>;
23
+ export declare const parseTransfers: (transfersStream: NodeJS.ReadableStream, stopsMap: ParsedStopsMap) => Promise<TransfersMap>;
@@ -1,6 +1,7 @@
1
+ import { StopId } from '../stops/stops.js';
1
2
  import { RoutesAdjacency, ServiceRouteId, ServiceRoutesMap, StopsAdjacency } from '../timetable/timetable.js';
2
3
  import { ServiceIds } from './services.js';
3
- import { StopIds } from './stops.js';
4
+ import { ParsedStopsMap } from './stops.js';
4
5
  import { TransfersMap } from './transfers.js';
5
6
  export type TripId = string;
6
7
  export type TripIdsMap = Map<TripId, ServiceRouteId>;
@@ -14,13 +15,14 @@ export type GtfsPickupDropOffType = '' | 0 | 1 | 2 | 3;
14
15
  * @returns A mapping of trip IDs to corresponding route IDs.
15
16
  */
16
17
  export declare const parseTrips: (tripsStream: NodeJS.ReadableStream, serviceIds: ServiceIds, routeIds: ServiceRoutesMap) => Promise<TripIdsMap>;
17
- export declare const buildStopsAdjacencyStructure: (validStops: StopIds, routes: RoutesAdjacency, transfersMap: TransfersMap) => StopsAdjacency;
18
+ export declare const buildStopsAdjacencyStructure: (validStops: Set<StopId>, routes: RoutesAdjacency, transfersMap: TransfersMap) => StopsAdjacency;
18
19
  /**
19
20
  * Parses the stop_times.txt data from a GTFS feed.
20
21
  *
21
22
  * @param stopTimesStream The readable stream containing the stop times data.
23
+ * @param stopsMap A map of parsed stops from the GTFS feed.
22
24
  * @param validTripIds A map of valid trip IDs to corresponding route IDs.
23
- * @param validStopIds A map of valid stop IDs.
24
- * @returns A mapping of route IDs to route details. The routes return corresponds to the set of trips from GTFS that share the same stop list.
25
+ * @param validStopIds A set of valid stop IDs.
26
+ * @returns A mapping of route IDs to route details. The routes returned correspond to the set of trips from GTFS that share the same stop list.
25
27
  */
26
- export declare const parseStopTimes: (stopTimesStream: NodeJS.ReadableStream, validTripIds: TripIdsMap, validStopIds: StopIds) => Promise<RoutesAdjacency>;
28
+ export declare const parseStopTimes: (stopTimesStream: NodeJS.ReadableStream, stopsMap: ParsedStopsMap, validTripIds: TripIdsMap, validStopIds: Set<StopId>) => Promise<RoutesAdjacency>;
@@ -1,17 +1,16 @@
1
1
  import { Parser } from 'csv-parse';
2
2
  export type Maybe<T> = T | undefined;
3
3
  /**
4
- * Generates a simple hash from a string.
4
+ * Generates a simple hash from an array of numeric IDs.
5
5
  *
6
- * This function computes a hash for a given string by iterating over each
7
- * character and applying bitwise operations to accumulate a hash value.
8
- * The final hash is then converted to a base-36 string and padded to
9
- * ensure a minimum length of 6 characters.
6
+ * This function computes a hash for a given array of numbers by iterating over each
7
+ * ID and applying bitwise operations to accumulate a hash value.
8
+ * The final hash is then converted to a base-36 string.
10
9
  *
11
- * @param str - The input string to hash.
12
- * @returns A hashed string representation of the input.
10
+ * @param ids - The array of numeric IDs to hash.
11
+ * @returns A hashed string representation of the input array.
13
12
  */
14
- export declare const hash: (str: string) => string;
13
+ export declare const hashIds: (ids: number[]) => string;
15
14
  /**
16
15
  * Parses a CSV stream with a sensible configuration for GTFS feeds.
17
16
  *