minotor 12.0.0 → 12.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.
@@ -12106,7 +12106,7 @@ class StopsIndex {
12106
12106
  this.stops = stops;
12107
12107
  this.sourceStopsMap = new Map();
12108
12108
  const stopsSet = new Map();
12109
- this.stopPoints = [];
12109
+ this.geoStopIds = [];
12110
12110
  for (let id = 0; id < stops.length; id++) {
12111
12111
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12112
12112
  const stop = stops[id];
@@ -12122,11 +12122,7 @@ class StopsIndex {
12122
12122
  });
12123
12123
  }
12124
12124
  if (stop.lat && stop.lon) {
12125
- this.stopPoints.push({
12126
- id: id,
12127
- lat: stop.lat,
12128
- lon: stop.lon,
12129
- });
12125
+ this.geoStopIds.push(id);
12130
12126
  }
12131
12127
  }
12132
12128
  this.textIndex = H({
@@ -12137,11 +12133,12 @@ class StopsIndex {
12137
12133
  });
12138
12134
  const stopsArray = Array.from(stopsSet.values());
12139
12135
  S(this.textIndex, stopsArray);
12140
- this.geoIndex = new KDBush(this.stopPoints.length);
12141
- for (let i = 0; i < this.stopPoints.length; i++) {
12136
+ this.geoIndex = new KDBush(this.geoStopIds.length);
12137
+ for (let i = 0; i < this.geoStopIds.length; i++) {
12142
12138
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12143
- const { lat, lon } = this.stopPoints[i];
12144
- this.geoIndex.add(lon, lat);
12139
+ const stop = this.stops[this.geoStopIds[i]];
12140
+ // Coordinates were checked when collecting geoStopIds.
12141
+ this.geoIndex.add(stop.lon, stop.lat);
12145
12142
  }
12146
12143
  this.geoIndex.finish();
12147
12144
  }
@@ -12183,8 +12180,9 @@ class StopsIndex {
12183
12180
  * @returns An array of Stop objects that match the search query.
12184
12181
  */
12185
12182
  findStopsByName(query, maxResults = 5) {
12186
- const results = R(this.textIndex, query).map((result) => this.stops[result.id]);
12187
- return results.slice(0, maxResults);
12183
+ return R(this.textIndex, query)
12184
+ .slice(0, maxResults)
12185
+ .map((result) => this.stops[result.id]);
12188
12186
  }
12189
12187
  /**
12190
12188
  * Finds stops by their geographic location using latitude and longitude.
@@ -12197,8 +12195,8 @@ class StopsIndex {
12197
12195
  */
12198
12196
  findStopsByLocation(lat, lon, maxResults = 5, radius = 0.5) {
12199
12197
  const nearestStops = around(this.geoIndex, lon, lat, maxResults, radius).map((id) => {
12200
- const stopPoint = this.stopPoints[id];
12201
- return this.stops[stopPoint.id];
12198
+ const stopId = this.geoStopIds[id];
12199
+ return this.stops[stopId];
12202
12200
  });
12203
12201
  return nearestStops;
12204
12202
  }
@@ -13244,11 +13242,14 @@ class Route {
13244
13242
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13245
13243
  const stopId = stops[i];
13246
13244
  const existingIndices = this.stopIndices.get(stopId);
13247
- if (existingIndices) {
13248
- existingIndices.push(i);
13245
+ if (existingIndices === undefined) {
13246
+ this.stopIndices.set(stopId, i);
13247
+ }
13248
+ else if (typeof existingIndices === 'number') {
13249
+ this.stopIndices.set(stopId, [existingIndices, i]);
13249
13250
  }
13250
13251
  else {
13251
- this.stopIndices.set(stopId, [i]);
13252
+ existingIndices.push(i);
13252
13253
  }
13253
13254
  }
13254
13255
  }
@@ -13529,8 +13530,19 @@ class Route {
13529
13530
  if (stopIndex === undefined) {
13530
13531
  return [];
13531
13532
  }
13533
+ if (typeof stopIndex === 'number') {
13534
+ // Preserve stable, mutable array results for callers that request all indices.
13535
+ const indices = [stopIndex];
13536
+ this.stopIndices.set(stopId, indices);
13537
+ return indices;
13538
+ }
13532
13539
  return stopIndex;
13533
13540
  }
13541
+ /** Returns the first occurrence without allocating an array. */
13542
+ firstStopRouteIndex(stopId) {
13543
+ const indices = this.stopIndices.get(stopId);
13544
+ return typeof indices === 'number' ? indices : indices === null || indices === void 0 ? void 0 : indices[0];
13545
+ }
13534
13546
  /**
13535
13547
  * Retrieves the id of a stop at a given index in a route.
13536
13548
  * @param stopRouteIndex The route index of the stop.
@@ -13715,11 +13727,17 @@ const deserializeStopsAdjacency = (protoStopsAdjacency) => {
13715
13727
  };
13716
13728
  const deserializeRoutesAdjacency = (protoRoutesAdjacency) => {
13717
13729
  const routesAdjacency = [];
13730
+ // Own the compact payload so small protobuf views do not retain the input file.
13731
+ const pickupDropOffStorage = new Uint8Array(protoRoutesAdjacency.reduce((size, route) => size + route.pickupDropOffTypes.byteLength, 0));
13732
+ let pickupOffset = 0;
13718
13733
  for (let i = 0; i < protoRoutesAdjacency.length; i++) {
13719
13734
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13720
13735
  const value = protoRoutesAdjacency[i];
13721
13736
  const stops = bytesToUint32Array(value.stops);
13722
- routesAdjacency.push(new Route(i, bytesToUint16Array(value.stopTimes), value.pickupDropOffTypes, stops, value.serviceRouteId));
13737
+ pickupDropOffStorage.set(value.pickupDropOffTypes, pickupOffset);
13738
+ const pickupDropOffTypes = pickupDropOffStorage.subarray(pickupOffset, pickupOffset + value.pickupDropOffTypes.byteLength);
13739
+ pickupOffset += value.pickupDropOffTypes.byteLength;
13740
+ routesAdjacency.push(new Route(i, bytesToUint16Array(value.stopTimes), pickupDropOffTypes, stops, value.serviceRouteId));
13723
13741
  }
13724
13742
  return routesAdjacency;
13725
13743
  };
@@ -14041,7 +14059,7 @@ class Timetable {
14041
14059
  if (!serviceRoute || !transportModes.has(serviceRoute.type))
14042
14060
  continue;
14043
14061
  }
14044
- const originStopIndex = route.stopRouteIndices(originStop)[0];
14062
+ const originStopIndex = route.firstStopRouteIndex(originStop);
14045
14063
  const existingHopOnStopIndex = reachableRoutes.get(route);
14046
14064
  if (existingHopOnStopIndex !== undefined) {
14047
14065
  if (originStopIndex < existingHopOnStopIndex) {