minotor 11.4.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.4.0](https://github.com/aubryio/minotor/compare/v11.3.0...v11.4.0) (2026-07-24)
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 service_ids in transfers.txt. ([d8e5fbd](https://github.com/aubryio/minotor/commit/d8e5fbd1fe99968aebc103ff8d51b98389322437))
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:
@@ -20429,24 +20411,27 @@ const processStopToStopTransfer = (transferEntry, fromStop, toStop, transfers) =
20429
20411
  */
20430
20412
  const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaiter(void 0, void 0, void 0, function* () {
20431
20413
  var _a, e_1, _b, _c;
20414
+ var _d;
20432
20415
  const transfers = new Map();
20416
+ const forbiddenTransfers = new Map();
20433
20417
  const tripContinuations = [];
20434
20418
  const guaranteedTripTransfers = [];
20435
20419
  try {
20436
- for (var _d = true, _e = __asyncValues(parseCsv(transfersStream, [
20420
+ for (var _e = true, _f = __asyncValues(parseCsv(transfersStream, [
20437
20421
  'transfer_type',
20438
20422
  'min_transfer_time',
20439
- ])), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
20440
- _c = _f.value;
20441
- _d = false;
20423
+ ])), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
20424
+ _c = _g.value;
20425
+ _e = false;
20442
20426
  const rawLine = _c;
20443
20427
  const transferEntry = rawLine;
20444
20428
  if (transferEntry.service_id &&
20445
20429
  !activeServiceIds.has(transferEntry.service_id)) {
20446
20430
  continue;
20447
20431
  }
20448
- if (transferEntry.transfer_type === 3 ||
20449
- transferEntry.transfer_type === 5) {
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) {
20450
20435
  continue;
20451
20436
  }
20452
20437
  if (!transferEntry.from_stop_id || !transferEntry.to_stop_id) {
@@ -20476,6 +20461,19 @@ const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaite
20476
20461
  processGuaranteedStopTransfer(transferEntry, fromStop.id, toStop.id, transfers);
20477
20462
  }
20478
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
+ }
20479
20477
  case 0: // Recommended transfer
20480
20478
  case 2: // Requires minimal time
20481
20479
  default:
@@ -20487,16 +20485,92 @@ const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaite
20487
20485
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
20488
20486
  finally {
20489
20487
  try {
20490
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
20488
+ if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
20491
20489
  }
20492
20490
  finally { if (e_1) throw e_1.error; }
20493
20491
  }
20494
20492
  return {
20495
20493
  transfers,
20494
+ forbiddenTransfers,
20496
20495
  tripContinuations,
20497
20496
  guaranteedTripTransfers,
20498
20497
  };
20499
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
+ };
20500
20574
  /**
20501
20575
  * Disambiguates stops involved in a transfer.
20502
20576
  *
@@ -21016,14 +21090,16 @@ class GtfsParser {
21016
21090
  const tripsEnd = performance.now();
21017
21091
  log.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
21018
21092
  let transfers = new Map();
21093
+ let forbiddenTransfers = new Map();
21019
21094
  let tripContinuationsList = [];
21020
21095
  let guaranteedTripTransfersList = [];
21021
21096
  if (entries[TRANSFERS_FILE]) {
21022
21097
  log.info(`Parsing ${TRANSFERS_FILE}`);
21023
21098
  const transfersStart = performance.now();
21024
21099
  const transfersStream = yield zip.stream(TRANSFERS_FILE);
21025
- const { transfers: parsedTransfers, tripContinuations: parsedTripContinuations, guaranteedTripTransfers: parsedGuaranteedTripTransfers, } = yield parseTransfers(transfersStream, parsedStops, activeServiceIds);
21100
+ const { transfers: parsedTransfers, forbiddenTransfers: parsedForbiddenTransfers, tripContinuations: parsedTripContinuations, guaranteedTripTransfers: parsedGuaranteedTripTransfers, } = yield parseTransfers(transfersStream, parsedStops, activeServiceIds);
21026
21101
  transfers = parsedTransfers;
21102
+ forbiddenTransfers = parsedForbiddenTransfers;
21027
21103
  tripContinuationsList = parsedTripContinuations;
21028
21104
  guaranteedTripTransfersList = parsedGuaranteedTripTransfers;
21029
21105
  const transfersEnd = performance.now();
@@ -21045,6 +21121,12 @@ class GtfsParser {
21045
21121
  const serviceRoutes = indexRoutes(validGtfsRoutes, serviceRoutesMap);
21046
21122
  const stopTimesEnd = performance.now();
21047
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
+ }
21048
21130
  if (this.transferGenerator) {
21049
21131
  log.info('Generating virtual transfers');
21050
21132
  const virtualTransfersStart = performance.now();
@@ -21055,22 +21137,7 @@ class GtfsParser {
21055
21137
  stop.lon !== undefined);
21056
21138
  const stopsIndex = new StopsIndex(Array.from(parsedStops.values()));
21057
21139
  const generatedTransfers = yield this.transferGenerator.generate(originStops, stopsIndex);
21058
- let addedTransfers = 0;
21059
- for (const [fromStop, newTransfers] of generatedTransfers) {
21060
- const existing = getOrInsert(transfers, fromStop, []);
21061
- // Deduplicate per directed pair against existing (feed) transfers, and
21062
- // only keep transfers into stops a route actually calls at.
21063
- const connected = new Set(existing.map((t) => t.destination));
21064
- for (const transfer of newTransfers) {
21065
- if (!activeStopIds.has(transfer.destination) ||
21066
- connected.has(transfer.destination)) {
21067
- continue;
21068
- }
21069
- connected.add(transfer.destination);
21070
- existing.push(transfer);
21071
- addedTransfers += 1;
21072
- }
21073
- }
21140
+ const addedTransfers = addGeneratedTransfers(generatedTransfers, activeStopIds, transfers, forbiddenTransfers);
21074
21141
  const virtualTransfersEnd = performance.now();
21075
21142
  log.info(`${addedTransfers} virtual transfers added. (${(virtualTransfersEnd - virtualTransfersStart).toFixed(2)}ms)`);
21076
21143
  }
@@ -21241,9 +21308,29 @@ const routeTypeParser = (routeType) => {
21241
21308
  }
21242
21309
  };
21243
21310
  const extendedGtfsProfile = {
21311
+ deriveSiblingTransfers: true,
21244
21312
  routeTypeParser,
21245
21313
  };
21246
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
+
21247
21334
  const DEFAULT_MAX_DISTANCE_METERS = 500;
21248
21335
  const DEFAULT_WALKING_SPEED_KMH = 4;
21249
21336
  const DEFAULT_DETOUR_FACTOR = 1.3;