spb/countryatlas
Public
TypeScript 57%
Python 38.6%
JavaScript 3.6%
CSS 0.6%
1import 'server-only';2import { request } from './api';3import type { MapResponse, RankingResponse } from './types';4import type { CompareMode, CompareResponse, CompareSnapshotResponse, IndicatorsResponse, RankHistoryResponse, RankingsListResponse, RegionsResponse } from './types-compare';56/**7 * Server-side endpoints for the compare / rankings pages (same `request<T>()` wrapper as `lib/api.ts`,8 * kept in a separate module so the two page groups can be developed concurrently).9 * The API caps `/compare` at 8 countries × 8 indicators per call; `/compare/snapshot` at 8 × 40.10 */11export const apiCompare = {12 compare: (countries: string[], indicators: string[], q: { from?: number | null; to?: number | null; mode?: CompareMode; include_forecast?: boolean } = {}) =>13 request<CompareResponse>('/compare', { countries: countries.join(','), indicators: indicators.slice(0, 8).join(','), from: q.from ?? undefined, to: q.to ?? undefined, mode: q.mode ?? 'absolute', include_forecast: q.include_forecast }),1415 snapshot: (countries: string[], q: { topic?: string | null; indicators?: string[] | null } = {}) =>16 request<CompareSnapshotResponse>('/compare/snapshot', { countries: countries.join(','), topic: q.indicators?.length ? undefined : q.topic ?? undefined, indicators: q.indicators?.length ? q.indicators.join(',') : undefined }),1718 rankings: (topic?: string) => request<RankingsListResponse>('/rankings', { topic }),1920 ranking: (slug: string, q: { year?: number | null; group?: string | null; sort?: 'asc' | 'desc' | null; limit?: number; offset?: number; sparkline?: boolean } = {}) =>21 request<RankingResponse>(`/rankings/${encodeURIComponent(slug)}`, { year: q.year ?? undefined, group: q.group ?? undefined, sort: q.sort ?? undefined, limit: q.limit ?? 300, offset: q.offset, sparkline: q.sparkline ?? true }),2223 rankHistory: (slug: string, countries: string[], q: { from?: number; to?: number } = {}) =>24 request<RankHistoryResponse>(`/rankings/${encodeURIComponent(slug)}/history`, { countries: countries.join(','), ...q }),2526 indicatorMap: (slug: string, q: { year?: number | null; nearest?: boolean } = {}) => request<MapResponse>(`/indicators/${encodeURIComponent(slug)}/map`, { year: q.year ?? undefined, nearest: q.nearest }),2728 indicators: (q: { topic?: string; q?: string; featured?: boolean } = {}) => request<IndicatorsResponse>('/indicators', q),2930 regions: (kind?: string) => request<RegionsResponse>('/regions', { kind }),31};32