UNPKG

minotor

Version:

A lightweight client-side transit routing library.

83 lines (82 loc) 4.03 kB
import { SourceStopId, StopId } from '../stops/stops.js'; import { ServiceRouteId, Timetable, Transfer, TripTransfers as TripTransfers } from '../timetable/timetable.js'; import { ServiceId, ServiceIds } from './services.js'; import { GtfsStopsMap } from './stops.js'; import { GtfsTripId, TripsMapping } from './trips.js'; export type GtfsTransferType = 0 | 1 | 2 | 3 | 4 | 5; export type TransfersMap = Map<StopId, Transfer[]>; /** * Directed stop pairs for which the feed explicitly disallows transfers. * * These constraints are retained during parsing so generated transfers do not * accidentally re-enable a connection declared with GTFS transfer_type=3. * They are not serialized into the routing timetable. */ export type ForbiddenTransfersMap = Map<StopId, Set<StopId>>; export type GtfsTripTransfer = { fromStop: StopId; fromTrip: GtfsTripId; toStop: StopId; toTrip: GtfsTripId; }; export type TransferEntry = { from_stop_id?: SourceStopId; to_stop_id?: SourceStopId; from_trip_id?: GtfsTripId; to_trip_id?: GtfsTripId; from_route_id?: ServiceRouteId; to_route_id?: ServiceRouteId; service_id?: ServiceId; transfer_type: GtfsTransferType; min_transfer_time?: number; }; /** * Parses the transfers.txt file from a GTFS feed. * * @param transfersStream The readable stream containing the transfers data. * @param stopsMap The parsed GTFS stops indexed by their source IDs. * @param activeServiceIds The service IDs active for the requested date. * @returns Parsed stop transfers, trip continuations, and guaranteed trip transfers. */ export declare const parseTransfers: (transfersStream: NodeJS.ReadableStream, stopsMap: GtfsStopsMap, activeServiceIds: ServiceIds) => Promise<{ transfers: TransfersMap; forbiddenTransfers: ForbiddenTransfersMap; tripContinuations: GtfsTripTransfer[]; guaranteedTripTransfers: GtfsTripTransfer[]; }>; /** * Adds missing directed transfers between route-served child stops belonging * to the same parent station. * * GTFS feeds commonly use parent_station to group platforms while omitting the * corresponding transfers.txt rows. The generated transfers intentionally do * not carry a fixed duration: routing applies the query's fallback minimum * transfer time. Explicit and forbidden feed entries always take precedence. * * @returns The number of directed sibling transfers added. */ export declare const addMissingSiblingTransfers: (stopsMap: GtfsStopsMap, activeStops: ReadonlySet<StopId>, transfers: TransfersMap, forbiddenTransfers?: ForbiddenTransfersMap) => number; /** * Merges generated transfers into parsed feed transfers. * * Only transfers between active stops are kept. Explicit feed transfers and * forbidden directed pairs take precedence over generated candidates. * * @returns The number of generated transfers added. */ export declare const addGeneratedTransfers: (generatedTransfers: ReadonlyMap<StopId, readonly Transfer[]>, activeStops: ReadonlySet<StopId>, transfers: TransfersMap, forbiddenTransfers?: ForbiddenTransfersMap) => number; /** * Builds trip continuations map from GTFS trip continuation data. * * This function processes GTFS in-seat transfer data and creates a mapping * from trip boarding IDs to continuation boarding information. It disambiguates * stop indices when routes have multiple stops with the same ID by finding * the most coherent transfer timing. * * @param tripsMapping Mapping from GTFS trip IDs to internal trip representations * @param gtfsTripTransfers Array of GTFS trip continuation data from transfers.txt * @param timetable The timetable containing route and timing information * @param activeStopIds Set of stop IDs that are active/enabled in the system * @returns A map from trip boarding IDs to arrays of continuation boarding options */ export declare const buildTripTransfers: (tripsMapping: TripsMapping, gtfsTripTransfers: GtfsTripTransfer[], timetable: Timetable, activeStopIds: Set<StopId>) => TripTransfers;