From f8a9866339fcc4f3199696d4ed25f71da103bcf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Mon, 15 Jun 2026 01:41:30 +0300 Subject: [PATCH] make mapping.ts little bit simple. add comment to file processing places. --- app/Dockerfile | 1 + app/src/mapping.ts | 16 ++++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/Dockerfile b/app/Dockerfile index da84bdd..1699fc5 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -7,6 +7,7 @@ RUN npm ci COPY tsconfig.json ./ COPY public ./public +# Runtime mappers read JSON files from src/mappings, so they must be copied into the image. COPY src ./src CMD ["npm", "run", "dev"] diff --git a/app/src/mapping.ts b/app/src/mapping.ts index c08300c..929f98c 100644 --- a/app/src/mapping.ts +++ b/app/src/mapping.ts @@ -7,11 +7,9 @@ export type MappedMetric = { value: number } -type MappingTagEntry = string | { tag: string } | { key: string } - type MappingConfig = { edge: string - tags: MappingTagEntry[] + tags: string[] } export type MetricMapper = { @@ -21,8 +19,9 @@ export type MetricMapper = { } type MetricMapperOptions = { - // filePath is set as a URL from import.meta.url for bundled mappings, - // or as a path string resolved by Node from the process working directory. + // filePath contract: + // - built-in mappings are passed as URL via new URL('../mappings/*.json', import.meta.url); + // - env overrides are expected as absolute paths inside the runtime container. filePath: string | URL } @@ -32,18 +31,15 @@ function readMappingConfig(filePath: string | URL): MappingConfig { export function createMetricMapper(options: MetricMapperOptions): MetricMapper { const config = readMappingConfig(options.filePath) - const tags = config.tags.map((entry) => - typeof entry === 'string' ? entry : 'tag' in entry ? entry.tag : entry.key, - ) return { edge: config.edge, - tagCount: tags.length, + tagCount: config.tags.length, mapValues: (values, timestamp) => values.map((value, index) => ({ edge: config.edge, timestamp, - tag: tags[index], + tag: config.tags[index], value, })), }