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
package/dist/cli.mjs CHANGED
@@ -10,7 +10,7 @@ import require$$2$1 from 'path';
10
10
  import require$$3$1 from 'events';
11
11
  import require$$4$1 from 'zlib';
12
12
  import require$$5, { Transform } from 'stream';
13
- import { performance } from 'perf_hooks';
13
+ import { performance as performance$1 } from 'perf_hooks';
14
14
  import repl from 'node:repl';
15
15
 
16
16
  /******************************************************************************
@@ -30,6 +30,18 @@ PERFORMANCE OF THIS SOFTWARE.
30
30
  /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
31
31
 
32
32
 
33
+ function __rest(s, e) {
34
+ var t = {};
35
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
36
+ t[p] = s[p];
37
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
38
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
39
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
40
+ t[p[i]] = s[p[i]];
41
+ }
42
+ return t;
43
+ }
44
+
33
45
  function __awaiter(thisArg, _arguments, P, generator) {
34
46
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
47
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -16621,148 +16633,6 @@ const Route$2 = {
16621
16633
  return message;
16622
16634
  },
16623
16635
  };
16624
- function createBaseRoutesAdjacency() {
16625
- return { routes: {} };
16626
- }
16627
- const RoutesAdjacency = {
16628
- encode(message, writer = new BinaryWriter()) {
16629
- Object.entries(message.routes).forEach(([key, value]) => {
16630
- RoutesAdjacency_RoutesEntry.encode({ key: key, value }, writer.uint32(10).fork()).join();
16631
- });
16632
- return writer;
16633
- },
16634
- decode(input, length) {
16635
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16636
- const end = length === undefined ? reader.len : reader.pos + length;
16637
- const message = createBaseRoutesAdjacency();
16638
- while (reader.pos < end) {
16639
- const tag = reader.uint32();
16640
- switch (tag >>> 3) {
16641
- case 1: {
16642
- if (tag !== 10) {
16643
- break;
16644
- }
16645
- const entry1 = RoutesAdjacency_RoutesEntry.decode(reader, reader.uint32());
16646
- if (entry1.value !== undefined) {
16647
- message.routes[entry1.key] = entry1.value;
16648
- }
16649
- continue;
16650
- }
16651
- }
16652
- if ((tag & 7) === 4 || tag === 0) {
16653
- break;
16654
- }
16655
- reader.skip(tag & 7);
16656
- }
16657
- return message;
16658
- },
16659
- fromJSON(object) {
16660
- return {
16661
- routes: isObject(object.routes)
16662
- ? Object.entries(object.routes).reduce((acc, [key, value]) => {
16663
- acc[key] = Route$2.fromJSON(value);
16664
- return acc;
16665
- }, {})
16666
- : {},
16667
- };
16668
- },
16669
- toJSON(message) {
16670
- const obj = {};
16671
- if (message.routes) {
16672
- const entries = Object.entries(message.routes);
16673
- if (entries.length > 0) {
16674
- obj.routes = {};
16675
- entries.forEach(([k, v]) => {
16676
- obj.routes[k] = Route$2.toJSON(v);
16677
- });
16678
- }
16679
- }
16680
- return obj;
16681
- },
16682
- create(base) {
16683
- return RoutesAdjacency.fromPartial(base !== null && base !== void 0 ? base : {});
16684
- },
16685
- fromPartial(object) {
16686
- var _a;
16687
- const message = createBaseRoutesAdjacency();
16688
- message.routes = Object.entries((_a = object.routes) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
16689
- if (value !== undefined) {
16690
- acc[key] = Route$2.fromPartial(value);
16691
- }
16692
- return acc;
16693
- }, {});
16694
- return message;
16695
- },
16696
- };
16697
- function createBaseRoutesAdjacency_RoutesEntry() {
16698
- return { key: "", value: undefined };
16699
- }
16700
- const RoutesAdjacency_RoutesEntry = {
16701
- encode(message, writer = new BinaryWriter()) {
16702
- if (message.key !== "") {
16703
- writer.uint32(10).string(message.key);
16704
- }
16705
- if (message.value !== undefined) {
16706
- Route$2.encode(message.value, writer.uint32(18).fork()).join();
16707
- }
16708
- return writer;
16709
- },
16710
- decode(input, length) {
16711
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16712
- const end = length === undefined ? reader.len : reader.pos + length;
16713
- const message = createBaseRoutesAdjacency_RoutesEntry();
16714
- while (reader.pos < end) {
16715
- const tag = reader.uint32();
16716
- switch (tag >>> 3) {
16717
- case 1: {
16718
- if (tag !== 10) {
16719
- break;
16720
- }
16721
- message.key = reader.string();
16722
- continue;
16723
- }
16724
- case 2: {
16725
- if (tag !== 18) {
16726
- break;
16727
- }
16728
- message.value = Route$2.decode(reader, reader.uint32());
16729
- continue;
16730
- }
16731
- }
16732
- if ((tag & 7) === 4 || tag === 0) {
16733
- break;
16734
- }
16735
- reader.skip(tag & 7);
16736
- }
16737
- return message;
16738
- },
16739
- fromJSON(object) {
16740
- return {
16741
- key: isSet(object.key) ? globalThis.String(object.key) : "",
16742
- value: isSet(object.value) ? Route$2.fromJSON(object.value) : undefined,
16743
- };
16744
- },
16745
- toJSON(message) {
16746
- const obj = {};
16747
- if (message.key !== "") {
16748
- obj.key = message.key;
16749
- }
16750
- if (message.value !== undefined) {
16751
- obj.value = Route$2.toJSON(message.value);
16752
- }
16753
- return obj;
16754
- },
16755
- create(base) {
16756
- return RoutesAdjacency_RoutesEntry.fromPartial(base !== null && base !== void 0 ? base : {});
16757
- },
16758
- fromPartial(object) {
16759
- var _a;
16760
- const message = createBaseRoutesAdjacency_RoutesEntry();
16761
- message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
16762
- message.value = (object.value !== undefined && object.value !== null) ? Route$2.fromPartial(object.value) : undefined;
16763
- return message;
16764
- },
16765
- };
16766
16636
  function createBaseTransfer() {
16767
16637
  return { destination: 0, type: 0, minTransferTime: undefined };
16768
16638
  }
@@ -16775,7 +16645,7 @@ const Transfer = {
16775
16645
  writer.uint32(16).int32(message.type);
16776
16646
  }
16777
16647
  if (message.minTransferTime !== undefined) {
16778
- writer.uint32(24).int32(message.minTransferTime);
16648
+ writer.uint32(24).uint32(message.minTransferTime);
16779
16649
  }
16780
16650
  return writer;
16781
16651
  },
@@ -16804,7 +16674,7 @@ const Transfer = {
16804
16674
  if (tag !== 24) {
16805
16675
  break;
16806
16676
  }
16807
- message.minTransferTime = reader.int32();
16677
+ message.minTransferTime = reader.uint32();
16808
16678
  continue;
16809
16679
  }
16810
16680
  }
@@ -16886,7 +16756,7 @@ const StopsAdjacency = {
16886
16756
  return {
16887
16757
  stops: isObject(object.stops)
16888
16758
  ? Object.entries(object.stops).reduce((acc, [key, value]) => {
16889
- acc[key] = StopsAdjacency_StopAdjacency.fromJSON(value);
16759
+ acc[globalThis.Number(key)] = StopsAdjacency_StopAdjacency.fromJSON(value);
16890
16760
  return acc;
16891
16761
  }, {})
16892
16762
  : {},
@@ -16913,7 +16783,7 @@ const StopsAdjacency = {
16913
16783
  const message = createBaseStopsAdjacency();
16914
16784
  message.stops = Object.entries((_a = object.stops) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
16915
16785
  if (value !== undefined) {
16916
- acc[key] = StopsAdjacency_StopAdjacency.fromPartial(value);
16786
+ acc[globalThis.Number(key)] = StopsAdjacency_StopAdjacency.fromPartial(value);
16917
16787
  }
16918
16788
  return acc;
16919
16789
  }, {});
@@ -16928,9 +16798,11 @@ const StopsAdjacency_StopAdjacency = {
16928
16798
  for (const v of message.transfers) {
16929
16799
  Transfer.encode(v, writer.uint32(10).fork()).join();
16930
16800
  }
16801
+ writer.uint32(18).fork();
16931
16802
  for (const v of message.routes) {
16932
- writer.uint32(18).string(v);
16803
+ writer.int32(v);
16933
16804
  }
16805
+ writer.join();
16934
16806
  return writer;
16935
16807
  },
16936
16808
  decode(input, length) {
@@ -16948,11 +16820,18 @@ const StopsAdjacency_StopAdjacency = {
16948
16820
  continue;
16949
16821
  }
16950
16822
  case 2: {
16951
- if (tag !== 18) {
16952
- break;
16823
+ if (tag === 16) {
16824
+ message.routes.push(reader.int32());
16825
+ continue;
16953
16826
  }
16954
- message.routes.push(reader.string());
16955
- continue;
16827
+ if (tag === 18) {
16828
+ const end2 = reader.uint32() + reader.pos;
16829
+ while (reader.pos < end2) {
16830
+ message.routes.push(reader.int32());
16831
+ }
16832
+ continue;
16833
+ }
16834
+ break;
16956
16835
  }
16957
16836
  }
16958
16837
  if ((tag & 7) === 4 || tag === 0) {
@@ -16967,7 +16846,7 @@ const StopsAdjacency_StopAdjacency = {
16967
16846
  transfers: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.transfers)
16968
16847
  ? object.transfers.map((e) => Transfer.fromJSON(e))
16969
16848
  : [],
16970
- routes: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.routes) ? object.routes.map((e) => globalThis.String(e)) : [],
16849
+ routes: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.routes) ? object.routes.map((e) => globalThis.Number(e)) : [],
16971
16850
  };
16972
16851
  },
16973
16852
  toJSON(message) {
@@ -16977,7 +16856,7 @@ const StopsAdjacency_StopAdjacency = {
16977
16856
  obj.transfers = message.transfers.map((e) => Transfer.toJSON(e));
16978
16857
  }
16979
16858
  if ((_b = message.routes) === null || _b === void 0 ? void 0 : _b.length) {
16980
- obj.routes = message.routes;
16859
+ obj.routes = message.routes.map((e) => Math.round(e));
16981
16860
  }
16982
16861
  return obj;
16983
16862
  },
@@ -16993,12 +16872,12 @@ const StopsAdjacency_StopAdjacency = {
16993
16872
  },
16994
16873
  };
16995
16874
  function createBaseStopsAdjacency_StopsEntry() {
16996
- return { key: "", value: undefined };
16875
+ return { key: 0, value: undefined };
16997
16876
  }
16998
16877
  const StopsAdjacency_StopsEntry = {
16999
16878
  encode(message, writer = new BinaryWriter()) {
17000
- if (message.key !== "") {
17001
- writer.uint32(10).string(message.key);
16879
+ if (message.key !== 0) {
16880
+ writer.uint32(8).uint32(message.key);
17002
16881
  }
17003
16882
  if (message.value !== undefined) {
17004
16883
  StopsAdjacency_StopAdjacency.encode(message.value, writer.uint32(18).fork()).join();
@@ -17013,10 +16892,10 @@ const StopsAdjacency_StopsEntry = {
17013
16892
  const tag = reader.uint32();
17014
16893
  switch (tag >>> 3) {
17015
16894
  case 1: {
17016
- if (tag !== 10) {
16895
+ if (tag !== 8) {
17017
16896
  break;
17018
16897
  }
17019
- message.key = reader.string();
16898
+ message.key = reader.uint32();
17020
16899
  continue;
17021
16900
  }
17022
16901
  case 2: {
@@ -17036,14 +16915,14 @@ const StopsAdjacency_StopsEntry = {
17036
16915
  },
17037
16916
  fromJSON(object) {
17038
16917
  return {
17039
- key: isSet(object.key) ? globalThis.String(object.key) : "",
16918
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
17040
16919
  value: isSet(object.value) ? StopsAdjacency_StopAdjacency.fromJSON(object.value) : undefined,
17041
16920
  };
17042
16921
  },
17043
16922
  toJSON(message) {
17044
16923
  const obj = {};
17045
- if (message.key !== "") {
17046
- obj.key = message.key;
16924
+ if (message.key !== 0) {
16925
+ obj.key = Math.round(message.key);
17047
16926
  }
17048
16927
  if (message.value !== undefined) {
17049
16928
  obj.value = StopsAdjacency_StopAdjacency.toJSON(message.value);
@@ -17056,7 +16935,7 @@ const StopsAdjacency_StopsEntry = {
17056
16935
  fromPartial(object) {
17057
16936
  var _a;
17058
16937
  const message = createBaseStopsAdjacency_StopsEntry();
17059
- message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
16938
+ message.key = (_a = object.key) !== null && _a !== void 0 ? _a : 0;
17060
16939
  message.value = (object.value !== undefined && object.value !== null)
17061
16940
  ? StopsAdjacency_StopAdjacency.fromPartial(object.value)
17062
16941
  : undefined;
@@ -17064,7 +16943,7 @@ const StopsAdjacency_StopsEntry = {
17064
16943
  },
17065
16944
  };
17066
16945
  function createBaseServiceRoute() {
17067
- return { type: 0, name: "" };
16946
+ return { type: 0, name: "", routes: [] };
17068
16947
  }
17069
16948
  const ServiceRoute = {
17070
16949
  encode(message, writer = new BinaryWriter()) {
@@ -17074,6 +16953,11 @@ const ServiceRoute = {
17074
16953
  if (message.name !== "") {
17075
16954
  writer.uint32(18).string(message.name);
17076
16955
  }
16956
+ writer.uint32(26).fork();
16957
+ for (const v of message.routes) {
16958
+ writer.int32(v);
16959
+ }
16960
+ writer.join();
17077
16961
  return writer;
17078
16962
  },
17079
16963
  decode(input, length) {
@@ -17097,6 +16981,20 @@ const ServiceRoute = {
17097
16981
  message.name = reader.string();
17098
16982
  continue;
17099
16983
  }
16984
+ case 3: {
16985
+ if (tag === 24) {
16986
+ message.routes.push(reader.int32());
16987
+ continue;
16988
+ }
16989
+ if (tag === 26) {
16990
+ const end2 = reader.uint32() + reader.pos;
16991
+ while (reader.pos < end2) {
16992
+ message.routes.push(reader.int32());
16993
+ }
16994
+ continue;
16995
+ }
16996
+ break;
16997
+ }
17100
16998
  }
17101
16999
  if ((tag & 7) === 4 || tag === 0) {
17102
17000
  break;
@@ -17109,9 +17007,11 @@ const ServiceRoute = {
17109
17007
  return {
17110
17008
  type: isSet(object.type) ? routeTypeFromJSON(object.type) : 0,
17111
17009
  name: isSet(object.name) ? globalThis.String(object.name) : "",
17010
+ routes: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.routes) ? object.routes.map((e) => globalThis.Number(e)) : [],
17112
17011
  };
17113
17012
  },
17114
17013
  toJSON(message) {
17014
+ var _a;
17115
17015
  const obj = {};
17116
17016
  if (message.type !== 0) {
17117
17017
  obj.type = routeTypeToJSON(message.type);
@@ -17119,16 +17019,20 @@ const ServiceRoute = {
17119
17019
  if (message.name !== "") {
17120
17020
  obj.name = message.name;
17121
17021
  }
17022
+ if ((_a = message.routes) === null || _a === void 0 ? void 0 : _a.length) {
17023
+ obj.routes = message.routes.map((e) => Math.round(e));
17024
+ }
17122
17025
  return obj;
17123
17026
  },
17124
17027
  create(base) {
17125
17028
  return ServiceRoute.fromPartial(base !== null && base !== void 0 ? base : {});
17126
17029
  },
17127
17030
  fromPartial(object) {
17128
- var _a, _b;
17031
+ var _a, _b, _c;
17129
17032
  const message = createBaseServiceRoute();
17130
17033
  message.type = (_a = object.type) !== null && _a !== void 0 ? _a : 0;
17131
17034
  message.name = (_b = object.name) !== null && _b !== void 0 ? _b : "";
17035
+ message.routes = ((_c = object.routes) === null || _c === void 0 ? void 0 : _c.map((e) => e)) || [];
17132
17036
  return message;
17133
17037
  },
17134
17038
  };
@@ -17277,7 +17181,7 @@ const ServiceRoutesMap_RoutesEntry = {
17277
17181
  },
17278
17182
  };
17279
17183
  function createBaseTimetable() {
17280
- return { version: "", stopsAdjacency: undefined, routesAdjacency: undefined, routes: undefined };
17184
+ return { version: "", stopsAdjacency: undefined, routesAdjacency: [], routes: undefined };
17281
17185
  }
17282
17186
  const Timetable$1 = {
17283
17187
  encode(message, writer = new BinaryWriter()) {
@@ -17287,8 +17191,8 @@ const Timetable$1 = {
17287
17191
  if (message.stopsAdjacency !== undefined) {
17288
17192
  StopsAdjacency.encode(message.stopsAdjacency, writer.uint32(18).fork()).join();
17289
17193
  }
17290
- if (message.routesAdjacency !== undefined) {
17291
- RoutesAdjacency.encode(message.routesAdjacency, writer.uint32(26).fork()).join();
17194
+ for (const v of message.routesAdjacency) {
17195
+ Route$2.encode(v, writer.uint32(26).fork()).join();
17292
17196
  }
17293
17197
  if (message.routes !== undefined) {
17294
17198
  ServiceRoutesMap.encode(message.routes, writer.uint32(34).fork()).join();
@@ -17320,7 +17224,7 @@ const Timetable$1 = {
17320
17224
  if (tag !== 26) {
17321
17225
  break;
17322
17226
  }
17323
- message.routesAdjacency = RoutesAdjacency.decode(reader, reader.uint32());
17227
+ message.routesAdjacency.push(Route$2.decode(reader, reader.uint32()));
17324
17228
  continue;
17325
17229
  }
17326
17230
  case 4: {
@@ -17342,11 +17246,14 @@ const Timetable$1 = {
17342
17246
  return {
17343
17247
  version: isSet(object.version) ? globalThis.String(object.version) : "",
17344
17248
  stopsAdjacency: isSet(object.stopsAdjacency) ? StopsAdjacency.fromJSON(object.stopsAdjacency) : undefined,
17345
- routesAdjacency: isSet(object.routesAdjacency) ? RoutesAdjacency.fromJSON(object.routesAdjacency) : undefined,
17249
+ routesAdjacency: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.routesAdjacency)
17250
+ ? object.routesAdjacency.map((e) => Route$2.fromJSON(e))
17251
+ : [],
17346
17252
  routes: isSet(object.routes) ? ServiceRoutesMap.fromJSON(object.routes) : undefined,
17347
17253
  };
17348
17254
  },
17349
17255
  toJSON(message) {
17256
+ var _a;
17350
17257
  const obj = {};
17351
17258
  if (message.version !== "") {
17352
17259
  obj.version = message.version;
@@ -17354,8 +17261,8 @@ const Timetable$1 = {
17354
17261
  if (message.stopsAdjacency !== undefined) {
17355
17262
  obj.stopsAdjacency = StopsAdjacency.toJSON(message.stopsAdjacency);
17356
17263
  }
17357
- if (message.routesAdjacency !== undefined) {
17358
- obj.routesAdjacency = RoutesAdjacency.toJSON(message.routesAdjacency);
17264
+ if ((_a = message.routesAdjacency) === null || _a === void 0 ? void 0 : _a.length) {
17265
+ obj.routesAdjacency = message.routesAdjacency.map((e) => Route$2.toJSON(e));
17359
17266
  }
17360
17267
  if (message.routes !== undefined) {
17361
17268
  obj.routes = ServiceRoutesMap.toJSON(message.routes);
@@ -17366,15 +17273,13 @@ const Timetable$1 = {
17366
17273
  return Timetable$1.fromPartial(base !== null && base !== void 0 ? base : {});
17367
17274
  },
17368
17275
  fromPartial(object) {
17369
- var _a;
17276
+ var _a, _b;
17370
17277
  const message = createBaseTimetable();
17371
17278
  message.version = (_a = object.version) !== null && _a !== void 0 ? _a : "";
17372
17279
  message.stopsAdjacency = (object.stopsAdjacency !== undefined && object.stopsAdjacency !== null)
17373
17280
  ? StopsAdjacency.fromPartial(object.stopsAdjacency)
17374
17281
  : undefined;
17375
- message.routesAdjacency = (object.routesAdjacency !== undefined && object.routesAdjacency !== null)
17376
- ? RoutesAdjacency.fromPartial(object.routesAdjacency)
17377
- : undefined;
17282
+ message.routesAdjacency = ((_b = object.routesAdjacency) === null || _b === void 0 ? void 0 : _b.map((e) => Route$2.fromPartial(e))) || [];
17378
17283
  message.routes = (object.routes !== undefined && object.routes !== null)
17379
17284
  ? ServiceRoutesMap.fromPartial(object.routes)
17380
17285
  : undefined;
@@ -17754,11 +17659,16 @@ let Route$1 = class Route {
17754
17659
  * @returns The pick-up type at the specified stop and trip.
17755
17660
  */
