Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

serve each country's regions from its own file, so the server no longer holds them all

Vini7277e35a96a5
diff --git a/Dockerfile b/Dockerfile
index d425e8549..6253a8eaf 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -91,7 +91,8 @@ ENV KITINERARY_EXTRACTOR_PATH=/usr/local/bin/kitinerary-extractor
COPY --chown=node:node --from=server-builder /app/server/dist ./server/dist
# Runtime data assets read from server/assets at runtime: airports.json (flight
-# transport search) and atlas/*.geojson.gz (Atlas country/region map). The build
+# transport search) and atlas/*.geojson.gz + atlas/admin1/*.geojson.gz (Atlas
+# country/region map). The build
# only emits dist, so these must be copied explicitly or the features silently
# degrade to empty in the image.
COPY --chown=node:node --from=server-builder /app/server/assets ./server/assets
diff --git a/NOTICE.md b/NOTICE.md
index db202a80f..8a0a6ed79 100644
--- a/NOTICE.md
+++ b/NOTICE.md
@@ -5,8 +5,9 @@ TREK bundles and uses third-party data that requires attribution.
## geoBoundaries — country & sub-national boundaries
The Atlas map's administrative boundaries (admin-0 countries and admin-1
-provinces/counties), shipped at `server/assets/atlas/admin0.geojson.gz` and
-`server/assets/atlas/admin1.geojson.gz` and generated by
+provinces/counties), shipped at `server/assets/atlas/admin0.geojson.gz`,
+`server/assets/atlas/admin1.geojson.gz` and `server/assets/atlas/admin1/<ISO_A2>.geojson.gz`
+(the same regions, one file per country) and generated by
`server/scripts/build-atlas-geo.mjs`, are derived from **geoBoundaries**.
> Runfola, D. et al. (2020) geoBoundaries: A global database of political
diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json
index a54f8e616..41c27b43c 100644
--- a/client/scripts/eslint-baseline.json
+++ b/client/scripts/eslint-baseline.json
@@ -5,7 +5,7 @@
"no-console": 88,
"complexity": 218,
"@typescript-eslint/no-explicit-any": 144,
- "trek/no-swallowed-catch": 129,
+ "trek/no-swallowed-catch": 128,
"max-params": 32,
"trek/store-without-selector": 67,
"react-hooks/refs": 555,
diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.json
index 0cd9653d3..80083bf96 100644
--- a/client/scripts/size-baseline.json
+++ b/client/scripts/size-baseline.json
@@ -22,7 +22,7 @@
"src/pages/JourneyDetailPage.test.tsx": 4030,
"src/pages/LoginPage.tsx": 1348,
"src/pages/TripPlannerPage.tsx": 1128,
- "src/pages/atlas/useAtlas.ts": 1211,
+ "src/pages/atlas/useAtlas.ts": 1210,
"src/pages/tripPlanner/useTripPlanner.roadtrip.test.tsx": 3518,
"src/pages/tripPlanner/useTripPlanner.test.tsx": 3270,
"src/styles/studio.css": 1918
diff --git a/client/src/pages/AtlasPage.test.tsx b/client/src/pages/AtlasPage.test.tsx
index ead8ebea6..f9d5a4cd2 100644
--- a/client/src/pages/AtlasPage.test.tsx
+++ b/client/src/pages/AtlasPage.test.tsx
@@ -215,7 +215,7 @@ function useDefaultAtlasHandlers() {
// country features override this handler via server.use(...).
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json({ type: 'FeatureCollection', features: [] })),
// Handler for region GeoJSON fetch (triggered by loadRegionsForViewport when intersects=true)
- http.get('/api/addons/atlas/regions/geo', () => HttpResponse.json({ features: [] })),
+ http.get('/api/addons/atlas/regions/geo/:code', () => HttpResponse.json({ features: [] })),
);
}
@@ -1589,7 +1589,7 @@ describe('AtlasPage', () => {
);
server.use(
- http.get('/api/addons/atlas/regions/geo', () => HttpResponse.json({ features: [] })),
+ http.get('/api/addons/atlas/regions/geo/:code', () => HttpResponse.json({ features: [] })),
);
render(<AtlasPage />);
@@ -1746,7 +1746,7 @@ describe('AtlasPage', () => {
type: 'FeatureCollection',
features: [{ type: 'Feature', properties: { ISO_A2: 'FR', ADM0_A3: 'FRA', ISO_A3: 'FRA', NAME: 'France', ADMIN: 'France' }, geometry: null }],
})),
- http.get('/api/addons/atlas/regions/geo', () => HttpResponse.json({
+ http.get('/api/addons/atlas/regions/geo/:code', () => HttpResponse.json({
type: 'FeatureCollection',
features: [{ type: 'Feature', properties: { iso_a2: 'FR', iso_3166_2: 'FR-IDF', name: 'Île-de-France', name_en: 'Île-de-France', admin: 'France' }, geometry: null }],
})),
diff --git a/client/src/pages/atlas/useAtlas.test.tsx b/client/src/pages/atlas/useAtlas.test.tsx
index 2f2001e70..4063fdd6f 100644
--- a/client/src/pages/atlas/useAtlas.test.tsx
+++ b/client/src/pages/atlas/useAtlas.test.tsx
@@ -274,7 +274,7 @@ function installAtlasHandlers(over: Partial<Record<string, unknown>> = {}) {
http.get('/api/addons/atlas/bucket-list', () => HttpResponse.json({ items: over.bucket ?? [] })),
http.get('/api/addons/atlas/regions', () => HttpResponse.json({ regions: over.regions ?? {} })),
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(over.geo ?? { type: 'FeatureCollection', features: [] })),
- http.get('/api/addons/atlas/regions/geo', () => HttpResponse.json(over.regionGeo ?? { features: [] })),
+ http.get('/api/addons/atlas/regions/geo/:code', () => HttpResponse.json(over.regionGeo ?? { features: [] })),
http.get('/api/atlas-layers', () => HttpResponse.json({ layers: over.layers ?? [] })),
);
}
@@ -1053,8 +1053,8 @@ describe('useAtlas', () => {
await waitFor(() => expect(atlas.atlas_country_options.length).toBe(seen.length));
const requested: string[] = [];
- server.use(http.get('/api/addons/atlas/regions/geo', ({ request }) => {
- requested.push(new URL(request.url).searchParams.get('countries') ?? '');
+ server.use(http.get('/api/addons/atlas/regions/geo/:code', ({ params }) => {
+ requested.push(String(params.code));
return HttpResponse.json(regionGeo);
}));
diff --git a/client/src/pages/atlas/useAtlas.ts b/client/src/pages/atlas/useAtlas.ts
index 679621008..d5556389d 100644
--- a/client/src/pages/atlas/useAtlas.ts
+++ b/client/src/pages/atlas/useAtlas.ts
@@ -317,18 +317,18 @@ export function useAtlas() {
}
if (!toLoad.length) return
for (const code of toLoad) pendingRegionCodes.current.add(code)
- apiClient.get(`/addons/atlas/regions/geo?countries=${toLoad.join(',')}`)
+ // One stable URL per country, so a country evicted by REGION_CACHE_MAX or seen on an earlier
+ // visit comes back from the browser cache. Every request settles; the layer rebuilds once.
+ void Promise.all(toLoad.map(c => apiClient.get(`/addons/atlas/regions/geo/${c}`)
.then(geoRes => {
- const geo = geoRes.data
- if (!geo?.features) return
- let added = false
- for (const c of toLoad) {
- const features = geo.features.filter((f: any) => f.properties?.iso_a2?.toUpperCase() === c)
- if (features.length > 0) { regionGeoCache.current[c] = { type: 'FeatureCollection', features }; touchRegionCode(c); added = true }
- }
- if (added) { evictRegionCache(); setRegionGeoLoaded(v => v + 1) }
+ const features = (geoRes.data?.features || []).filter((f: any) => f.properties?.iso_a2?.toUpperCase() === c)
+ if (features.length === 0) return false
+ regionGeoCache.current[c] = { type: 'FeatureCollection', features }
+ touchRegionCode(c)
+ return true
})
- .catch(() => {})
+ .catch(() => false)))
+ .then(added => { if (added.some(Boolean)) { evictRegionCache(); setRegionGeoLoaded(v => v + 1) } })
.finally(() => { for (const code of toLoad) pendingRegionCodes.current.delete(code) })
}
loadRegionsForViewportRef.current = loadRegionsForViewport
diff --git a/server/assets/atlas/admin1/AD.geojson.gz b/server/assets/atlas/admin1/AD.geojson.gz
new file mode 100644
index 000000000..fb4339f7f
Binary files /dev/null and b/server/assets/atlas/admin1/AD.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AE.geojson.gz b/server/assets/atlas/admin1/AE.geojson.gz
new file mode 100644
index 000000000..b0eb08ea1
Binary files /dev/null and b/server/assets/atlas/admin1/AE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AF.geojson.gz b/server/assets/atlas/admin1/AF.geojson.gz
new file mode 100644
index 000000000..742b48e32
Binary files /dev/null and b/server/assets/atlas/admin1/AF.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AG.geojson.gz b/server/assets/atlas/admin1/AG.geojson.gz
new file mode 100644
index 000000000..bd8efae6b
Binary files /dev/null and b/server/assets/atlas/admin1/AG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AL.geojson.gz b/server/assets/atlas/admin1/AL.geojson.gz
new file mode 100644
index 000000000..beb9f1f34
Binary files /dev/null and b/server/assets/atlas/admin1/AL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AM.geojson.gz b/server/assets/atlas/admin1/AM.geojson.gz
new file mode 100644
index 000000000..f2a09f8a1
Binary files /dev/null and b/server/assets/atlas/admin1/AM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AO.geojson.gz b/server/assets/atlas/admin1/AO.geojson.gz
new file mode 100644
index 000000000..951b2e6d3
Binary files /dev/null and b/server/assets/atlas/admin1/AO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AR.geojson.gz b/server/assets/atlas/admin1/AR.geojson.gz
new file mode 100644
index 000000000..87d2c8297
Binary files /dev/null and b/server/assets/atlas/admin1/AR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AT.geojson.gz b/server/assets/atlas/admin1/AT.geojson.gz
new file mode 100644
index 000000000..ae6b2de1e
Binary files /dev/null and b/server/assets/atlas/admin1/AT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AU.geojson.gz b/server/assets/atlas/admin1/AU.geojson.gz
new file mode 100644
index 000000000..123846fb5
Binary files /dev/null and b/server/assets/atlas/admin1/AU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/AZ.geojson.gz b/server/assets/atlas/admin1/AZ.geojson.gz
new file mode 100644
index 000000000..10464c199
Binary files /dev/null and b/server/assets/atlas/admin1/AZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BA.geojson.gz b/server/assets/atlas/admin1/BA.geojson.gz
new file mode 100644
index 000000000..afbda8b6e
Binary files /dev/null and b/server/assets/atlas/admin1/BA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BB.geojson.gz b/server/assets/atlas/admin1/BB.geojson.gz
new file mode 100644
index 000000000..5253b36fa
Binary files /dev/null and b/server/assets/atlas/admin1/BB.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BD.geojson.gz b/server/assets/atlas/admin1/BD.geojson.gz
new file mode 100644
index 000000000..e13a0f56d
Binary files /dev/null and b/server/assets/atlas/admin1/BD.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BE.geojson.gz b/server/assets/atlas/admin1/BE.geojson.gz
new file mode 100644
index 000000000..0a642d811
Binary files /dev/null and b/server/assets/atlas/admin1/BE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BF.geojson.gz b/server/assets/atlas/admin1/BF.geojson.gz
new file mode 100644
index 000000000..cc932c4b9
Binary files /dev/null and b/server/assets/atlas/admin1/BF.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BG.geojson.gz b/server/assets/atlas/admin1/BG.geojson.gz
new file mode 100644
index 000000000..8349a49ab
Binary files /dev/null and b/server/assets/atlas/admin1/BG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BH.geojson.gz b/server/assets/atlas/admin1/BH.geojson.gz
new file mode 100644
index 000000000..5269d039b
Binary files /dev/null and b/server/assets/atlas/admin1/BH.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BI.geojson.gz b/server/assets/atlas/admin1/BI.geojson.gz
new file mode 100644
index 000000000..85421e7b4
Binary files /dev/null and b/server/assets/atlas/admin1/BI.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BJ.geojson.gz b/server/assets/atlas/admin1/BJ.geojson.gz
new file mode 100644
index 000000000..7a53c8daf
Binary files /dev/null and b/server/assets/atlas/admin1/BJ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BN.geojson.gz b/server/assets/atlas/admin1/BN.geojson.gz
new file mode 100644
index 000000000..0d28b8fee
Binary files /dev/null and b/server/assets/atlas/admin1/BN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BO.geojson.gz b/server/assets/atlas/admin1/BO.geojson.gz
new file mode 100644
index 000000000..65c09919e
Binary files /dev/null and b/server/assets/atlas/admin1/BO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BR.geojson.gz b/server/assets/atlas/admin1/BR.geojson.gz
new file mode 100644
index 000000000..be682c651
Binary files /dev/null and b/server/assets/atlas/admin1/BR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BS.geojson.gz b/server/assets/atlas/admin1/BS.geojson.gz
new file mode 100644
index 000000000..36536fcda
Binary files /dev/null and b/server/assets/atlas/admin1/BS.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BT.geojson.gz b/server/assets/atlas/admin1/BT.geojson.gz
new file mode 100644
index 000000000..7ffd8e039
Binary files /dev/null and b/server/assets/atlas/admin1/BT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BW.geojson.gz b/server/assets/atlas/admin1/BW.geojson.gz
new file mode 100644
index 000000000..b674a7d14
Binary files /dev/null and b/server/assets/atlas/admin1/BW.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BY.geojson.gz b/server/assets/atlas/admin1/BY.geojson.gz
new file mode 100644
index 000000000..61a6a7caa
Binary files /dev/null and b/server/assets/atlas/admin1/BY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/BZ.geojson.gz b/server/assets/atlas/admin1/BZ.geojson.gz
new file mode 100644
index 000000000..1ad34e2e6
Binary files /dev/null and b/server/assets/atlas/admin1/BZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CA.geojson.gz b/server/assets/atlas/admin1/CA.geojson.gz
new file mode 100644
index 000000000..419b97096
Binary files /dev/null and b/server/assets/atlas/admin1/CA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CD.geojson.gz b/server/assets/atlas/admin1/CD.geojson.gz
new file mode 100644
index 000000000..4269b4249
Binary files /dev/null and b/server/assets/atlas/admin1/CD.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CF.geojson.gz b/server/assets/atlas/admin1/CF.geojson.gz
new file mode 100644
index 000000000..1a630297c
Binary files /dev/null and b/server/assets/atlas/admin1/CF.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CG.geojson.gz b/server/assets/atlas/admin1/CG.geojson.gz
new file mode 100644
index 000000000..3addca65f
Binary files /dev/null and b/server/assets/atlas/admin1/CG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CH.geojson.gz b/server/assets/atlas/admin1/CH.geojson.gz
new file mode 100644
index 000000000..6c8fb2aaf
Binary files /dev/null and b/server/assets/atlas/admin1/CH.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CI.geojson.gz b/server/assets/atlas/admin1/CI.geojson.gz
new file mode 100644
index 000000000..2f0344e83
Binary files /dev/null and b/server/assets/atlas/admin1/CI.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CL.geojson.gz b/server/assets/atlas/admin1/CL.geojson.gz
new file mode 100644
index 000000000..9b7f489e8
Binary files /dev/null and b/server/assets/atlas/admin1/CL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CM.geojson.gz b/server/assets/atlas/admin1/CM.geojson.gz
new file mode 100644
index 000000000..eff0d5375
Binary files /dev/null and b/server/assets/atlas/admin1/CM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CN.geojson.gz b/server/assets/atlas/admin1/CN.geojson.gz
new file mode 100644
index 000000000..2cb47aa16
Binary files /dev/null and b/server/assets/atlas/admin1/CN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CO.geojson.gz b/server/assets/atlas/admin1/CO.geojson.gz
new file mode 100644
index 000000000..1ff6713b9
Binary files /dev/null and b/server/assets/atlas/admin1/CO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CR.geojson.gz b/server/assets/atlas/admin1/CR.geojson.gz
new file mode 100644
index 000000000..67b015397
Binary files /dev/null and b/server/assets/atlas/admin1/CR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CU.geojson.gz b/server/assets/atlas/admin1/CU.geojson.gz
new file mode 100644
index 000000000..779f395e9
Binary files /dev/null and b/server/assets/atlas/admin1/CU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CV.geojson.gz b/server/assets/atlas/admin1/CV.geojson.gz
new file mode 100644
index 000000000..9acf07324
Binary files /dev/null and b/server/assets/atlas/admin1/CV.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CY.geojson.gz b/server/assets/atlas/admin1/CY.geojson.gz
new file mode 100644
index 000000000..68e6b295a
Binary files /dev/null and b/server/assets/atlas/admin1/CY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/CZ.geojson.gz b/server/assets/atlas/admin1/CZ.geojson.gz
new file mode 100644
index 000000000..2509eaafb
Binary files /dev/null and b/server/assets/atlas/admin1/CZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/DE.geojson.gz b/server/assets/atlas/admin1/DE.geojson.gz
new file mode 100644
index 000000000..0ff6a2227
Binary files /dev/null and b/server/assets/atlas/admin1/DE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/DJ.geojson.gz b/server/assets/atlas/admin1/DJ.geojson.gz
new file mode 100644
index 000000000..c2e095a22
Binary files /dev/null and b/server/assets/atlas/admin1/DJ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/DK.geojson.gz b/server/assets/atlas/admin1/DK.geojson.gz
new file mode 100644
index 000000000..be0e97ac0
Binary files /dev/null and b/server/assets/atlas/admin1/DK.geojson.gz differ
diff --git a/server/assets/atlas/admin1/DM.geojson.gz b/server/assets/atlas/admin1/DM.geojson.gz
new file mode 100644
index 000000000..ea2abe7c7
Binary files /dev/null and b/server/assets/atlas/admin1/DM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/DO.geojson.gz b/server/assets/atlas/admin1/DO.geojson.gz
new file mode 100644
index 000000000..fd38e76d4
Binary files /dev/null and b/server/assets/atlas/admin1/DO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/DZ.geojson.gz b/server/assets/atlas/admin1/DZ.geojson.gz
new file mode 100644
index 000000000..fe2fbfc93
Binary files /dev/null and b/server/assets/atlas/admin1/DZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/EC.geojson.gz b/server/assets/atlas/admin1/EC.geojson.gz
new file mode 100644
index 000000000..f680e60ea
Binary files /dev/null and b/server/assets/atlas/admin1/EC.geojson.gz differ
diff --git a/server/assets/atlas/admin1/EE.geojson.gz b/server/assets/atlas/admin1/EE.geojson.gz
new file mode 100644
index 000000000..89cebda33
Binary files /dev/null and b/server/assets/atlas/admin1/EE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/EG.geojson.gz b/server/assets/atlas/admin1/EG.geojson.gz
new file mode 100644
index 000000000..21ac5942b
Binary files /dev/null and b/server/assets/atlas/admin1/EG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ER.geojson.gz b/server/assets/atlas/admin1/ER.geojson.gz
new file mode 100644
index 000000000..20ce2389a
Binary files /dev/null and b/server/assets/atlas/admin1/ER.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ES.geojson.gz b/server/assets/atlas/admin1/ES.geojson.gz
new file mode 100644
index 000000000..3cdc56e05
Binary files /dev/null and b/server/assets/atlas/admin1/ES.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ET.geojson.gz b/server/assets/atlas/admin1/ET.geojson.gz
new file mode 100644
index 000000000..cc51d4b2d
Binary files /dev/null and b/server/assets/atlas/admin1/ET.geojson.gz differ
diff --git a/server/assets/atlas/admin1/FI.geojson.gz b/server/assets/atlas/admin1/FI.geojson.gz
new file mode 100644
index 000000000..b0a0fae01
Binary files /dev/null and b/server/assets/atlas/admin1/FI.geojson.gz differ
diff --git a/server/assets/atlas/admin1/FJ.geojson.gz b/server/assets/atlas/admin1/FJ.geojson.gz
new file mode 100644
index 000000000..0ff5db3ad
Binary files /dev/null and b/server/assets/atlas/admin1/FJ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/FM.geojson.gz b/server/assets/atlas/admin1/FM.geojson.gz
new file mode 100644
index 000000000..fdae40c92
Binary files /dev/null and b/server/assets/atlas/admin1/FM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/FR.geojson.gz b/server/assets/atlas/admin1/FR.geojson.gz
new file mode 100644
index 000000000..6870e60c8
Binary files /dev/null and b/server/assets/atlas/admin1/FR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GA.geojson.gz b/server/assets/atlas/admin1/GA.geojson.gz
new file mode 100644
index 000000000..1e3c94b82
Binary files /dev/null and b/server/assets/atlas/admin1/GA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GB.geojson.gz b/server/assets/atlas/admin1/GB.geojson.gz
new file mode 100644
index 000000000..15144a181
Binary files /dev/null and b/server/assets/atlas/admin1/GB.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GD.geojson.gz b/server/assets/atlas/admin1/GD.geojson.gz
new file mode 100644
index 000000000..0eb36cf51
Binary files /dev/null and b/server/assets/atlas/admin1/GD.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GE.geojson.gz b/server/assets/atlas/admin1/GE.geojson.gz
new file mode 100644
index 000000000..5d62ec000
Binary files /dev/null and b/server/assets/atlas/admin1/GE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GH.geojson.gz b/server/assets/atlas/admin1/GH.geojson.gz
new file mode 100644
index 000000000..93a18cdb4
Binary files /dev/null and b/server/assets/atlas/admin1/GH.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GL.geojson.gz b/server/assets/atlas/admin1/GL.geojson.gz
new file mode 100644
index 000000000..fc3850477
Binary files /dev/null and b/server/assets/atlas/admin1/GL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GM.geojson.gz b/server/assets/atlas/admin1/GM.geojson.gz
new file mode 100644
index 000000000..cb9a8b020
Binary files /dev/null and b/server/assets/atlas/admin1/GM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GN.geojson.gz b/server/assets/atlas/admin1/GN.geojson.gz
new file mode 100644
index 000000000..314fe794d
Binary files /dev/null and b/server/assets/atlas/admin1/GN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GQ.geojson.gz b/server/assets/atlas/admin1/GQ.geojson.gz
new file mode 100644
index 000000000..908d27b17
Binary files /dev/null and b/server/assets/atlas/admin1/GQ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GR.geojson.gz b/server/assets/atlas/admin1/GR.geojson.gz
new file mode 100644
index 000000000..a9396dac1
Binary files /dev/null and b/server/assets/atlas/admin1/GR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GT.geojson.gz b/server/assets/atlas/admin1/GT.geojson.gz
new file mode 100644
index 000000000..319555787
Binary files /dev/null and b/server/assets/atlas/admin1/GT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GW.geojson.gz b/server/assets/atlas/admin1/GW.geojson.gz
new file mode 100644
index 000000000..a5e5030ab
Binary files /dev/null and b/server/assets/atlas/admin1/GW.geojson.gz differ
diff --git a/server/assets/atlas/admin1/GY.geojson.gz b/server/assets/atlas/admin1/GY.geojson.gz
new file mode 100644
index 000000000..2336802e3
Binary files /dev/null and b/server/assets/atlas/admin1/GY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/HN.geojson.gz b/server/assets/atlas/admin1/HN.geojson.gz
new file mode 100644
index 000000000..75839c452
Binary files /dev/null and b/server/assets/atlas/admin1/HN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/HR.geojson.gz b/server/assets/atlas/admin1/HR.geojson.gz
new file mode 100644
index 000000000..c23685bc7
Binary files /dev/null and b/server/assets/atlas/admin1/HR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/HT.geojson.gz b/server/assets/atlas/admin1/HT.geojson.gz
new file mode 100644
index 000000000..d182bbc95
Binary files /dev/null and b/server/assets/atlas/admin1/HT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/HU.geojson.gz b/server/assets/atlas/admin1/HU.geojson.gz
new file mode 100644
index 000000000..32a7f0fc4
Binary files /dev/null and b/server/assets/atlas/admin1/HU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ID.geojson.gz b/server/assets/atlas/admin1/ID.geojson.gz
new file mode 100644
index 000000000..04cfe018e
Binary files /dev/null and b/server/assets/atlas/admin1/ID.geojson.gz differ
diff --git a/server/assets/atlas/admin1/IE.geojson.gz b/server/assets/atlas/admin1/IE.geojson.gz
new file mode 100644
index 000000000..966bc8936
Binary files /dev/null and b/server/assets/atlas/admin1/IE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/IL.geojson.gz b/server/assets/atlas/admin1/IL.geojson.gz
new file mode 100644
index 000000000..3227ed63a
Binary files /dev/null and b/server/assets/atlas/admin1/IL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/IN.geojson.gz b/server/assets/atlas/admin1/IN.geojson.gz
new file mode 100644
index 000000000..89eadac40
Binary files /dev/null and b/server/assets/atlas/admin1/IN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/IQ.geojson.gz b/server/assets/atlas/admin1/IQ.geojson.gz
new file mode 100644
index 000000000..dceec057a
Binary files /dev/null and b/server/assets/atlas/admin1/IQ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/IR.geojson.gz b/server/assets/atlas/admin1/IR.geojson.gz
new file mode 100644
index 000000000..0ce550bdc
Binary files /dev/null and b/server/assets/atlas/admin1/IR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/IS.geojson.gz b/server/assets/atlas/admin1/IS.geojson.gz
new file mode 100644
index 000000000..8dcd647fb
Binary files /dev/null and b/server/assets/atlas/admin1/IS.geojson.gz differ
diff --git a/server/assets/atlas/admin1/IT.geojson.gz b/server/assets/atlas/admin1/IT.geojson.gz
new file mode 100644
index 000000000..18ce45512
Binary files /dev/null and b/server/assets/atlas/admin1/IT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/JM.geojson.gz b/server/assets/atlas/admin1/JM.geojson.gz
new file mode 100644
index 000000000..1a8f291c1
Binary files /dev/null and b/server/assets/atlas/admin1/JM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/JO.geojson.gz b/server/assets/atlas/admin1/JO.geojson.gz
new file mode 100644
index 000000000..6fac17f78
Binary files /dev/null and b/server/assets/atlas/admin1/JO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/JP.geojson.gz b/server/assets/atlas/admin1/JP.geojson.gz
new file mode 100644
index 000000000..83a605f6c
Binary files /dev/null and b/server/assets/atlas/admin1/JP.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KE.geojson.gz b/server/assets/atlas/admin1/KE.geojson.gz
new file mode 100644
index 000000000..1cefe2218
Binary files /dev/null and b/server/assets/atlas/admin1/KE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KG.geojson.gz b/server/assets/atlas/admin1/KG.geojson.gz
new file mode 100644
index 000000000..376fbee9f
Binary files /dev/null and b/server/assets/atlas/admin1/KG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KH.geojson.gz b/server/assets/atlas/admin1/KH.geojson.gz
new file mode 100644
index 000000000..7a980cb3b
Binary files /dev/null and b/server/assets/atlas/admin1/KH.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KI.geojson.gz b/server/assets/atlas/admin1/KI.geojson.gz
new file mode 100644
index 000000000..c1d14dc5f
Binary files /dev/null and b/server/assets/atlas/admin1/KI.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KM.geojson.gz b/server/assets/atlas/admin1/KM.geojson.gz
new file mode 100644
index 000000000..3c43ef225
Binary files /dev/null and b/server/assets/atlas/admin1/KM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KN.geojson.gz b/server/assets/atlas/admin1/KN.geojson.gz
new file mode 100644
index 000000000..d8ee5cd1b
Binary files /dev/null and b/server/assets/atlas/admin1/KN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KP.geojson.gz b/server/assets/atlas/admin1/KP.geojson.gz
new file mode 100644
index 000000000..59cba1189
Binary files /dev/null and b/server/assets/atlas/admin1/KP.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KR.geojson.gz b/server/assets/atlas/admin1/KR.geojson.gz
new file mode 100644
index 000000000..7d395f35f
Binary files /dev/null and b/server/assets/atlas/admin1/KR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KW.geojson.gz b/server/assets/atlas/admin1/KW.geojson.gz
new file mode 100644
index 000000000..fdf66e88a
Binary files /dev/null and b/server/assets/atlas/admin1/KW.geojson.gz differ
diff --git a/server/assets/atlas/admin1/KZ.geojson.gz b/server/assets/atlas/admin1/KZ.geojson.gz
new file mode 100644
index 000000000..7a006db6f
Binary files /dev/null and b/server/assets/atlas/admin1/KZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LA.geojson.gz b/server/assets/atlas/admin1/LA.geojson.gz
new file mode 100644
index 000000000..18e9283f3
Binary files /dev/null and b/server/assets/atlas/admin1/LA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LB.geojson.gz b/server/assets/atlas/admin1/LB.geojson.gz
new file mode 100644
index 000000000..ddadf6d2b
Binary files /dev/null and b/server/assets/atlas/admin1/LB.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LC.geojson.gz b/server/assets/atlas/admin1/LC.geojson.gz
new file mode 100644
index 000000000..16c7049ba
Binary files /dev/null and b/server/assets/atlas/admin1/LC.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LI.geojson.gz b/server/assets/atlas/admin1/LI.geojson.gz
new file mode 100644
index 000000000..84b9da672
Binary files /dev/null and b/server/assets/atlas/admin1/LI.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LK.geojson.gz b/server/assets/atlas/admin1/LK.geojson.gz
new file mode 100644
index 000000000..f6c800401
Binary files /dev/null and b/server/assets/atlas/admin1/LK.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LR.geojson.gz b/server/assets/atlas/admin1/LR.geojson.gz
new file mode 100644
index 000000000..e67152cbf
Binary files /dev/null and b/server/assets/atlas/admin1/LR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LS.geojson.gz b/server/assets/atlas/admin1/LS.geojson.gz
new file mode 100644
index 000000000..eb1461d0d
Binary files /dev/null and b/server/assets/atlas/admin1/LS.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LT.geojson.gz b/server/assets/atlas/admin1/LT.geojson.gz
new file mode 100644
index 000000000..051006101
Binary files /dev/null and b/server/assets/atlas/admin1/LT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LU.geojson.gz b/server/assets/atlas/admin1/LU.geojson.gz
new file mode 100644
index 000000000..4adb4f82c
Binary files /dev/null and b/server/assets/atlas/admin1/LU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LV.geojson.gz b/server/assets/atlas/admin1/LV.geojson.gz
new file mode 100644
index 000000000..6ec6af989
Binary files /dev/null and b/server/assets/atlas/admin1/LV.geojson.gz differ
diff --git a/server/assets/atlas/admin1/LY.geojson.gz b/server/assets/atlas/admin1/LY.geojson.gz
new file mode 100644
index 000000000..0b1f56864
Binary files /dev/null and b/server/assets/atlas/admin1/LY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MA.geojson.gz b/server/assets/atlas/admin1/MA.geojson.gz
new file mode 100644
index 000000000..ffcfc9dcd
Binary files /dev/null and b/server/assets/atlas/admin1/MA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MC.geojson.gz b/server/assets/atlas/admin1/MC.geojson.gz
new file mode 100644
index 000000000..fdbbbad71
Binary files /dev/null and b/server/assets/atlas/admin1/MC.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MD.geojson.gz b/server/assets/atlas/admin1/MD.geojson.gz
new file mode 100644
index 000000000..3f1921167
Binary files /dev/null and b/server/assets/atlas/admin1/MD.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ME.geojson.gz b/server/assets/atlas/admin1/ME.geojson.gz
new file mode 100644
index 000000000..63c9fcca5
Binary files /dev/null and b/server/assets/atlas/admin1/ME.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MG.geojson.gz b/server/assets/atlas/admin1/MG.geojson.gz
new file mode 100644
index 000000000..9c50b35cb
Binary files /dev/null and b/server/assets/atlas/admin1/MG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MH.geojson.gz b/server/assets/atlas/admin1/MH.geojson.gz
new file mode 100644
index 000000000..3ad65d604
Binary files /dev/null and b/server/assets/atlas/admin1/MH.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MK.geojson.gz b/server/assets/atlas/admin1/MK.geojson.gz
new file mode 100644
index 000000000..d7b817cda
Binary files /dev/null and b/server/assets/atlas/admin1/MK.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ML.geojson.gz b/server/assets/atlas/admin1/ML.geojson.gz
new file mode 100644
index 000000000..dcea97c19
Binary files /dev/null and b/server/assets/atlas/admin1/ML.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MM.geojson.gz b/server/assets/atlas/admin1/MM.geojson.gz
new file mode 100644
index 000000000..e531b5494
Binary files /dev/null and b/server/assets/atlas/admin1/MM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MN.geojson.gz b/server/assets/atlas/admin1/MN.geojson.gz
new file mode 100644
index 000000000..55fe055b6
Binary files /dev/null and b/server/assets/atlas/admin1/MN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MR.geojson.gz b/server/assets/atlas/admin1/MR.geojson.gz
new file mode 100644
index 000000000..25a876239
Binary files /dev/null and b/server/assets/atlas/admin1/MR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MT.geojson.gz b/server/assets/atlas/admin1/MT.geojson.gz
new file mode 100644
index 000000000..1f37b56d0
Binary files /dev/null and b/server/assets/atlas/admin1/MT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MU.geojson.gz b/server/assets/atlas/admin1/MU.geojson.gz
new file mode 100644
index 000000000..8b665567a
Binary files /dev/null and b/server/assets/atlas/admin1/MU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MV.geojson.gz b/server/assets/atlas/admin1/MV.geojson.gz
new file mode 100644
index 000000000..09599e0a0
Binary files /dev/null and b/server/assets/atlas/admin1/MV.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MW.geojson.gz b/server/assets/atlas/admin1/MW.geojson.gz
new file mode 100644
index 000000000..fd3a3eb45
Binary files /dev/null and b/server/assets/atlas/admin1/MW.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MX.geojson.gz b/server/assets/atlas/admin1/MX.geojson.gz
new file mode 100644
index 000000000..89e6c57bd
Binary files /dev/null and b/server/assets/atlas/admin1/MX.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MY.geojson.gz b/server/assets/atlas/admin1/MY.geojson.gz
new file mode 100644
index 000000000..097562f46
Binary files /dev/null and b/server/assets/atlas/admin1/MY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/MZ.geojson.gz b/server/assets/atlas/admin1/MZ.geojson.gz
new file mode 100644
index 000000000..3326d7ce9
Binary files /dev/null and b/server/assets/atlas/admin1/MZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NA.geojson.gz b/server/assets/atlas/admin1/NA.geojson.gz
new file mode 100644
index 000000000..7c9ebaa42
Binary files /dev/null and b/server/assets/atlas/admin1/NA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NE.geojson.gz b/server/assets/atlas/admin1/NE.geojson.gz
new file mode 100644
index 000000000..a612504ba
Binary files /dev/null and b/server/assets/atlas/admin1/NE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NG.geojson.gz b/server/assets/atlas/admin1/NG.geojson.gz
new file mode 100644
index 000000000..2f3e8b8ea
Binary files /dev/null and b/server/assets/atlas/admin1/NG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NI.geojson.gz b/server/assets/atlas/admin1/NI.geojson.gz
new file mode 100644
index 000000000..1327550f7
Binary files /dev/null and b/server/assets/atlas/admin1/NI.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NL.geojson.gz b/server/assets/atlas/admin1/NL.geojson.gz
new file mode 100644
index 000000000..7af0ced06
Binary files /dev/null and b/server/assets/atlas/admin1/NL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NO.geojson.gz b/server/assets/atlas/admin1/NO.geojson.gz
new file mode 100644
index 000000000..751e362ad
Binary files /dev/null and b/server/assets/atlas/admin1/NO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NP.geojson.gz b/server/assets/atlas/admin1/NP.geojson.gz
new file mode 100644
index 000000000..fe1706a92
Binary files /dev/null and b/server/assets/atlas/admin1/NP.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NR.geojson.gz b/server/assets/atlas/admin1/NR.geojson.gz
new file mode 100644
index 000000000..55baf15c2
Binary files /dev/null and b/server/assets/atlas/admin1/NR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NU.geojson.gz b/server/assets/atlas/admin1/NU.geojson.gz
new file mode 100644
index 000000000..825e2dc31
Binary files /dev/null and b/server/assets/atlas/admin1/NU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/NZ.geojson.gz b/server/assets/atlas/admin1/NZ.geojson.gz
new file mode 100644
index 000000000..cb9b9970f
Binary files /dev/null and b/server/assets/atlas/admin1/NZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/OM.geojson.gz b/server/assets/atlas/admin1/OM.geojson.gz
new file mode 100644
index 000000000..4706f142c
Binary files /dev/null and b/server/assets/atlas/admin1/OM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PA.geojson.gz b/server/assets/atlas/admin1/PA.geojson.gz
new file mode 100644
index 000000000..23c7c16b6
Binary files /dev/null and b/server/assets/atlas/admin1/PA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PE.geojson.gz b/server/assets/atlas/admin1/PE.geojson.gz
new file mode 100644
index 000000000..029afd353
Binary files /dev/null and b/server/assets/atlas/admin1/PE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PG.geojson.gz b/server/assets/atlas/admin1/PG.geojson.gz
new file mode 100644
index 000000000..ed707a59c
Binary files /dev/null and b/server/assets/atlas/admin1/PG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PH.geojson.gz b/server/assets/atlas/admin1/PH.geojson.gz
new file mode 100644
index 000000000..aedcdbce7
Binary files /dev/null and b/server/assets/atlas/admin1/PH.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PK.geojson.gz b/server/assets/atlas/admin1/PK.geojson.gz
new file mode 100644
index 000000000..e0a6fec3e
Binary files /dev/null and b/server/assets/atlas/admin1/PK.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PL.geojson.gz b/server/assets/atlas/admin1/PL.geojson.gz
new file mode 100644
index 000000000..38e6b79e5
Binary files /dev/null and b/server/assets/atlas/admin1/PL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PS.geojson.gz b/server/assets/atlas/admin1/PS.geojson.gz
new file mode 100644
index 000000000..112a53afd
Binary files /dev/null and b/server/assets/atlas/admin1/PS.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PT.geojson.gz b/server/assets/atlas/admin1/PT.geojson.gz
new file mode 100644
index 000000000..34dd65fe7
Binary files /dev/null and b/server/assets/atlas/admin1/PT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PW.geojson.gz b/server/assets/atlas/admin1/PW.geojson.gz
new file mode 100644
index 000000000..efb750ff5
Binary files /dev/null and b/server/assets/atlas/admin1/PW.geojson.gz differ
diff --git a/server/assets/atlas/admin1/PY.geojson.gz b/server/assets/atlas/admin1/PY.geojson.gz
new file mode 100644
index 000000000..2232b8fb5
Binary files /dev/null and b/server/assets/atlas/admin1/PY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/QA.geojson.gz b/server/assets/atlas/admin1/QA.geojson.gz
new file mode 100644
index 000000000..d80a06aef
Binary files /dev/null and b/server/assets/atlas/admin1/QA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/RO.geojson.gz b/server/assets/atlas/admin1/RO.geojson.gz
new file mode 100644
index 000000000..e5a208a95
Binary files /dev/null and b/server/assets/atlas/admin1/RO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/RS.geojson.gz b/server/assets/atlas/admin1/RS.geojson.gz
new file mode 100644
index 000000000..b4c98dc85
Binary files /dev/null and b/server/assets/atlas/admin1/RS.geojson.gz differ
diff --git a/server/assets/atlas/admin1/RU.geojson.gz b/server/assets/atlas/admin1/RU.geojson.gz
new file mode 100644
index 000000000..ecbe45106
Binary files /dev/null and b/server/assets/atlas/admin1/RU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/RW.geojson.gz b/server/assets/atlas/admin1/RW.geojson.gz
new file mode 100644
index 000000000..0716ed463
Binary files /dev/null and b/server/assets/atlas/admin1/RW.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SA.geojson.gz b/server/assets/atlas/admin1/SA.geojson.gz
new file mode 100644
index 000000000..64cc84d62
Binary files /dev/null and b/server/assets/atlas/admin1/SA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SB.geojson.gz b/server/assets/atlas/admin1/SB.geojson.gz
new file mode 100644
index 000000000..3316b372c
Binary files /dev/null and b/server/assets/atlas/admin1/SB.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SC.geojson.gz b/server/assets/atlas/admin1/SC.geojson.gz
new file mode 100644
index 000000000..e2ff5a6f5
Binary files /dev/null and b/server/assets/atlas/admin1/SC.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SD.geojson.gz b/server/assets/atlas/admin1/SD.geojson.gz
new file mode 100644
index 000000000..339afd18b
Binary files /dev/null and b/server/assets/atlas/admin1/SD.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SE.geojson.gz b/server/assets/atlas/admin1/SE.geojson.gz
new file mode 100644
index 000000000..8220faee2
Binary files /dev/null and b/server/assets/atlas/admin1/SE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SG.geojson.gz b/server/assets/atlas/admin1/SG.geojson.gz
new file mode 100644
index 000000000..2a9958400
Binary files /dev/null and b/server/assets/atlas/admin1/SG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SI.geojson.gz b/server/assets/atlas/admin1/SI.geojson.gz
new file mode 100644
index 000000000..e59939258
Binary files /dev/null and b/server/assets/atlas/admin1/SI.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SK.geojson.gz b/server/assets/atlas/admin1/SK.geojson.gz
new file mode 100644
index 000000000..690c6d36a
Binary files /dev/null and b/server/assets/atlas/admin1/SK.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SL.geojson.gz b/server/assets/atlas/admin1/SL.geojson.gz
new file mode 100644
index 000000000..14f903421
Binary files /dev/null and b/server/assets/atlas/admin1/SL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SM.geojson.gz b/server/assets/atlas/admin1/SM.geojson.gz
new file mode 100644
index 000000000..37e4e13a7
Binary files /dev/null and b/server/assets/atlas/admin1/SM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SN.geojson.gz b/server/assets/atlas/admin1/SN.geojson.gz
new file mode 100644
index 000000000..81468cd8a
Binary files /dev/null and b/server/assets/atlas/admin1/SN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SO.geojson.gz b/server/assets/atlas/admin1/SO.geojson.gz
new file mode 100644
index 000000000..3b5c88505
Binary files /dev/null and b/server/assets/atlas/admin1/SO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SR.geojson.gz b/server/assets/atlas/admin1/SR.geojson.gz
new file mode 100644
index 000000000..a11863f36
Binary files /dev/null and b/server/assets/atlas/admin1/SR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SS.geojson.gz b/server/assets/atlas/admin1/SS.geojson.gz
new file mode 100644
index 000000000..b6b890a09
Binary files /dev/null and b/server/assets/atlas/admin1/SS.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ST.geojson.gz b/server/assets/atlas/admin1/ST.geojson.gz
new file mode 100644
index 000000000..2ef741ec5
Binary files /dev/null and b/server/assets/atlas/admin1/ST.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SV.geojson.gz b/server/assets/atlas/admin1/SV.geojson.gz
new file mode 100644
index 000000000..d43ebc335
Binary files /dev/null and b/server/assets/atlas/admin1/SV.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SY.geojson.gz b/server/assets/atlas/admin1/SY.geojson.gz
new file mode 100644
index 000000000..85fe93698
Binary files /dev/null and b/server/assets/atlas/admin1/SY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/SZ.geojson.gz b/server/assets/atlas/admin1/SZ.geojson.gz
new file mode 100644
index 000000000..a3cdf350e
Binary files /dev/null and b/server/assets/atlas/admin1/SZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TD.geojson.gz b/server/assets/atlas/admin1/TD.geojson.gz
new file mode 100644
index 000000000..ed10616a0
Binary files /dev/null and b/server/assets/atlas/admin1/TD.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TG.geojson.gz b/server/assets/atlas/admin1/TG.geojson.gz
new file mode 100644
index 000000000..b41f08a17
Binary files /dev/null and b/server/assets/atlas/admin1/TG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TH.geojson.gz b/server/assets/atlas/admin1/TH.geojson.gz
new file mode 100644
index 000000000..76246da05
Binary files /dev/null and b/server/assets/atlas/admin1/TH.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TJ.geojson.gz b/server/assets/atlas/admin1/TJ.geojson.gz
new file mode 100644
index 000000000..520bee6ed
Binary files /dev/null and b/server/assets/atlas/admin1/TJ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TL.geojson.gz b/server/assets/atlas/admin1/TL.geojson.gz
new file mode 100644
index 000000000..8da4a8f20
Binary files /dev/null and b/server/assets/atlas/admin1/TL.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TM.geojson.gz b/server/assets/atlas/admin1/TM.geojson.gz
new file mode 100644
index 000000000..501954b19
Binary files /dev/null and b/server/assets/atlas/admin1/TM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TN.geojson.gz b/server/assets/atlas/admin1/TN.geojson.gz
new file mode 100644
index 000000000..f1503c2e4
Binary files /dev/null and b/server/assets/atlas/admin1/TN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TO.geojson.gz b/server/assets/atlas/admin1/TO.geojson.gz
new file mode 100644
index 000000000..563cf7007
Binary files /dev/null and b/server/assets/atlas/admin1/TO.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TR.geojson.gz b/server/assets/atlas/admin1/TR.geojson.gz
new file mode 100644
index 000000000..97f91dff6
Binary files /dev/null and b/server/assets/atlas/admin1/TR.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TT.geojson.gz b/server/assets/atlas/admin1/TT.geojson.gz
new file mode 100644
index 000000000..22322ec61
Binary files /dev/null and b/server/assets/atlas/admin1/TT.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TV.geojson.gz b/server/assets/atlas/admin1/TV.geojson.gz
new file mode 100644
index 000000000..c9c9460e2
Binary files /dev/null and b/server/assets/atlas/admin1/TV.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TW.geojson.gz b/server/assets/atlas/admin1/TW.geojson.gz
new file mode 100644
index 000000000..896ac13c7
Binary files /dev/null and b/server/assets/atlas/admin1/TW.geojson.gz differ
diff --git a/server/assets/atlas/admin1/TZ.geojson.gz b/server/assets/atlas/admin1/TZ.geojson.gz
new file mode 100644
index 000000000..e420d64f5
Binary files /dev/null and b/server/assets/atlas/admin1/TZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/UA.geojson.gz b/server/assets/atlas/admin1/UA.geojson.gz
new file mode 100644
index 000000000..fe4239014
Binary files /dev/null and b/server/assets/atlas/admin1/UA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/UG.geojson.gz b/server/assets/atlas/admin1/UG.geojson.gz
new file mode 100644
index 000000000..397261685
Binary files /dev/null and b/server/assets/atlas/admin1/UG.geojson.gz differ
diff --git a/server/assets/atlas/admin1/US.geojson.gz b/server/assets/atlas/admin1/US.geojson.gz
new file mode 100644
index 000000000..3c28be666
Binary files /dev/null and b/server/assets/atlas/admin1/US.geojson.gz differ
diff --git a/server/assets/atlas/admin1/UY.geojson.gz b/server/assets/atlas/admin1/UY.geojson.gz
new file mode 100644
index 000000000..d536db239
Binary files /dev/null and b/server/assets/atlas/admin1/UY.geojson.gz differ
diff --git a/server/assets/atlas/admin1/UZ.geojson.gz b/server/assets/atlas/admin1/UZ.geojson.gz
new file mode 100644
index 000000000..1e955afac
Binary files /dev/null and b/server/assets/atlas/admin1/UZ.geojson.gz differ
diff --git a/server/assets/atlas/admin1/VC.geojson.gz b/server/assets/atlas/admin1/VC.geojson.gz
new file mode 100644
index 000000000..5a33b66f0
Binary files /dev/null and b/server/assets/atlas/admin1/VC.geojson.gz differ
diff --git a/server/assets/atlas/admin1/VE.geojson.gz b/server/assets/atlas/admin1/VE.geojson.gz
new file mode 100644
index 000000000..53c8b6be9
Binary files /dev/null and b/server/assets/atlas/admin1/VE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/VN.geojson.gz b/server/assets/atlas/admin1/VN.geojson.gz
new file mode 100644
index 000000000..9c68abe89
Binary files /dev/null and b/server/assets/atlas/admin1/VN.geojson.gz differ
diff --git a/server/assets/atlas/admin1/VU.geojson.gz b/server/assets/atlas/admin1/VU.geojson.gz
new file mode 100644
index 000000000..cdae4914a
Binary files /dev/null and b/server/assets/atlas/admin1/VU.geojson.gz differ
diff --git a/server/assets/atlas/admin1/WS.geojson.gz b/server/assets/atlas/admin1/WS.geojson.gz
new file mode 100644
index 000000000..da17e0704
Binary files /dev/null and b/server/assets/atlas/admin1/WS.geojson.gz differ
diff --git a/server/assets/atlas/admin1/XK.geojson.gz b/server/assets/atlas/admin1/XK.geojson.gz
new file mode 100644
index 000000000..c862b894d
Binary files /dev/null and b/server/assets/atlas/admin1/XK.geojson.gz differ
diff --git a/server/assets/atlas/admin1/YE.geojson.gz b/server/assets/atlas/admin1/YE.geojson.gz
new file mode 100644
index 000000000..386c2d8f1
Binary files /dev/null and b/server/assets/atlas/admin1/YE.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ZA.geojson.gz b/server/assets/atlas/admin1/ZA.geojson.gz
new file mode 100644
index 000000000..434ce3237
Binary files /dev/null and b/server/assets/atlas/admin1/ZA.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ZM.geojson.gz b/server/assets/atlas/admin1/ZM.geojson.gz
new file mode 100644
index 000000000..b4fd66e5d
Binary files /dev/null and b/server/assets/atlas/admin1/ZM.geojson.gz differ
diff --git a/server/assets/atlas/admin1/ZW.geojson.gz b/server/assets/atlas/admin1/ZW.geojson.gz
new file mode 100644
index 000000000..81719c19f
Binary files /dev/null and b/server/assets/atlas/admin1/ZW.geojson.gz differ
diff --git a/server/scripts/build-atlas-geo.mjs b/server/scripts/build-atlas-geo.mjs
index ff856d309..9560c27a7 100644
--- a/server/scripts/build-atlas-geo.mjs
+++ b/server/scripts/build-atlas-geo.mjs
@@ -1,5 +1,6 @@
#!/usr/bin/env node
-// Build server/assets/atlas/{admin0,admin1}.geojson.gz from geoBoundaries (gbOpen).
+// Build server/assets/atlas/{admin0,admin1}.geojson.gz and server/assets/atlas/admin1/<ISO_A2>.geojson.gz
+// from geoBoundaries (gbOpen).
//
// Why: Atlas previously fetched country + sub-national boundaries from Natural Earth's
// GitHub `master` at runtime. Natural Earth is stale (e.g. it still shows Norway's
@@ -9,8 +10,9 @@
//
// This downloads the *simplified* per-country gbOpen ADM0 (countries) and ADM1
// (regions) layers from a pinned geoBoundaries revision, normalizes each feature to
-// the property names the Atlas client/server already read, and writes two gzipped
-// FeatureCollections that the server serves at runtime (no network at boot).
+// the property names the Atlas client/server already read, and writes gzipped
+// FeatureCollections that the server serves at runtime (no network at boot): one for
+// every country's borders, and one per country for its regions.
//
// geoBoundaries: CC BY 4.0 — https://www.geoboundaries.org/ (attribution required).
import fs from 'node:fs';
@@ -461,7 +463,7 @@ function normalizeAdm1(geo, a3, countryName) {
}
return {
type: 'Feature',
- // Property names the Atlas region layer + server getRegionGeo already read.
+ // Property names the Atlas region layer + server region lookup already read.
properties: {
iso_a2: a2,
iso_3166_2: code,
@@ -516,8 +518,25 @@ async function main() {
};
write('admin0', adm0Features);
+ // Read only by two shipped migrations (Migration20200101021500/…031500), whose bodies
+ // never change; the server itself reads the per-country files below.
write('admin1', adm1Features);
+ // admin1 also goes out as one file per country, named by ISO_A2, so the server can hand
+ // a country's regions to the map straight from disk and read only the country it needs
+ // for a lookup — the single bundle had to be held whole in memory to do either. A
+ // feature with no alpha-2 code has no file to go in, and nothing could look it up.
+ const byCountry = new Map();
+ for (const f of adm1Features) {
+ const a2 = f.properties.iso_a2;
+ if (!a2) continue;
+ if (!byCountry.has(a2)) byCountry.set(a2, []);
+ byCountry.get(a2).push(f);
+ }
+ fs.rmSync(path.join(OUT_DIR, 'admin1'), { recursive: true, force: true });
+ fs.mkdirSync(path.join(OUT_DIR, 'admin1'));
+ for (const [a2, features] of byCountry) write(`admin1/${a2}`, features);
+
const missing1 = COUNTRIES.filter((a3, i) => !normalizeAdm1(adm1Raw[i], a3, '').length);
console.log(`[atlas-geo] ADM0 country features: ${adm0Features.length}`);
console.log(`[atlas-geo] ADM1 countries without regions (skipped/404): ${missing1.length}`);
diff --git a/server/scripts/eslint-baseline.json b/server/scripts/eslint-baseline.json
index 51de21574..efa01fcb2 100644
--- a/server/scripts/eslint-baseline.json
+++ b/server/scripts/eslint-baseline.json
@@ -6,7 +6,7 @@
"@typescript-eslint/no-unsafe-function-type": 1,
"@typescript-eslint/no-unused-vars": 36,
"no-await-in-loop": 562,
- "no-console": 235,
+ "no-console": 234,
"no-empty": 6
},
"suppressed": {
@@ -16,7 +16,7 @@
"no-misleading-character-class": 1
},
"tests": {
- "@typescript-eslint/no-explicit-any": 1562,
+ "@typescript-eslint/no-explicit-any": 1559,
"@typescript-eslint/no-non-null-assertion": 1755,
"@typescript-eslint/no-require-imports": 25,
"@typescript-eslint/no-unsafe-function-type": 7,
diff --git a/server/scripts/size-baseline.json b/server/scripts/size-baseline.json
index d36978050..5462aae78 100644
--- a/server/scripts/size-baseline.json
+++ b/server/scripts/size-baseline.json
@@ -5,7 +5,7 @@
"src/db/repositories/Reservations.repository.ts": 1604,
"src/db/repositories/Trips.repository.ts": 1121,
"src/db/repositories/Users.repository.ts": 1445,
- "src/nest/atlas/atlas.service.ts": 1182,
+ "src/nest/atlas/atlas.service.ts": 1177,
"src/nest/auth/auth.service.ts": 1143,
"src/nest/budget/budget.service.ts": 1617,
"src/nest/collections/collections.service.ts": 1478,
diff --git a/server/scripts/test-size-baseline.json b/server/scripts/test-size-baseline.json
index b30382988..a461eb9e1 100644
--- a/server/scripts/test-size-baseline.json
+++ b/server/scripts/test-size-baseline.json
@@ -1,5 +1,5 @@
{
- "tests/unit/nest/atlas.service.test.ts": 2193,
+ "tests/unit/nest/atlas.service.test.ts": 2154,
"tests/unit/nest/budget.service.db.test.ts": 2220,
"tests/unit/nest/doc-sync/doc-sync.service.test.ts": 2511,
"tests/unit/nest/journey-domain.service.test.ts": 3876,
diff --git a/server/src/nest/atlas/atlas-geo.ts b/server/src/nest/atlas/atlas-geo.ts
index 7653fa506..ee84f9f6d 100644
--- a/server/src/nest/atlas/atlas-geo.ts
+++ b/server/src/nest/atlas/atlas-geo.ts
@@ -1,10 +1,10 @@
import { Place } from '../../types';
import fs from 'fs';
+import path from 'path';
import zlib from 'zlib';
import {
- assetPath,
- createFeatureSplitter,
+ admin1AssetPath,
getCountryFromCoords,
isPointInCountryBox,
loadAdmin0Gz,
@@ -17,7 +17,7 @@ import { cacheKeyFor, getCached, nominatimFetch, setCached } from '../geo/nomina
// ── Pure geo machinery for the atlas domain ─────────────────────────────────
//
// Plain module on purpose (same class as maps.helpers.ts / tripAccess): no DI,
-// no DB access, no Nest imports. The caches below (admin1 per-country store,
+// no DB access, no Nest imports. The caches below (parsed admin1 region features,
// geocode/region caches, the shared Nominatim throttle and the geocodingInFlight
// dedup set) are file-scoped so their lifetime stays process-global no matter how
// many AtlasService instances exist (container singleton + test helpers) —
@@ -37,10 +37,10 @@ export { getCountryFromCoords, isPointInCountryBox };
//
// Neither parsed bundle is cached. admin0 (~145MB) and admin1 (~260MB) parsed at once are
// what exhausted a 512MB host while using Atlas (#1576). Instead we retain only compact
-// derivatives: the raw admin0 .gz bytes for direct serving, a Float64Array poly/box index
-// for server-side point-in-polygon (see buildCountryIndexes in utils/country-borders.ts),
-// and admin1 pre-split per country into ready-to-serve GeoJSON strings, built by
-// streaming the gz so the full bundle is never materialised in one piece.
+// derivatives: the raw admin0 .gz bytes for direct serving and a Float64Array poly/box
+// index for server-side point-in-polygon (see buildCountryIndexes in
+// utils/country-borders.ts). admin1 ships as one gzipped file per country, which is
+// served from disk as it is and read one country at a time for region lookups.
/** admin-0 country borders as gzipped GeoJSON bytes, served to the client map with
* Content-Encoding: gzip so the server never holds the parsed FeatureCollection. */
@@ -57,75 +57,68 @@ export function getCountryGeo(): any {
return JSON.parse(zlib.gunzipSync(gz).toString('utf8'));
}
-export async function getRegionGeo(countryCodes: string[]): Promise<any> {
- const store = await getAdmin1Store();
- const seen = new Set<string>();
- const parts: string[] = [];
- for (const code of countryCodes) {
- const c = code.toUpperCase();
- if (seen.has(c)) continue;
- seen.add(c);
- const s = store.get(c);
- if (s) parts.push(s);
+// A country's admin-1 file, or null for anything that is not a two-letter code, so
+// nothing a client sends can name a path outside the folder. A country without a file
+// has no regions; the whole folder missing is a broken install, said once.
+let admin1Checked = false;
+function admin1File(countryCode: string): string | null {
+ const cc = countryCode.toUpperCase();
+ if (!/^[A-Z]{2}$/.test(cc)) return null;
+ const file = admin1AssetPath(cc);
+ if (!admin1Checked) {
+ admin1Checked = true;
+ if (!fs.existsSync(path.dirname(file))) {
+ console.warn(`[Atlas] admin1 region files missing — run \`node scripts/build-atlas-geo.mjs\``);
+ }
}
- if (parts.length === 0) return { type: 'FeatureCollection', features: [] };
- // Each stored value is that country's features as comma-joined GeoJSON text; wrap the
- // requested subset into one FeatureCollection and parse only that (per-viewport, small).
- return JSON.parse(`{"type":"FeatureCollection","features":[${parts.join(',')}]}`);
+ return file;
}
-// admin1 regions, pre-split per ISO_A2 into comma-joined feature text. Built once by
-// streaming the gz through a brace-depth splitter that emits one Feature at a time, so the
-// ~260MB full parse never happens (it OOMs a 512MB host). Concurrent first-callers share
-// one in-flight build via admin1Building.
-let admin1Store: Map<string, string> | null = null;
-let admin1Building: Promise<Map<string, string>> | null = null;
-
-function getAdmin1Store(): Promise<Map<string, string>> {
- if (admin1Store) return Promise.resolve(admin1Store);
- // `=== null`, not `!admin1Building`: a Promise in a boolean condition is what
- // no-misused-promises/checksConditionals exists to catch, and the distinction
- // matters once every DB-touching method returns one.
- if (admin1Building === null) {
- admin1Building = buildAdmin1Store().then((s) => {
- admin1Store = s;
- admin1Building = null;
- return s;
- });
+// A country's admin-1 FeatureCollection as JSON bytes, or null when the bundle has no
+// regions for it. Synchronous like the parse that follows it; one country is a small file.
+function readAdmin1Json(countryCode: string): Buffer | null {
+ const file = admin1File(countryCode);
+ if (!file) return null;
+ try {
+ return zlib.gunzipSync(fs.readFileSync(file));
+ } catch {
+ return null;
}
- return admin1Building;
}
-function buildAdmin1Store(): Promise<Map<string, string>> {
- const file = assetPath('admin1');
- if (!fs.existsSync(file)) {
- console.warn(`[Atlas] admin1.geojson.gz missing — run \`node scripts/build-atlas-geo.mjs\``);
- return Promise.resolve(new Map());
+/** One country's admin-1 regions as gzipped GeoJSON bytes, served to the client map with
+ * Content-Encoding: gzip like getCountryGeoGz, so the server never parses them. */
+export async function getRegionGeoGz(countryCode: string): Promise<Buffer | null> {
+ const file = admin1File(countryCode);
+ if (!file) return null;
+ try {
+ return await fs.promises.readFile(file);
+ } catch {
+ return null;
+ }
+}
+
+// How build-atlas-geo.mjs writes every per-country file; atlasBundle.test.ts holds it to that.
+const FC_HEAD = '{"type":"FeatureCollection","features":[';
+const FC_TAIL = ']}';
+
+/**
+ * Several countries' regions as one FeatureCollection, for clients that still ask
+ * /regions/geo?countries=… from before the map fetched one country per request. Each
+ * file's features are cut out and joined as bytes, never parsed (#1576).
+ */
+export function getRegionGeoJson(countryCodes: string[]): Buffer {
+ const parts: Buffer[] = [Buffer.from(FC_HEAD)];
+ let first = true;
+ for (const cc of new Set(countryCodes.map((c) => c.toUpperCase()))) {
+ const json = readAdmin1Json(cc);
+ if (!json) continue;
+ if (!first) parts.push(Buffer.from(','));
+ parts.push(json.subarray(FC_HEAD.length, json.length - FC_TAIL.length));
+ first = false;
}
- // Concatenate each country's features straight into the store as we stream, rather than
- // collecting arrays and joining at the end (that doubling, plus the source bundle's
- // whitespace, peaked high enough to OOM a 512MB host on the first build). Re-serialising
- // each feature via JSON drops the source formatting (~114MB → ~68MB retained) and the
- // parse/stringify garbage is per-feature and short-lived.
- const store = new Map<string, string>();
- const split = createFeatureSplitter((text) => {
- const f = JSON.parse(text);
- const code = f.properties?.iso_a2?.toUpperCase();
- if (!code) return; // features with a null iso_a2 are skipped, matching the old filter
- const compact = JSON.stringify(f);
- const prev = store.get(code);
- store.set(code, prev ? prev + ',' + compact : compact);
- });
- return new Promise((resolve, reject) => {
- fs.createReadStream(file)
- .pipe(zlib.createGunzip())
- .on('data', (chunk: Buffer) => split(chunk.toString('utf8')))
- .on('end', () => {
- console.log(`[Atlas] Indexed admin1 GeoJSON: ${store.size} countries`);
- resolve(store);
- })
- .on('error', reject);
- });
+ parts.push(Buffer.from(FC_TAIL));
+ return Buffer.concat(parts);
}
// ── Country names, for the address fallback ─────────────────────────────────
@@ -524,9 +517,9 @@ const regionCache = new Map<string, RegionInfo | null>();
// getCountryFromCoords does for admin0 (#1331) — sidesteps the whole class of bug: the
// stored region_code/region_name are then guaranteed to equal a bundle feature.
//
-// The admin1 bundle is streamed and held as per-country GeoJSON text (never parsed whole,
-// #1576), so a country's region features are parsed and flattened to CompactGeom on first
-// use and cached — only visited countries ever pay the parse.
+// The admin1 regions ship as one file per country (never parsed whole, #1576), so a
+// country's region features are read, parsed and flattened to CompactGeom on first use
+// and cached — only visited countries ever pay the parse.
type RegionFeature = { code: string; name: string; nameEn: string; geom: CompactGeom; boxes: Box[] };
const regionFeatureCache = new Map<string, RegionFeature[]>();
@@ -534,15 +527,14 @@ async function getRegionFeatures(countryCode: string): Promise<RegionFeature[]>
const cc = countryCode.toUpperCase();
const cached = regionFeatureCache.get(cc);
if (cached) return cached;
- const store = await getAdmin1Store();
- const text = store.get(cc);
- if (!text) {
+ const json = readAdmin1Json(cc);
+ if (!json) {
regionFeatureCache.set(cc, []);
return [];
}
let features: { properties?: Record<string, string>; geometry?: { type: string; coordinates: unknown } }[];
try {
- features = JSON.parse(`{"type":"FeatureCollection","features":[${text}]}`).features ?? [];
+ features = JSON.parse(json.toString('utf8')).features ?? [];
} catch {
regionFeatureCache.set(cc, []);
return [];
diff --git a/server/src/nest/atlas/atlas.controller.ts b/server/src/nest/atlas/atlas.controller.ts
index 45e04cf36..84767242d 100644
--- a/server/src/nest/atlas/atlas.controller.ts
+++ b/server/src/nest/atlas/atlas.controller.ts
@@ -1,6 +1,8 @@
import type { User } from '../../types';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
+import { ZodValidationPipe } from '../common/zod-validation.pipe';
+import { getRegionGeoGz, getRegionGeoJson } from './atlas-geo';
import { AtlasWritesService } from './atlas-writes.service';
import { AtlasMarkRegionDto, AtlasCreateBucketItemDto, AtlasUpdateBucketItemDto } from './atlas.dto';
import { AtlasService, BucketItemExistsError } from './atlas.service';
@@ -20,7 +22,8 @@ import {
Res,
UseGuards,
} from '@nestjs/common';
-import type { AtlasLocateResponse, RegionGeo } from '@trek/shared';
+import { regionGeoParamsSchema } from '@trek/shared';
+import type { AtlasLocateResponse, RegionGeoParams } from '@trek/shared';
import type { Response } from 'express';
@@ -78,20 +81,42 @@ export class AtlasController {
return this.atlas.locate(latNum, lngNum);
}
+ // Kept for clients from before the map asked for one country at a time (below). They
+ // get the same FeatureCollection as before, joined from the per-country files without
+ // a parse; drop it once those clients are gone.
@Get('regions/geo')
- async regionGeo(
- @Query('countries') countries: string | undefined,
- @Res({ passthrough: true }) res: Response,
- ): Promise<RegionGeo> {
+ regionGeo(@Query('countries') countries: string | undefined, @Res() res: Response): void {
const list = (countries || '').split(',').filter(Boolean);
if (list.length === 0) {
- return { type: 'FeatureCollection', features: [] };
+ res.json({ type: 'FeatureCollection', features: [] });
+ return;
}
- const geo = await this.atlas.regionGeo(list);
+ const json = getRegionGeoJson(list);
// Cache only a non-empty result, matching the legacy route (the empty
// short-circuit above sends no Cache-Control header).
res.setHeader('Cache-Control', 'public, max-age=86400');
- return geo;
+ res.type('application/json').send(json);
+ }
+
+ // response-contract-exempt: sends a gzipped file through @Res() as it is, there is no JSON body to check.
+ @Get('regions/geo/:code')
+ async regionGeoForCountry(
+ @Param(new ZodValidationPipe(regionGeoParamsSchema)) params: RegionGeoParams,
+ @Res() res: Response,
+ ): Promise<void> {
+ // One country's pre-gzipped admin-1 file, served the way countries/geo is: the server
+ // never parses or holds it (#1576), and the browser caches every country on its own. A
+ // country the bundle has no regions for gets an empty FeatureCollection, cached the
+ // same, so it is not asked again; a code that is not two letters is a 400.
+ const gz = await getRegionGeoGz(params.code);
+ res.setHeader('Cache-Control', 'public, max-age=86400');
+ if (!gz) {
+ res.json({ type: 'FeatureCollection', features: [] });
+ return;
+ }
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
+ res.setHeader('Content-Encoding', 'gzip');
+ res.send(gz);
}
@Get('countries/geo')
diff --git a/server/src/nest/atlas/atlas.service.ts b/server/src/nest/atlas/atlas.service.ts
index 47ee26905..00a0aac7b 100644
--- a/server/src/nest/atlas/atlas.service.ts
+++ b/server/src/nest/atlas/atlas.service.ts
@@ -28,7 +28,6 @@ import {
getCountryFromCoords,
getCountryGeoGz,
getRegionFromCoords,
- getRegionGeo,
geocodingInFlight,
resolveCountryCodeSync,
resolveRegionFromBundle,
@@ -877,10 +876,6 @@ export class AtlasService {
};
}
- regionGeo(countries: string[]) {
- return getRegionGeo(countries);
- }
-
countryGeoGz(): Buffer | null {
return getCountryGeoGz();
}
diff --git a/server/src/utils/country-borders.ts b/server/src/utils/country-borders.ts
index b184130b1..8fb5b738f 100644
--- a/server/src/utils/country-borders.ts
+++ b/server/src/utils/country-borders.ts
@@ -11,8 +11,8 @@ import zlib from 'zlib';
// for the country an index suggestion names. Importing it from atlas tied maps into
// an import cycle with atlas (lint:boundaries).
//
-// atlas-geo builds its admin-1 region index on the asset path, the feature splitter
-// and the ring test exported here. The admin0 gz bytes and the country poly/box
+// atlas-geo resolves admin-1 regions with the per-country asset path and the ring test
+// exported here. The admin0 gz bytes and the country poly/box
// indexes below are file-scoped for the reason atlas-geo gives: their lifetime stays
// process-global however many callers there are, so the indexes are built once per
// process, which the #1576 OOM fix depends on.
@@ -20,18 +20,24 @@ import zlib from 'zlib';
// ── Bundled boundary GeoJSON (admin-0 countries + admin-1 regions) ─────────
//
// Sourced from geoBoundaries (CC BY 4.0), normalized + quantized offline by
-// scripts/build-atlas-geo.mjs into gzipped FeatureCollections under server/assets.
-// They are read + decompressed once and cached in memory — no network at runtime.
+// scripts/build-atlas-geo.mjs into gzipped FeatureCollections under server/assets:
+// admin0 as one file, admin1 as one file per country (the whole admin1 bundle ships
+// too, for two migrations that read it). No network at runtime.
// (Replaces the previous runtime fetch of Natural Earth, which was stale for recent
// sub-national reforms and depicts some contested borders in unwanted ways.)
//
// __dirname is server/dist/utils at runtime and server/src/utils under vitest;
// both resolve ../../assets to server/assets.
-export function assetPath(name: 'admin0' | 'admin1'): string {
+function assetPath(name: 'admin0'): string {
return path.join(__dirname, '..', '..', 'assets', 'atlas', `${name}.geojson.gz`);
}
+/** One country's admin-1 regions, a FeatureCollection of its own, named by ISO_A2. */
+export function admin1AssetPath(countryCode: string): string {
+ return path.join(__dirname, '..', '..', 'assets', 'atlas', 'admin1', `${countryCode}.geojson.gz`);
+}
+
let admin0Gz: Buffer | null | undefined;
export function loadAdmin0Gz(): Buffer | null {
if (admin0Gz !== undefined) return admin0Gz;
@@ -46,13 +52,14 @@ export function loadAdmin0Gz(): Buffer | null {
// Feed arbitrary gunzip chunks; invokes onFeature(text) once per top-level Feature object
// inside "features":[ … ]. `pending` holds only the unconsumed tail (at most one partial
// feature + the current chunk), keeping memory flat regardless of bundle size.
-export function createFeatureSplitter(onFeature: (text: string) => void): (chunk: string) => void {
+function createFeatureSplitter(onFeature: (text: string) => void): (chunk: string) => void {
let pending = '';
let started = false;
// Scan progress is carried across chunks so each character is examined exactly once.
// A large Feature (e.g. Canada, ~5.5MB) spans hundreds of gunzip chunks; re-scanning the
// accumulated partial from the start on every chunk was O(n²) per feature and pushed the
- // one-time admin1 build past the 15s test timeout under coverage/CI (#1576-followup).
+ // one-time admin1 build (since replaced by per-country files) past the 15s test timeout
+ // under coverage/CI (#1576-followup).
let scanning = false; // currently inside a Feature object?
let depth = 0,
inStr = false,
diff --git a/server/tests/integration/atlas.test.ts b/server/tests/integration/atlas.test.ts
index fe63d47a9..f70050545 100644
--- a/server/tests/integration/atlas.test.ts
+++ b/server/tests/integration/atlas.test.ts
@@ -5,7 +5,6 @@
import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { PlaceRegions } from '../../src/db/entities/PlaceRegions.entity';
-import { getRegionGeo } from '../../src/nest/atlas/atlas-geo';
import { authCookie } from '../helpers/auth';
import { createUser, createTrip } from '../helpers/factories';
import type { FactoryOrm } from '../helpers/factories/context';
@@ -53,12 +52,6 @@ beforeAll(async () => {
nestApp = await buildApp();
app = nestApp.getHttpAdapter().getInstance();
-
- // Warm the admin-1 store here rather than inside ATLAS-013. The first call streams
- // the multi-MB bundle through the brace-depth splitter and caches it for the process,
- // which costs ~3s on a quiet machine and more when every worker is busy — so whichever
- // test hit it first used to pay for it inside its own 5s budget and fail under load.
- await getRegionGeo(['ZZ']);
}, 60_000);
beforeEach(async () => {
@@ -497,6 +490,49 @@ describe('Regions geo', () => {
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('type', 'FeatureCollection');
+ expect(
+ new Set((res.body.features as { properties: { iso_a2: string } }[]).map((f) => f.properties.iso_a2)),
+ ).toEqual(new Set(['DE', 'FR']));
+ });
+
+ it('ATLAS-016 — GET /regions/geo/:code serves that country gzipped, cached for a day', async () => {
+ const { user } = createUser(testDb);
+
+ const res = await request(app)
+ .get('/api/addons/atlas/regions/geo/no')
+ .set('Accept-Encoding', 'gzip')
+ .set('Cookie', authCookie(user.id));
+
+ expect(res.status).toBe(200);
+ expect(res.headers['content-encoding']).toBe('gzip');
+ expect(res.headers['cache-control']).toBe('public, max-age=86400');
+ expect(res.body.type).toBe('FeatureCollection');
+ expect(res.body.features.length).toBeGreaterThan(0);
+ expect((res.body.features as { properties: { iso_a2: string } }[]).every((f) => f.properties.iso_a2 === 'NO')).toBe(
+ true,
+ );
+ });
+
+ it('ATLAS-017 — GET /regions/geo/:code answers a country without regions with an empty FeatureCollection', async () => {
+ const { user } = createUser(testDb);
+
+ const res = await request(app).get('/api/addons/atlas/regions/geo/ZZ').set('Cookie', authCookie(user.id));
+
+ expect(res.status).toBe(200);
+ expect(res.body).toEqual({ type: 'FeatureCollection', features: [] });
+ });
+
+ it('ATLAS-018 — GET /regions/geo/:code refuses a code that is not two letters with a 400', async () => {
+ const { user } = createUser(testDb);
+
+ const codes = ['NOR', '..%2Fadmin0'];
+ const answers = await Promise.all(
+ codes.map((code) => request(app).get(`/api/addons/atlas/regions/geo/${code}`).set('Cookie', authCookie(user.id))),
+ );
+ for (const [i, res] of answers.entries()) {
+ expect(res.status, codes[i]).toBe(400);
+ expect(res.body.error, codes[i]).toMatch(/^code: /);
+ }
});
});
diff --git a/server/tests/unit/nest/atlas-region-files.test.ts b/server/tests/unit/nest/atlas-region-files.test.ts
new file mode 100644
index 000000000..4d11555c2
--- /dev/null
+++ b/server/tests/unit/nest/atlas-region-files.test.ts
@@ -0,0 +1,59 @@
+import { getRegionGeoGz, getRegionGeoJson } from '../../../src/nest/atlas/atlas-geo';
+
+import { describe, it, expect } from 'vitest';
+import zlib from 'zlib';
+
+// The admin-1 regions behind the Atlas region layer and region lookups, read from the
+// committed geoBoundaries files (server/assets/atlas/admin1/<ISO_A2>.geojson.gz), so these
+// double as a guard that the bundle ships current sub-national data (#1119).
+
+type RegionFeature = { properties: { iso_a2: string; iso_3166_2: string; name: string } };
+type RegionGeo = { type: string; features: RegionFeature[] };
+
+const regionGeo = (codes: string[]) => JSON.parse(getRegionGeoJson(codes).toString('utf8')) as RegionGeo;
+const countriesOf = (geo: RegionGeo) => new Set(geo.features.map((f) => f.properties.iso_a2));
+
+describe('getRegionGeoJson', () => {
+ it('ATLAS-SVC-017: returns an empty FeatureCollection for a country with no admin-1 features', () => {
+ expect(regionGeo(['ZZ'])).toEqual({ type: 'FeatureCollection', features: [] });
+ });
+
+ it('ATLAS-SVC-018: returns the current geoBoundaries regions for a country, case-insensitively', () => {
+ const result = regionGeo(['no']);
+
+ expect(result.type).toBe('FeatureCollection');
+ expect(result.features.length).toBeGreaterThan(0);
+ expect(countriesOf(result)).toEqual(new Set(['NO']));
+
+ const names = result.features.map((f) => f.properties.name);
+ const codes = result.features.map((f) => f.properties.iso_3166_2);
+ // Post-2020 reform is present…
+ expect(codes).toContain('NO-34'); // Innlandet
+ expect(codes).toContain('NO-46'); // Vestland
+ // …and the merged-away pre-2020 counties are gone (the original #1119 bug).
+ expect(names).not.toContain('Oppland');
+ expect(names).not.toContain('Hordaland');
+ expect(names).not.toContain('Sogn og Fjordane');
+ });
+
+ it('ATLAS-SVC-048: joins several countries into one FeatureCollection, each once, skipping unknown codes', () => {
+ const result = regionGeo(['DE', 'zz', 'FR', 'de']);
+ expect(countriesOf(result)).toEqual(new Set(['DE', 'FR']));
+ expect(result.features.length).toBe(regionGeo(['DE']).features.length + regionGeo(['FR']).features.length);
+ });
+});
+
+describe('getRegionGeoGz', () => {
+ it("ATLAS-SVC-049: returns the country's gzipped FeatureCollection, case-insensitively", async () => {
+ const gz = await getRegionGeoGz('no');
+ expect(gz).toBeInstanceOf(Buffer);
+ const geo = JSON.parse(zlib.gunzipSync(gz ?? Buffer.alloc(0)).toString('utf8')) as RegionGeo;
+ expect(geo.type).toBe('FeatureCollection');
+ expect(countriesOf(geo)).toEqual(new Set(['NO']));
+ });
+
+ it('ATLAS-SVC-050: returns null for a country without regions and for anything that is not a two-letter code', async () => {
+ const codes = ['ZZ', 'NOR', '', '../admin0', '..', 'N/'];
+ expect(await Promise.all(codes.map((code) => getRegionGeoGz(code)))).toEqual(codes.map(() => null));
+ });
+});
diff --git a/server/tests/unit/nest/atlas.controller.test.ts b/server/tests/unit/nest/atlas.controller.test.ts
index 34fee5412..6e3186c7b 100644
--- a/server/tests/unit/nest/atlas.controller.test.ts
+++ b/server/tests/unit/nest/atlas.controller.test.ts
@@ -9,6 +9,7 @@ import { HttpException, RequestMethod } from '@nestjs/common';
import type { Response } from 'express';
import { describe, it, expect, vi } from 'vitest';
+import zlib from 'zlib';
const user = { id: 8 } as User;
@@ -18,10 +19,13 @@ function makeController(svc: Partial<AtlasService> & Partial<AtlasWritesService>
}
function makeRes() {
- return { setHeader: vi.fn(), send: vi.fn(), json: vi.fn() } as unknown as Response & {
+ const res = { setHeader: vi.fn(), send: vi.fn(), json: vi.fn(), type: vi.fn() };
+ res.type.mockReturnValue(res);
+ return res as unknown as Response & {
setHeader: ReturnType<typeof vi.fn>;
send: ReturnType<typeof vi.fn>;
json: ReturnType<typeof vi.fn>;
+ type: ReturnType<typeof vi.fn>;
};
}
@@ -43,23 +47,45 @@ describe('AtlasController (parity with the legacy /api/addons/atlas route)', ()
expect(stats).toHaveBeenCalledWith(8);
});
+ // The region routes read the committed per-country files (server/assets/atlas/admin1).
+ type RegionFeatures = { features: { properties: { iso_a2: string } }[] };
+ const countriesOf = (geo: RegionFeatures) => new Set(geo.features.map((f) => f.properties.iso_a2));
+
describe('GET /regions/geo', () => {
- it('returns an empty FeatureCollection without a cache header when no countries given', async () => {
- const regionGeo = vi.fn();
+ it('returns an empty FeatureCollection without a cache header when no countries given', () => {
const res = makeRes();
- const out = await makeController({ regionGeo }).regionGeo(undefined, res);
- expect(out).toEqual({ type: 'FeatureCollection', features: [] });
- expect(regionGeo).not.toHaveBeenCalled();
+ makeController({}).regionGeo(undefined, res);
+ expect(res.json).toHaveBeenCalledWith({ type: 'FeatureCollection', features: [] });
expect(res.setHeader).not.toHaveBeenCalled();
});
- it('caches a non-empty result for a day', async () => {
- const regionGeo = vi.fn().mockResolvedValue({ type: 'FeatureCollection', features: [{ id: 1 }] });
+ it('sends the countries joined into one FeatureCollection and caches them for a day', () => {
+ const res = makeRes();
+ makeController({}).regionGeo('DE,FR', res);
+ expect(res.type).toHaveBeenCalledWith('application/json');
+ expect(res.setHeader).toHaveBeenCalledWith('Cache-Control', 'public, max-age=86400');
+ const body = JSON.parse(String(res.send.mock.calls[0][0])) as RegionFeatures;
+ expect(countriesOf(body)).toEqual(new Set(['DE', 'FR']));
+ });
+ });
+
+ describe('GET /regions/geo/:code', () => {
+ it("serves the country's gzipped admin-1 file with Content-Encoding and a day of cache", async () => {
+ const res = makeRes();
+ await makeController({}).regionGeoForCountry({ code: 'NO' }, res);
+ expect(res.setHeader).toHaveBeenCalledWith('Content-Type', 'application/json; charset=utf-8');
+ expect(res.setHeader).toHaveBeenCalledWith('Content-Encoding', 'gzip');
+ expect(res.setHeader).toHaveBeenCalledWith('Cache-Control', 'public, max-age=86400');
+ const body = JSON.parse(zlib.gunzipSync(res.send.mock.calls[0][0] as Buffer).toString()) as RegionFeatures;
+ expect(countriesOf(body)).toEqual(new Set(['NO']));
+ });
+
+ it('answers a country without regions with a cached empty FeatureCollection', async () => {
const res = makeRes();
- const out = await makeController({ regionGeo }).regionGeo('DE,FR', res);
- expect(out).toEqual({ type: 'FeatureCollection', features: [{ id: 1 }] });
- expect(regionGeo).toHaveBeenCalledWith(['DE', 'FR']);
+ await makeController({}).regionGeoForCountry({ code: 'ZZ' }, res);
+ expect(res.json).toHaveBeenCalledWith({ type: 'FeatureCollection', features: [] });
expect(res.setHeader).toHaveBeenCalledWith('Cache-Control', 'public, max-age=86400');
+ expect(res.setHeader).not.toHaveBeenCalledWith('Content-Encoding', 'gzip');
});
});
diff --git a/server/tests/unit/nest/atlas.service.test.ts b/server/tests/unit/nest/atlas.service.test.ts
index f2446d2eb..bb758cbe7 100644
--- a/server/tests/unit/nest/atlas.service.test.ts
+++ b/server/tests/unit/nest/atlas.service.test.ts
@@ -28,7 +28,7 @@ vi.mock('../../../src/db/database', async () => {
import { db as testDb } from '../../../src/db/database';
import { resetTestDb } from '../../helpers/test-db';
import { createUser, createTrip, createReservation } from '../../helpers/factories';
-import { getCountryFromCoords, getCountryFromAddress, isPointInCountryBox, reverseGeocodeCountry, getRegionGeo, getCountryGeo } from '../../../src/nest/atlas/atlas-geo';
+import { getCountryFromCoords, getCountryFromAddress, isPointInCountryBox, reverseGeocodeCountry, getCountryGeo } from '../../../src/nest/atlas/atlas-geo';
import { cacheKeyFor, getCached, setCached } from '../../../src/nest/geo/nominatim.client';
import { AtlasService, BucketItemExistsError, bucketRegionCode } from '../../../src/nest/atlas/atlas.service';
import { createTestUnitOfWork, createTestTripsRepo, createTestPlacesRepo, createTestReservationEndpointsRepo, sharedTestOrm } from '../../helpers/test-uow';
@@ -687,45 +687,6 @@ describe('reverseGeocodeCountry', () => {
});
});
-// ── getRegionGeo ────────────────────────────────────────────────────────────
-
-// These read the committed geoBoundaries bundle (server/assets/atlas/admin1.geojson.gz),
-// so they double as a guard that the bundle ships current sub-national data (#1119).
-describe('getRegionGeo', () => {
- // The first call streams the multi-MB admin1.geojson.gz through the brace-depth
- // splitter and caches the result for the process. That build alone takes ~2.5s on a
- // quiet machine and more when every vitest worker is busy, so whichever test called
- // getRegionGeo first used to pay for it and blow the 5s default. Warm the store here
- // with a budget that fits the build; the tests below then measure only the lookup.
- beforeAll(async () => {
- await getRegionGeo(['ZZ']);
- }, 60_000);
-
- it('ATLAS-SVC-017: returns an empty FeatureCollection for a country with no admin-1 features', async () => {
- const result = await getRegionGeo(['ZZ']);
- expect(result).toEqual({ type: 'FeatureCollection', features: [] });
- });
-
- it('ATLAS-SVC-018: returns the current geoBoundaries regions for a country, case-insensitively', async () => {
- // Pass lowercase 'no' — getRegionGeo uppercases internally for matching.
- const result = await getRegionGeo(['no']);
-
- expect(result.type).toBe('FeatureCollection');
- expect(result.features.length).toBeGreaterThan(0);
- expect(result.features.every((f: any) => f.properties.iso_a2 === 'NO')).toBe(true);
-
- const names = result.features.map((f: any) => f.properties.name);
- const codes = result.features.map((f: any) => f.properties.iso_3166_2);
- // Post-2020 reform is present…
- expect(codes).toContain('NO-34'); // Innlandet
- expect(codes).toContain('NO-46'); // Vestland
- // …and the merged-away pre-2020 counties are gone (the original #1119 bug).
- expect(names).not.toContain('Oppland');
- expect(names).not.toContain('Hordaland');
- expect(names).not.toContain('Sogn og Fjordane');
- });
-});
-
describe('getCountryGeo', () => {
it('ATLAS-SVC-019: returns the admin-0 FeatureCollection with ISO_A2/ADM0_A3 properties', () => {
const geo = getCountryGeo();
diff --git a/server/tests/unit/nest/atlasBundle.test.ts b/server/tests/unit/nest/atlasBundle.test.ts
index 229e069f4..ab28e47e6 100644
--- a/server/tests/unit/nest/atlasBundle.test.ts
+++ b/server/tests/unit/nest/atlasBundle.test.ts
@@ -27,13 +27,43 @@ describe('Atlas admin0 country bundle (#1609)', () => {
});
describe('Atlas admin1 region bundle (#1217)', () => {
- const bundlePath = path.join(__dirname, '..', '..', '..', 'assets', 'atlas', 'admin1.geojson.gz');
- const features = JSON.parse(zlib.gunzipSync(fs.readFileSync(bundlePath)).toString()).features as {
+ const dir = path.join(__dirname, '..', '..', '..', 'assets', 'atlas', 'admin1');
+ const files = fs
+ .readdirSync(dir)
+ .filter((name) => name.endsWith('.geojson.gz'))
+ .map((name) => ({ name, text: zlib.gunzipSync(fs.readFileSync(path.join(dir, name))).toString() }));
+ const features = files.flatMap(({ text }) => JSON.parse(text).features) as {
properties: { iso_a2: string | null; iso_3166_2: string };
}[];
const regions = (a2: string) => features.filter((f) => f.properties.iso_a2 === a2);
+ // The server joins countries for /regions/geo?countries= by cutting each file's
+ // features out between these two, and a lookup reads the file its name points at.
+ it('ATLAS-BUNDLE-007 — one compact FeatureCollection per country, named by its ISO_A2', () => {
+ expect(files.length).toBeGreaterThan(150);
+ for (const { name, text } of files) {
+ expect(text.startsWith('{"type":"FeatureCollection","features":[{'), name).toBe(true);
+ expect(text.endsWith('}]}'), name).toBe(true);
+ const a2s = new Set(
+ JSON.parse(text).features.map((f: { properties: { iso_a2: string } }) => f.properties.iso_a2),
+ );
+ expect(
+ [...a2s].map((a2) => `${a2}.geojson.gz`),
+ name,
+ ).toEqual([name]);
+ }
+ });
+
+ // admin1.geojson.gz stays for the two shipped migrations that read it; the server reads
+ // the per-country files. Both have to carry the same regions.
+ it('ATLAS-BUNDLE-008 — the per-country files hold exactly the features of admin1.geojson.gz', () => {
+ const bundle = JSON.parse(zlib.gunzipSync(fs.readFileSync(path.join(dir, '..', 'admin1.geojson.gz'))).toString())
+ .features as unknown[];
+ const key = (f: unknown) => JSON.stringify(f);
+ expect(features.map(key).sort()).toEqual(bundle.map(key).sort());
+ });
+
it('ATLAS-BUNDLE-001 — previously-broken countries now have distinct region codes', () => {
for (const a2 of ['ES', 'CN', 'CL', 'OM']) {
const f = regions(a2);
diff --git a/shared/src/atlas/atlas.schema.spec.ts b/shared/src/atlas/atlas.schema.spec.ts
index 458c5a7e1..4aa6c537e 100644
--- a/shared/src/atlas/atlas.schema.spec.ts
+++ b/shared/src/atlas/atlas.schema.spec.ts
@@ -2,6 +2,7 @@ import {
markRegionRequestSchema,
createBucketItemRequestSchema,
regionGeoSchema,
+ regionGeoParamsSchema,
visitStatusSchema,
todayUtc,
tripVisitStatus,
@@ -76,6 +77,19 @@ describe('regionGeoSchema', () => {
});
});
+describe('regionGeoParamsSchema', () => {
+ it('takes a two-letter code from the path and uppercases it', () => {
+ expect(regionGeoParamsSchema.parse({ code: 'no' })).toEqual({ code: 'NO' });
+ expect(regionGeoParamsSchema.parse({ code: 'GB' })).toEqual({ code: 'GB' });
+ });
+
+ it('refuses anything that is not two letters', () => {
+ for (const code of ['NOR', 'N', '', '..', '../admin0', 'N/', '12']) {
+ expect(regionGeoParamsSchema.safeParse({ code }).success, code).toBe(false);
+ }
+ });
+});
+
describe('visitStatusSchema', () => {
it('accepts the three buckets and nothing else', () => {
expect(visitStatusSchema.safeParse('visited').success).toBe(true);
diff --git a/shared/src/atlas/atlas.schema.ts b/shared/src/atlas/atlas.schema.ts
index ebe48d6a1..ef7a9ef4b 100644
--- a/shared/src/atlas/atlas.schema.ts
+++ b/shared/src/atlas/atlas.schema.ts
@@ -71,6 +71,15 @@ export const regionGeoSchema = z.object({
});
export type RegionGeo = z.infer<typeof regionGeoSchema>;
+/** GET /regions/geo/:code — one country's regions, by ISO 3166-1 alpha-2 code in any case. */
+export const regionGeoParamsSchema = z.object({
+ code: z
+ .string()
+ .regex(/^[A-Za-z]{2}$/, 'a two-letter country code')
+ .transform((code) => code.toUpperCase()),
+});
+export type RegionGeoParams = z.infer<typeof regionGeoParamsSchema>;
+
/**
* Where a coordinate lands on the atlas map (#1115). Both fields are nullable: the
* point may sit outside every bundled polygon (open sea, a simplification gap at a