tfl-ts
Version:
🚇 Fully-typed TypeScript client for Transport for London (TfL) API • Zero dependencies • Auto-generated types • Real-time arrivals • Journey planning • Universal compatibility
436 lines (435 loc) • 17.5 kB
TypeScript
import { Api, TflApiPresentationEntitiesRoadCorridor, TflApiPresentationEntitiesRoadDisruption } from './generated/tfl';
import { ROAD_DATA } from './generated/jsdoc/Road';
import { RoadCategory, roadSeverity, SeverityDescription, SeverityByMode } from './generated/meta/Road';
type RoadCategoryType = RoadCategory;
type RoadSeverityType = roadSeverity;
type SeverityDescriptionType = SeverityDescription;
declare const ROAD_CATEGORIES: readonly RoadCategoryType[];
declare const ROAD_SEVERITY_DESCRIPTIONS: readonly SeverityDescriptionType[];
/**
* Query options for road status requests
* @example
* // Get status for specific roads
* const status = await client.road.getStatus({
* ids: ['A406', 'A2'],
* dateRange: {
* startDate: '2023-01-01',
* endDate: '2023-01-31'
* }
* });
*/
interface RoadStatusQuery {
/** Comma-separated list of road identifiers (e.g., 'A406, A2') or 'all' for all roads */
ids: string[];
/** Optional date range for filtering */
dateRange?: {
/** Start date in ISO format */
startDate: string;
/** End date in ISO format */
endDate: string;
};
/** Whether to keep $type fields in the response */
keepTflTypes?: boolean;
}
/**
* Query options for road disruption requests
* @example
* // Get disruptions for specific roads
* const disruptions = await client.road.getDisruptions({
* ids: ['A406', 'A2'],
* stripContent: false,
* severities: ['Good Service', 'Minor Delays']
* });
*/
interface RoadDisruptionQuery {
/** Comma-separated list of road identifiers (e.g., 'A406, A2') or 'all' for all roads */
ids: string[];
/** Whether to strip content to essential fields only */
stripContent?: boolean;
/** Array of severity names to filter on */
severities?: SeverityDescriptionType[];
/** Array of category names to filter on */
categories?: RoadCategoryType[];
/** Whether to always include road closures regardless of severity filter */
closures?: boolean;
/** Whether to keep $type fields in the response */
keepTflTypes?: boolean;
}
/**
* Query options for road street disruption requests
* @example
* // Get disrupted streets
* const streets = await client.road.getDisruptedStreets({
* startDate: '2023-01-01',
* endDate: '2023-01-31'
* });
*/
interface RoadStreetDisruptionQuery {
/** Start time to filter on */
startDate: string;
/** End time to filter on */
endDate: string;
/** Whether to keep $type fields in the response */
keepTflTypes?: boolean;
}
/**
* Query options for road disruption by ID requests
* @example
* // Get specific disruptions by ID
* const disruption = await client.road.getDisruptionById({
* disruptionIds: ['12345', '67890'],
* stripContent: true
* });
*/
interface RoadDisruptionByIdQuery {
/** Comma-separated list of disruption identifiers */
disruptionIds: string[];
/** Whether to strip content to essential fields only */
stripContent?: boolean;
/** Whether to keep $type fields in the response */
keepTflTypes?: boolean;
}
/**
* Road corridor information returned by the TfL API
* @example
* {
* id: "A406",
* displayName: "North Circular (A406)",
* group: "Red Routes",
* statusSeverity: "Good Service",
* statusSeverityDescription: "No issues reported"
* }
*/
export interface RoadCorridorInfo {
/** Unique identifier for the road */
id: string;
/** Display name of the road */
displayName: string;
/** Road group classification */
group: string;
/** Status severity level */
statusSeverity: string;
/** Description of the status severity */
statusSeverityDescription: string;
/** Additional road information */
[key: string]: any;
}
/**
* Road class for interacting with TfL Road API endpoints
* @example
* // Get all roads managed by TfL
* const allRoads = await client.road.get();
*
* // Get status for specific roads
* const status = await client.road.getStatus({ ids: ['A406', 'A2'] });
*
* // Get disruptions for roads
* const disruptions = await client.road.getDisruptions({ ids: ['A406'] });
*
* // Access static metadata (no HTTP request)
* const categories = client.road.ROAD_CATEGORIES;
* const severities = client.road.ROAD_SEVERITY_DESCRIPTIONS;
*/
export declare class Road {
private api;
/** Available API endpoints (static, no HTTP request needed) */
readonly ENDPOINTS: readonly [{
readonly path: "/Road";
readonly method: "GET";
readonly summary: "Gets all roads managed by TfL";
readonly parameters: readonly [];
readonly returnType: "RoadCorridor[]";
readonly deprecated: false;
readonly tags: readonly ["Road"];
}, {
readonly path: "/Road/{ids}";
readonly method: "GET";
readonly summary: "Gets the road with the specified id (e.g. A1)";
readonly parameters: readonly [{
readonly name: "ids";
readonly type: "any";
readonly required: true;
readonly description: "Comma-separated list of road identifiers e.g. \"A406, A2\" (a full list of supported road identifiers can be found at the /Road/ endpoint)";
}];
readonly returnType: "RoadCorridor[]";
readonly deprecated: false;
readonly tags: readonly ["Road"];
}, {
readonly path: "/Road/{ids}/Status";
readonly method: "GET";
readonly summary: "Gets the specified roads with the status aggregated over the date range specified, or now until the end of today if no dates are passed.";
readonly parameters: readonly [{
readonly name: "ids";
readonly type: "any";
readonly required: true;
readonly description: "Comma-separated list of road identifiers e.g. \"A406, A2\" or use \"all\" to ignore id filter (a full list of supported road identifiers can be found at the /Road/ endpoint)";
}, {
readonly name: "dateRangeNullable.startDate";
readonly type: "string";
readonly required: false;
}, {
readonly name: "dateRangeNullable.endDate";
readonly type: "string";
readonly required: false;
}];
readonly returnType: "RoadCorridor[]";
readonly deprecated: false;
readonly tags: readonly ["Road"];
}, {
readonly path: "/Road/{ids}/Disruption";
readonly method: "GET";
readonly summary: "Get active disruptions, filtered by road ids";
readonly parameters: readonly [{
readonly name: "ids";
readonly type: "any";
readonly required: true;
readonly description: "Comma-separated list of road identifiers e.g. \"A406, A2\" use all for all to ignore id filter (a full list of supported road identifiers can be found at the /Road/ endpoint)";
}, {
readonly name: "stripContent";
readonly type: "boolean";
readonly required: false;
readonly description: "Optional, defaults to false. When true, removes every property/node except for id, point, severity, severityDescription, startDate, endDate, corridor details, location, comments and streets";
}, {
readonly name: "severities";
readonly type: "any";
readonly required: false;
readonly description: "an optional list of Severity names to filter on (a valid list of severities can be obtained from the /Road/Meta/severities endpoint)";
}, {
readonly name: "categories";
readonly type: "any";
readonly required: false;
readonly description: "an optional list of category names to filter on (a valid list of categories can be obtained from the /Road/Meta/categories endpoint)";
}, {
readonly name: "closures";
readonly type: "boolean";
readonly required: false;
readonly description: "Optional, defaults to true. When true, always includes disruptions that have road closures, regardless of the severity filter. When false, the severity filter works as normal.";
}];
readonly returnType: "RoadDisruption[]";
readonly deprecated: false;
readonly tags: readonly ["Road"];
}, {
readonly path: "/Road/all/Street/Disruption";
readonly method: "GET";
readonly summary: "Gets a list of disrupted streets. If no date filters are provided, current disruptions are returned.";
readonly parameters: readonly [{
readonly name: "startDate";
readonly type: "string";
readonly required: true;
readonly description: "Optional, the start time to filter on.";
}, {
readonly name: "endDate";
readonly type: "string";
readonly required: true;
readonly description: "Optional, The end time to filter on.";
}];
readonly returnType: "Object";
readonly deprecated: false;
readonly tags: readonly ["Road"];
}, {
readonly path: "/Road/all/Disruption/{disruptionIds}";
readonly method: "GET";
readonly summary: "Gets a list of active disruptions filtered by disruption Ids.";
readonly parameters: readonly [{
readonly name: "disruptionIds";
readonly type: "any";
readonly required: true;
readonly description: "Comma-separated list of disruption identifiers to filter by.";
}, {
readonly name: "stripContent";
readonly type: "boolean";
readonly required: false;
readonly description: "Optional, defaults to false. When true, removes every property/node except for id, point, severity, severityDescription, startDate, endDate, corridor details, location and comments.";
}];
readonly returnType: "RoadDisruption";
readonly deprecated: false;
readonly tags: readonly ["Road"];
}];
/** Total number of available endpoints (static, no HTTP request needed) */
readonly TOTAL_ENDPOINTS: 6;
/** API section name (static, no HTTP request needed) */
readonly SECTION: "Road";
/** Generation timestamp (static, no HTTP request needed) */
readonly GENERATED_AT: "2025-07-10T01:28:59.106Z";
/** Available road categories (static, no HTTP request needed) */
readonly ROAD_CATEGORIES: readonly RoadCategoryType[];
/** Available road severity descriptions (static, no HTTP request needed) */
readonly ROAD_SEVERITY_DESCRIPTIONS: readonly SeverityDescriptionType[];
/** Road severity by mode mapping (static, no HTTP request needed) */
readonly SEVERITY_BY_MODE: {
readonly road: "roadSeverity";
};
constructor(api: Api<{}>);
/**
* Gets all roads managed by TfL
*
* This method returns a comprehensive list of all roads managed by TfL,
* including major arterial routes, red routes, and other strategic roads.
*
* @param options - Options for the request
* @returns Promise resolving to an array of road corridors
* @example
* // Get all roads managed by TfL
* const allRoads = await client.road.get();
*
* // Get roads with type fields preserved
* const allRoads = await client.road.get({ keepTflTypes: true });
*
* // Process road data
* allRoads.forEach(road => {
* console.log(`${road.displayName}: ${road.statusSeverityDescription}`);
* });
*/
get(options?: {
keepTflTypes?: boolean;
}): Promise<TflApiPresentationEntitiesRoadCorridor[]>;
/**
* Gets the road with the specified id
*
* This method returns detailed information about specific roads by their identifiers.
*
* @param ids - Array of road identifiers (e.g., ['A406', 'A2'])
* @param options - Options for the request
* @returns Promise resolving to an array of road corridors
* @example
* // Get specific roads by ID
* const roads = await client.road.getById(['A406', 'A2']);
*
* // Get single road
* const road = await client.road.getById(['A406']);
*/
getById(ids: string[], options?: {
keepTflTypes?: boolean;
}): Promise<TflApiPresentationEntitiesRoadCorridor[]>;
/**
* Gets the specified roads with the status aggregated over the date range specified
*
* This method returns road status information aggregated over a specified date range,
* or from now until the end of today if no dates are provided.
*
* @param options - Query options for road status
* @returns Promise resolving to an array of road corridors with status
* @example
* // Get status for specific roads
* const status = await client.road.getStatus({
* ids: ['A406', 'A2'],
* dateRange: {
* startDate: '2023-01-01',
* endDate: '2023-01-31'
* }
* });
*
* // Get current status for all roads
* const allStatus = await client.road.getStatus({ ids: ['all'] });
*
* // Get status with type fields preserved
* const status = await client.road.getStatus({
* ids: ['A406'],
* keepTflTypes: true
* });
*/
getStatus(options: RoadStatusQuery): Promise<TflApiPresentationEntitiesRoadCorridor[]>;
/**
* Get active disruptions, filtered by road ids
*
* This method returns active road disruptions with optional filtering by
* severity, category, and content stripping options.
*
* @param options - Query options for road disruptions
* @returns Promise resolving to an array of road disruptions
* @example
* // Get disruptions for specific roads
* const disruptions = await client.road.getDisruptions({
* ids: ['A406', 'A2'],
* stripContent: false,
* severities: ['Good Service', 'Minor Delays']
* });
*
* // Get all disruptions for all roads
* const allDisruptions = await client.road.getDisruptions({
* ids: ['all'],
* categories: ['RealTime', 'PlannedWork']
* });
*
* // Get minimal disruption data
* const minimalDisruptions = await client.road.getDisruptions({
* ids: ['A406'],
* stripContent: true
* });
*/
getDisruptions(options: RoadDisruptionQuery): Promise<TflApiPresentationEntitiesRoadDisruption[]>;
/**
* Gets a list of disrupted streets
*
* This method returns a list of streets that are currently disrupted.
* If no date filters are provided, current disruptions are returned.
*
* @param options - Query options for street disruptions
* @returns Promise resolving to disrupted streets data
* @example
* // Get disrupted streets for a date range
* const streets = await client.road.getDisruptedStreets({
* startDate: '2023-01-01',
* endDate: '2023-01-31'
* });
*
* // Get current disrupted streets
* const currentStreets = await client.road.getDisruptedStreets({
* startDate: new Date().toISOString(),
* endDate: new Date().toISOString()
* });
*/
getDisruptedStreets(options: RoadStreetDisruptionQuery): Promise<any>;
/**
* Gets a list of active disruptions filtered by disruption Ids
*
* This method returns specific disruptions by their identifiers,
* with optional content stripping for minimal data.
*
* @param options - Query options for disruption by ID
* @returns Promise resolving to road disruption data
* @example
* // Get specific disruptions by ID
* const disruption = await client.road.getDisruptionById({
* disruptionIds: ['12345', '67890'],
* stripContent: true
* });
*
* // Get full disruption details
* const fullDisruption = await client.road.getDisruptionById({
* disruptionIds: ['12345'],
* stripContent: false
* });
*/
getDisruptionById(options: RoadDisruptionByIdQuery): Promise<TflApiPresentationEntitiesRoadDisruption>;
/**
* Get road metadata (makes HTTP request to TfL API)
*
* This method fetches live metadata from the TfL API. For static metadata
* that doesn't change frequently, consider using the static properties
* instead to save HTTP round trips.
*
* @param options - Options for metadata request
* @returns Promise resolving to road metadata
* @example
* // Get live metadata from TfL API
* const meta = await client.road.getMeta();
*
* // Use static metadata instead (no HTTP request)
* const categories = client.road.ROAD_CATEGORIES;
* const severities = client.road.ROAD_SEVERITY_DESCRIPTIONS;
*/
getMeta(options?: {
keepTflTypes?: boolean;
}): Promise<{
endpoints: typeof ROAD_DATA.endpoints;
totalEndpoints: number;
section: string;
generatedAt: string;
categories: readonly RoadCategoryType[];
severities: readonly SeverityDescriptionType[];
severityByMode: typeof SeverityByMode;
}>;
}
export { RoadStatusQuery, RoadDisruptionQuery, RoadStreetDisruptionQuery, RoadDisruptionByIdQuery };
export { RoadCategoryType, RoadSeverityType, SeverityDescriptionType, ROAD_CATEGORIES, ROAD_SEVERITY_DESCRIPTIONS, SeverityByMode, ROAD_DATA };