17756
17661
  pickUpTypeFrom(stopId, tripIndex) {
17757
- const pickUpIndex = (tripIndex * this.stops.length + this.stopIndex(stopId)) * 2;
17758
- const pickUpValue = this.pickUpDropOffTypes[pickUpIndex];
17759
- if (pickUpValue === undefined) {
17662
+ const globalIndex = tripIndex * this.stops.length + this.stopIndex(stopId);
17663
+ const byteIndex = Math.floor(globalIndex / 2);
17664
+ const isSecondPair = globalIndex % 2 === 1;
17665
+ const byte = this.pickUpDropOffTypes[byteIndex];
17666
+ if (byte === undefined) {
17760
17667
  throw new Error(`Pick up type not found for stop ${stopId} at trip index ${tripIndex} in route ${this.serviceRouteId}`);
17761
17668
  }
17669
+ const pickUpValue = isSecondPair
17670
+ ? (byte >> 6) & 0x03 // Upper 2 bits for second pair
17671
+ : (byte >> 2) & 0x03; // Bits 2-3 for first pair
17762
17672
  return toPickupDropOffType(pickUpValue);
17763
17673
  }
17764
17674
  /**
@@ -17769,11 +17679,16 @@ let Route$1 = class Route {
17769
17679
  * @returns The drop-off type at the specified stop and trip.
17770
17680
  */
17771
17681
  dropOffTypeAt(stopId, tripIndex) {
17772
- const dropOffIndex = (tripIndex * this.stops.length + this.stopIndex(stopId)) * 2 + 1;
17773
- const dropOffValue = this.pickUpDropOffTypes[dropOffIndex];
17774
- if (dropOffValue === undefined) {
17682
+ const globalIndex = tripIndex * this.stops.length + this.stopIndex(stopId);
17683
+ const byteIndex = Math.floor(globalIndex / 2);
17684
+ const isSecondPair = globalIndex % 2 === 1;
17685
+ const byte = this.pickUpDropOffTypes[byteIndex];
17686
+ if (byte === undefined) {
17775
17687
  throw new Error(`Drop off type not found for stop ${stopId} at trip index ${tripIndex} in route ${this.serviceRouteId}`);
17776
17688
  }
17689
+ const dropOffValue = isSecondPair
17690
+ ? (byte >> 4) & 0x03 // Bits 4-5 for second pair
17691
+ : byte & 0x03; // Lower 2 bits for first pair
17777
17692
  return toPickupDropOffType(dropOffValue);
17778
17693
  }
17779
17694
  /**
@@ -17928,17 +17843,15 @@ const serializeStopsAdjacency = (stopsAdjacency) => {
17928
17843
  return protoStopsAdjacency;
17929
17844
  };
17930
17845
  const serializeRoutesAdjacency = (routesAdjacency) => {
17931
- const protoRoutesAdjacency = {
17932
- routes: {},
17933
- };
17934
- routesAdjacency.forEach((route, key) => {
17846
+ const protoRoutesAdjacency = [];
17847
+ routesAdjacency.forEach((route) => {
17935
17848
  const routeData = route.serialize();
17936
- protoRoutesAdjacency.routes[key] = {
17849
+ protoRoutesAdjacency.push({
17937
17850
  stopTimes: uint16ArrayToBytes(routeData.stopTimes),
17938
17851
  pickUpDropOffTypes: routeData.pickUpDropOffTypes,
17939
17852
  stops: uint32ArrayToBytes(routeData.stops),
17940
17853
  serviceRouteId: routeData.serviceRouteId,
17941
- };
17854
+ });
17942
17855
  });
17943
17856
  return protoRoutesAdjacency;
17944
17857
  };
@@ -17950,6 +17863,7 @@ const serializeServiceRoutesMap = (serviceRoutesMap) => {
17950
17863
  protoServiceRoutesMap.routes[key] = {
17951
17864
  type: serializeRouteType(value.type),
17952
17865
  name: value.name,
17866
+ routes: value.routes,
17953
17867
  };
17954
17868
  });
17955
17869
  return protoServiceRoutesMap;
@@ -17968,10 +17882,10 @@ const deserializeStopsAdjacency = (protoStopsAdjacency) => {
17968
17882
  return stopsAdjacency;
17969
17883
  };
17970
17884
  const deserializeRoutesAdjacency = (protoRoutesAdjacency) => {
17971
- const routesAdjacency = new Map();
17972
- Object.entries(protoRoutesAdjacency.routes).forEach(([key, value]) => {
17885
+ const routesAdjacency = [];
17886
+ protoRoutesAdjacency.forEach((value) => {
17973
17887
  const stops = bytesToUint32Array(value.stops);
17974
- routesAdjacency.set(key, new Route$1(bytesToUint16Array(value.stopTimes), value.pickUpDropOffTypes, stops, value.serviceRouteId));
17888
+ routesAdjacency.push(new Route$1(bytesToUint16Array(value.stopTimes), value.pickUpDropOffTypes, stops, value.serviceRouteId));
17975
17889
  });
17976
17890
  return routesAdjacency;
17977
17891
  };
@@ -17981,6 +17895,7 @@ const deserializeServiceRoutesMap = (protoServiceRoutesMap) => {
17981
17895
  serviceRoutesMap.set(key, {
17982
17896
  type: parseRouteType(value.type),
17983
17897
  name: value.name,
17898
+ routes: value.routes,
17984
17899
  });
17985
17900
  });
17986
17901
  return serviceRoutesMap;
@@ -18075,7 +17990,7 @@ const ALL_TRANSPORT_MODES = new Set([
18075
17990
  'TROLLEYBUS',
18076
17991
  'MONORAIL',
18077
17992
  ]);
18078
- const CURRENT_VERSION = '0.0.3';
17993
+ const CURRENT_VERSION = '0.0.5';
18079
17994
  /**
18080
17995
  * The internal transit timetable format.
18081
17996
  */
@@ -18115,9 +18030,7 @@ class Timetable {
18115
18030
  }
18116
18031
  return new Timetable(
18117
18032
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18118
- deserializeStopsAdjacency(protoTimetable.stopsAdjacency), deserializeRoutesAdjacency(
18119
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18120
- protoTimetable.routesAdjacency),
18033
+ deserializeStopsAdjacency(protoTimetable.stopsAdjacency), deserializeRoutesAdjacency(protoTimetable.routesAdjacency),
18121
18034
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18122
18035
  deserializeServiceRoutesMap(protoTimetable.routes));
18123
18036
  }
@@ -18129,7 +18042,7 @@ class Timetable {
18129
18042
  * or undefined if no such route exists.
18130
18043
  */
18131
18044
  getRoute(routeId) {
18132
- return this.routesAdjacency.get(routeId);
18045
+ return this.routesAdjacency[routeId];
18133
18046
  }
18134
18047
  /**
18135
18048
  * Retrieves all transfer options available at the specified stop.
@@ -18149,9 +18062,14 @@ class Timetable {
18149
18062
  * @param route - The route for which the service route is to be retrieved.
18150
18063
  * @returns The service route corresponding to the provided route.
18151
18064
  */
18152
- getServiceRoute(route) {
18153
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18154
- return this.routes.get(route.serviceRoute());
18065
+ getServiceRouteInfo(route) {
18066
+ const serviceRoute = this.routes.get(route.serviceRoute());
18067
+ if (!serviceRoute) {
18068
+ throw new Error(`Service route not found for route ID: ${route.serviceRoute()}`);
18069
+ }
18070
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18071
+ const { routes } = serviceRoute, serviceRouteInfo = __rest(serviceRoute, ["routes"]);
18072
+ return serviceRouteInfo;
18155
18073
  }
18156
18074
  /**
18157
18075
  * Finds all routes passing through a stop.
@@ -18166,7 +18084,7 @@ class Timetable {
18166
18084
  }
18167
18085
  const routes = [];
18168
18086
  for (const routeId of stopData.routes) {
18169
- const route = this.routesAdjacency.get(routeId);
18087
+ const route = this.routesAdjacency[routeId];
18170
18088
  if (route) {
18171
18089
  routes.push(route);
18172
18090
  }
@@ -18186,7 +18104,7 @@ class Timetable {
18186
18104
  const reachableRoutes = new Map();
18187
18105
  for (const originStop of fromStops) {
18188
18106
  const validRoutes = this.routesPassingThrough(originStop).filter((route) => {
18189
- const serviceRoute = this.getServiceRoute(route);
18107
+ const serviceRoute = this.getServiceRouteInfo(route);
18190
18108
  return transportModes.has(serviceRoute.type);
18191
18109
  });
18192
18110
  for (const route of validRoutes) {
@@ -20197,6 +20115,7 @@ const parseRoutes = (routesStream_1, ...args_1) => __awaiter(void 0, [routesStre
20197
20115
  routes.set(line.route_id, {
20198
20116
  name: line.route_short_name,
20199
20117
  type: routeType,
20118
+ routes: [],
20200
20119
  });
20201
20120
  }
20202
20121
  }
@@ -20506,15 +20425,95 @@ const parseGtfsTransferType = (gtfsTransferType) => {
20506
20425
  }
20507
20426
  };
20508
20427
 
20428
+ /**
20429
+ * Encodes pickup/drop-off types into a Uint8Array using 2 bits per value.
20430
+ * Layout per byte: [drop_off_1][pickup_1][drop_off_0][pickup_0] for stops 0 and 1
20431
+ */
20432
+ const encodePickUpDropOffTypes = (pickUpTypes, dropOffTypes) => {
20433
+ const stopsCount = pickUpTypes.length;
20434
+ // Each byte stores 2 pickup/drop-off pairs (4 bits each)
20435
+ const arraySize = Math.ceil(stopsCount / 2);
20436
+ const encoded = new Uint8Array(arraySize);
20437
+ for (let i = 0; i < stopsCount; i++) {
20438
+ const byteIndex = Math.floor(i / 2);
20439
+ const isSecondPair = i % 2 === 1;
20440
+ const dropOffType = dropOffTypes[i];
20441
+ const pickUpType = pickUpTypes[i];
20442
+ if (dropOffType !== undefined &&
20443
+ pickUpType !== undefined &&
20444
+ byteIndex < encoded.length) {
20445
+ if (isSecondPair) {
20446
+ // Second pair: upper 4 bits
20447
+ const currentByte = encoded[byteIndex];
20448
+ if (currentByte !== undefined) {
20449
+ encoded[byteIndex] =
20450
+ currentByte | (dropOffType << 4) | (pickUpType << 6);
20451
+ }
20452
+ }
20453
+ else {
20454
+ // First pair: lower 4 bits
20455
+ const currentByte = encoded[byteIndex];
20456
+ if (currentByte !== undefined) {
20457
+ encoded[byteIndex] = currentByte | dropOffType | (pickUpType << 2);
20458
+ }
20459
+ }
20460
+ }
20461
+ }
20462
+ return encoded;
20463
+ };
20464
+ /**
20465
+ * Sorts trips by departure time and creates optimized typed arrays
20466
+ */
20467
+ const finalizeRouteFromBuilder = (builder) => {
20468
+ builder.trips.sort((a, b) => a.firstDeparture - b.firstDeparture);
20469
+ const stopsCount = builder.stops.length;
20470
+ const tripsCount = builder.trips.length;
20471
+ const stopsArray = new Uint32Array(builder.stops);
20472
+ const stopTimesArray = new Uint16Array(stopsCount * tripsCount * 2);
20473
+ const allPickUpTypes = [];
20474
+ const allDropOffTypes = [];
20475
+ for (let tripIndex = 0; tripIndex < tripsCount; tripIndex++) {
20476
+ const trip = builder.trips[tripIndex];
20477
+ if (!trip) {
20478
+ throw new Error(`Missing trip data at index ${tripIndex}`);
20479
+ }
20480
+ const baseIndex = tripIndex * stopsCount * 2;
20481
+ for (let stopIndex = 0; stopIndex < stopsCount; stopIndex++) {
20482
+ const timeIndex = baseIndex + stopIndex * 2;
20483
+ const arrivalTime = trip.arrivalTimes[stopIndex];
20484
+ const departureTime = trip.departureTimes[stopIndex];
20485
+ const pickUpType = trip.pickUpTypes[stopIndex];
20486
+ const dropOffType = trip.dropOffTypes[stopIndex];
20487
+ if (arrivalTime === undefined ||
20488
+ departureTime === undefined ||
20489
+ pickUpType === undefined ||
20490
+ dropOffType === undefined) {
20491
+ throw new Error(`Missing trip data for trip ${tripIndex} at stop ${stopIndex}`);
20492
+ }
20493
+ stopTimesArray[timeIndex] = arrivalTime;
20494
+ stopTimesArray[timeIndex + 1] = departureTime;
20495
+ allDropOffTypes.push(dropOffType);
20496
+ allPickUpTypes.push(pickUpType);
20497
+ }
20498
+ }
20499
+ // Use 2-bit encoding for pickup/drop-off types
20500
+ const pickUpDropOffTypesArray = encodePickUpDropOffTypes(allPickUpTypes, allDropOffTypes);
20501
+ return {
20502
+ serviceRouteId: builder.serviceRouteId,
20503
+ stops: stopsArray,
20504
+ stopTimes: stopTimesArray,
20505
+ pickUpDropOffTypes: pickUpDropOffTypesArray,
20506
+ };
20507
+ };
20509
20508
  /**
20510
20509
  * Parses the trips.txt file from a GTFS feed
20511
20510
  *
20512
20511
  * @param tripsStream The readable stream containing the trips data.
20513
20512
  * @param serviceIds A mapping of service IDs to corresponding route IDs.
20514
- * @param routeIds A mapping of route IDs to route details.
20513
+ * @param serviceRoutes A mapping of route IDs to route details.
20515
20514
  * @returns A mapping of trip IDs to corresponding route IDs.
20516
20515
  */
20517
- const parseTrips = (tripsStream, serviceIds, routeIds) => __awaiter(void 0, void 0, void 0, function* () {
20516
+ const parseTrips = (tripsStream, serviceIds, serviceRoutes) => __awaiter(void 0, void 0, void 0, function* () {
20518
20517
  var _a, e_1, _b, _c;
20519
20518
  const trips = new Map();
20520
20519
  try {
@@ -20527,7 +20526,7 @@ const parseTrips = (tripsStream, serviceIds, routeIds) => __awaiter(void 0, void
20527
20526
  // The trip doesn't correspond to an active service
20528
20527
  continue;
20529
20528
  }
20530
- if (!routeIds.get(line.route_id)) {
20529
+ if (!serviceRoutes.get(line.route_id)) {
20531
20530
  // The trip doesn't correspond to a supported route
20532
20531
  continue;
20533
20532
  }
@@ -20543,21 +20542,22 @@ const parseTrips = (tripsStream, serviceIds, routeIds) => __awaiter(void 0, void
20543
20542
  }
20544
20543
  return trips;
20545
20544
  });
20546
- const buildStopsAdjacencyStructure = (validStops, routes, transfersMap) => {
20547
- var _a;
20545
+ const buildStopsAdjacencyStructure = (validStops, serviceRoutes, routes, transfersMap) => {
20548
20546
  const stopsAdjacency = new Map();
20549
- for (const routeId of routes.keys()) {
20550
- const route = routes.get(routeId);
20551
- if (!route) {
20552
- throw new Error(`Route ${routeId} not found`);
20553
- }
20547
+ routes.forEach((route, index) => {
20548
+ var _a;
20554
20549
  for (const stop of route.stopsIterator()) {
20555
20550
  if (!stopsAdjacency.get(stop) && validStops.has(stop)) {
20556
20551
  stopsAdjacency.set(stop, { routes: [], transfers: [] });
20557
20552
  }
20558
- (_a = stopsAdjacency.get(stop)) === null || _a === void 0 ? void 0 : _a.routes.push(routeId);
20553
+ (_a = stopsAdjacency.get(stop)) === null || _a === void 0 ? void 0 : _a.routes.push(index);
20559
20554
  }
20560
- }
20555
+ const serviceRoute = serviceRoutes.get(route.serviceRoute());
20556
+ if (!serviceRoute) {
20557
+ throw new Error(`Service route ${route.serviceRoute()} not found for route ${index}.`);
20558
+ }
20559
+ serviceRoute.routes.push(index);
20560
+ });
20561
20561
  for (const [stop, transfers] of transfersMap) {
20562
20562
  const s = stopsAdjacency.get(stop);
20563
20563
  if (s) {
@@ -20583,11 +20583,11 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
20583
20583
  var _a, e_2, _b, _c;
20584
20584
  var _d, _e;
20585
20585
  /**
20586
- * Inserts a trip at the right place in the routes adjacency structure.
20586
+ * Adds a trip to the appropriate route builder
20587
20587
  */
20588
20588
  const addTrip = (currentTripId) => {
20589
20589
  const gtfsRouteId = validTripIds.get(currentTripId);
20590
- if (!gtfsRouteId) {
20590
+ if (!gtfsRouteId || stops.length === 0) {
20591
20591
  stops = [];
20592
20592
  arrivalTimes = [];
20593
20593
  departureTimes = [];
@@ -20596,83 +20596,42 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
20596
20596
  return;
20597
20597
  }
20598
20598
  const routeId = `${gtfsRouteId}_${hashIds(stops)}`;
20599
- let route = routes.get(routeId);
20600
- if (!route) {
20601
- const stopsCount = stops.length;
20602
- const stopsArray = new Uint32Array(stops);
20603
- const stopTimesArray = new Uint16Array(stopsCount * 2);
20604
- for (let i = 0; i < stopsCount; i++) {
20605
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20606
- stopTimesArray[i * 2] = arrivalTimes[i];
20607
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20608
- stopTimesArray[i * 2 + 1] = departureTimes[i];
20609
- }
20610
- const pickUpDropOffTypesArray = new Uint8Array(stopsCount * 2);
20611
- for (let i = 0; i < stopsCount; i++) {
20612
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20613
- pickUpDropOffTypesArray[i * 2] = pickUpTypes[i];
20614
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20615
- pickUpDropOffTypesArray[i * 2 + 1] = dropOffTypes[i];
20616
- }
20617
- route = {
20599
+ const firstDeparture = departureTimes[0];
20600
+ if (firstDeparture === undefined) {
20601
+ console.warn(`Empty trip ${currentTripId}`);
20602
+ stops = [];
20603
+ arrivalTimes = [];
20604
+ departureTimes = [];
20605
+ pickUpTypes = [];
20606
+ dropOffTypes = [];
20607
+ return;
20608
+ }
20609
+ let routeBuilder = routeBuilders.get(routeId);
20610
+ if (!routeBuilder) {
20611
+ routeBuilder = {
20618
20612
  serviceRouteId: gtfsRouteId,
20619
- stops: stopsArray,
20620
- stopTimes: stopTimesArray,
20621
- pickUpDropOffTypes: pickUpDropOffTypesArray,
20613
+ stops: [...stops],
20614
+ trips: [],
20622
20615
  };
20623
- routes.set(routeId, route);
20616
+ routeBuilders.set(routeId, routeBuilder);
20624
20617
  for (const stop of stops) {
20625
20618
  validStopIds.add(stop);
20626
20619
  }
20627
20620
  }
20628
- else {
20629
- const tripFirstStopDeparture = departureTimes[0];
20630
- if (tripFirstStopDeparture === undefined) {
20631
- throw new Error(`Empty trip ${currentTripId}`);
20632
- }
20633
- // Find the correct position to insert the new trip
20634
- const stopsCount = stops.length;
20635
- let insertPosition = 0;
20636
- const existingTripsCount = route.stopTimes.length / (stopsCount * 2);
20637
- for (let tripIndex = 0; tripIndex < existingTripsCount; tripIndex++) {
20638
- const currentDeparture = route.stopTimes[tripIndex * stopsCount * 2 + 1];
20639
- if (currentDeparture && tripFirstStopDeparture > currentDeparture) {
20640
- insertPosition = (tripIndex + 1) * stopsCount;
20641
- }
20642
- else {
20643
- break;
20644
- }
20645
- }
20646
- // insert data for the new trip at the right place
20647
- const newStopTimesLength = route.stopTimes.length + stopsCount * 2;
20648
- const newStopTimes = new Uint16Array(newStopTimesLength);
20649
- const newPickUpDropOffTypes = new Uint8Array(newStopTimesLength);
20650
- newStopTimes.set(route.stopTimes.slice(0, insertPosition * 2), 0);
20651
- newPickUpDropOffTypes.set(route.pickUpDropOffTypes.slice(0, insertPosition * 2), 0);
20652
- for (let i = 0; i < stopsCount; i++) {
20653
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20654
- newStopTimes[(insertPosition + i) * 2] = arrivalTimes[i];
20655
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20656
- newStopTimes[(insertPosition + i) * 2 + 1] = departureTimes[i];
20657
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20658
- newPickUpDropOffTypes[(insertPosition + i) * 2] = pickUpTypes[i];
20659
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20660
- newPickUpDropOffTypes[(insertPosition + i) * 2 + 1] = dropOffTypes[i];
20661
- }
20662
- const afterInsertionSlice = route.stopTimes.slice(insertPosition * 2);
20663
- newStopTimes.set(afterInsertionSlice, (insertPosition + stopsCount) * 2);
20664
- const afterInsertionTypesSlice = route.pickUpDropOffTypes.slice(insertPosition * 2);
20665
- newPickUpDropOffTypes.set(afterInsertionTypesSlice, (insertPosition + stopsCount) * 2);
20666
- route.stopTimes = newStopTimes;
20667
- route.pickUpDropOffTypes = newPickUpDropOffTypes;
20668
- }
20621
+ routeBuilder.trips.push({
20622
+ firstDeparture,
20623
+ arrivalTimes: [...arrivalTimes],
20624
+ departureTimes: [...departureTimes],
20625
+ pickUpTypes: [...pickUpTypes],
20626
+ dropOffTypes: [...dropOffTypes],
20627
+ });
20669
20628
  stops = [];
20670
20629
  arrivalTimes = [];
20671
20630
  departureTimes = [];
20672
20631
  pickUpTypes = [];
20673
20632
  dropOffTypes = [];
20674
20633
  };
20675
- const routes = new Map();
20634
+ const routeBuilders = new Map();
20676
20635
  let previousSeq = 0;
20677
20636
  let stops = [];
20678
20637
  let arrivalTimes = [];
@@ -20687,27 +20646,33 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
20687
20646
  const rawLine = _c;
20688
20647
  const line = rawLine;
20689
20648
  if (line.trip_id === currentTripId && line.stop_sequence <= previousSeq) {
20690
- console.warn(`Stop sequences not increasing for trip ${line.trip_id}.`);
20649
+ console.warn(`Stop sequences not increasing for trip ${line.trip_id}: ${line.stop_sequence} > ${previousSeq}.`);
20691
20650
  continue;
20692
20651
  }
20693
20652
  if (!line.arrival_time && !line.departure_time) {
20694
20653
  console.warn(`Missing arrival or departure time for ${line.trip_id} at stop ${line.stop_id}.`);
20695
20654
  continue;
20696
20655
  }
20697
- if (line.pickup_type === 1 && line.drop_off_type === 1) {
20656
+ if (line.pickup_type === '1' && line.drop_off_type === '1') {
20698
20657
  continue;
20699
20658
  }
20700
20659
  if (currentTripId && line.trip_id !== currentTripId && stops.length > 0) {
20701
20660
  addTrip(currentTripId);
20702
20661
  }
20703
20662
  currentTripId = line.trip_id;
20704
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20705
- stops.push(stopsMap.get(line.stop_id).id);
20663
+ const stopData = stopsMap.get(line.stop_id);
20664
+ if (!stopData) {
20665
+ console.warn(`Unknown stop ID: ${line.stop_id}`);
20666
+ continue;
20667
+ }
20668
+ stops.push(stopData.id);
20706
20669
  const departure = (_d = line.departure_time) !== null && _d !== void 0 ? _d : line.arrival_time;
20707
20670
  const arrival = (_e = line.arrival_time) !== null && _e !== void 0 ? _e : line.departure_time;
20708
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20671
+ if (!arrival || !departure) {
20672
+ console.warn(`Missing time data for ${line.trip_id} at stop ${line.stop_id}`);
20673
+ continue;
20674
+ }
20709
20675
  arrivalTimes.push(toTime(arrival).toMinutes());
20710
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20711
20676
  departureTimes.push(toTime(departure).toMinutes());
20712
20677
  pickUpTypes.push(parsePickupDropOffType(line.pickup_type));
20713
20678
  dropOffTypes.push(parsePickupDropOffType(line.drop_off_type));
@@ -20724,9 +20689,10 @@ const parseStopTimes = (stopTimesStream, stopsMap, validTripIds, validStopIds) =
20724
20689
  if (currentTripId) {
20725
20690
  addTrip(currentTripId);
20726
20691
  }
20727
- const routesAdjacency = new Map();
20728
- for (const [routeId, routeData] of routes) {
20729
- routesAdjacency.set(routeId, new Route$1(routeData.stopTimes, routeData.pickUpDropOffTypes, routeData.stops, routeData.serviceRouteId));
20692
+ const routesAdjacency = [];
20693
+ for (const [, routeBuilder] of routeBuilders) {
20694
+ const routeData = finalizeRouteFromBuilder(routeBuilder);
20695
+ routesAdjacency.push(new Route$1(routeData.stopTimes, routeData.pickUpDropOffTypes, routeData.stops, routeData.serviceRouteId));
20730
20696
  }
20731
20697
  return routesAdjacency;
20732
20698
  });
@@ -20734,13 +20700,13 @@ const parsePickupDropOffType = (gtfsType) => {
20734
20700
  switch (gtfsType) {
20735
20701
  default:
20736
20702
  return REGULAR;
20737
- case 0:
20703
+ case '0':
20738
20704
  return REGULAR;
20739
- case 1:
20705
+ case '1':
20740
20706
  return NOT_AVAILABLE;
20741
- case 2:
20707
+ case '2':
20742
20708
  return MUST_PHONE_AGENCY;
20743
- case 3:
20709
+ case '3':
20744
20710
  return MUST_COORDINATE_WITH_DRIVER;
20745
20711
  }
20746
20712
  };
@@ -20768,54 +20734,74 @@ class GtfsParser {
20768
20734
  */
20769
20735
  parse(date) {
20770
20736
  return __awaiter(this, void 0, void 0, function* () {
20737
+ log.setLevel('INFO');
20771
20738
  const zip = new StreamZip.async({ file: this.path });
20772
20739
  const entries = yield zip.entries();
20773
20740
  const datetime = DateTime.fromJSDate(date);
20774
20741
  const validServiceIds = new Set();
20775
20742
  const validStopIds = new Set();
20776
20743
  log.info(`Parsing ${STOPS_FILE}`);
20744
+ const stopsStart = performance.now();
20777
20745
  const stopsStream = yield zip.stream(STOPS_FILE);
20778
20746
  const parsedStops = yield parseStops(stopsStream, this.profile.platformParser);
20779
- log.info(`${parsedStops.size} parsed stops.`);
20747
+ const stopsEnd = performance.now();
20748
+ log.info(`${parsedStops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
20780
20749
  if (entries[CALENDAR_FILE]) {
20781
20750
  log.info(`Parsing ${CALENDAR_FILE}`);
20751
+ const calendarStart = performance.now();
20782
20752
  const calendarStream = yield zip.stream(CALENDAR_FILE);
20783
20753
  yield parseCalendar(calendarStream, validServiceIds, datetime);
20784
- log.info(`${validServiceIds.size} valid services.`);
20754
+ const calendarEnd = performance.now();
20755
+ log.info(`${validServiceIds.size} valid services. (${(calendarEnd - calendarStart).toFixed(2)}ms)`);
20785
20756
  }
20786
20757
  if (entries[CALENDAR_DATES_FILE]) {
20787
20758
  log.info(`Parsing ${CALENDAR_DATES_FILE}`);
20759
+ const calendarDatesStart = performance.now();
20788
20760
  const calendarDatesStream = yield zip.stream(CALENDAR_DATES_FILE);
20789
20761
  yield parseCalendarDates(calendarDatesStream, validServiceIds, datetime);
20790
- log.info(`${validServiceIds.size} valid services.`);
20762
+ const calendarDatesEnd = performance.now();
20763
+ log.info(`${validServiceIds.size} valid services. (${(calendarDatesEnd - calendarDatesStart).toFixed(2)}ms)`);
20791
20764
  }
20792
20765
  log.info(`Parsing ${ROUTES_FILE}`);
20766
+ const routesStart = performance.now();
20793
20767
  const routesStream = yield zip.stream(ROUTES_FILE);
20794
20768
  const validGtfsRoutes = yield parseRoutes(routesStream, this.profile);
20795
- log.info(`${validGtfsRoutes.size} valid GTFS routes.`);
20769
+ const routesEnd = performance.now();
20770
+ log.info(`${validGtfsRoutes.size} valid GTFS routes. (${(routesEnd - routesStart).toFixed(2)}ms)`);
20796
20771
  log.info(`Parsing ${TRIPS_FILE}`);
20772
+ const tripsStart = performance.now();
20797
20773
  const tripsStream = yield zip.stream(TRIPS_FILE);
20798
20774
  const trips = yield parseTrips(tripsStream, validServiceIds, validGtfsRoutes);
20799
- log.info(`${trips.size} valid trips.`);
20775
+ const tripsEnd = performance.now();
20776
+ log.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
20800
20777
  let transfers = new Map();
20801
20778
  if (entries[TRANSFERS_FILE]) {
20802
20779
  log.info(`Parsing ${TRANSFERS_FILE}`);
20780
+ const transfersStart = performance.now();
20803
20781
  const transfersStream = yield zip.stream(TRANSFERS_FILE);
20804
20782
  transfers = yield parseTransfers(transfersStream, parsedStops);
20805
- log.info(`${transfers.size} valid transfers.`);
20783
+ const transfersEnd = performance.now();
20784
+ log.info(`${transfers.size} valid transfers. (${(transfersEnd - transfersStart).toFixed(2)}ms)`);
20806
20785
  }
20807
20786
  log.info(`Parsing ${STOP_TIMES_FILE}`);
20787
+ const stopTimesStart = performance.now();
20808
20788
  const stopTimesStream = yield zip.stream(STOP_TIMES_FILE);
20809
20789
  const routesAdjacency = yield parseStopTimes(stopTimesStream, parsedStops, trips, validStopIds);
20810
- const stopsAdjacency = buildStopsAdjacencyStructure(validStopIds, routesAdjacency, transfers);
20811
- log.info(`${routesAdjacency.size} valid unique routes.`);
20790
+ const stopsAdjacency = buildStopsAdjacencyStructure(validStopIds, validGtfsRoutes, routesAdjacency, transfers);
20791
+ const stopTimesEnd = performance.now();
20792
+ log.info(`${routesAdjacency.length} valid unique routes. (${(stopTimesEnd - stopTimesStart).toFixed(2)}ms)`);
20812
20793
  log.info(`Removing unused stops.`);
20794
+ const indexStopsStart = performance.now();
20813
20795
  const stops = indexStops(parsedStops, validStopIds);
20814
- log.info(`${stops.size} used stop stops, ${parsedStops.size - stops.size} unused.`);
20796
+ const indexStopsEnd = performance.now();
20797
+ log.info(`${stops.size} used stop stops, ${parsedStops.size - stops.size} unused. (${(indexStopsEnd - indexStopsStart).toFixed(2)}ms)`);
20815
20798
  yield zip.close();
20816
20799
  const timetable = new Timetable(stopsAdjacency, routesAdjacency, validGtfsRoutes);
20817
20800
  log.info(`Building stops index.`);
20801
+ const stopsIndexStart = performance.now();
20818
20802
  const stopsIndex = new StopsIndex(stops);
20803
+ const stopsIndexEnd = performance.now();
20804
+ log.info(`Stops index built. (${(stopsIndexEnd - stopsIndexStart).toFixed(2)}ms)`);
20819
20805
  log.info('Parsing complete.');
20820
20806
  return { timetable, stopsIndex };
20821
20807
  });
@@ -20831,9 +20817,11 @@ class GtfsParser {
20831
20817
  return __awaiter(this, void 0, void 0, function* () {
20832
20818
  const zip = new StreamZip.async({ file: this.path });
20833
20819
  log.info(`Parsing ${STOPS_FILE}`);
20820
+ const stopsStart = performance.now();
20834
20821
  const stopsStream = yield zip.stream(STOPS_FILE);
20835
20822
  const stops = indexStops(yield parseStops(stopsStream, this.profile.platformParser));
20836
- log.info(`${stops.size} parsed stops.`);
20823
+ const stopsEnd = performance.now();
20824
+ log.info(`${stops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
20837
20825
  yield zip.close();
20838
20826
  return new StopsIndex(stops);
20839
20827
  });
@@ -21376,7 +21364,7 @@ class Router {
21376
21364
  to: this.stopsIndex.findStopById(currentStop),
21377
21365
  departureTime: bestHopOnDepartureTime,
21378
21366
  arrivalTime: currentArrivalTime,
21379
- route: this.timetable.getServiceRoute(route),
21367
+ route: this.timetable.getServiceRouteInfo(route),
21380
21368
  },
21381
21369
  });
21382
21370
  earliestArrivals.set(currentStop, {
@@ -21456,9 +21444,9 @@ const testRouterPerformance = (router, stopsIndex, tasks, iterations) => {
21456
21444
  global.gc();
21457
21445
  }
21458
21446
  const startMemory = process.memoryUsage().heapUsed;
21459
- const startTime = performance.now();
21447
+ const startTime = performance$1.now();
21460
21448
  router.route(task);
21461
- const endTime = performance.now();
21449
+ const endTime = performance$1.now();
21462
21450
  const endMemory = process.memoryUsage().heapUsed;
21463
21451
  totalTime += endTime - startTime;
21464
21452
  if (endMemory >= startMemory) {
@@ -21610,7 +21598,6 @@ const startRepl = (stopsPath, timetablePath) => {
21610
21598
  if (bestRoute) {
21611
21599
  console.log(`Found route from ${fromStop.name} to ${toStop.name}:`);
21612
21600
  console.log(bestRoute.toString());
21613
- console.log(JSON.stringify(bestRoute.asJson(), null, 2));
21614
21601
  }
21615
21602
  else {
21616
21603
  console.log('No route found');