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