flight-planner
Version:
Plan and route VFR flights
71 lines (70 loc) • 2.71 kB
TypeScript
import { ICAO } from "../index.js";
import { Aerodrome } from "../waypoint.js";
import RepositoryBase from "../repository.js";
/**
* 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.
*/
declare class AerodromeService {
private repository;
private aerodromes;
private accessOrder;
private maxCacheSize;
/**
* Creates a new instance of the AerodromeService class.
*
* @param repository - An optional repository for fetching aerodrome data.
* @param maxCacheSize - Maximum number of aerodromes to keep in the cache (default: 1000).
*/
constructor(repository: RepositoryBase<Aerodrome>, maxCacheSize?: number);
/**
* 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[];
/**
* Updates the access order for the LRU cache.
*
* @param icao - The ICAO code that was accessed.
*/
private updateAccessOrder;
/**
* Enforces the cache size limit by removing least recently used items.
*/
private enforceCacheLimit;
/**
* Adds aerodromes to the service.
*
* @param aerodromes - An array of Aerodrome objects or a single Aerodrome object to add.
*/
private addToCache;
/**
* Finds aerodromes by ICAO code(s).
*
* @param icao - A single ICAO code or an array of ICAO codes to search for.
* @returns A promise that resolves to an array of Aerodrome objects, or undefined if not found.
* @throws Error if the repository is not set or doesn't support fetchByICAO.
*/
get(icao: string | 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>;
}
export default AerodromeService;