minotor
Version:
A lightweight client-side transit routing library.
107 lines (106 loc) • 3.85 kB
TypeScript
import { StopId } from '../stops/stops.js';
import { Duration } from './duration.js';
import { Time } from './time.js';
export type RouteId = string;
export declare const REGULAR = 0;
export declare const NOT_AVAILABLE = 1;
export declare const MUST_PHONE_AGENCY = 2;
export declare const MUST_COORDINATE_WITH_DRIVER = 3;
export type PickUpDropOffType = 0 | 1 | 2 | 3;
export type Route = {
/**
* Arrivals and departures encoded as minutes from midnight.
* Format: [arrival1, departure1, arrival2, departure2, etc.]
*/
stopTimes: Uint16Array;
/**
* PickUp and DropOff types represented as a binary Uint8Array.
* Values:
* 0: REGULAR
* 1: NOT_AVAILABLE
* 2: MUST_PHONE_AGENCY
* 3: MUST_COORDINATE_WITH_DRIVER
* Format: [pickupTypeStop1, dropOffTypeStop1, pickupTypeStop2, dropOffTypeStop2, etc.]
*/
pickUpDropOffTypes: Uint8Array;
/**
* A binary array of stopIds in the route.
* [stop1, stop2, stop3,...]
*/
stops: Uint32Array;
/**
* A reverse mapping of each stop with their index in the route:
* {
* 4: 0,
* 5: 1,
* ...
* }
*/
stopIndices: Map<StopId, number>;
/**
* The identifier of the route as a service shown to users.
*/
serviceRouteId: ServiceRouteId;
};
export type RoutesAdjacency = Map<RouteId, Route>;
export type TransferType = 'RECOMMENDED' | 'GUARANTEED' | 'REQUIRES_MINIMAL_TIME' | 'IN_SEAT';
export type Transfer = {
destination: StopId;
type: TransferType;
minTransferTime?: Duration;
};
export type StopsAdjacency = Map<StopId, {
transfers: Transfer[];
routes: RouteId[];
}>;
export type ServiceRouteId = string;
export type RouteType = 'TRAM' | 'SUBWAY' | 'RAIL' | 'BUS' | 'FERRY' | 'CABLE_TRAM' | 'AERIAL_LIFT' | 'FUNICULAR' | 'TROLLEYBUS' | 'MONORAIL';
export type ServiceRoute = {
type: RouteType;
name: string;
};
export type ServiceRoutesMap = Map<ServiceRouteId, ServiceRoute>;
type TripIndex = number;
export declare const ALL_TRANSPORT_MODES: RouteType[];
export declare const CURRENT_VERSION = "0.0.3";
/**
* The internal transit timetable format
* reuses some GTFS concepts for the sake of simplicity for now.
*/
export declare class Timetable {
private readonly stopsAdjacency;
private readonly routesAdjacency;
private readonly routes;
constructor(stopsAdjacency: StopsAdjacency, routesAdjacency: RoutesAdjacency, routes: ServiceRoutesMap);
/**
* Serializes the Timetable into a binary protobuf.
*
* @returns {Uint8Array} - The serialized binary data.
*/
serialize(): Uint8Array;
/**
* Deserializes a binary protobuf into a Timetable object.
*
* @param {Uint8Array} data - The binary data to deserialize.
* @returns {Timetable} - The deserialized Timetable object.
*/
static fromData(data: Uint8Array): Timetable;
getRoutesThroughStop(stopId: StopId): RouteId[];
getRoute(routeId: RouteId): Route | undefined;
getTransfers(stopId: StopId): Transfer[];
/**
* Finds routes that are reachable from a set of stop IDs.
* Also identifies the first stop available to hop on each route among
* the input stops.
*/
findReachableRoutes(fromStops: Set<StopId>, transportModes?: RouteType[]): Map<RouteId, StopId>;
getServiceRouteFromRouteId(routeId: RouteId): ServiceRoute | undefined;
getServiceRoute(serviceRouteId: ServiceRouteId): ServiceRoute | undefined;
/**
* Finds the earliest trip that can be taken from a specific stop on a given route,
* optionally constrained by a latest trip index and a time before which the trip
* should not depart.
*/
findEarliestTrip(route: Route, stopId: StopId, beforeTrip?: TripIndex, after?: Time): TripIndex | undefined;
}
export {};