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 tsconfig.json ./
COPY public ./public COPY public ./public
# Runtime mappers read JSON files from src/mappings, so they must be copied into the image.
COPY src ./src COPY src ./src
CMD ["npm", "run", "dev"] CMD ["npm", "run", "dev"]

View File

@@ -7,11 +7,9 @@ export type MappedMetric = {
value: number value: number
} }
type MappingTagEntry = string | { tag: string } | { key: string }
type MappingConfig = { type MappingConfig = {
edge: string edge: string
tags: MappingTagEntry[] tags: string[]
} }
export type MetricMapper = { export type MetricMapper = {
@@ -21,8 +19,9 @@ export type MetricMapper = {
} }
type MetricMapperOptions = { type MetricMapperOptions = {
// filePath is set as a URL from import.meta.url for bundled mappings, // filePath contract:
// or as a path string resolved by Node from the process working directory. // - 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 filePath: string | URL
} }
@@ -32,18 +31,15 @@ function readMappingConfig(filePath: string | URL): MappingConfig {
export function createMetricMapper(options: MetricMapperOptions): MetricMapper { export function createMetricMapper(options: MetricMapperOptions): MetricMapper {
const config = readMappingConfig(options.filePath) const config = readMappingConfig(options.filePath)
const tags = config.tags.map((entry) =>
typeof entry === 'string' ? entry : 'tag' in entry ? entry.tag : entry.key,
)
return { return {
edge: config.edge, edge: config.edge,
tagCount: tags.length, tagCount: config.tags.length,
mapValues: (values, timestamp) => mapValues: (values, timestamp) =>
values.map((value, index) => ({ values.map((value, index) => ({
edge: config.edge, edge: config.edge,
timestamp, timestamp,
tag: tags[index], tag: config.tags[index],
value, value,
})), })),
} }