refactor: compose configurable geocoding and route services

This commit is contained in:
Sameh Khamis committed 2026-09-13 21:23:13 -07:00
1 parent 3b91feffdc
commit 8b36c28b06
25 files changed
+764 -211

No files matched your search

+1 -32
View File
@@ -1,32 +1 @@
import {
createPlaceSearch,
createGoogleGeocoder,
createPhotonGeocoder,
} from '../search/index.js';
/** Google first when configured, then keyless Photon; transport stays local to setup. */
export function createStandalonePlaceSearch({
resolveApiKey,
fetchImpl = (...args) => fetch(...args),
signal,
} = {}) {
return createPlaceSearch({
signal,
providers: [
createGoogleGeocoder({
request(query, { bias, signal }) {
const key = resolveApiKey?.();
if (!key) return null;
const url = new URL(
'https://maps.googleapis.com/maps/api/geocode/json',
);
url.searchParams.set('address', query);
url.searchParams.set('key', key);
if (bias) url.searchParams.set('bounds', bias);
return fetchImpl(url.toString(), { signal });
},
}),
createPhotonGeocoder({ fetchImpl }),
],
});
}
export { createDefaultPlaceSearch as createStandalonePlaceSearch } from '../search/defaults.js';