make mapping.ts little bit simple. add comment to file processing places.

This commit is contained in:
Первов Артем
2026-06-15 01:41:30 +03:00
parent e450346e58
commit f8a9866339
2 changed files with 7 additions and 10 deletions

View File

@@ -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"]

View File

@@ -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,
})),
}