minotor 5.0.1 → 7.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 (58) hide show
  1. package/CHANGELOG.md +8 -3
  2. package/dist/cli.mjs +282 -654
  3. package/dist/cli.mjs.map +1 -1
  4. package/dist/gtfs/parser.d.ts +4 -10
  5. package/dist/gtfs/routes.d.ts +16 -2
  6. package/dist/gtfs/stops.d.ts +3 -13
  7. package/dist/gtfs/transfers.d.ts +2 -2
  8. package/dist/gtfs/trips.d.ts +12 -8
  9. package/dist/parser.cjs.js +257 -644
  10. package/dist/parser.cjs.js.map +1 -1
  11. package/dist/parser.esm.js +257 -644
  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.esm.js +1 -1
  16. package/dist/router.esm.js.map +1 -1
  17. package/dist/router.umd.js +1 -1
  18. package/dist/router.umd.js.map +1 -1
  19. package/dist/stops/io.d.ts +3 -3
  20. package/dist/stops/proto/stops.d.ts +1 -8
  21. package/dist/stops/stops.d.ts +0 -4
  22. package/dist/stops/stopsIndex.d.ts +3 -3
  23. package/dist/timetable/io.d.ts +6 -6
  24. package/dist/timetable/proto/timetable.d.ts +5 -27
  25. package/dist/timetable/route.d.ts +2 -11
  26. package/dist/timetable/timetable.d.ts +17 -9
  27. package/package.json +1 -1
  28. package/src/__e2e__/timetable/stops.bin +2 -2
  29. package/src/__e2e__/timetable/timetable.bin +2 -2
  30. package/src/cli/minotor.ts +3 -4
  31. package/src/gtfs/__tests__/parser.test.ts +5 -6
  32. package/src/gtfs/__tests__/routes.test.ts +0 -3
  33. package/src/gtfs/__tests__/stops.test.ts +1 -124
  34. package/src/gtfs/__tests__/transfers.test.ts +7 -7
  35. package/src/gtfs/__tests__/trips.test.ts +74 -45
  36. package/src/gtfs/parser.ts +32 -49
  37. package/src/gtfs/routes.ts +43 -5
  38. package/src/gtfs/stops.ts +2 -44
  39. package/src/gtfs/transfers.ts +2 -2
  40. package/src/gtfs/trips.ts +66 -43
  41. package/src/routing/__tests__/result.test.ts +48 -48
  42. package/src/routing/__tests__/router.test.ts +279 -363
  43. package/src/routing/router.ts +22 -8
  44. package/src/stops/__tests__/io.test.ts +25 -31
  45. package/src/stops/__tests__/stopFinder.test.ts +82 -103
  46. package/src/stops/io.ts +8 -17
  47. package/src/stops/proto/stops.proto +3 -3
  48. package/src/stops/proto/stops.ts +16 -120
  49. package/src/stops/stops.ts +0 -4
  50. package/src/stops/stopsIndex.ts +37 -41
  51. package/src/timetable/__tests__/io.test.ts +44 -54
  52. package/src/timetable/__tests__/route.test.ts +10 -29
  53. package/src/timetable/__tests__/timetable.test.ts +29 -37
  54. package/src/timetable/io.ts +66 -74
  55. package/src/timetable/proto/timetable.proto +7 -14
  56. package/src/timetable/proto/timetable.ts +49 -391
  57. package/src/timetable/route.ts +2 -32
  58. package/src/timetable/timetable.ts +51 -31
@@ -11461,10 +11461,10 @@ const Stop = {
11461
11461
  writer.uint32(18).string(message.sourceStopId);
11462
11462
  }
11463
11463
  if (message.lat !== undefined) {
11464
- writer.uint32(25).double(message.lat);
11464
+ writer.uint32(29).float(message.lat);
11465
11465
  }
11466
11466
  if (message.lon !== undefined) {
11467
- writer.uint32(33).double(message.lon);
11467
+ writer.uint32(37).float(message.lon);
11468
11468
  }
11469
11469
  writer.uint32(42).fork();
