UNPKG

flight-planner

Version:

Plan and route VFR flights

86 lines (85 loc) 3.67 kB
import { ICAO } from "./index.js"; import { Aerodrome } from "./airport.js"; import { WeatherService } from "./weather-service.js"; /** * RepositoryBase interface defines the methods for fetching data from a repository. * * @interface RepositoryBase<T> * @template T - The type of data to be fetched. * @property {function(ICAO[]): Promise<T[]>} fetchByICAO - Fetches data by ICAO codes. * @property {function(GeoJSON.BBox): Promise<T[]>} [fetchByBbox] - Optional method to fetch data by bounding box. * @property {function(GeoJSON.Position, number): Promise<T[]>} [fetchByRadius] - Optional method to fetch data by radius. */ export interface RepositoryBase<T> { fetchByICAO(icao: ICAO[]): Promise<T[]>; fetchByBbox?(bbox: GeoJSON.BBox): Promise<T[]>; fetchByRadius?(location: GeoJSON.Position, distance: number): Promise<T[]>; } /** * AerodromeServiceOptions interface defines the options for initializing the AerodromeService. * * @interface AerodromeServiceOptions * @property {Aerodrome[]} [aerodromes] - Optional array of aerodromes to initialize the service with. * @property {RepositoryBase<Aerodrome>} [repository] - Optional repository for fetching aerodrome data. * @property {WeatherService} [weatherService] - Optional weather service for fetching METAR data. */ export interface AerodromeServiceOptions { aerodromes?: Aerodrome[]; repository?: RepositoryBase<Aerodrome>; weatherService?: WeatherService; } /** * AerodromeService class provides methods to manage and retrieve aerodrome data. * * @class AerodromeService * @property {Map<ICAO, Aerodrome>} aerodromes - A map of ICAO codes to Aerodrome objects. * @property {RepositoryBase<Aerodrome>} [repository] - Optional repository for fetching aerodrome data. * @property {WeatherService} [weatherService] - Optional weather service for fetching METAR data. */ export declare class AerodromeService { private aerodromes; private repository?; private weatherService?; /** * Creates a new instance of the AerodromeService class. * * @param options - An object containing optional properties for initializing the service. * @returns An instance of the AerodromeService class. */ constructor(options?: AerodromeServiceOptions); /** * Returns an array of ICAO codes for the aerodromes. * * @returns An array of ICAO codes. */ keys(): ICAO[]; /** * Returns an array of aerodromes. * * @returns An array of Aerodrome objects. */ values(): Aerodrome[]; /** * Adds aerodromes to the service. * * @param aerodromes - An array of Aerodrome objects or a single Aerodrome object to add. */ add(aerodromes: Aerodrome | Aerodrome[]): Promise<void>; /** * Finds an aerodrome by its ICAO code. * * @param icao - The ICAO code of the aerodrome. * @returns A promise that resolves to the aerodrome, or undefined if not found. */ get(icao: string): Promise<Aerodrome | undefined>; /** * Finds the nearest aerodrome to the given location. * * @param location - The geographical location to find the nearest aerodrome to. * @param radius - The search radius in kilometers (default is 100 km). * @param exclude - An optional array of ICAO codes to exclude from the search. * @returns A promise that resolves to the nearest aerodrome, or undefined if not found. * @throws Error if no aerodromes are available and the repository doesn't support radius search. */ nearest(location: GeoJSON.Position, radius?: number, exclude?: string[]): Promise<Aerodrome | undefined>; }