Skip to main content

Adding an adapter

Part of Architecture, which is built from ARCHITECTURE.md in the repository, where it is edited.

An adapter reaches the ui through the services. Arrows run from the port towards the code that uses it.

Diagram of 5 boxes and 4 arrows SearchProvider port, in packages/core points to NominatimSearchProvider in packages/web/src/adapters. NominatimSearchProvider in packages/web/src/adapters points to createServices() real adapters, then the test seam, then options.overrides. createServices() real adapters, then the test seam, then options.overrides points to ServicesProvider in routes/app.tsx. ServicesProvider in routes/app.tsx points to useSearch, useSettings, ... hooks in packages/map. SearchProvider port, in packages/core NominatimSearchProvider in packages/web/src/adapters createServices() real adapters, then the test seam, then options.overrides ServicesProvider in routes/app.tsx useSearch, useSettings, ... hooks in packages/map
  1. Define or extend the port in packages/core/src/ports, with typed errors and an AbortSignal on async calls.
  2. Write the fake in packages/core/src/fakes and the contract suite in packages/core/src/contracts.
  3. Write the real adapter in packages/web/src/adapters, passing the same suite. Helpers that more than one adapter uses (reading media queries, fetching and reading JSON) live in packages/web/src/adapters/shared. The MapLibre adapter is the exception: it is the package packages/adapter-maplibre, which depends on core and theme only, keeps its event emitter beside it, and runs the same contract suite over a scripted engine.
  4. Register it in createServices(). An optional port whose data belongs to the host, as the selection and the feature query do, is not built there: list it in HOST_SUPPLIED_PORT_NAMES (packages/core/src/contracts/portRegistry.ts) and the host supplies it.
  5. Read it in the ui through a typed hook (useSettings, useSearch and so on).