Module: database/repositories/metricSamplesRepo

Repository for the generic time-series metric_samples table (MET-001). Backs every "value over time per project" surface — healing savings (CAP-004), Web Vitals trends (AUTO-017.3), flaky-rate (DIF-004), accessibility violations (AUTO-016) — so each consumer doesn't reinvent its own aggregation table.

Schema (migration 016_metric_samples.sql): metric_samples(id, projectId, metricKey, ts, value, tags, createdAt) indexed on (projectId, metricKey, ts)

tags is JSON-serialised on write and parsed on read so callers can attach structured context (e.g. { testId, strategy }) without a separate join table.

Source:

Methods

(static) getSeries(projectId, metricKey, optsopt) → {Array.<{ts: number, value: number, tags: (Object|null)}>}

Read a project's samples for a metric, ordered ascending by timestamp.

Parameters:
Name Type Attributes Description
projectId string
metricKey string
opts Object <optional>
Properties
Name Type Attributes Default Description
since number <optional>
0

Lower-bound timestamp (epoch ms, inclusive). Default 0 returns all samples.

limit number <optional>
200

Row cap; oldest-first within the window.

Source:
Returns:
Type
Array.<{ts: number, value: number, tags: (Object|null)}>

(static) insertSample(sample)

Insert a single time-series sample.

Parameters:
Name Type Description
sample Object
Properties
Name Type Attributes Default Description
projectId string
metricKey string

Stable metric identifier (e.g. "healing.savings", "webVitals.lcp").

ts number <optional>
Date.now()

Sample timestamp, epoch ms.

value number

Numeric sample value (must be a finite number — validate at the call site or use recordMetric).

tags Object | null <optional>
null

Optional structured context; JSON-serialised on write.

Source: