minotor 11.3.0 → 11.5.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
- # [11.3.0](https://github.com/aubryio/minotor/compare/v11.2.3...v11.3.0) (2026-07-21)
1
+ # [11.5.0](https://github.com/aubryio/minotor/compare/v11.4.0...v11.5.0) (2026-07-25)
2
2
 
3
3
 
4
4
  ### Features
5
5
 
6
- * support for virtual transfers ([#73](https://github.com/aubryio/minotor/issues/73)) ([295ff24](https://github.com/aubryio/minotor/commit/295ff248c935e0fb7bdeddad802cbffb1142b0cb))
6
+ * sibling stops transfers ([#75](https://github.com/aubryio/minotor/issues/75)) ([22919e5](https://github.com/aubryio/minotor/commit/22919e5fb411b066ff5305c928dd00ce677dda25)), closes [#59](https://github.com/aubryio/minotor/issues/59)
package/dist/cli.mjs CHANGED
@@ -18067,25 +18067,6 @@ const transferTypeToString = (type) => {
18067
18067
  }
18068
18068
  };
18069
18069
 
18070
- /**
18071
- * Returns the value stored under `key`, inserting and returning `defaultValue`
18072
- * when the key is absent. Mirrors the TC39 `Map.prototype.getOrInsert`
18073
- * proposal.
18074
- *
18075
- * TODO: remove this helper and call `map.getOrInsert(key, defaultValue)`
18076
- * directly once we only target Node 26+ (where the method is built in).
18077
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/getOrInsert
18078
- */
18079
- const getOrInsert = (map, key, defaultValue) => {
18080
- if (map.has(key)) {
18081
- // Key is present, so `get` returns the stored value (which may itself be a
18082
- // legitimately-stored `undefined`).
18083
- return map.get(key);
18084
- }
18085
- map.set(key, defaultValue);
18086
- return defaultValue;
18087
- };
18088
-
18089
18070
  const toGtfsDate = (date) => {
18090
18071
  return parseInt(date.toFormat('yyyyLLdd'));
18091
18072
  };
@@ -20094,6 +20075,7 @@ const parseFrequencies = (stream, activeTripIds) => __awaiter(void 0, void 0, vo
20094
20075
  });
20095
20076
 
20096
20077
  const standardGtfsProfile = {
20078
+ deriveSiblingTransfers: true,
20097
20079
  routeTypeParser: (routeType) => {
20098
20080
  switch (routeType) {
20099
20081
  case 0:
@@ -20422,25 +20404,34 @@ const processStopToStopTransfer = (transferEntry, fromStop, toStop, transfers) =
20422
20404
  /**
20423
20405
  * Parses the transfers.txt file from a GTFS feed.
20424
20406
  *
20425
- * @param stopsStream The readable stream containing the stops data.
20426
- * @return A mapping of stop IDs to corresponding stop details.
20407
+ * @param transfersStream The readable stream containing the transfers data.
20408
+ * @param stopsMap The parsed GTFS stops indexed by their source IDs.
20409
+ * @param activeServiceIds The service IDs active for the requested date.
20410
+ * @returns Parsed stop transfers, trip continuations, and guaranteed trip transfers.
20427
20411
  */
20428
- const parseTransfers = (transfersStream, stopsMap) => __awaiter(void 0, void 0, void 0, function* () {
20412
+ const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaiter(void 0, void 0, void 0, function* () {
20429
20413
  var _a, e_1, _b, _c;
20414
+ var _d;
20430
20415
  const transfers = new Map();
20416
+ const forbiddenTransfers = new Map();
20431
20417
  const tripContinuations = [];
20432
20418
  const guaranteedTripTransfers = [];
20433
20419
  try {
20434
- for (var _d = true, _e = __asyncValues(parseCsv(transfersStream, [
20420
+ for (var _e = true, _f = __asyncValues(parseCsv(transfersStream, [
20435
20421
  'transfer_type',
20436
20422
  'min_transfer_time',
20437
- ])), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
20438
- _c = _f.value;
20439
- _d = false;
20423
+ ])), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
20424
+ _c = _g.value;
20425
+ _e = false;
20440
20426
  const rawLine = _c;
20441
20427
  const transferEntry = rawLine;
20442
- if (transferEntry.transfer_type === 3 ||
20443
- transferEntry.transfer_type === 5) {
20428
+ if (transferEntry.service_id &&
20429
+ !activeServiceIds.has(transferEntry.service_id)) {
20430
+ continue;
20431
+ }
20432
+ // Type 5 only prevents remaining seated between two specific trips. It
20433
+ // does not prohibit an ordinary stop-to-stop transfer.
20434
+ if (transferEntry.transfer_type === 5) {
20444
20435
  continue;
20445
20436
  }
20446
20437
  if (!transferEntry.from_stop_id || !transferEntry.to_stop_id) {
@@ -20470,6 +20461,19 @@ const parseTransfers = (transfersStream, stopsMap) => __awaiter(void 0, void 0,
20470
20461
  processGuaranteedStopTransfer(transferEntry, fromStop.id, toStop.id, transfers);
20471
20462
  }
20472
20463
  break;
20464
+ case 3: {
20465
+ if (transferEntry.from_trip_id ||
20466
+ transferEntry.to_trip_id ||
20467
+ transferEntry.from_route_id ||
20468
+ transferEntry.to_route_id) {
20469
+ log.warn(`Unsupported transfer of type 3 with trip or route constraints: from_trip_id=${transferEntry.from_trip_id}, to_trip_id=${transferEntry.to_trip_id}, from_route_id=${transferEntry.from_route_id}, to_route_id=${transferEntry.to_route_id}.`);
20470
+ break;
20471
+ }
20472
+ const forbiddenDestinations = (_d = forbiddenTransfers.get(fromStop.id)) !== null && _d !== void 0 ? _d : new Set();
20473
+ forbiddenDestinations.add(toStop.id);
20474
+ forbiddenTransfers.set(fromStop.id, forbiddenDestinations);
20475
+ break;
20476
+ }
20473
20477
  case 0: // Recommended transfer
20474
20478
  case 2: // Requires minimal time
20475
20479
  default:
@@ -20481,16 +20485,92 @@ const parseTransfers = (transfersStream, stopsMap) => __awaiter(void 0, void 0,
20481
20485
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
20482
20486
  finally {
20483
20487
  try {
20484
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
20488
+ if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
20485
20489
  }
20486
20490
  finally { if (e_1) throw e_1.error; }
20487
20491
  }
20488
20492
  return {
20489
20493
  transfers,
20494
+ forbiddenTransfers,
20490
20495
  tripContinuations,
20491
20496
  guaranteedTripTransfers,
20492
20497
  };
20493
20498
  });
20499
+ /**
20500
+ * Adds missing directed transfers between route-served child stops belonging
20501
+ * to the same parent station.
20502
+ *
20503
+ * GTFS feeds commonly use parent_station to group platforms while omitting the
20504
+ * corresponding transfers.txt rows. The generated transfers intentionally do
20505
+ * not carry a fixed duration: routing applies the query's fallback minimum
20506
+ * transfer time. Explicit and forbidden feed entries always take precedence.
20507
+ *
20508
+ * @returns The number of directed sibling transfers added.
20509
+ */
20510
+ const addMissingSiblingTransfers = (stopsMap, activeStops, transfers, forbiddenTransfers = new Map()) => {
20511
+ var _a;
20512
+ let addedTransfers = 0;
20513
+ for (const parent of stopsMap.values()) {
20514
+ const activeChildren = parent.children.filter((child) => activeStops.has(child));
20515
+ if (activeChildren.length < 2)
20516
+ continue;
20517
+ for (const fromStop of activeChildren) {
20518
+ const existing = (_a = transfers.get(fromStop)) !== null && _a !== void 0 ? _a : [];
20519
+ const connected = new Set(existing.map((transfer) => transfer.destination));
20520
+ const forbidden = forbiddenTransfers.get(fromStop);
20521
+ for (const toStop of activeChildren) {
20522
+ if (toStop === fromStop ||
20523
+ connected.has(toStop) ||
20524
+ (forbidden === null || forbidden === void 0 ? void 0 : forbidden.has(toStop))) {
20525
+ continue;
20526
+ }
20527
+ existing.push({
20528
+ destination: toStop,
20529
+ type: TransferTypes.REQUIRES_MINIMAL_TIME,
20530
+ });
20531
+ connected.add(toStop);
20532
+ addedTransfers += 1;
20533
+ }
20534
+ if (existing.length > 0) {
20535
+ transfers.set(fromStop, existing);
20536
+ }
20537
+ }
20538
+ }
20539
+ return addedTransfers;
20540
+ };
20541
+ /**
20542
+ * Merges generated transfers into parsed feed transfers.
20543
+ *
20544
+ * Only transfers between active stops are kept. Explicit feed transfers and
20545
+ * forbidden directed pairs take precedence over generated candidates.
20546
+ *
20547
+ * @returns The number of generated transfers added.
20548
+ */
20549
+ const addGeneratedTransfers = (generatedTransfers, activeStops, transfers, forbiddenTransfers = new Map()) => {
20550
+ var _a;
20551
+ let addedTransfers = 0;
20552
+ for (const [fromStop, candidates] of generatedTransfers) {
20553
+ if (!activeStops.has(fromStop))
20554
+ continue;
20555
+ const existing = (_a = transfers.get(fromStop)) !== null && _a !== void 0 ? _a : [];
20556
+ const connected = new Set(existing.map((transfer) => transfer.destination));
20557
+ const forbidden = forbiddenTransfers.get(fromStop);
20558
+ for (const transfer of candidates) {
20559
+ if (!activeStops.has(transfer.destination) ||
20560
+ connected.has(transfer.destination) ||
20561
+ (forbidden === null || forbidden === void 0 ? void 0 : forbidden.has(transfer.destination))) {
20562
+ continue;
20563
+ }
20564
+ connected.add(transfer.destination);
20565
+ existing.push(transfer);
20566
+ addedTransfers += 1;
20567
+ }
20568
+ if (existing.length > 0) {
20569
+ transfers.set(fromStop, existing);
20570
+ }
20571
+ }
20572
+ return addedTransfers;
20573
+ };
20494
20574
  /**
20495
20575
  * Disambiguates stops involved in a transfer.
20496
20576
  *
@@ -21010,14 +21090,16 @@ class GtfsParser {
21010
21090
  const tripsEnd = performance.now();
21011
21091
  log.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
21012
21092
  let transfers = new Map();
21093
+ let forbiddenTransfers = new Map();
21013
21094
  let tripContinuationsList = [];
21014
21095
  let guaranteedTripTransfersList = [];
21015
21096
  if (entries[TRANSFERS_FILE]) {
21016
21097
  log.info(`Parsing ${TRANSFERS_FILE}`);
21017
21098
  const transfersStart = performance.now();
21018
21099
  const transfersStream = yield zip.stream(TRANSFERS_FILE);
21019
- const { transfers: parsedTransfers, tripContinuations: parsedTripContinuations, guaranteedTripTransfers: parsedGuaranteedTripTransfers, } = yield parseTransfers(transfersStream, parsedStops);
21100
+ const { transfers: parsedTransfers, forbiddenTransfers: parsedForbiddenTransfers, tripContinuations: parsedTripContinuations, guaranteedTripTransfers: parsedGuaranteedTripTransfers, } = yield parseTransfers(transfersStream, parsedStops, activeServiceIds);
21020
21101
  transfers = parsedTransfers;
21102
+ forbiddenTransfers = parsedForbiddenTransfers;
21021
21103
  tripContinuationsList = parsedTripContinuations;
21022
21104
  guaranteedTripTransfersList = parsedGuaranteedTripTransfers;
21023
21105
  const transfersEnd = performance.now();
@@ -21039,6 +21121,12 @@ class GtfsParser {
21039
21121
  const serviceRoutes = indexRoutes(validGtfsRoutes, serviceRoutesMap);
21040
21122
  const stopTimesEnd = performance.now();
21041
21123
  log.info(`${routes.length} valid unique routes. (${(stopTimesEnd - stopTimesStart).toFixed(2)}ms)`);
21124
+ if (this.profile.deriveSiblingTransfers !== false) {
21125
+ const siblingTransfersStart = performance.now();
21126
+ const siblingTransfersAdded = addMissingSiblingTransfers(parsedStops, activeStopIds, transfers, forbiddenTransfers);
21127
+ const siblingTransfersEnd = performance.now();
21128
+ log.info(`${siblingTransfersAdded} sibling transfers added. (${(siblingTransfersEnd - siblingTransfersStart).toFixed(2)}ms)`);
21129
+ }
21042
21130
  if (this.transferGenerator) {
21043
21131
  log.info('Generating virtual transfers');
21044
21132
  const virtualTransfersStart = performance.now();
@@ -21049,22 +21137,7 @@ class GtfsParser {
21049
21137
  stop.lon !== undefined);
21050
21138
  const stopsIndex = new StopsIndex(Array.from(parsedStops.values()));
21051
21139
  const generatedTransfers = yield this.transferGenerator.generate(originStops, stopsIndex);
21052
- let addedTransfers = 0;
21053
- for (const [fromStop, newTransfers] of generatedTransfers) {
21054
- const existing = getOrInsert(transfers, fromStop, []);
21055
- // Deduplicate per directed pair against existing (feed) transfers, and
21056
- // only keep transfers into stops a route actually calls at.
21057
- const connected = new Set(existing.map((t) => t.destination));
21058
- for (const transfer of newTransfers) {
21059
- if (!activeStopIds.has(transfer.destination) ||
21060
- connected.has(transfer.destination)) {
21061
- continue;
21062
- }
21063
- connected.add(transfer.destination);
21064
- existing.push(transfer);
21065
- addedTransfers += 1;
21066
- }
21067
- }
21140
+ const addedTransfers = addGeneratedTransfers(generatedTransfers, activeStopIds, transfers, forbiddenTransfers);
21068
21141
  const virtualTransfersEnd = performance.now();
21069
21142
  log.info(`${addedTransfers} virtual transfers added. (${(virtualTransfersEnd - virtualTransfersStart).toFixed(2)}ms)`);
21070
21143
  }
@@ -21235,9 +21308,29 @@ const routeTypeParser = (routeType) => {
21235
21308
  }
21236
21309
  };
21237
21310
  const extendedGtfsProfile = {
21311
+ deriveSiblingTransfers: true,
21238
21312
  routeTypeParser,
21239
21313
  };
21240
21314
 
21315
+ /**
21316
+ * Returns the value stored under `key`, inserting and returning `defaultValue`
21317
+ * when the key is absent. Mirrors the TC39 `Map.prototype.getOrInsert`
21318
+ * proposal.
21319
+ *
21320
+ * TODO: remove this helper and call `map.getOrInsert(key, defaultValue)`
21321
+ * directly once we only target Node 26+ (where the method is built in).
21322
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/getOrInsert
21323
+ */
21324
+ const getOrInsert = (map, key, defaultValue) => {
21325
+ if (map.has(key)) {
21326
+ // Key is present, so `get` returns the stored value (which may itself be a
21327
+ // legitimately-stored `undefined`).
21328
+ return map.get(key);
21329
+ }
21330
+ map.set(key, defaultValue);
21331
+ return defaultValue;
21332
+ };
21333
+
21241
21334
  const DEFAULT_MAX_DISTANCE_METERS = 500;
21242
21335
  const DEFAULT_WALKING_SPEED_KMH = 4;
21243
21336
  const DEFAULT_DETOUR_FACTOR = 1.3;