11470
11470
  for (const v of message.children) {
@@ -11504,17 +11504,17 @@ const Stop = {
11504
11504
  continue;
11505
11505
  }
11506
11506
  case 3: {
11507
- if (tag !== 25) {
11507
+ if (tag !== 29) {
11508
11508
  break;
11509
11509
  }
11510
- message.lat = reader.double();
11510
+ message.lat = reader.float();
11511
11511
  continue;
11512
11512
  }
11513
11513
  case 4: {
11514
- if (tag !== 33) {
11514
+ if (tag !== 37) {
11515
11515
  break;
11516
11516
  }
11517
- message.lon = reader.double();
11517
+ message.lon = reader.float();
11518
11518
  continue;
11519
11519
  }
11520
11520
  case 5: {
@@ -11619,16 +11619,16 @@ const Stop = {
11619
11619
  },
11620
11620
  };
11621
11621
  function createBaseStopsMap() {
11622
- return { version: "", stops: {} };
11622
+ return { version: "", stops: [] };
11623
11623
  }
11624
11624
  const StopsMap = {
11625
11625
  encode(message, writer = new BinaryWriter()) {
11626
11626
  if (message.version !== "") {
11627
11627
  writer.uint32(10).string(message.version);
11628
11628
  }
11629
- Object.entries(message.stops).forEach(([key, value]) => {
11630
- StopsMap_StopsEntry.encode({ key: key, value }, writer.uint32(18).fork()).join();
11631
- });
11629
+ for (const v of message.stops) {
11630
+ Stop.encode(v, writer.uint32(18).fork()).join();
11631
+ }
11632
11632
  return writer;
11633
11633
  },
11634
11634
  decode(input, length) {
@@ -11649,10 +11649,7 @@ const StopsMap = {
11649
11649
  if (tag !== 18) {
11650
11650
  break;
11651
11651
  }
11652
- const entry2 = StopsMap_StopsEntry.decode(reader, reader.uint32());
11653
- if (entry2.value !== undefined) {
11654
- message.stops[entry2.key] = entry2.value;
11655
- }
11652
+ message.stops.push(Stop.decode(reader, reader.uint32()));
11656
11653
  continue;
11657
11654
  }
11658
11655
  }
@@ -11666,27 +11663,17 @@ const StopsMap = {
11666
11663
  fromJSON(object) {
11667
11664
  return {
11668
11665
  version: isSet$1(object.version) ? globalThis.String(object.version) : "",
11669
- stops: isObject$1(object.stops)
11670
- ? Object.entries(object.stops).reduce((acc, [key, value]) => {
11671
- acc[globalThis.Number(key)] = Stop.fromJSON(value);
11672
- return acc;
11673
- }, {})
11674
- : {},
11666
+ stops: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.stops) ? object.stops.map((e) => Stop.fromJSON(e)) : [],
11675
11667
  };
11676
11668
  },
11677
11669
  toJSON(message) {
11670
+ var _a;
11678
11671
  const obj = {};
11679
11672
  if (message.version !== "") {
11680
11673
  obj.version = message.version;
11681
11674
  }
11682
- if (message.stops) {
11683
- const entries = Object.entries(message.stops);
11684
- if (entries.length > 0) {
11685
- obj.stops = {};
11686
- entries.forEach(([k, v]) => {
11687
- obj.stops[k] = Stop.toJSON(v);
11688
- });
11689
- }
11675
+ if ((_a = message.stops) === null || _a === void 0 ? void 0 : _a.length) {
11676
+ obj.stops = message.stops.map((e) => Stop.toJSON(e));
11690
11677
  }
11691
11678
  return obj;
11692
11679
  },
@@ -11697,92 +11684,15 @@ const StopsMap = {
11697
11684
  var _a, _b;
11698
11685
  const message = createBaseStopsMap();
11699
11686
  message.version = (_a = object.version) !== null && _a !== void 0 ? _a : "";
11700
- message.stops = Object.entries((_b = object.stops) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
11701
- if (value !== undefined) {
11702
- acc[globalThis.Number(key)] = Stop.fromPartial(value);
11703
- }
11704
- return acc;
11705
- }, {});
11706
- return message;
11707
- },
11708
- };
11709
- function createBaseStopsMap_StopsEntry() {
11710
- return { key: 0, value: undefined };
11711
- }
11712
- const StopsMap_StopsEntry = {
11713
- encode(message, writer = new BinaryWriter()) {
11714
- if (message.key !== 0) {
11715
- writer.uint32(8).uint32(message.key);
11716
- }
11717
- if (message.value !== undefined) {
11718
- Stop.encode(message.value, writer.uint32(18).fork()).join();
11719
- }
11720
- return writer;
11721
- },
11722
- decode(input, length) {
11723
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
11724
- const end = length === undefined ? reader.len : reader.pos + length;
11725
- const message = createBaseStopsMap_StopsEntry();
11726
- while (reader.pos < end) {
11727
- const tag = reader.uint32();
11728
- switch (tag >>> 3) {
11729
- case 1: {
11730
- if (tag !== 8) {
11731
- break;
11732
- }
11733
- message.key = reader.uint32();
11734
- continue;
11735
- }
11736
- case 2: {
11737
- if (tag !== 18) {
11738
- break;
11739
- }
11740
- message.value = Stop.decode(reader, reader.uint32());
11741
- continue;
11742
- }
11743
- }
11744
- if ((tag & 7) === 4 || tag === 0) {
11745
- break;
11746
- }
11747
- reader.skip(tag & 7);
11748
- }
11749
- return message;
11750
- },
11751
- fromJSON(object) {
11752
- return {
11753
- key: isSet$1(object.key) ? globalThis.Number(object.key) : 0,
11754
- value: isSet$1(object.value) ? Stop.fromJSON(object.value) : undefined,
11755
- };
11756
- },
11757
- toJSON(message) {
11758
- const obj = {};
11759
- if (message.key !== 0) {
11760
- obj.key = Math.round(message.key);
11761
- }
11762
- if (message.value !== undefined) {
11763
- obj.value = Stop.toJSON(message.value);
11764
- }
11765
- return obj;
11766
- },
11767
- create(base) {
11768
- return StopsMap_StopsEntry.fromPartial(base !== null && base !== void 0 ? base : {});
11769
- },
11770
- fromPartial(object) {
11771
- var _a;
11772
- const message = createBaseStopsMap_StopsEntry();
11773
- message.key = (_a = object.key) !== null && _a !== void 0 ? _a : 0;
11774
- message.value = (object.value !== undefined && object.value !== null) ? Stop.fromPartial(object.value) : undefined;
11687
+ message.stops = ((_b = object.stops) === null || _b === void 0 ? void 0 : _b.map((e) => Stop.fromPartial(e))) || [];
11775
11688
  return message;
11776
11689
  },
11777
11690
  };
11778
- function isObject$1(value) {
11779
- return typeof value === "object" && value !== null;
11780
- }
11781
11691
  function isSet$1(value) {
11782
11692
  return value !== null && value !== undefined;
11783
11693
  }
11784
11694
 
11785
- const CURRENT_VERSION$1 = '0.0.2';
11695
+ const CURRENT_VERSION$1 = '0.0.3';
11786
11696
  const serializeStop = (stop) => {
11787
11697
  return {
11788
11698
  name: stop.name,
@@ -11795,14 +11705,11 @@ const serializeStop = (stop) => {
11795
11705
  platform: stop.platform,
11796
11706
  };
11797
11707
  };
11798
- const serializeStopsMap = (stopsMap) => {
11708
+ const serializeStopsMap = (stops) => {
11799
11709
  const protoStopsMap = {
11800
11710
  version: CURRENT_VERSION$1,
11801
- stops: {},
11711
+ stops: stops.map((value) => serializeStop(value)),
11802
11712
  };
11803
- stopsMap.forEach((value, key) => {
11804
- protoStopsMap.stops[key] = serializeStop(value);
11805
- });
11806
11713
  return protoStopsMap;
11807
11714
  };
11808
11715
  const deserializeStop = (stopId, protoStop) => {
@@ -11822,12 +11729,7 @@ const deserializeStopsMap = (protoStopsMap) => {
11822
11729
  if (protoStopsMap.version !== CURRENT_VERSION$1) {
11823
11730
  throw new Error(`Unsupported stopMap version ${protoStopsMap.version}`);
11824
11731
  }
11825
- const stopsMap = new Map();
11826
- Object.entries(protoStopsMap.stops).forEach(([key, value]) => {
11827
- const intKey = parseInt(key, 10);
11828
- stopsMap.set(intKey, deserializeStop(intKey, value));
11829
- });
11830
- return stopsMap;
11732
+ return protoStopsMap.stops.map((value, intKey) => deserializeStop(intKey, value));
11831
11733
  };
11832
11734
  const parseProtoLocationType = (protoLocationType) => {
11833
11735
  switch (protoLocationType) {
@@ -11866,45 +11768,44 @@ const serializeLocationType = (locationType) => {
11866
11768
  * to efficiently find stops based on user queries.
11867
11769
  */
11868
11770
  class StopsIndex {
11869
- constructor(stopsMap) {
11771
+ constructor(stops) {
11870
11772
  var _a;
11871
- this.stopsMap = stopsMap;
11773
+ this.stops = stops;
11872
11774
  this.sourceStopsMap = new Map();
11873
- for (const [id, stop] of stopsMap.entries()) {
11874
- this.sourceStopsMap.set(stop.sourceStopId, id);
11875
- }
11876
- this.textIndex = lt({
11877
- fields: ['name'],
11878
- storeFields: ['id'],
11879
- searchOptions: { prefix: true, fuzzy: 0.2 },
11880
- processTerm: generateAccentVariants,
11881
- });
11882
11775
  const stopsSet = new Map();
11883
- for (const [id, stop] of stopsMap.entries()) {
11776
+ this.stopPoints = [];
11777
+ for (let id = 0; id < stops.length; id++) {
11778
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11779
+ const stop = stops[id];
11780
+ this.sourceStopsMap.set(stop.sourceStopId, id);
11884
11781
  const effectiveStopId = (_a = stop.parent) !== null && _a !== void 0 ? _a : id;
11885
11782
  if (!stopsSet.has(effectiveStopId)) {
11886
11783
  stopsSet.set(effectiveStopId, {
11887
11784
  id: effectiveStopId,
11888
11785
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11889
- name: stop.parent ? this.stopsMap.get(stop.parent).name : stop.name,
11786
+ name: stop.parent ? this.stops[stop.parent].name : stop.name,
11787
+ });
11788
+ }
11789
+ if (stop.lat && stop.lon) {
11790
+ this.stopPoints.push({
11791
+ id: id,
11792
+ lat: stop.lat,
11793
+ lon: stop.lon,
11890
11794
  });
11891
11795
  }
11892
11796
  }
11797
+ this.textIndex = lt({
11798
+ fields: ['name'],
11799
+ storeFields: ['id'],
11800
+ searchOptions: { prefix: true, fuzzy: 0.2 },
11801
+ processTerm: generateAccentVariants,
11802
+ });
11893
11803
  const stopsArray = Array.from(stopsSet.values());
11894
11804
  q(this.textIndex, stopsArray);
11895
- this.stopPoints = Array.from(this.stopsMap.entries())
11896
- .filter(([, stop]) => {
11897
- if (stop.lat && stop.lon)
11898
- return true;
11899
- return false;
11900
- })
11901
- .map(([id, stop]) => ({
11902
- id: id,
11903
- lat: stop.lat,
11904
- lon: stop.lon,
11905
- }));
11906
11805
  this.geoIndex = new KDBush(this.stopPoints.length);
11907
- for (const { lat, lon } of this.stopPoints) {
11806
+ for (let i = 0; i < this.stopPoints.length; i++) {
11807
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11808
+ const { lat, lon } = this.stopPoints[i];
11908
11809
  this.geoIndex.add(lon, lat);
11909
11810
  }
11910
11811
  this.geoIndex.finish();
@@ -11926,7 +11827,7 @@ class StopsIndex {
11926
11827
  * @returns The serialized binary data.
11927
11828
  */
11928
11829
  serialize() {
11929
- const protoStopsMap = serializeStopsMap(this.stopsMap);
11830
+ const protoStopsMap = serializeStopsMap(this.stops);
11930
11831
  const writer = new BinaryWriter();
11931
11832
  StopsMap.encode(protoStopsMap, writer);
11932
11833
  return writer.finish();
@@ -11937,7 +11838,7 @@ class StopsIndex {
11937
11838
  * @returns The total number of stops.
11938
11839
  */
11939
11840
  size() {
11940
- return this.stopsMap.size;
11841
+ return this.stops.length;
11941
11842
  }
11942
11843
  /**
11943
11844
  * Finds stops by their name using a text search.
@@ -11947,7 +11848,7 @@ class StopsIndex {
11947
11848
  * @returns An array of Stop objects that match the search query.
11948
11849
  */
11949
11850
  findStopsByName(query, maxResults = 5) {
11950
- const results = dt(this.textIndex, query).map((result) => this.stopsMap.get(result.id));
11851
+ const results = dt(this.textIndex, query).map((result) => this.stops[result.id]);
11951
11852
  return results.slice(0, maxResults);
11952
11853
  }
11953
11854
  /**
@@ -11962,7 +11863,7 @@ class StopsIndex {
11962
11863
  findStopsByLocation(lat, lon, maxResults = 5, radius = 0.5) {
11963
11864
  const nearestStops = around(this.geoIndex, lon, lat, maxResults, radius).map((id) => {
11964
11865
  const stopPoint = this.stopPoints[id];
11965
- return this.stopsMap.get(stopPoint.id);
11866
+ return this.stops[stopPoint.id];
11966
11867
  });
11967
11868
  return nearestStops;
11968
11869
  }
@@ -11973,7 +11874,7 @@ class StopsIndex {
11973
11874
  * @returns The Stop object that matches the specified ID, or undefined if not found.
11974
11875
  */
11975
11876
  findStopById(id) {
11976
- return this.stopsMap.get(id);
11877
+ return this.stops[id];
11977
11878
  }
11978
11879
  /**
11979
11880
  * Finds a stop by its ID in the transit data source (e.g. GTFS).
@@ -11997,14 +11898,14 @@ class StopsIndex {
11997
11898
  if (id === undefined) {
11998
11899
  return [];
11999
11900
  }
12000
- const stop = this.stopsMap.get(id);
11901
+ const stop = this.stops[id];
12001
11902
  if (!stop) {
12002
11903
  return [];
12003
11904
  }
12004
11905
  const equivalentStops = stop.parent
12005
- ? ((_b = (_a = this.stopsMap.get(stop.parent)) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : [])
11906
+ ? ((_b = (_a = this.stops[stop.parent]) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : [])
12006
11907
  : stop.children;
12007
- return Array.from(new Set([id, ...equivalentStops])).map((stopId) => this.stopsMap.get(stopId));
11908
+ return Array.from(new Set([id, ...equivalentStops])).map((stopId) => this.stops[stopId]);
12008
11909
  }
12009
11910
  }
12010
11911
 
@@ -12222,7 +12123,7 @@ function createBaseRoute() {
12222
12123
  stopTimes: new Uint8Array(0),
12223
12124
  pickUpDropOffTypes: new Uint8Array(0),
12224
12125
  stops: new Uint8Array(0),
12225
- serviceRouteId: "",
12126
+ serviceRouteId: 0,
12226
12127
  };
12227
12128
  }
12228
12129
  const Route$1 = {
@@ -12236,8 +12137,8 @@ const Route$1 = {
12236
12137
  if (message.stops.length !== 0) {
12237
12138
  writer.uint32(26).bytes(message.stops);
12238
12139
  }
12239
- if (message.serviceRouteId !== "") {
12240
- writer.uint32(34).string(message.serviceRouteId);
12140
+ if (message.serviceRouteId !== 0) {
12141
+ writer.uint32(32).uint32(message.serviceRouteId);
12241
12142
  }
12242
12143
  return writer;
12243
12144
  },
@@ -12270,10 +12171,10 @@ const Route$1 = {
12270
12171
  continue;
12271
12172
  }
12272
12173
  case 4: {
12273
- if (tag !== 34) {
12174
+ if (tag !== 32) {
12274
12175
  break;
12275
12176
  }
12276
- message.serviceRouteId = reader.string();
12177
+ message.serviceRouteId = reader.uint32();
12277
12178
  continue;
12278
12179
  }
12279
12180
  }
@@ -12291,7 +12192,7 @@ const Route$1 = {
12291
12192
  ? bytesFromBase64(object.pickUpDropOffTypes)
12292
12193
  : new Uint8Array(0),
12293
12194
  stops: isSet(object.stops) ? bytesFromBase64(object.stops) : new Uint8Array(0),
12294
- serviceRouteId: isSet(object.serviceRouteId) ? globalThis.String(object.serviceRouteId) : "",
12195
+ serviceRouteId: isSet(object.serviceRouteId) ? globalThis.Number(object.serviceRouteId) : 0,
12295
12196
  };
12296
12197
  },
12297
12198
  toJSON(message) {
@@ -12305,8 +12206,8 @@ const Route$1 = {
12305
12206
  if (message.stops.length !== 0) {
12306
12207
  obj.stops = base64FromBytes(message.stops);
12307
12208
  }
12308
- if (message.serviceRouteId !== "") {
12309
- obj.serviceRouteId = message.serviceRouteId;
12209
+ if (message.serviceRouteId !== 0) {
12210
+ obj.serviceRouteId = Math.round(message.serviceRouteId);
12310
12211
  }
12311
12212
  return obj;
12312
12213
  },
@@ -12319,7 +12220,7 @@ const Route$1 = {
12319
12220
  message.stopTimes = (_a = object.stopTimes) !== null && _a !== void 0 ? _a : new Uint8Array(0);
12320
12221
  message.pickUpDropOffTypes = (_b = object.pickUpDropOffTypes) !== null && _b !== void 0 ? _b : new Uint8Array(0);
12321
12222
  message.stops = (_c = object.stops) !== null && _c !== void 0 ? _c : new Uint8Array(0);
12322
- message.serviceRouteId = (_d = object.serviceRouteId) !== null && _d !== void 0 ? _d : "";
12223
+ message.serviceRouteId = (_d = object.serviceRouteId) !== null && _d !== void 0 ? _d : 0;
12323
12224
  return message;
12324
12225
  },
12325
12226
  };
@@ -12407,90 +12308,17 @@ const Transfer = {
12407
12308
  return message;
12408
12309
  },
12409
12310
  };
12410
- function createBaseStopsAdjacency() {
12411
- return { stops: {} };
12412
- }
12413
- const StopsAdjacency = {
12414
- encode(message, writer = new BinaryWriter()) {
12415
- Object.entries(message.stops).forEach(([key, value]) => {
12416
- StopsAdjacency_StopsEntry.encode({ key: key, value }, writer.uint32(10).fork()).join();
12417
- });
12418
- return writer;
12419
- },
12420
- decode(input, length) {
12421
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12422
- const end = length === undefined ? reader.len : reader.pos + length;
12423
- const message = createBaseStopsAdjacency();
12424
- while (reader.pos < end) {
12425
- const tag = reader.uint32();
12426
- switch (tag >>> 3) {
12427
- case 1: {
12428
- if (tag !== 10) {
12429
- break;
12430
- }
12431
- const entry1 = StopsAdjacency_StopsEntry.decode(reader, reader.uint32());
12432
- if (entry1.value !== undefined) {
12433
- message.stops[entry1.key] = entry1.value;
12434
- }
12435
- continue;
12436
- }
12437
- }
12438
- if ((tag & 7) === 4 || tag === 0) {
12439
- break;
12440
- }
12441
- reader.skip(tag & 7);
12442
- }
12443
- return message;
12444
- },
12445
- fromJSON(object) {
12446
- return {
12447
- stops: isObject(object.stops)
12448
- ? Object.entries(object.stops).reduce((acc, [key, value]) => {
12449
- acc[globalThis.Number(key)] = StopsAdjacency_StopAdjacency.fromJSON(value);
12450
- return acc;
12451
- }, {})
12452
- : {},
12453
- };
12454
- },
12455
- toJSON(message) {
12456
- const obj = {};
12457
- if (message.stops) {
12458
- const entries = Object.entries(message.stops);
12459
- if (entries.length > 0) {
12460
- obj.stops = {};
12461
- entries.forEach(([k, v]) => {
12462
- obj.stops[k] = StopsAdjacency_StopAdjacency.toJSON(v);
12463
- });
12464
- }
12465
- }
12466
- return obj;
12467
- },
12468
- create(base) {
12469
- return StopsAdjacency.fromPartial(base !== null && base !== void 0 ? base : {});
12470
- },
12471
- fromPartial(object) {
12472
- var _a;
12473
- const message = createBaseStopsAdjacency();
12474
- message.stops = Object.entries((_a = object.stops) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
12475
- if (value !== undefined) {
12476
- acc[globalThis.Number(key)] = StopsAdjacency_StopAdjacency.fromPartial(value);
12477
- }
12478
- return acc;
12479
- }, {});
12480
- return message;
12481
- },
12482
- };
12483
- function createBaseStopsAdjacency_StopAdjacency() {
12311
+ function createBaseStopAdjacency() {
12484
12312
  return { transfers: [], routes: [] };
12485
12313
  }
12486
- const StopsAdjacency_StopAdjacency = {
12314
+ const StopAdjacency = {
12487
12315
  encode(message, writer = new BinaryWriter()) {
12488
12316
  for (const v of message.transfers) {
12489
12317
  Transfer.encode(v, writer.uint32(10).fork()).join();
12490
12318
  }
12491
12319
  writer.uint32(18).fork();
12492
12320
  for (const v of message.routes) {
12493
- writer.int32(v);
12321
+ writer.uint32(v);
12494
12322
  }
12495
12323
  writer.join();
12496
12324
  return writer;
@@ -12498,7 +12326,7 @@ const StopsAdjacency_StopAdjacency = {
12498
12326
  decode(input, length) {
12499
12327
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12500
12328
  const end = length === undefined ? reader.len : reader.pos + length;
12501
- const message = createBaseStopsAdjacency_StopAdjacency();
12329
+ const message = createBaseStopAdjacency();
12502
12330
  while (reader.pos < end) {
12503
12331
  const tag = reader.uint32();
12504
12332
  switch (tag >>> 3) {
@@ -12511,13 +12339,13 @@ const StopsAdjacency_StopAdjacency = {
12511
12339
  }
12512
12340
  case 2: {
12513
12341
  if (tag === 16) {
12514
- message.routes.push(reader.int32());
12342
+ message.routes.push(reader.uint32());
12515
12343
  continue;
12516
12344
  }
12517
12345
  if (tag === 18) {
12518
12346
  const end2 = reader.uint32() + reader.pos;
12519
12347
  while (reader.pos < end2) {
12520
- message.routes.push(reader.int32());
12348
+ message.routes.push(reader.uint32());
12521
12349
  }
12522
12350
  continue;
12523
12351
  }
@@ -12551,87 +12379,16 @@ const StopsAdjacency_StopAdjacency = {
12551
12379
  return obj;
12552
12380
  },
12553
12381
  create(base) {
12554
- return StopsAdjacency_StopAdjacency.fromPartial(base !== null && base !== void 0 ? base : {});
12382
+ return StopAdjacency.fromPartial(base !== null && base !== void 0 ? base : {});
12555
12383
  },
12556
12384
  fromPartial(object) {
12557
12385
  var _a, _b;
12558
- const message = createBaseStopsAdjacency_StopAdjacency();
12386
+ const message = createBaseStopAdjacency();
12559
12387
  message.transfers = ((_a = object.transfers) === null || _a === void 0 ? void 0 : _a.map((e) => Transfer.fromPartial(e))) || [];
12560
12388
  message.routes = ((_b = object.routes) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
12561
12389
  return message;
12562
12390
  },
12563
12391
  };
12564
- function createBaseStopsAdjacency_StopsEntry() {
12565
- return { key: 0, value: undefined };
12566
- }
12567
- const StopsAdjacency_StopsEntry = {
12568
- encode(message, writer = new BinaryWriter()) {
12569
- if (message.key !== 0) {
12570
- writer.uint32(8).uint32(message.key);
12571
- }
12572
- if (message.value !== undefined) {
12573
- StopsAdjacency_StopAdjacency.encode(message.value, writer.uint32(18).fork()).join();
12574
- }
12575
- return writer;
12576
- },
12577
- decode(input, length) {
12578
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12579
- const end = length === undefined ? reader.len : reader.pos + length;
12580
- const message = createBaseStopsAdjacency_StopsEntry();
12581
- while (reader.pos < end) {
12582
- const tag = reader.uint32();
12583
- switch (tag >>> 3) {
12584
- case 1: {
12585
- if (tag !== 8) {
12586
- break;
12587
- }
12588
- message.key = reader.uint32();
12589
- continue;
12590
- }
12591
- case 2: {
12592
- if (tag !== 18) {
12593
- break;
12594
- }
12595
- message.value = StopsAdjacency_StopAdjacency.decode(reader, reader.uint32());
12596
- continue;
12597
- }
12598
- }
12599
- if ((tag & 7) === 4 || tag === 0) {
12600
- break;
12601
- }
12602
- reader.skip(tag & 7);
12603
- }
12604
- return message;
12605
- },
12606
- fromJSON(object) {
12607
- return {
12608
- key: isSet(object.key) ? globalThis.Number(object.key) : 0,
12609
- value: isSet(object.value) ? StopsAdjacency_StopAdjacency.fromJSON(object.value) : undefined,
12610
- };
12611
- },
12612
- toJSON(message) {
12613
- const obj = {};
12614
- if (message.key !== 0) {
12615
- obj.key = Math.round(message.key);
12616
- }
12617
- if (message.value !== undefined) {
12618
- obj.value = StopsAdjacency_StopAdjacency.toJSON(message.value);
12619
- }
12620
- return obj;
12621
- },
12622
- create(base) {
12623
- return StopsAdjacency_StopsEntry.fromPartial(base !== null && base !== void 0 ? base : {});
12624
- },
12625
- fromPartial(object) {
12626
- var _a;
12627
- const message = createBaseStopsAdjacency_StopsEntry();
12628
- message.key = (_a = object.key) !== null && _a !== void 0 ? _a : 0;
12629
- message.value = (object.value !== undefined && object.value !== null)
12630
- ? StopsAdjacency_StopAdjacency.fromPartial(object.value)
12631
- : undefined;
12632
- return message;
12633
- },
12634
- };
12635
12392
  function createBaseServiceRoute() {
12636
12393
  return { type: 0, name: "", routes: [] };
12637
12394
  }
@@ -12645,7 +12402,7 @@ const ServiceRoute = {
12645
12402
  }
12646
12403
  writer.uint32(26).fork();
12647
12404
  for (const v of message.routes) {
12648
- writer.int32(v);
12405
+ writer.uint32(v);
12649
12406
  }
12650
12407
  writer.join();
12651
12408
  return writer;
@@ -12673,13 +12430,13 @@ const ServiceRoute = {
12673
12430
  }
12674
12431
  case 3: {
12675
12432
  if (tag === 24) {
12676
- message.routes.push(reader.int32());
12433
+ message.routes.push(reader.uint32());
12677
12434
  continue;
12678
12435
  }
12679
12436
  if (tag === 26) {
12680
12437
  const end2 = reader.uint32() + reader.pos;
12681
12438
  while (reader.pos < end2) {
12682
- message.routes.push(reader.int32());
12439
+ message.routes.push(reader.uint32());
12683
12440
  }
12684
12441
  continue;
12685
12442
  }
@@ -12726,166 +12483,22 @@ const ServiceRoute = {
12726
12483
  return message;
12727
12484
  },
12728
12485
  };
12729
- function createBaseServiceRoutesMap() {
12730
- return { routes: {} };
12731
- }
12732
- const ServiceRoutesMap = {
12733
- encode(message, writer = new BinaryWriter()) {
12734
- Object.entries(message.routes).forEach(([key, value]) => {
12735
- ServiceRoutesMap_RoutesEntry.encode({ key: key, value }, writer.uint32(10).fork()).join();
12736
- });
12737
- return writer;
12738
- },
12739
- decode(input, length) {
12740
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12741
- const end = length === undefined ? reader.len : reader.pos + length;
12742
- const message = createBaseServiceRoutesMap();
12743
- while (reader.pos < end) {
12744
- const tag = reader.uint32();
12745
- switch (tag >>> 3) {
12746
- case 1: {
12747
- if (tag !== 10) {
12748
- break;
12749
- }
12750
- const entry1 = ServiceRoutesMap_RoutesEntry.decode(reader, reader.uint32());
12751
- if (entry1.value !== undefined) {
12752
- message.routes[entry1.key] = entry1.value;
12753
- }
12754
- continue;
12755
- }
12756
- }
12757
- if ((tag & 7) === 4 || tag === 0) {
12758
- break;
12759
- }
12760
- reader.skip(tag & 7);
12761
- }
12762
- return message;
12763
- },
12764
- fromJSON(object) {
12765
- return {
12766
- routes: isObject(object.routes)
12767
- ? Object.entries(object.routes).reduce((acc, [key, value]) => {
12768
- acc[key] = ServiceRoute.fromJSON(value);
12769
- return acc;
12770
- }, {})
12771
- : {},
12772
- };
12773
- },
12774
- toJSON(message) {
12775
- const obj = {};
12776
- if (message.routes) {
12777
- const entries = Object.entries(message.routes);
12778
- if (entries.length > 0) {
12779
- obj.routes = {};
12780
- entries.forEach(([k, v]) => {
12781
- obj.routes[k] = ServiceRoute.toJSON(v);
12782
- });
12783
- }
12784
- }
12785
- return obj;
12786
- },
12787
- create(base) {
12788
- return ServiceRoutesMap.fromPartial(base !== null && base !== void 0 ? base : {});
12789
- },
12790
- fromPartial(object) {
12791
- var _a;
12792
- const message = createBaseServiceRoutesMap();
12793
- message.routes = Object.entries((_a = object.routes) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
12794
- if (value !== undefined) {
12795
- acc[key] = ServiceRoute.fromPartial(value);
12796
- }
12797
- return acc;
12798
- }, {});
12799
- return message;
12800
- },
12801
- };
12802
- function createBaseServiceRoutesMap_RoutesEntry() {
12803
- return { key: "", value: undefined };
12804
- }
12805
- const ServiceRoutesMap_RoutesEntry = {
12806
- encode(message, writer = new BinaryWriter()) {
12807
- if (message.key !== "") {
12808
- writer.uint32(10).string(message.key);
12809
- }
12810
- if (message.value !== undefined) {
12811
- ServiceRoute.encode(message.value, writer.uint32(18).fork()).join();
12812
- }
12813
- return writer;
12814
- },
12815
- decode(input, length) {
12816
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12817
- const end = length === undefined ? reader.len : reader.pos + length;
12818
- const message = createBaseServiceRoutesMap_RoutesEntry();
12819
- while (reader.pos < end) {
12820
- const tag = reader.uint32();
12821
- switch (tag >>> 3) {
12822
- case 1: {
12823
- if (tag !== 10) {
12824
- break;
12825
- }
12826
- message.key = reader.string();
12827
- continue;
12828
- }
12829
- case 2: {
12830
- if (tag !== 18) {
12831
- break;
12832
- }
12833
- message.value = ServiceRoute.decode(reader, reader.uint32());
12834
- continue;
12835
- }
12836
- }
12837
- if ((tag & 7) === 4 || tag === 0) {
12838
- break;
12839
- }
12840
- reader.skip(tag & 7);
12841
- }
12842
- return message;
12843
- },
12844
- fromJSON(object) {
12845
- return {
12846
- key: isSet(object.key) ? globalThis.String(object.key) : "",
12847
- value: isSet(object.value) ? ServiceRoute.fromJSON(object.value) : undefined,
12848
- };
12849
- },
12850
- toJSON(message) {
12851
- const obj = {};
12852
- if (message.key !== "") {
12853
- obj.key = message.key;
12854
- }
12855
- if (message.value !== undefined) {
12856
- obj.value = ServiceRoute.toJSON(message.value);
12857
- }
12858
- return obj;
12859
- },
12860
- create(base) {
12861
- return ServiceRoutesMap_RoutesEntry.fromPartial(base !== null && base !== void 0 ? base : {});
12862
- },
12863
- fromPartial(object) {
12864
- var _a;
12865
- const message = createBaseServiceRoutesMap_RoutesEntry();
12866
- message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
12867
- message.value = (object.value !== undefined && object.value !== null)
12868
- ? ServiceRoute.fromPartial(object.value)
12869
- : undefined;
12870
- return message;
12871
- },
12872
- };
12873
12486
  function createBaseTimetable() {
12874
- return { version: "", stopsAdjacency: undefined, routesAdjacency: [], routes: undefined };
12487
+ return { version: "", stopsAdjacency: [], routesAdjacency: [], serviceRoutes: [] };
12875
12488
  }
12876
12489
  const Timetable$1 = {
12877
12490
  encode(message, writer = new BinaryWriter()) {
12878
12491
  if (message.version !== "") {
12879
12492
  writer.uint32(10).string(message.version);
12880
12493
  }
12881
- if (message.stopsAdjacency !== undefined) {
12882
- StopsAdjacency.encode(message.stopsAdjacency, writer.uint32(18).fork()).join();
12494
+ for (const v of message.stopsAdjacency) {
12495
+ StopAdjacency.encode(v, writer.uint32(18).fork()).join();
12883
12496
  }
12884
12497
  for (const v of message.routesAdjacency) {
12885
12498
  Route$1.encode(v, writer.uint32(26).fork()).join();
12886
12499
  }
12887
- if (message.routes !== undefined) {
12888
- ServiceRoutesMap.encode(message.routes, writer.uint32(34).fork()).join();
12500
+ for (const v of message.serviceRoutes) {
12501
+ ServiceRoute.encode(v, writer.uint32(34).fork()).join();
12889
12502
  }
12890
12503
  return writer;
12891
12504
  },
@@ -12907,7 +12520,7 @@ const Timetable$1 = {
12907
12520
  if (tag !== 18) {
12908
12521
  break;
12909
12522
  }
12910
- message.stopsAdjacency = StopsAdjacency.decode(reader, reader.uint32());
12523
+ message.stopsAdjacency.push(StopAdjacency.decode(reader, reader.uint32()));
12911
12524
  continue;
12912
12525
  }
12913
12526
  case 3: {
@@ -12921,7 +12534,7 @@ const Timetable$1 = {
12921
12534
  if (tag !== 34) {
12922
12535
  break;
12923
12536
  }
12924
- message.routes = ServiceRoutesMap.decode(reader, reader.uint32());
12537
+ message.serviceRoutes.push(ServiceRoute.decode(reader, reader.uint32()));
12925
12538
  continue;
12926
12539
  }
12927
12540
  }
@@ -12935,27 +12548,31 @@ const Timetable$1 = {
12935
12548
  fromJSON(object) {
12936
12549
  return {
12937
12550
  version: isSet(object.version) ? globalThis.String(object.version) : "",
12938
- stopsAdjacency: isSet(object.stopsAdjacency) ? StopsAdjacency.fromJSON(object.stopsAdjacency) : undefined,
12551
+ stopsAdjacency: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.stopsAdjacency)
12552
+ ? object.stopsAdjacency.map((e) => StopAdjacency.fromJSON(e))
12553
+ : [],
12939
12554
  routesAdjacency: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.routesAdjacency)
12940
12555
  ? object.routesAdjacency.map((e) => Route$1.fromJSON(e))
12941
12556
  : [],
12942
- routes: isSet(object.routes) ? ServiceRoutesMap.fromJSON(object.routes) : undefined,
12557
+ serviceRoutes: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.serviceRoutes)
12558
+ ? object.serviceRoutes.map((e) => ServiceRoute.fromJSON(e))
12559
+ : [],
12943
12560
  };
12944
12561
  },
12945
12562
  toJSON(message) {
12946
- var _a;
12563
+ var _a, _b, _c;
12947
12564
  const obj = {};
12948
12565
  if (message.version !== "") {
12949
12566
  obj.version = message.version;
12950
12567
  }
12951
- if (message.stopsAdjacency !== undefined) {
12952
- obj.stopsAdjacency = StopsAdjacency.toJSON(message.stopsAdjacency);
12568
+ if ((_a = message.stopsAdjacency) === null || _a === void 0 ? void 0 : _a.length) {
12569
+ obj.stopsAdjacency = message.stopsAdjacency.map((e) => StopAdjacency.toJSON(e));
12953
12570
  }
12954
- if ((_a = message.routesAdjacency) === null || _a === void 0 ? void 0 : _a.length) {
12571
+ if ((_b = message.routesAdjacency) === null || _b === void 0 ? void 0 : _b.length) {
12955
12572
  obj.routesAdjacency = message.routesAdjacency.map((e) => Route$1.toJSON(e));
12956
12573
  }
12957
- if (message.routes !== undefined) {
12958
- obj.routes = ServiceRoutesMap.toJSON(message.routes);
12574
+ if ((_c = message.serviceRoutes) === null || _c === void 0 ? void 0 : _c.length) {
12575
+ obj.serviceRoutes = message.serviceRoutes.map((e) => ServiceRoute.toJSON(e));
12959
12576
  }
12960
12577
  return obj;
12961
12578
  },
@@ -12963,16 +12580,12 @@ const Timetable$1 = {
12963
12580
  return Timetable$1.fromPartial(base !== null && base !== void 0 ? base : {});
12964
12581
  },
12965
12582
  fromPartial(object) {
12966
- var _a, _b;
12583
+ var _a, _b, _c, _d;
12967
12584
  const message = createBaseTimetable();
12968
12585
  message.version = (_a = object.version) !== null && _a !== void 0 ? _a : "";
12969
- message.stopsAdjacency = (object.stopsAdjacency !== undefined && object.stopsAdjacency !== null)
12970
- ? StopsAdjacency.fromPartial(object.stopsAdjacency)
12971
- : undefined;
12972
- message.routesAdjacency = ((_b = object.routesAdjacency) === null || _b === void 0 ? void 0 : _b.map((e) => Route$1.fromPartial(e))) || [];
12973
- message.routes = (object.routes !== undefined && object.routes !== null)
12974
- ? ServiceRoutesMap.fromPartial(object.routes)
12975
- : undefined;
12586
+ message.stopsAdjacency = ((_b = object.stopsAdjacency) === null || _b === void 0 ? void 0 : _b.map((e) => StopAdjacency.fromPartial(e))) || [];
12587
+ message.routesAdjacency = ((_c = object.routesAdjacency) === null || _c === void 0 ? void 0 : _c.map((e) => Route$1.fromPartial(e))) || [];
12588
+ message.serviceRoutes = ((_d = object.serviceRoutes) === null || _d === void 0 ? void 0 : _d.map((e) => ServiceRoute.fromPartial(e))) || [];
12976
12589
  return message;
12977
12590
  },
12978
12591
  };
@@ -13001,9 +12614,6 @@ function base64FromBytes(arr) {
13001
12614
  return globalThis.btoa(bin.join(""));
13002
12615
  }
13003
12616
  }
13004
- function isObject(value) {
13005
- return typeof value === "object" && value !== null;
13006
- }
13007
12617
  function isSet(value) {
13008
12618
  return value !== null && value !== undefined;
13009
12619
  }
@@ -13381,27 +12991,6 @@ class Route {
13381
12991
  : byte & 0x03; // Lower 2 bits for first pair
13382
12992
  return toPickupDropOffType(dropOffValue);
13383
12993
  }
13384
- /**
13385
- * Iterates over the stops in the route, starting from an optional specified stop.
13386
- * If no start stop is provided, the iteration begins from the first stop in the route.
13387
- *
13388
- * @param [startStopId] - (Optional) The StopId of the stop to start the iteration from.
13389
- * @returns An IterableIterator of StopIds, starting from the specified stop or the first stop.
13390
- * @throws An error if the specified start stop is not found in the route.
13391
- */
13392
- stopsIterator(startStopId) {
13393
- const startIndex = startStopId !== undefined ? this.stopIndices.get(startStopId) : 0;
13394
- if (startIndex === undefined) {
13395
- throw new Error(`Start stop ${startStopId} not found in route ${this.serviceRouteId}`);
13396
- }
13397
- function* generator(stops, startIndex) {
13398
- for (let i = startIndex; i < stops.length; i++) {
13399
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13400
- yield stops[i];
13401
- }
13402
- }
13403
- return generator(this.stops, startIndex);
13404
- }
13405
12994
  /**
13406
12995
  * Finds the earliest trip that can be taken from a specific stop on a given route,
13407
12996
  * optionally constrained by a latest trip index and a time before which the trip
@@ -13519,18 +13108,14 @@ const bytesToUint16Array = (bytes) => {
13519
13108
  return result;
13520
13109
  };
13521
13110
  const serializeStopsAdjacency = (stopsAdjacency) => {
13522
- const protoStopsAdjacency = {
13523
- stops: {},
13524
- };
13525
- stopsAdjacency.forEach((value, key) => {
13526
- protoStopsAdjacency.stops[key] = {
13111
+ return stopsAdjacency.map((value) => {
13112
+ return {
13527
13113
  transfers: value.transfers.map((transfer) => (Object.assign({ destination: transfer.destination, type: serializeTransferType(transfer.type) }, (transfer.minTransferTime !== undefined && {
13528
13114
  minTransferTime: transfer.minTransferTime.toSeconds(),
13529
13115
  })))),
13530
13116
  routes: value.routes,
13531
13117
  };
13532
13118
  });
13533
- return protoStopsAdjacency;
13534
13119
  };
13535
13120
  const serializeRoutesAdjacency = (routesAdjacency) => {
13536
13121
  const protoRoutesAdjacency = [];
@@ -13545,50 +13130,58 @@ const serializeRoutesAdjacency = (routesAdjacency) => {
13545
13130
  });
13546
13131
  return protoRoutesAdjacency;
13547
13132
  };
13548
- const serializeServiceRoutesMap = (serviceRoutesMap) => {
13549
- const protoServiceRoutesMap = {
13550
- routes: {},
13551
- };
13552
- serviceRoutesMap.forEach((value, key) => {
13553
- protoServiceRoutesMap.routes[key] = {
13133
+ const serializeServiceRoutesMap = (serviceRoutes) => {
13134
+ return serviceRoutes.map((value) => {
13135
+ return {
13554
13136
  type: serializeRouteType(value.type),
13555
13137
  name: value.name,
13556
13138
  routes: value.routes,
13557
13139
  };
13558
13140
  });
13559
- return protoServiceRoutesMap;
13560
13141
  };
13561
13142
  const deserializeStopsAdjacency = (protoStopsAdjacency) => {
13562
- const stopsAdjacency = new Map();
13563
- Object.entries(protoStopsAdjacency.stops).forEach(([keyStr, value]) => {
13564
- const key = parseInt(keyStr, 10);
13565
- stopsAdjacency.set(key, {
13566
- transfers: value.transfers.map((transfer) => (Object.assign({ destination: transfer.destination, type: parseTransferType(transfer.type) }, (transfer.minTransferTime !== undefined && {
13143
+ const result = [];
13144
+ for (let i = 0; i < protoStopsAdjacency.length; i++) {
13145
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13146
+ const value = protoStopsAdjacency[i];
13147
+ const transfers = [];
13148
+ for (let j = 0; j < value.transfers.length; j++) {
13149
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13150
+ const transfer = value.transfers[j];
13151
+ const newTransfer = Object.assign({ destination: transfer.destination, type: parseTransferType(transfer.type) }, (transfer.minTransferTime !== undefined && {
13567
13152
  minTransferTime: Duration.fromSeconds(transfer.minTransferTime),
13568
- })))),
13153
+ }));
13154
+ transfers.push(newTransfer);
13155
+ }
13156
+ result.push({
13157
+ transfers: transfers,
13569
13158
  routes: value.routes,
13570
13159
  });
13571
- });
13572
- return stopsAdjacency;
13160
+ }
13161
+ return result;
13573
13162
  };
13574
13163
  const deserializeRoutesAdjacency = (protoRoutesAdjacency) => {
13575
13164
  const routesAdjacency = [];
13576
- protoRoutesAdjacency.forEach((value) => {
13165
+ for (let i = 0; i < protoRoutesAdjacency.length; i++) {
13166
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13167
+ const value = protoRoutesAdjacency[i];
13577
13168
  const stops = bytesToUint32Array(value.stops);
13578
13169
  routesAdjacency.push(new Route(bytesToUint16Array(value.stopTimes), value.pickUpDropOffTypes, stops, value.serviceRouteId));
13579
- });
13170
+ }
13580
13171
  return routesAdjacency;
13581
13172
  };
13582
- const deserializeServiceRoutesMap = (protoServiceRoutesMap) => {
13583
- const serviceRoutesMap = new Map();
13584
- Object.entries(protoServiceRoutesMap.routes).forEach(([key, value]) => {
13585
- serviceRoutesMap.set(key, {
13173
+ const deserializeServiceRoutesMap = (protoServiceRoutes) => {
13174
+ const result = [];
13175
+ for (let i = 0; i < protoServiceRoutes.length; i++) {
13176
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13177
+ const value = protoServiceRoutes[i];
13178
+ result.push({
13586
13179
  type: parseRouteType(value.type),
13587
13180
  name: value.name,
13588
13181
  routes: value.routes,
13589
13182
  });
13590
- });
13591
- return serviceRoutesMap;
13183
+ }
13184
+ return result;
13592
13185
  };
13593
13186
  const parseTransferType = (type) => {
13594
13187
  switch (type) {
@@ -13680,7 +13273,7 @@ const ALL_TRANSPORT_MODES = new Set([
13680
13273
  'TROLLEYBUS',
13681
13274
  'MONORAIL',
13682
13275
  ]);
13683
- const CURRENT_VERSION = '0.0.5';
13276
+ const CURRENT_VERSION = '0.0.7';
13684
13277
  /**
13685
13278
  * The internal transit timetable format.
13686
13279
  */
@@ -13688,7 +13281,15 @@ class Timetable {
13688
13281
  constructor(stopsAdjacency, routesAdjacency, routes) {
13689
13282
  this.stopsAdjacency = stopsAdjacency;
13690
13283
  this.routesAdjacency = routesAdjacency;
13691
- this.routes = routes;
13284
+ this.serviceRoutes = routes;
13285
+ this.activeStops = new Set();
13286
+ for (let i = 0; i < stopsAdjacency.length; i++) {
13287
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13288
+ const stop = stopsAdjacency[i];
13289
+ if (stop.routes.length > 0 || stop.transfers.length > 0) {
13290
+ this.activeStops.add(i);
13291
+ }
13292
+ }
13692
13293
  }
13693
13294
  /**
13694
13295
  * Serializes the Timetable into a binary array.
@@ -13700,7 +13301,7 @@ class Timetable {
13700
13301
  version: CURRENT_VERSION,
13701
13302
  stopsAdjacency: serializeStopsAdjacency(this.stopsAdjacency),
13702
13303
  routesAdjacency: serializeRoutesAdjacency(this.routesAdjacency),
13703
- routes: serializeServiceRoutesMap(this.routes),
13304
+ serviceRoutes: serializeServiceRoutesMap(this.serviceRoutes),
13704
13305
  };
13705
13306
  const writer = new BinaryWriter();
13706
13307
  Timetable$1.encode(protoTimetable, writer);
@@ -13718,11 +13319,18 @@ class Timetable {
13718
13319
  if (protoTimetable.version !== CURRENT_VERSION) {
13719
13320
  throw new Error(`Unsupported timetable version ${protoTimetable.version}`);
13720
13321
  }
13721
- return new Timetable(
13722
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13723
- deserializeStopsAdjacency(protoTimetable.stopsAdjacency), deserializeRoutesAdjacency(protoTimetable.routesAdjacency),
13724
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13725
- deserializeServiceRoutesMap(protoTimetable.routes));
13322
+ return new Timetable(deserializeStopsAdjacency(protoTimetable.stopsAdjacency), deserializeRoutesAdjacency(protoTimetable.routesAdjacency), deserializeServiceRoutesMap(protoTimetable.serviceRoutes));
13323
+ }
13324
+ /**
13325
+ * Checks if the given stop is active on the timetable.
13326
+ * An active stop is a stop reached by a route that is active on the timetable
13327
+ * or by a transfer reachable from an active route.
13328
+ *
13329
+ * @param stopId - The ID of the stop to check.
13330
+ * @returns True if the stop is active, false otherwise.
13331
+ */
13332
+ isActive(stopId) {
13333
+ return this.activeStops.has(stopId);
13726
13334
  }
13727
13335
  /**
13728
13336
  * Retrieves the route associated with the given route ID.
@@ -13742,7 +13350,7 @@ class Timetable {
13742
13350
  */
13743
13351
  getTransfers(stopId) {
13744
13352
  var _a, _b;
13745
- return (_b = (_a = this.stopsAdjacency.get(stopId)) === null || _a === void 0 ? void 0 : _a.transfers) !== null && _b !== void 0 ? _b : [];
13353
+ return (_b = (_a = this.stopsAdjacency[stopId]) === null || _a === void 0 ? void 0 : _a.transfers) !== null && _b !== void 0 ? _b : [];
13746
13354
  }
13747
13355
  /**
13748
13356
  * Retrieves the service route associated with the given route.
@@ -13753,7 +13361,7 @@ class Timetable {
13753
13361
  * @returns The service route corresponding to the provided route.
13754
13362
  */
13755
13363
  getServiceRouteInfo(route) {
13756
- const serviceRoute = this.routes.get(route.serviceRoute());
13364
+ const serviceRoute = this.serviceRoutes[route.serviceRoute()];
13757
13365
  if (!serviceRoute) {
13758
13366
  throw new Error(`Service route not found for route ID: ${route.serviceRoute()}`);
13759
13367
  }
@@ -13768,12 +13376,13 @@ class Timetable {
13768
13376
  * @returns An array of routes passing through the specified stop.
13769
13377
  */
13770
13378
  routesPassingThrough(stopId) {
13771
- const stopData = this.stopsAdjacency.get(stopId);
13379
+ const stopData = this.stopsAdjacency[stopId];
13772
13380
  if (!stopData) {
13773
13381
  return [];
13774
13382
  }
13775
13383
  const routes = [];
13776
- for (const routeId of stopData.routes) {
13384
+ for (let i = 0; i < stopData.routes.length; i++) {
13385
+ const routeId = stopData.routes[i];
13777
13386
  const route = this.routesAdjacency[routeId];
13778
13387
  if (route) {
13779
13388
  routes.push(route);
@@ -13792,12 +13401,15 @@ class Timetable {
13792
13401
  */
13793
13402
  findReachableRoutes(fromStops, transportModes = ALL_TRANSPORT_MODES) {
13794
13403
  const reachableRoutes = new Map();
13795
- for (const originStop of fromStops) {
13404
+ const fromStopsArray = Array.from(fromStops);
13405
+ for (let i = 0; i < fromStopsArray.length; i++) {
13406
+ const originStop = fromStopsArray[i];
13796
13407
  const validRoutes = this.routesPassingThrough(originStop).filter((route) => {
13797
13408
  const serviceRoute = this.getServiceRouteInfo(route);
13798
13409
  return transportModes.has(serviceRoute.type);
13799
13410
  });
13800
- for (const route of validRoutes) {
13411
+ for (let j = 0; j < validRoutes.length; j++) {
13412
+ const route = validRoutes[j];
13801
13413
  const hopOnStop = reachableRoutes.get(route);
13802
13414
  if (hopOnStop) {
13803
13415
  if (route.isBefore(originStop, hopOnStop)) {
@@ -15799,7 +15411,6 @@ const parseRoutes = (routesStream_1, ...args_1) => __awaiter(void 0, [routesStre
15799
15411
  routes.set(line.route_id, {
15800
15412
  name: line.route_short_name,
15801
15413
  type: routeType,
15802
- routes: [],
15803
15414
  });
15804
15415
  }
15805
15416
  }
@@ -15812,6 +15423,29 @@ const parseRoutes = (routesStream_1, ...args_1) => __awaiter(void 0, [routesStre
15812
15423
  }
15813
15424
  return routes;
15814
15425
  });
15426
+ /**
15427
+ * Creates an array of ServiceRoute objects by combining GTFS route data with service route mappings.
15428
+ *
15429
+ * @param gtfsRoutesMap A map containing GTFS route information indexed by route ID
15430
+ * @param serviceRoutesMap A map linking GTFS route IDs to service route IDs
15431
+ * @returns An array of ServiceRoute objects with route information
15432
+ */
15433
+ const indexRoutes = (gtfsRoutesMap, serviceRoutesMap) => {
15434
+ const serviceRoutes = new Array(serviceRoutesMap.size);
15435
+ for (const [gtfsRouteId, serviceRouteId] of serviceRoutesMap) {
15436
+ const route = gtfsRoutesMap.get(gtfsRouteId);
15437
+ if (route === undefined) {
15438
+ log.warn(`Route ${gtfsRouteId} not found.`);
15439
+ continue;
15440
+ }
15441
+ serviceRoutes[serviceRouteId] = {
15442
+ name: route.name,
15443
+ type: route.type,
15444
+ routes: [],
15445
+ };
15446
+ }
15447
+ return serviceRoutes;
15448
+ };
15815
15449
 
15816
15450
  const toGtfsDate = (date) => {
15817
15451
  return parseInt(date.toFormat('yyyyLLdd'));
@@ -15979,37 +15613,6 @@ const parseStops = (stopsStream) => __awaiter(void 0, void 0, void 0, function*
15979
15613
  }
15980
15614
  return parsedStops;
15981
15615
  });
15982
- /**
15983
- * Builds the final stop map indexed by internal IDs.
15984
- * Excludes all stops that do not have at least one valid stopId
15985
- * as a child, a parent, or being valid itself.
15986
- *
15987
- * @param parsedStops - The map of parsed stops.
15988
- * @param validStops - A set of valid stop IDs.
15989
- * @returns A map of stops indexed by internal IDs.
15990
- */
15991
- const indexStops = (parsedStops, validStops) => {
15992
- const stops = new Map();
15993
- for (const [, stop] of parsedStops) {
15994
- if (!validStops ||
15995
- validStops.has(stop.id) ||
15996
- (stop.parent && validStops.has(stop.parent)) ||
15997
- stop.children.some((childId) => validStops.has(childId))) {
15998
- stops.set(stop.id, {
15999
- id: stop.id,
16000
- sourceStopId: stop.sourceStopId,
16001
- name: stop.name,
16002
- lat: stop.lat,
16003
- lon: stop.lon,
16004
- locationType: stop.locationType,
16005
- platform: stop.platform,
16006
- children: stop.children.filter((childId) => !validStops || validStops.has(childId)),
16007
- parent: stop.parent,
16008
- });
16009
- }
16010
- }
16011
- return stops;
16012
- };
16013
15616
  const parseGtfsLocationType = (gtfsLocationType) => {
16014
15617
  switch (gtfsLocationType) {
16015
15618
  case 0:
@@ -16186,7 +15789,7 @@ const finalizeRouteFromBuilder = (builder) => {
16186
15789
  * @param serviceRoutes A mapping of route IDs to route details.
16187
15790
  * @returns A mapping of trip IDs to corresponding route IDs.
16188
15791
  */
16189
- const parseTrips = (tripsStream, serviceIds, serviceRoutes) => __awaiter(void 0, void 0, void 0, function* () {
15792
+ const parseTrips = (tripsStream, serviceIds, validGtfsRoutes) => __awaiter(void 0, void 0, void 0, function* () {
16190
15793
  var _a, e_1, _b, _c;
16191
15794
  const trips = new Map();
16192
15795
  try {
@@ -16199,7 +15802,7 @@ const parseTrips = (tripsStream, serviceIds, serviceRoutes) => __awaiter(void 0,
16199
15802
  // The trip doesn't correspond to an active service
16200
15803
  continue;
16201
15804
  }
16202
- if (!serviceRoutes.get(line.route_id)) {
15805
+ if (!validGtfsRoutes.has(line.route_id)) {
16203
15806
  // The trip doesn't correspond to a supported route
16204
15807
  continue;
16205
15808
  }
@@ -16215,29 +15818,38 @@ const parseTrips = (tripsStream, serviceIds, serviceRoutes) => __awaiter(void 0,
16215
15818
  }
16216
15819
  return trips;
16217
15820
  });
16218
- const buildStopsAdjacencyStructure = (validStops, serviceRoutes, routes, transfersMap) => {
16219
- const stopsAdjacency = new Map();
16220
- routes.forEach((route, index) => {
16221
- var _a;
16222
- for (const stop of route.stopsIterator()) {
16223
- if (!stopsAdjacency.get(stop) && validStops.has(stop)) {
16224
- stopsAdjacency.set(stop, { routes: [], transfers: [] });
15821
+ const buildStopsAdjacencyStructure = (serviceRoutes, routes, transfersMap, nbStops, activeStops) => {
15822
+ // TODO somehow works when it's a map
15823
+ const stopsAdjacency = new Array(nbStops);
15824
+ for (let i = 0; i < nbStops; i++) {
15825
+ stopsAdjacency[i] = { routes: [], transfers: [] };
15826
+ }
15827
+ for (let index = 0; index < routes.length; index++) {
15828
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15829
+ const route = routes[index];
15830
+ for (let j = 0; j < route.getNbStops(); j++) {
15831
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15832
+ const stop = route.stops[j];
15833
+ if (activeStops.has(stop)) {
15834
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15835
+ stopsAdjacency[stop].routes.push(index);
16225
15836
  }
16226
- (_a = stopsAdjacency.get(stop)) === null || _a === void 0 ? void 0 : _a.routes.push(index);
16227
15837
  }
16228
- const serviceRoute = serviceRoutes.get(route.serviceRoute());
16229
- if (!serviceRoute) {
15838
+ const serviceRoute = serviceRoutes[route.serviceRoute()];
15839
+ if (serviceRoute === undefined) {
16230
15840
  throw new Error(`Service route ${route.serviceRoute()} not found for route ${index}.`);
16231
15841
  }
16232
15842
  serviceRoute.routes.push(index);
16233
- });
15843
+ }
16234
15844
  for (const [stop, transfers] of transfersMap) {
16235
- const s = stopsAdjacency.get(stop);
16236
- if (s) {
16237
- for (const transfer of transfers) {
16238
- if (validStops.has(transfer.destination)) {
16239
- s.transfers.push(transfer);
16240
- }
15845
+ for (let i = 0; i < transfers.length; i++) {
15846
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15847
+ const transfer = transfers[i];
15848
+ if (activeStops.has(stop) || activeStops.has(transfer.destination)) {
15849
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15850
+ stopsAdjacency[stop].transfers.push(transfer);
15851
+ activeStops.add(transfer.destination);
15852
+ activeStops.add(stop);
16241
15853
  }
16242
15854
  }
16243
15855
  }
@@ -16248,18 +15860,18 @@ const buildStopsAdjacencyStructure = (validStops, serviceRoutes, routes, transfe
16248
15860
  *
16249
15861
  * @param stopTimesStream The readable stream containing the stop times data.
16250
15862
  * @param stopsMap A map of parsed stops from the GTFS feed.
16251
- * @param validTripIds A map of valid trip IDs to corresponding route IDs.
16252
- * @param validStopIds A set of valid stop IDs.
15863
+ * @param activeTripIds A map of valid trip IDs to corresponding route IDs.
15864
+ * @param activeStopIds A set of valid stop IDs.
16253
15865
  * @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.
16254
15866
  */
16255
- const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) => __awaiter(void 0, void 0, void 0, function* () {
15867
+ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds) => __awaiter(void 0, void 0, void 0, function* () {
16256
15868
  var _a, e_2, _b, _c;
16257
15869
  var _d, _e;
16258
15870
  /**
16259
15871
  * Adds a trip to the appropriate route builder
16260
15872
  */
16261
15873
  const addTrip = (currentTripId) => {
16262
- const gtfsRouteId = validTripIds.get(currentTripId);
15874
+ const gtfsRouteId = activeTripIds.get(currentTripId);
16263
15875
  if (!gtfsRouteId || stops.length === 0) {
16264
15876
  stops = [];
16265
15877
  arrivalTimes = [];
@@ -16268,7 +15880,6 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
16268
15880
  dropOffTypes = [];
16269
15881
  return;
16270
15882
  }
16271
- const routeId = `${gtfsRouteId}_${hashIds(stops)}`;
16272
15883
  const firstDeparture = departureTimes[0];
16273
15884
  if (firstDeparture === undefined) {
16274
15885
  console.warn(`Empty trip ${currentTripId}`);
@@ -16279,24 +15890,31 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
16279
15890
  dropOffTypes = [];
16280
15891
  return;
16281
15892
  }
15893
+ const routeId = `${gtfsRouteId}_${hashIds(stops)}`;
16282
15894
  let routeBuilder = routeBuilders.get(routeId);
16283
15895
  if (!routeBuilder) {
15896
+ let serviceRouteId = serviceRoutesMap.get(gtfsRouteId);
15897
+ if (serviceRouteId === undefined) {
15898
+ serviceRouteId = currentServiceRouteId;
15899
+ serviceRoutesMap.set(gtfsRouteId, serviceRouteId);
15900
+ currentServiceRouteId = currentServiceRouteId + 1;
15901
+ }
16284
15902
  routeBuilder = {
16285
- serviceRouteId: gtfsRouteId,
16286
- stops: [...stops],
15903
+ serviceRouteId,
15904
+ stops,
16287
15905
  trips: [],
16288
15906
  };
16289
15907
  routeBuilders.set(routeId, routeBuilder);
16290
15908
  for (const stop of stops) {
16291
- validStopIds.add(stop);
15909
+ activeStopIds.add(stop);
16292
15910
  }
16293
15911
  }
16294
15912
  routeBuilder.trips.push({
16295
15913
  firstDeparture,
16296
- arrivalTimes: [...arrivalTimes],
16297
- departureTimes: [...departureTimes],
16298
- pickUpTypes: [...pickUpTypes],
16299
- dropOffTypes: [...dropOffTypes],
15914
+ arrivalTimes: arrivalTimes,
15915
+ departureTimes: departureTimes,
15916
+ pickUpTypes: pickUpTypes,
15917
+ dropOffTypes: dropOffTypes,
16300
15918
  });
16301
15919
  stops = [];
16302
15920
  arrivalTimes = [];
@@ -16305,6 +15923,9 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
16305
15923
  dropOffTypes = [];
16306
15924
  };
16307
15925
  const routeBuilders = new Map();
15926
+ const serviceRoutesMap = new Map();
15927
+ // incrementally generate service route IDs
15928
+ let currentServiceRouteId = 0;
16308
15929
  let previousSeq = 0;
16309
15930
  let stops = [];
16310
15931
  let arrivalTimes = [];
@@ -16367,7 +15988,7 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
16367
15988
  const routeData = finalizeRouteFromBuilder(routeBuilder);
16368
15989
  routesAdjacency.push(new Route(routeData.stopTimes, routeData.pickUpDropOffTypes, routeData.stops, routeData.serviceRouteId));
16369
15990
  }
16370
- return routesAdjacency;
15991
+ return { routes: routesAdjacency, serviceRoutesMap };
16371
15992
  });
16372
15993
  const parsePickupDropOffType = (gtfsType) => {
16373
15994
  switch (gtfsType) {
@@ -16401,18 +16022,16 @@ class GtfsParser {
16401
16022
  * Parses a GTFS feed to extract all the data relevant to a given day in a transit-planner friendly format.
16402
16023
  *
16403
16024
  * @param date The active date.
16404
- * @param gtfsPath A path to the zipped GTFS feed.
16405
- * @param gtfsProfile The GTFS profile configuration.
16406
- * @returns An object containing the timetable and stops map.
16025
+ * @returns The parsed timetable.
16407
16026
  */
16408
- parse(date) {
16027
+ parseTimetable(date) {
16409
16028
  return __awaiter(this, void 0, void 0, function* () {
16410
16029
  log.setLevel('INFO');
16411
16030
  const zip = new StreamZip.async({ file: this.path });
16412
16031
  const entries = yield zip.entries();
16413
16032
  const datetime = DateTime.fromJSDate(date);
16414
- const validServiceIds = new Set();
16415
- const validStopIds = new Set();
16033
+ const activeServiceIds = new Set();
16034
+ const activeStopIds = new Set();
16416
16035
  log.info(`Parsing ${STOPS_FILE}`);
16417
16036
  const stopsStart = performance.now();
16418
16037
  const stopsStream = yield zip.stream(STOPS_FILE);
@@ -16423,17 +16042,17 @@ class GtfsParser {
16423
16042
  log.info(`Parsing ${CALENDAR_FILE}`);
16424
16043
  const calendarStart = performance.now();
16425
16044
  const calendarStream = yield zip.stream(CALENDAR_FILE);
16426
- yield parseCalendar(calendarStream, validServiceIds, datetime);
16045
+ yield parseCalendar(calendarStream, activeServiceIds, datetime);
16427
16046
  const calendarEnd = performance.now();
16428
- log.info(`${validServiceIds.size} valid services. (${(calendarEnd - calendarStart).toFixed(2)}ms)`);
16047
+ log.info(`${activeServiceIds.size} valid services. (${(calendarEnd - calendarStart).toFixed(2)}ms)`);
16429
16048
  }
16430
16049
  if (entries[CALENDAR_DATES_FILE]) {
16431
16050
  log.info(`Parsing ${CALENDAR_DATES_FILE}`);
16432
16051
  const calendarDatesStart = performance.now();
16433
16052
  const calendarDatesStream = yield zip.stream(CALENDAR_DATES_FILE);
16434
- yield parseCalendarDates(calendarDatesStream, validServiceIds, datetime);
16053
+ yield parseCalendarDates(calendarDatesStream, activeServiceIds, datetime);
16435
16054
  const calendarDatesEnd = performance.now();
16436
- log.info(`${validServiceIds.size} valid services. (${(calendarDatesEnd - calendarDatesStart).toFixed(2)}ms)`);
16055
+ log.info(`${activeServiceIds.size} valid services. (${(calendarDatesEnd - calendarDatesStart).toFixed(2)}ms)`);
16437
16056
  }
16438
16057
  log.info(`Parsing ${ROUTES_FILE}`);
16439
16058
  const routesStart = performance.now();
@@ -16444,7 +16063,7 @@ class GtfsParser {
16444
16063
  log.info(`Parsing ${TRIPS_FILE}`);
16445
16064
  const tripsStart = performance.now();
16446
16065
  const tripsStream = yield zip.stream(TRIPS_FILE);
16447
- const trips = yield parseTrips(tripsStream, validServiceIds, validGtfsRoutes);
16066
+ const trips = yield parseTrips(tripsStream, activeServiceIds, validGtfsRoutes);
16448
16067
  const tripsEnd = performance.now();
16449
16068
  log.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
16450
16069
  let transfers = new Map();
@@ -16459,32 +16078,26 @@ class GtfsParser {
16459
16078
  log.info(`Parsing ${STOP_TIMES_FILE}`);
16460
16079
  const stopTimesStart = performance.now();
16461
16080
  const stopTimesStream = yield zip.stream(STOP_TIMES_FILE);
16462
- const routesAdjacency = yield parseStopTimes(stopTimesStream, parsedStops, trips, validStopIds);
16463
- const stopsAdjacency = buildStopsAdjacencyStructure(validStopIds, validGtfsRoutes, routesAdjacency, transfers);
16081
+ const { routes, serviceRoutesMap } = yield parseStopTimes(stopTimesStream, parsedStops, trips, activeStopIds);
16082
+ const serviceRoutes = indexRoutes(validGtfsRoutes, serviceRoutesMap);
16464
16083
  const stopTimesEnd = performance.now();
16465
- log.info(`${routesAdjacency.length} valid unique routes. (${(stopTimesEnd - stopTimesStart).toFixed(2)}ms)`);
16466
- log.info(`Removing unused stops.`);
16467
- const indexStopsStart = performance.now();
16468
- const stops = indexStops(parsedStops, validStopIds);
16469
- const indexStopsEnd = performance.now();
16470
- log.info(`${stops.size} used stop stops, ${parsedStops.size - stops.size} unused. (${(indexStopsEnd - indexStopsStart).toFixed(2)}ms)`);
16084
+ log.info(`${routes.length} valid unique routes. (${(stopTimesEnd - stopTimesStart).toFixed(2)}ms)`);
16085
+ log.info('Building stops adjacency structure');
16086
+ const stopsAdjacencyStart = performance.now();
16087
+ const stopsAdjacency = buildStopsAdjacencyStructure(serviceRoutes, routes, transfers, parsedStops.size, activeStopIds);
16088
+ const stopsAdjacencyEnd = performance.now();
16089
+ log.info(`${stopsAdjacency.length} valid stops in the structure. (${(stopsAdjacencyEnd - stopsAdjacencyStart).toFixed(2)}ms)`);
16471
16090
  yield zip.close();
16472
- const timetable = new Timetable(stopsAdjacency, routesAdjacency, validGtfsRoutes);
16473
- log.info(`Building stops index.`);
16474
- const stopsIndexStart = performance.now();
16475
- const stopsIndex = new StopsIndex(stops);
16476
- const stopsIndexEnd = performance.now();
16477
- log.info(`Stops index built. (${(stopsIndexEnd - stopsIndexStart).toFixed(2)}ms)`);
16091
+ const timetable = new Timetable(stopsAdjacency, routes, serviceRoutes);
16478
16092
  log.info('Parsing complete.');
16479
- return { timetable, stopsIndex };
16093
+ return timetable;
16480
16094
  });
16481
16095
  }
16482
16096
  /**
16483
16097
  * Parses a GTFS feed to extract all stops.
16484
16098
  *
16485
- * @param gtfsPath A path the zipped GTFS feed.
16486
- * @param gtfsProfile The GTFS profile configuration.
16487
- * @returns An object containing the timetable and stops map.
16099
+ * @param activeStops The set of active stop IDs to include in the index.
16100
+ * @returns An index of stops.
16488
16101
  */
16489
16102
  parseStops() {
16490
16103
  return __awaiter(this, void 0, void 0, function* () {
@@ -16492,11 +16105,11 @@ class GtfsParser {
16492
16105
  log.info(`Parsing ${STOPS_FILE}`);
16493
16106
  const stopsStart = performance.now();
16494
16107
  const stopsStream = yield zip.stream(STOPS_FILE);
16495
- const stops = indexStops(yield parseStops(stopsStream));
16108
+ const stops = yield parseStops(stopsStream);
16496
16109
  const stopsEnd = performance.now();
16497
16110
  log.info(`${stops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
16498
16111
  yield zip.close();
16499
- return new StopsIndex(stops);
16112
+ return new StopsIndex(Array.from(stops.values()));
16500
16113
  });
16501
16114
  }
16502
16115
  }