UNPKG

minotor

Version:

A lightweight client-side transit routing library.

173 lines (172 loc) 7.53 kB
import { StopId } from '../stops/stops.js'; import { Route, RouteId, StopRouteIndex, TripRouteIndex } from './route.js'; import { Duration, Time } from './time.js'; import { TripStopId } from './tripStopId.js'; export declare const TransferTypes: { readonly RECOMMENDED: 1; readonly GUARANTEED: 2; readonly REQUIRES_MINIMAL_TIME: 3; readonly IN_SEAT: 4; }; export type TransferType = (typeof TransferTypes)[keyof typeof TransferTypes]; export type TransferTypeString = keyof typeof TransferTypes; export type Transfer = { destination: StopId; type: TransferType; minTransferTime?: Duration; }; export type TripStop = { stopIndex: StopRouteIndex; routeId: RouteId; tripIndex: TripRouteIndex; }; export type StopAdjacency = { transfers?: Transfer[]; routes: RouteId[]; }; export type TripTransfers = Map<TripStopId, TripStop[]>; export type ServiceRouteId = number; export declare const RouteTypes: { readonly TRAM: 1; readonly SUBWAY: 2; readonly RAIL: 3; readonly BUS: 4; readonly FERRY: 5; readonly CABLE_TRAM: 6; readonly AERIAL_LIFT: 7; readonly FUNICULAR: 8; readonly TROLLEYBUS: 9; readonly MONORAIL: 10; }; export type RouteType = (typeof RouteTypes)[keyof typeof RouteTypes]; export type RouteTypeString = keyof typeof RouteTypes; export type ServiceRoute = { type: RouteType; name: string; routes: RouteId[]; }; export type ServiceRouteInfo = Omit<ServiceRoute, 'routes'>; export declare const ALL_TRANSPORT_MODES: Set<RouteType>; /** * The internal transit timetable format. */ export declare class Timetable { private readonly stopsAdjacency; private readonly routesAdjacency; private readonly serviceRoutes; private readonly tripContinuations?; private readonly guaranteedTripTransfers?; private readonly activeStops; constructor(stopsAdjacency: StopAdjacency[], routesAdjacency: Route[], routes: ServiceRoute[], tripContinuations?: TripTransfers, guaranteedTripTransfers?: TripTransfers); /** * Serializes the Timetable into a binary array. * * @returns The serialized binary data. */ serialize(): Uint8Array; /** * Deserializes a binary protobuf into a Timetable object. * * @param data - The binary data to deserialize. * @returns The deserialized Timetable object. */ static fromData(data: Uint8Array): Timetable; /** * Checks if the given stop is active on the timetable. * An active stop is a stop reached by a route that is active on the timetable * or by a transfer reachable from an active route. * * @param stopId - The ID of the stop to check. * @returns True if the stop is active, false otherwise. */ isActive(stopId: StopId): boolean; /** * Returns the total number of stops in the timetable. */ nbStops(): number; /** * Retrieves the route associated with the given route ID. * * @param routeId - The ID of the route to be retrieved. * @returns The route corresponding to the provided ID, * or undefined if no such route exists. */ getRoute(routeId: RouteId): Route | undefined; /** * Retrieves all transfer options available at the specified stop. * * @param stopId - The ID of the stop to get transfers for. * @returns An array of transfer options available at the stop. */ getTransfers(stopId: StopId): Transfer[]; /** * Retrieves all trip continuation options available at the specified stop for a given trip. * * @param stopIndex - The index in the route of the stop to get trip continuations for. * @param routeId - The ID of the route to get continuations for. * @param tripIndex - The index of the trip to get continuations for. * @returns An array of trip continuation options available at the stop for the specified trip. */ getContinuousTrips(stopIndex: StopRouteIndex, routeId: RouteId, tripIndex: TripRouteIndex): TripStop[]; /** * Retrieves the service route associated with the given route. * A service route refers to a collection of trips that are displayed * to riders as a single service. * * @param route - The route for which the service route is to be retrieved. * @returns The service route corresponding to the provided route. */ getServiceRouteInfo(route: Route): ServiceRouteInfo; /** * Finds all routes passing through a stop. * * @param stopId - The ID of the stop to find routes for. * @returns An array of routes passing through the specified stop. */ routesPassingThrough(stopId: StopId): Route[]; /** * Finds routes that are reachable from a set of stop IDs. * Also identifies the first stop index available to hop on each route among * the input stops. * * @param fromStops - The set of stop IDs to find reachable routes from. * @param transportModes - The set of transport modes to consider for reachable routes. * @returns A map of reachable routes to the first stop index available to hop on each route. */ findReachableRoutes(fromStops: Set<StopId>, transportModes?: Set<RouteType>): Map<Route, StopRouteIndex>; /** * Checks if a trip transfer is guaranteed for a given trip boarding. * * @param fromTripStop - The trip stop for the trip transfer origin. * @param toTripStop - The trip stop to check if it's guaranteed. * @returns True if the trip transfer is guaranteed, false otherwise. */ isTripTransferGuaranteed(fromTripStop: TripStop, toTripStop: TripStop): boolean; /** * Finds the first trip on `route` at `stopIndex` that can be boarded, starting * from `earliestTrip` and respecting pickup availability, transfer guarantees, * and minimum transfer times. * * @param stopIndex Stop at which boarding is attempted. * @param route The route to search. * @param earliestTrip First trip index to consider. * @param after Earliest time after which boarding is allowed. * @param beforeTrip Exclusive upper bound on the trip index (omit to search all). * @param fromTripStop The alighted trip stop when transferring from another trip; * `undefined` when boarding from a walk or origin. * @param transferTime Minimum transfer time required between trips. * @returns The index of the first boardable trip, or `undefined` if none found. */ findFirstBoardableTrip(stopIndex: StopRouteIndex, route: Route, earliestTrip: TripRouteIndex, after?: Time, beforeTrip?: TripRouteIndex, fromTripStop?: TripStop, transferTime?: Duration): TripRouteIndex | undefined; /** * Retrieves all guaranteed trip transfer options available at the specified stop for a given trip. * * @param stopIndex - The index in the route of the stop to get guaranteed trip transfers for. * @param routeId - The ID of the route to get guaranteed transfers for. * @param tripIndex - The index of the trip to get guaranteed transfers for. * @returns An array of trip boarding options that are guaranteed for the specified trip. */ getGuaranteedTripTransfers(stopIndex: StopRouteIndex, routeId: RouteId, tripIndex: TripRouteIndex): TripStop[]; } export declare const routeTypeToString: (type: RouteType) => RouteTypeString; export declare const transferTypeToString: (type: TransferType) => TransferTypeString;