+57
-0
@@ -11,2 +11,5 @@ import { defaultEndpoints, subwayRouteColors } from "./src/defaults"; | ||
| BusArrivalQuery, | ||
| BusArrivalBoardQuery, | ||
| BusArrivalBoardStop, | ||
| BusRouteStopsQuery, | ||
| BusVehicleQuery, | ||
@@ -18,7 +21,15 @@ Direction, | ||
| Route, | ||
| RouteCatalogEntry, | ||
| RouteStopsResponse, | ||
| RoutesListQuery, | ||
| Stop, | ||
| StopLookup, | ||
| StopsByIdsQuery, | ||
| StopsNearQuery, | ||
| SubwayArrivalQuery, | ||
| SubwayArrivalBoardQuery, | ||
| SubwayArrivalBoardStation, | ||
| SubwayDirectionQuery, | ||
| SubwayDirectionResolution, | ||
| SubwayRouteStationsQuery, | ||
| TransitMode, | ||
@@ -34,2 +45,3 @@ Vehicle, | ||
| readonly stops: StopsClient; | ||
| readonly routes: RoutesClient; | ||
@@ -68,2 +80,3 @@ readonly fetch: typeof fetch; | ||
| this.stops = new StopsClient(this); | ||
| this.routes = new RoutesClient(this); | ||
| } | ||
@@ -146,2 +159,20 @@ | ||
| arrivalBoard(query: SubwayArrivalBoardQuery): Promise<SubwayArrivalBoardStation[]> { | ||
| return this.mta.hostedJson<SubwayArrivalBoardStation[]>("/api/v1/subway/arrival-board", { | ||
| ...query, | ||
| route: query.route ? normalizeRouteId(query.route) : undefined, | ||
| }); | ||
| } | ||
| routeStations(query: SubwayRouteStationsQuery): Promise<RouteStopsResponse> { | ||
| return this.mta.hostedJson<RouteStopsResponse>( | ||
| `/api/v1/subway/routes/${encodeURIComponent(normalizeRouteId(query.route))}/stations`, | ||
| { | ||
| ...query, | ||
| route: undefined, | ||
| direction: normalizeDirection(query.direction, query.route), | ||
| }, | ||
| ); | ||
| } | ||
| private feedForRoute(route: string) { | ||
@@ -304,2 +335,16 @@ const feed = this.mta.endpoints.subwayFeeds[route]; | ||
| arrivalBoard(query: BusArrivalBoardQuery): Promise<BusArrivalBoardStop[]> { | ||
| return this.mta.hostedJson<BusArrivalBoardStop[]>("/api/v1/bus/arrival-board", query); | ||
| } | ||
| routeStops(query: BusRouteStopsQuery): Promise<RouteStopsResponse> { | ||
| return this.mta.hostedJson<RouteStopsResponse>( | ||
| `/api/v1/bus/routes/${encodeURIComponent(query.route)}/stops`, | ||
| { | ||
| ...query, | ||
| route: undefined, | ||
| }, | ||
| ); | ||
| } | ||
| private requireKey() { | ||
@@ -370,4 +415,16 @@ if (!this.mta.busTimeKey) throw new MissingBusTimeKeyError(); | ||
| } | ||
| byIds(query: StopsByIdsQuery): Promise<StopLookup[]> { | ||
| return this.mta.hostedJson<StopLookup[]>("/api/v1/stops", query); | ||
| } | ||
| } | ||
| class RoutesClient { | ||
| constructor(private readonly mta: MTA) {} | ||
| list(query: RoutesListQuery = {}): Promise<RouteCatalogEntry[]> { | ||
| return this.mta.hostedJson<RouteCatalogEntry[]>("/api/v1/routes", query); | ||
| } | ||
| } | ||
| function serializeHostedQuery(query: object) { | ||
@@ -374,0 +431,0 @@ const params: Record<string, string | number | boolean | undefined> = {}; |
+1
-1
| { | ||
| "name": "mta-js", | ||
| "version": "2.2.0", | ||
| "version": "2.3.0", | ||
| "description": "A TypeScript client for MTA realtime feeds and the hosted MTA API.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+45
-5
@@ -10,3 +10,3 @@ # mta-js | ||
| ```ts | ||
| ```js | ||
| import { MTA } from "mta-js"; | ||
@@ -36,2 +36,36 @@ | ||
| }); | ||
| const subwayBoard = await mta.subway.arrivalBoard({ | ||
| lat: 40.7356, | ||
| lon: -73.9906, | ||
| limitStations: 5, | ||
| limitArrivals: 3, | ||
| }); | ||
| const busBoard = await mta.bus.arrivalBoard({ | ||
| lat: 40.7421, | ||
| lon: -73.9914, | ||
| route: "M23", | ||
| limitStops: 8, | ||
| limitArrivals: 3, | ||
| }); | ||
| const favoriteStops = await mta.stops.byIds({ | ||
| ids: ["A27", "L06", "308214"], | ||
| includeRoutes: true, | ||
| }); | ||
| const routes = await mta.routes.list({ | ||
| modes: ["subway", "bus"], | ||
| }); | ||
| const lStations = await mta.subway.routeStations({ | ||
| route: "L", | ||
| direction: "uptown", | ||
| }); | ||
| const m23Stops = await mta.bus.routeStops({ | ||
| route: "M23", | ||
| direction: 0, | ||
| }); | ||
| ``` | ||
@@ -43,6 +77,6 @@ | ||
| ```ts | ||
| ```js | ||
| for (const arrival of lTrain) { | ||
| console.log( | ||
| `${arrival.route.shortName} ${arrival.displayDirection} from ${arrival.stop.displayName}`, | ||
| `${arrival.route.shortName} ${arrival.displayDirection ?? arrival.destination ?? "unknown direction"} from ${arrival.stop.displayName ?? arrival.stop.name}`, | ||
| ); | ||
@@ -69,3 +103,3 @@ } | ||
| ```ts | ||
| ```js | ||
| const mta = new MTA({ | ||
@@ -84,3 +118,3 @@ busTimeKey: process.env.MTA_BUS_KEY, | ||
| ```ts | ||
| ```js | ||
| const mta = new MTA({ | ||
@@ -123,6 +157,12 @@ staticData: { | ||
| - `mta.subway.arrivals(...)` | ||
| - `mta.subway.arrivalBoard(...)` | ||
| - `mta.subway.direction(...)` | ||
| - `mta.subway.routeStations(...)` | ||
| - `mta.bus.arrivals(...)` | ||
| - `mta.bus.arrivalBoard(...)` | ||
| - `mta.bus.routeStops(...)` | ||
| - `mta.bus.vehicles(...)` | ||
| - `mta.alerts.current(...)` | ||
| - `mta.routes.list(...)` | ||
| - `mta.stops.byIds(...)` | ||
| - `mta.stops.near(...)` |
+101
-1
@@ -22,5 +22,7 @@ import type { | ||
| export type TransitMode = "subway" | "bus" | "lirr" | "metro-north"; | ||
| export type StopMode = "subway" | "bus"; | ||
| export type Direction = "north" | "south" | "east" | "west" | "unknown"; | ||
| export type SubwayResolvedDirection = "north" | "south"; | ||
| export type SubwayDirectionAlias = Direction | "uptown" | "downtown"; | ||
@@ -161,2 +163,13 @@ export type DirectionHeadsigns = Record<string, string[]>; | ||
| export type StopLookup = { | ||
| requestedId: string; | ||
| found: boolean; | ||
| stop?: Stop; | ||
| servedRoutes?: ServedRoute[]; | ||
| }; | ||
| export type RouteCatalogEntry = Route & { | ||
| mode: StopMode; | ||
| }; | ||
| export interface Arrival { | ||
@@ -212,3 +225,3 @@ mode: TransitMode; | ||
| route?: SubwayRoute; | ||
| direction?: Direction | "uptown" | "downtown"; | ||
| direction?: SubwayDirectionAlias; | ||
| limit?: number; | ||
@@ -218,2 +231,24 @@ includeRaw?: boolean; | ||
| export interface SubwayArrivalBoardQuery { | ||
| lat: number; | ||
| lon: number; | ||
| route?: SubwayRoute; | ||
| radiusMeters?: number; | ||
| limitStations?: number; | ||
| limitArrivals?: number; | ||
| includeRaw?: boolean; | ||
| } | ||
| export type ArrivalBoardDirection = { | ||
| direction: Direction; | ||
| headsign?: string; | ||
| arrivals: Arrival[]; | ||
| }; | ||
| export type SubwayArrivalBoardStation = { | ||
| station: Stop; | ||
| distanceMeters: number; | ||
| directions: ArrivalBoardDirection[]; | ||
| }; | ||
| export interface SubwayDirectionQuery { | ||
@@ -246,2 +281,24 @@ route: SubwayRoute; | ||
| export interface BusArrivalBoardQuery { | ||
| lat: number; | ||
| lon: number; | ||
| route?: BusRoute; | ||
| radiusMeters?: number; | ||
| limitStops?: number; | ||
| limitArrivals?: number; | ||
| includeRaw?: boolean; | ||
| } | ||
| export type BusArrivalBoardRoute = { | ||
| route: Route; | ||
| headsign?: string; | ||
| arrivals: Arrival[]; | ||
| }; | ||
| export type BusArrivalBoardStop = { | ||
| stop: Stop; | ||
| distanceMeters: number; | ||
| routes: BusArrivalBoardRoute[]; | ||
| }; | ||
| export interface BusVehicleQuery { | ||
@@ -270,1 +327,44 @@ route?: BusRoute; | ||
| } | ||
| export interface StopsByIdsQuery { | ||
| ids: StopId[]; | ||
| includeRoutes?: boolean; | ||
| } | ||
| export interface RoutesListQuery { | ||
| modes?: StopMode[]; | ||
| } | ||
| export type RoutePatternStop = Stop & { | ||
| arrivals?: Arrival[]; | ||
| }; | ||
| export type RoutePattern = { | ||
| direction: string; | ||
| headsigns?: string[]; | ||
| stops: RoutePatternStop[]; | ||
| }; | ||
| export type RouteStopsResponse = { | ||
| route: Route; | ||
| mode: StopMode; | ||
| directions: RoutePattern[]; | ||
| }; | ||
| export interface SubwayRouteStationsQuery { | ||
| route: SubwayRoute; | ||
| direction?: SubwayDirectionAlias; | ||
| includeArrivals?: boolean; | ||
| limitArrivals?: number; | ||
| limitStops?: number; | ||
| includeRaw?: boolean; | ||
| } | ||
| export interface BusRouteStopsQuery { | ||
| route: BusRoute; | ||
| direction?: number | string; | ||
| includeArrivals?: boolean; | ||
| limitArrivals?: number; | ||
| limitStops?: number; | ||
| includeRaw?: boolean; | ||
| } |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
144982
3.25%9047
1.51%163
32.52%