UNPKG

openf1-hooks

Version:

React Query hooks for the OpenF1 API

423 lines (407 loc) 14.2 kB
import * as _tanstack_react_query from '@tanstack/react-query'; import { UseQueryOptions, QueryKey } from '@tanstack/react-query'; /** * Base type for query parameters common to multiple endpoints. * Allows filtering by `session_key` and `meeting_key`. */ interface BaseParams { session_key?: number | 'latest'; meeting_key?: number | 'latest'; driver_number?: number; [key: string]: any; } /** * Represents the structure of a single car data entry from the API. */ interface CarData { brake: number; date: string; driver_number: number; drs: number; meeting_key: number; n_gear: number; rpm: number; session_key: number; speed: number; throttle: number; } /** * Type alias for query parameters for the car_data endpoint. * Uses BaseParams for common filters and allows specific car_data field filtering. */ type CarDataParams = BaseParams; /** * Represents the structure of a single driver entry from the API. */ interface Driver { broadcast_name: string; country_code: string; driver_number: number; first_name: string; full_name: string; headshot_url: string; last_name: string; meeting_key: number; name_acronym: string; session_key: number; team_colour: string; team_name: string; } /** * Type alias for query parameters for the drivers endpoint. */ type DriversParams = BaseParams; /** * Represents the structure of a single interval entry from the API. */ interface Interval { date: string; driver_number: number; gap_to_leader: number | string | null; interval: number | string | null; meeting_key: number; session_key: number; } /** * Type alias for query parameters for the intervals endpoint. */ type IntervalsParams = BaseParams; /** * Represents the structure of a single lap entry from the API. */ interface Lap { date_start: string; driver_number: number; duration_sector_1: number | null; duration_sector_2: number | null; duration_sector_3: number | null; i1_speed: number | null; i2_speed: number | null; is_pit_out_lap: boolean; lap_duration: number | null; lap_number: number; meeting_key: number; segments_sector_1: number[]; segments_sector_2: number[]; segments_sector_3: number[]; session_key: number; st_speed: number | null; } /** * Type alias for query parameters for the laps endpoint. * Adds `lap_number` to the base parameters. */ interface LapsParams extends BaseParams { lap_number?: number; } /** * Represents the structure of a single location entry (car position) from the API. */ interface Location { date: string; driver_number: number; meeting_key: number; session_key: number; x: number; y: number; z: number; } /** * Type alias for query parameters for the location endpoint. * Allows filtering by date ranges in addition to base params. */ interface LocationParams extends BaseParams { date?: string; } /** * Represents the structure of a single meeting (Grand Prix event) from the API. */ interface Meeting { circuit_key: number; circuit_short_name: string; country_code: string; country_key: number; country_name: string; date_start: string; gmt_offset: string; location: string; meeting_key: number; meeting_name: string; meeting_official_name: string; year: number; } /** * Type alias for query parameters for the meetings endpoint. */ interface MeetingsParams extends BaseParams { year?: number; country_name?: string; country_code?: string; circuit_key?: number; circuit_short_name?: string; meeting_name?: string; } /** * Represents the structure of a single pit stop entry from the API. */ interface Pit { date: string; driver_number: number; lap_number: number; meeting_key: number; pit_duration: number; session_key: number; } /** * Type alias for query parameters for the pit endpoint. */ interface PitParams extends BaseParams { lap_number?: number; pit_duration?: number; } /** * Represents the structure of a single position entry from the API. */ interface Position { date: string; driver_number: number; meeting_key: number; position: number; session_key: number; } /** * Type alias for query parameters for the position endpoint. */ interface PositionParams extends BaseParams { position?: number; } /** * Represents the structure of a single race control message from the API. */ interface RaceControl { category: string; date: string; driver_number: number | null; flag: string | null; lap_number: number | null; meeting_key: number; message: string; scope: string; sector: number | null; session_key: number; } /** * Type alias for query parameters for the race_control endpoint. */ interface RaceControlParams extends BaseParams { category?: string; flag?: string; lap_number?: number; scope?: string; sector?: number; date?: string; } /** * Represents the structure of a single session entry (Practice, Qualifying, Race) from the API. */ interface Session { circuit_key: number; circuit_short_name: string; country_code: string; country_key: number; country_name: string; date_end: string; date_start: string; gmt_offset: string; location: string; meeting_key: number; session_key: number; session_name: string; session_type: string; year: number; } /** * Type alias for query parameters for the sessions endpoint. */ interface SessionsParams extends BaseParams { year?: number; country_name?: string; country_code?: string; circuit_key?: number; circuit_short_name?: string; location?: string; session_name?: string; session_type?: string; } /** * Represents the structure of a single stint entry from the API. */ interface Stint { compound: string; driver_number: number; lap_end: number; lap_start: number; meeting_key: number; session_key: number; stint_number: number; tyre_age_at_start: number; } /** * Type alias for query parameters for the stints endpoint. */ interface StintsParams extends BaseParams { compound?: string; lap_start?: number; lap_end?: number; stint_number?: number; tyre_age_at_start?: number; } /** * Represents the structure of a single team radio recording entry from the API. */ interface TeamRadio { date: string; driver_number: number; meeting_key: number; recording_url: string; session_key: number; } /** * Type alias for query parameters for the team_radio endpoint. */ interface TeamRadioParams extends BaseParams { date?: string; } /** * Represents the structure of a single weather entry from the API. */ interface Weather { air_temperature: number; date: string; humidity: number; meeting_key: number; pressure: number; rainfall: number; session_key: number; track_temperature: number; wind_direction: number; wind_speed: number; } /** * Type alias for query parameters for the weather endpoint. */ interface WeatherParams extends BaseParams { air_temperature?: number; humidity?: number; pressure?: number; rainfall?: number; track_temperature?: number; wind_direction?: number; wind_speed?: number; date?: string; } /** * Custom hook to fetch car data from the OpenF1 API. * * @param params - Optional parameters to filter the car data (conforms to CarDataParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useCarData: (params?: CarDataParams, options?: Omit<UseQueryOptions<CarData[], Error, CarData[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<CarData[], Error>; /** * Custom hook to fetch driver data from the OpenF1 API. * * @param params - Optional parameters to filter the driver data (conforms to DriversParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useDrivers: (params?: DriversParams, options?: Omit<UseQueryOptions<Driver[], Error, Driver[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Driver[], Error>; /** * Custom hook to fetch interval data from the OpenF1 API. * * @param params - Optional parameters to filter the interval data (conforms to IntervalsParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useIntervals: (params?: IntervalsParams, options?: Omit<UseQueryOptions<Interval[], Error, Interval[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Interval[], Error>; /** * Custom hook to fetch lap data from the OpenF1 API. * * @param params - Optional parameters to filter the lap data (conforms to LapsParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useLaps: (params?: LapsParams, options?: Omit<UseQueryOptions<Lap[], Error, Lap[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Lap[], Error>; /** * Custom hook to fetch location data (car positions) from the OpenF1 API. * * @param params - Optional parameters to filter the location data (conforms to LocationParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useLocation: (params?: LocationParams, options?: Omit<UseQueryOptions<Location[], Error, Location[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Location[], Error>; /** * Custom hook to fetch meeting data (Grand Prix events) from the OpenF1 API. * * @param params - Optional parameters to filter the meeting data (conforms to MeetingsParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useMeetings: (params?: MeetingsParams, options?: Omit<UseQueryOptions<Meeting[], Error, Meeting[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Meeting[], Error>; /** * Custom hook to fetch pit stop data from the OpenF1 API. * * @param params - Optional parameters to filter the pit stop data (conforms to PitParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const usePit: (params?: PitParams, options?: Omit<UseQueryOptions<Pit[], Error, Pit[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Pit[], Error>; /** * Custom hook to fetch position data from the OpenF1 API. * * @param params - Optional parameters to filter the position data (conforms to PositionParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const usePosition: (params?: PositionParams, options?: Omit<UseQueryOptions<Position[], Error, Position[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Position[], Error>; /** * Custom hook to fetch race control messages from the OpenF1 API. * * @param params - Optional parameters to filter the race control messages (conforms to RaceControlParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useRaceControl: (params?: RaceControlParams, options?: Omit<UseQueryOptions<RaceControl[], Error, RaceControl[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<RaceControl[], Error>; /** * Custom hook to fetch session data from the OpenF1 API. * * @param params - Optional parameters to filter the session data (conforms to SessionsParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useSessions: (params?: SessionsParams, options?: Omit<UseQueryOptions<Session[], Error, Session[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Session[], Error>; /** * Custom hook to fetch stint data from the OpenF1 API. * * @param params - Optional parameters to filter the stint data (conforms to StintsParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useStints: (params?: StintsParams, options?: Omit<UseQueryOptions<Stint[], Error, Stint[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Stint[], Error>; /** * Custom hook to fetch team radio data from the OpenF1 API. * * @param params - Optional parameters to filter the team radio data (conforms to TeamRadioParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useTeamRadio: (params?: TeamRadioParams, options?: Omit<UseQueryOptions<TeamRadio[], Error, TeamRadio[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<TeamRadio[], Error>; /** * Custom hook to fetch weather data from the OpenF1 API. * * @param params - Optional parameters to filter the weather data (conforms to WeatherParams). * @param options - Optional React Query options. * @returns The result of the useQuery hook. */ declare const useWeather: (params?: WeatherParams, options?: Omit<UseQueryOptions<Weather[], Error, Weather[], QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<Weather[], Error>; export { type BaseParams, type CarData, type CarDataParams, type Driver, type DriversParams, type Interval, type IntervalsParams, type Lap, type LapsParams, type Location, type LocationParams, type Meeting, type MeetingsParams, type Pit, type PitParams, type Position, type PositionParams, type RaceControl, type RaceControlParams, type Session, type SessionsParams, type Stint, type StintsParams, type TeamRadio, type TeamRadioParams, type Weather, type WeatherParams, useCarData, useDrivers, useIntervals, useLaps, useLocation, useMeetings, usePit, usePosition, useRaceControl, useSessions, useStints, useTeamRadio, useWeather };