UNPKG

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

115 lines (114 loc) 3.96 kB
import { Api, TflApiPresentationEntitiesAccidentStatsAccidentDetail as TflAccidentDetail } from './generated/tfl'; /** * Query options for accident statistics requests * @example * // Get accident statistics for 2023 * const accidents = await client.accidentStats.get({ year: 2023 }); */ interface AccidentStatsQuery { /** The year for which to filter the accidents on */ year: number; /** Whether to keep $type fields in the response */ keepTflTypes?: boolean; } /** * Accident statistics information returned by the TfL API * @example * { * id: 12345, * lat: 51.5074, * lon: -0.1278, * location: "Oxford Street, London", * date: "2023-01-15T10:30:00Z", * severity: "Slight", * borough: "Westminster", * casualties: [ * { * age: 25, * class: "Pedestrian", * severity: "Slight" * } * ] * } */ export interface AccidentStatsInfo { /** Unique identifier for the accident */ id: number; /** Latitude coordinate of the accident location */ lat: number; /** Longitude coordinate of the accident location */ lon: number; /** Human-readable location description */ location: string; /** Date and time of the accident */ date: string; /** Severity level of the accident */ severity: string; /** Borough where the accident occurred */ borough: string; /** Additional accident information */ [key: string]: any; } /** * ⚠️ **DEPRECATED API - NOT RECOMMENDED FOR USE** * * Access accident statistics for London roads. * * This API appears to be poorly maintained on TfL's side and may not return * current or reliable data. Recent testing shows that most years return * "Invalid year parameter" errors, suggesting the API is no longer actively * supported. * * **RECOMMENDED ALTERNATIVES:** * - London Datastore: https://data.london.gov.uk/dataset/?tags=GIS&tag=accidents * - TfL Road Safety Data: https://tfl.gov.uk/corporate/publications-and-reports/road-safety * * This is a simple API that provides accident statistics data by year. * No metadata constants are provided as this API only deals with accident data. * * @example * // Get accident statistics for a specific year * const accidents = await client.accidentStats.get({ year: 2023 }); * * // Process accident data * accidents.forEach(accident => { * console.log(`Accident on ${accident.date} at ${accident.location}`); * console.log(`Severity: ${accident.severity}, Borough: ${accident.borough}`); * }); */ export declare class AccidentStats { private api; constructor(api: Api<{}>); /** * Gets all accident details for accidents occurring in the specified year * * ⚠️ **WARNING: This method is part of a deprecated API.** * See the class documentation above for details and recommended alternatives. * * This method returns comprehensive accident statistics including: * - Location details (coordinates, borough, street name) * - Accident details (date, time, severity) * - Casualty information (age, type, severity) * - Vehicle information (type, details) * * @param options - Query options for accident statistics * @returns Promise resolving to an array of accident details * @example * // Get all accidents from 2023 * const accidents = await client.accidentStats.get({ year: 2023 }); * * // Get accidents with type fields preserved * const accidents = await client.accidentStats.get({ * year: 2023, * keepTflTypes: true * }); * * // Process accident data * accidents.forEach(accident => { * console.log(`Accident on ${accident.date} at ${accident.location}`); * console.log(`Severity: ${accident.severity}, Borough: ${accident.borough}`); * }); */ get(options: AccidentStatsQuery): Promise<TflAccidentDetail[]>; } export { AccidentStatsQuery };