minotor 6.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11767,20 +11767,15 @@ const serializeLocationType = (locationType) => {
11767
11767
  */
11768
11768
  class StopsIndex {
11769
11769
  constructor(stops) {
11770
+ var _a;
11770
11771
  this.stops = stops;
11771
11772
  this.sourceStopsMap = new Map();
11772
- stops.forEach((stop, id) => {
11773
- this.sourceStopsMap.set(stop.sourceStopId, id);
11774
- });
11775
- this.textIndex = lt({
11776
- fields: ['name'],
11777
- storeFields: ['id'],
11778
- searchOptions: { prefix: true, fuzzy: 0.2 },
11779
- processTerm: generateAccentVariants,
11780
- });
11781
11773
  const stopsSet = new Map();
11782
- stops.forEach((stop, id) => {
11783
- var _a;
11774
+ this.stopPoints = [];
11775
+ for (let id = 0; id < stops.length; id++) {
11776
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11777
+ const stop = stops[id];
11778
+ this.sourceStopsMap.set(stop.sourceStopId, id);
11784
11779
  const effectiveStopId = (_a = stop.parent) !== null && _a !== void 0 ? _a : id;
11785
11780
  if (!stopsSet.has(effectiveStopId)) {
11786
11781
  stopsSet.set(effectiveStopId, {
@@ -11789,22 +11784,26 @@ class StopsIndex {
11789
11784
  name: stop.parent ? this.stops[stop.parent].name : stop.name,
11790
11785
  });
11791
11786
  }
11787
+ if (stop.lat && stop.lon) {
11788
+ this.stopPoints.push({
11789
+ id: id,
11790
+ lat: stop.lat,
11791
+ lon: stop.lon,
11792
+ });
11793
+ }
11794
+ }
11795
+ this.textIndex = lt({
11796
+ fields: ['name'],
11797
+ storeFields: ['id'],
11798
+ searchOptions: { prefix: true, fuzzy: 0.2 },
11799
+ processTerm: generateAccentVariants,
11792
11800
  });
11793
11801
  const stopsArray = Array.from(stopsSet.values());
11794
11802
  q(this.textIndex, stopsArray);
11795
- this.stopPoints = this.stops
11796
- .filter((stop) => {
11797
- if (stop.lat && stop.lon)
11798
- return true;
11799
- return false;
11800
- })
11801
- .map((stop, id) => ({
11802
- id: id,
11803
- lat: stop.lat,
11804
- lon: stop.lon,
11805
- }));
11806
11803
  this.geoIndex = new KDBush(this.stopPoints.length);
11807
- for (const { lat, lon } of this.stopPoints) {
11804
+ for (let i = 0; i < this.stopPoints.length; i++) {
11805
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11806
+ const { lat, lon } = this.stopPoints[i];
11808
11807
  this.geoIndex.add(lon, lat);
11809
11808
  }
11810
11809
  this.geoIndex.finish();
@@ -12317,7 +12316,7 @@ const StopAdjacency = {
12317
12316
  }
12318
12317
  writer.uint32(18).fork();
12319
12318
  for (const v of message.routes) {
12320
- writer.int32(v);
12319
+ writer.uint32(v);
12321
12320
  }
12322
12321
  writer.join();
12323
12322
  return writer;
@@ -12338,13 +12337,13 @@ const StopAdjacency = {
12338
12337
  }
12339
12338
  case 2: {
12340
12339
  if (tag === 16) {
12341
- message.routes.push(reader.int32());
12340
+ message.routes.push(reader.uint32());
12342
12341
  continue;
12343
12342
  }
12344
12343
  if (tag === 18) {
12345
12344
  const end2 = reader.uint32() + reader.pos;
12346
12345
  while (reader.pos < end2) {
12347
- message.routes.push(reader.int32());
12346
+ message.routes.push(reader.uint32());
12348
12347
  }
12349
12348
  continue;
12350
12349
  }
@@ -12401,7 +12400,7 @@ const ServiceRoute = {
12401
12400
  }
12402
12401
  writer.uint32(26).fork();
12403
12402
  for (const v of message.routes) {
12404
- writer.int32(v);
12403
+ writer.uint32(v);
12405
12404
  }
12406
12405
  writer.join();
12407
12406
  return writer;
@@ -12429,13 +12428,13 @@ const ServiceRoute = {
12429
12428
  }
12430
12429
  case 3: {
12431
12430
  if (tag === 24) {
12432
- message.routes.push(reader.int32());
12431
+ message.routes.push(reader.uint32());
12433
12432
  continue;
12434
12433
  }
12435
12434
  if (tag === 26) {
12436
12435
  const end2 = reader.uint32() + reader.pos;
12437
12436
  while (reader.pos < end2) {
12438
- message.routes.push(reader.int32());
12437
+ message.routes.push(reader.uint32());
12439
12438
  }
12440
12439
  continue;
12441
12440
  }
@@ -12990,27 +12989,6 @@ class Route {
12990
12989
  : byte & 0x03; // Lower 2 bits for first pair
12991
12990
  return toPickupDropOffType(dropOffValue);
12992
12991
  }
12993
- /**
12994
- * Iterates over the stops in the route, starting from an optional specified stop.
12995
- * If no start stop is provided, the iteration begins from the first stop in the route.
12996
- *
12997
- * @param [startStopId] - (Optional) The StopId of the stop to start the iteration from.
12998
- * @returns An IterableIterator of StopIds, starting from the specified stop or the first stop.
12999
- * @throws An error if the specified start stop is not found in the route.
13000
- */
13001
- stopsIterator(startStopId) {
13002
- const startIndex = startStopId !== undefined ? this.stopIndices.get(startStopId) : 0;
13003
- if (startIndex === undefined) {
13004
- throw new Error(`Start stop ${startStopId} not found in route ${this.serviceRouteId}`);
13005
- }
13006
- function* generator(stops, startIndex) {
13007
- for (let i = startIndex; i < stops.length; i++) {
13008
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13009
- yield stops[i];
13010
- }
13011
- }
13012
- return generator(this.stops, startIndex);
13013
- }
13014
12992
  /**
13015
12993
  * Finds the earliest trip that can be taken from a specific stop on a given route,
13016
12994
  * optionally constrained by a latest trip index and a time before which the trip
@@ -13024,29 +13002,35 @@ class Route {
13024
13002
  * @returns The index of the earliest trip meeting the criteria, or undefined if no such trip is found.
13025
13003
  */
13026
13004
  findEarliestTrip(stopId, after = Time.origin(), beforeTrip) {
13027
- const maxTripIndex = beforeTrip !== undefined
13028
- ? Math.min(beforeTrip - 1, this.nbTrips - 1)
13029
- : this.nbTrips - 1;
13030
- if (maxTripIndex < 0) {
13005
+ if (this.nbTrips <= 0)
13031
13006
  return undefined;
13032
- }
13033
- let earliestTripIndex;
13034
- let lowTrip = 0;
13035
- let highTrip = maxTripIndex;
13036
- while (lowTrip <= highTrip) {
13037
- const midTrip = Math.floor((lowTrip + highTrip) / 2);
13038
- const departure = this.departureFrom(stopId, midTrip);
13039
- const pickUpType = this.pickUpTypeFrom(stopId, midTrip);
13040
- if ((departure.isAfter(after) || departure.equals(after)) &&
13041
- pickUpType !== 'NOT_AVAILABLE') {
13042
- earliestTripIndex = midTrip;
13043
- highTrip = midTrip - 1;
13007
+ let hi = this.nbTrips - 1;
13008
+ if (beforeTrip !== undefined)
13009
+ hi = Math.min(hi, beforeTrip - 1);
13010
+ if (hi < 0)
13011
+ return undefined;
13012
+ let lo = 0;
13013
+ let lb = -1;
13014
+ while (lo <= hi) {
13015
+ const mid = (lo + hi) >>> 1;
13016
+ const depMid = this.departureFrom(stopId, mid);
13017
+ if (depMid.isBefore(after)) {
13018
+ lo = mid + 1;
13044
13019
  }
13045
13020
  else {
13046
- lowTrip = midTrip + 1;
13021
+ lb = mid;
13022
+ hi = mid - 1;
13047
13023
  }
13048
13024
  }
13049
- return earliestTripIndex;
13025
+ if (lb === -1)
13026
+ return undefined;
13027
+ for (let t = lb; t < (beforeTrip !== null && beforeTrip !== void 0 ? beforeTrip : this.nbTrips); t++) {
13028
+ const pickup = this.pickUpTypeFrom(stopId, t);
13029
+ if (pickup !== 'NOT_AVAILABLE') {
13030
+ return t;
13031
+ }
13032
+ }
13033
+ return undefined;
13050
13034
  }
13051
13035
  /**
13052
13036
  * Retrieves the index of a stop within the route.
@@ -13160,31 +13144,48 @@ const serializeServiceRoutesMap = (serviceRoutes) => {
13160
13144
  });
13161
13145
  };
13162
13146
  const deserializeStopsAdjacency = (protoStopsAdjacency) => {
13163
- return protoStopsAdjacency.map((value) => {
13164
- return {
13165
- transfers: value.transfers.map((transfer) => (Object.assign({ destination: transfer.destination, type: parseTransferType(transfer.type) }, (transfer.minTransferTime !== undefined && {
13147
+ const result = [];
13148
+ for (let i = 0; i < protoStopsAdjacency.length; i++) {
13149
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13150
+ const value = protoStopsAdjacency[i];
13151
+ const transfers = [];
13152
+ for (let j = 0; j < value.transfers.length; j++) {
13153
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13154
+ const transfer = value.transfers[j];
13155
+ const newTransfer = Object.assign({ destination: transfer.destination, type: parseTransferType(transfer.type) }, (transfer.minTransferTime !== undefined && {
13166
13156
  minTransferTime: Duration.fromSeconds(transfer.minTransferTime),
13167
- })))),
13157
+ }));
13158
+ transfers.push(newTransfer);
13159
+ }
13160
+ result.push({
13161
+ transfers: transfers,
13168
13162
  routes: value.routes,
13169
- };
13170
- });
13163
+ });
13164
+ }
13165
+ return result;
13171
13166
  };
13172
13167
  const deserializeRoutesAdjacency = (protoRoutesAdjacency) => {
13173
13168
  const routesAdjacency = [];
13174
- protoRoutesAdjacency.forEach((value) => {
13169
+ for (let i = 0; i < protoRoutesAdjacency.length; i++) {
13170
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13171
+ const value = protoRoutesAdjacency[i];
13175
13172
  const stops = bytesToUint32Array(value.stops);
13176
13173
  routesAdjacency.push(new Route(bytesToUint16Array(value.stopTimes), value.pickUpDropOffTypes, stops, value.serviceRouteId));
13177
- });
13174
+ }
13178
13175
  return routesAdjacency;
13179
13176
  };
13180
13177
  const deserializeServiceRoutesMap = (protoServiceRoutes) => {
13181
- return protoServiceRoutes.map((value) => {
13182
- return {
13178
+ const result = [];
13179
+ for (let i = 0; i < protoServiceRoutes.length; i++) {
13180
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13181
+ const value = protoServiceRoutes[i];
13182
+ result.push({
13183
13183
  type: parseRouteType(value.type),
13184
13184
  name: value.name,
13185
13185
  routes: value.routes,
13186
- };
13187
- });
13186
+ });
13187
+ }
13188
+ return result;
13188
13189
  };
13189
13190
  const parseTransferType = (type) => {
13190
13191
  switch (type) {
@@ -13276,7 +13277,7 @@ const ALL_TRANSPORT_MODES = new Set([
13276
13277
  'TROLLEYBUS',
13277
13278
  'MONORAIL',
13278
13279
  ]);
13279
- const CURRENT_VERSION = '0.0.6';
13280
+ const CURRENT_VERSION = '0.0.7';
13280
13281
  /**
13281
13282
  * The internal transit timetable format.
13282
13283
  */
@@ -13384,7 +13385,8 @@ class Timetable {
13384
13385
  return [];
13385
13386
  }
13386
13387
  const routes = [];
13387
- for (const routeId of stopData.routes) {
13388
+ for (let i = 0; i < stopData.routes.length; i++) {
13389
+ const routeId = stopData.routes[i];
13388
13390
  const route = this.routesAdjacency[routeId];
13389
13391
  if (route) {
13390
13392
  routes.push(route);
@@ -13403,12 +13405,15 @@ class Timetable {
13403
13405
  */
13404
13406
  findReachableRoutes(fromStops, transportModes = ALL_TRANSPORT_MODES) {
13405
13407
  const reachableRoutes = new Map();
13406
- for (const originStop of fromStops) {
13408
+ const fromStopsArray = Array.from(fromStops);
13409
+ for (let i = 0; i < fromStopsArray.length; i++) {
13410
+ const originStop = fromStopsArray[i];
13407
13411
  const validRoutes = this.routesPassingThrough(originStop).filter((route) => {
13408
13412
  const serviceRoute = this.getServiceRouteInfo(route);
13409
13413
  return transportModes.has(serviceRoute.type);
13410
13414
  });
13411
- for (const route of validRoutes) {
13415
+ for (let j = 0; j < validRoutes.length; j++) {
13416
+ const route = validRoutes[j];
13412
13417
  const hopOnStop = reachableRoutes.get(route);
13413
13418
  if (hopOnStop) {
13414
13419
  if (route.isBefore(originStop, hopOnStop)) {
@@ -15823,8 +15828,12 @@ const buildStopsAdjacencyStructure = (serviceRoutes, routes, transfersMap, nbSto
15823
15828
  for (let i = 0; i < nbStops; i++) {
15824
15829
  stopsAdjacency[i] = { routes: [], transfers: [] };
15825
15830
  }
15826
- routes.forEach((route, index) => {
15827
- for (const stop of route.stopsIterator()) {
15831
+ for (let index = 0; index < routes.length; index++) {
15832
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15833
+ const route = routes[index];
15834
+ for (let j = 0; j < route.getNbStops(); j++) {
15835
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15836
+ const stop = route.stops[j];
15828
15837
  if (activeStops.has(stop)) {
15829
15838
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15830
15839
  stopsAdjacency[stop].routes.push(index);
@@ -15835,9 +15844,11 @@ const buildStopsAdjacencyStructure = (serviceRoutes, routes, transfersMap, nbSto
15835
15844
  throw new Error(`Service route ${route.serviceRoute()} not found for route ${index}.`);
15836
15845
  }
15837
15846
  serviceRoute.routes.push(index);
15838
- });
15847
+ }
15839
15848
  for (const [stop, transfers] of transfersMap) {
15840
- for (const transfer of transfers) {
15849
+ for (let i = 0; i < transfers.length; i++) {
15850
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15851
+ const transfer = transfers[i];
15841
15852
  if (activeStops.has(stop) || activeStops.has(transfer.destination)) {
15842
15853
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15843
15854
  stopsAdjacency[stop].transfers.push(transfer);