|
2 | 2 | * Resolves OSM class/type pairs to human-readable English labels using the |
3 | 3 | * iD editor's tagging schema (@openstreetmap/id-tagging-schema). The full |
4 | 4 | * JSON is loaded once at startup — server-side only, never sent to the client. |
| 5 | + * |
| 6 | + * Uses static JSON imports so esbuild inlines the data into the api bundle |
| 7 | + * at build time. A runtime `require()` would fail in the containerized api |
| 8 | + * image because `@openstreetmap/id-tagging-schema` is a sub-dep of the |
| 9 | + * geocoding integration, not a root-hoisted package that `createRequire` |
| 10 | + * can find from `apps/api/dist/server.js`. |
5 | 11 | */ |
6 | 12 |
|
7 | | -import { createRequire } from "node:module"; |
8 | | - |
9 | | -const require = createRequire(import.meta.url); |
| 13 | +import presets from "@openstreetmap/id-tagging-schema/dist/presets.json" with { type: "json" }; |
| 14 | +import enTranslations from "@openstreetmap/id-tagging-schema/dist/translations/en.json" with { |
| 15 | + type: "json", |
| 16 | +}; |
10 | 17 |
|
11 | 18 | type PresetEntry = { name?: string }; |
12 | 19 | type TranslationEntry = { name?: string }; |
13 | 20 | type EnTranslations = { en?: { presets?: { presets?: Record<string, TranslationEntry> } } }; |
14 | 21 |
|
15 | | -const schema = require("@openstreetmap/id-tagging-schema/dist/presets.json") as Record< |
16 | | - string, |
17 | | - PresetEntry |
18 | | ->; |
19 | | - |
20 | | -const translations = |
21 | | - (require("@openstreetmap/id-tagging-schema/dist/translations/en.json") as EnTranslations).en |
22 | | - ?.presets?.presets ?? {}; |
| 22 | +const schema = presets as Record<string, PresetEntry>; |
| 23 | +const translations = (enTranslations as EnTranslations).en?.presets?.presets ?? {}; |
23 | 24 |
|
24 | 25 | // iD names include editing-context qualifiers that are verbose in a display context. |
25 | 26 | // Strip them wherever they appear as a trailing suffix. |
|
0 commit comments