airports: publish the airport of a code as a contract the place search reads

The search turned an airport code into its airport by reaching into the
airports domain's data module. airports.contract.ts publishes that lookup
instead, as the import boundaries ask.
This commit is contained in:
Maurice
2026-10-30 17:14:55 +01:00
parent 51bbd337c9
commit 3b675eed60
2 changed files with 24 additions and 4 deletions
@@ -0,0 +1,20 @@
/**
* What the airports domain offers other domains without its service: the
* bundled airport of an IATA code. The place search reads it to turn "JFK"
* into the airport it names (maps/providers/osm-geocoding.ts), a lookup in
* memory that needs neither the database nor the module.
*/
import { findByIata } from './airports.data';
/** An airport by name and coordinate, the part of it a lookup by code hands on. */
export interface AirportByCode {
iata: string;
name: string;
lat: number;
lng: number;
}
export function airportByCode(code: string): AirportByCode | null {
const airport = findByIata(code);
return airport ? { iata: airport.iata, name: airport.name, lat: airport.lat, lng: airport.lng } : null;
}
@@ -9,7 +9,7 @@
* the installation's geocoder these answer alone; Nominatim is OsmClient's
* business, for installations without the TREK services.
*/
import { findByIata, type Airport } from '../../airports/airports.data';
import { airportByCode, type AirportByCode } from '../../airports/airports.contract';
import { buildOsmDetails, haversineMetres, namesOverlap, toApiLang } from '../maps.helpers';
import type { NominatimResult, NominatimReverse, OverpassElement } from './osm.client';
import type { PhotonClient } from './photon.client';
@@ -100,9 +100,9 @@ export async function photonSuggest(
* coordinate, where the aerodrome comes first. Lower case is left alone, so
* "Ber" typed on the way to "Berlin" stays a search for Berlin.
*/
function airportOfCode(query: string): Airport | null {
function airportOfCode(query: string): AirportByCode | null {
const code = query.trim();
return /^[A-Z]{3}$/.test(code) ? findByIata(code) : null;
return /^[A-Z]{3}$/.test(code) ? airportByCode(code) : null;
}
/**
@@ -111,7 +111,7 @@ function airportOfCode(query: string): Airport | null {
* airport, which is how OpenStreetMap files Haneda (an island named "Tokyo
* International Airport").
*/
function airportLead(ranked: PhotonFeature[], airport: Airport): PhotonLead | null {
function airportLead(ranked: PhotonFeature[], airport: AirportByCode): PhotonLead | null {
const near = ranked
.map((feature) => ({ feature, row: asSuggestion(feature) }))
.filter(