deepsource-mcp-server
Version:
Model Context Protocol server for DeepSource
153 lines (152 loc) • 4.75 kB
TypeScript
/**
* @fileoverview QualityMetrics aggregate root
*
* This module defines the QualityMetrics aggregate which represents quality metrics
* for a project with their thresholds, measurements, and history.
*/
import { AggregateRoot } from '../../shared/aggregate-root.js';
import { ProjectKey, GraphQLNodeId } from '../../../types/branded.js';
import { ThresholdValue } from '../../value-objects/threshold-value.js';
import { MetricValue } from '../../value-objects/metric-value.js';
import { MetricConfiguration, MetricHistoryEntry, MetricTrend, ThresholdStatus, CreateQualityMetricsParams, UpdateMetricConfigParams, RecordMeasurementParams } from './quality-metrics.types.js';
/**
* QualityMetrics aggregate root
*
* Represents quality metrics for a project with configuration, thresholds, and history.
* Tracks metric values over time and evaluates compliance with thresholds.
*
* @example
* ```typescript
* const metrics = QualityMetrics.create({
* projectKey: asProjectKey('my-project'),
* repositoryId: asGraphQLNodeId('repo123'),
* configuration: {
* name: 'Line Coverage',
* shortcode: MetricShortcode.LCV,
* metricKey: MetricKey.AGGREGATE,
* unit: '%',
* minAllowed: 0,
* maxAllowed: 100,
* positiveDirection: 'UPWARD',
* isReported: true,
* isThresholdEnforced: true,
* threshold: ThresholdValue.createPercentage(80)
* }
* });
*
* metrics.recordMeasurement({ value: 85.5, commitOid: 'abc123' });
* console.log(metrics.isCompliant); // true
* ```
*/
export declare class QualityMetrics extends AggregateRoot<string> {
private _projectKey;
private _repositoryId;
private _configuration;
private _currentValue;
private _history;
private _lastUpdated;
private static readonly MAX_HISTORY_ENTRIES;
private constructor();
/**
* Creates a new QualityMetrics aggregate
*
* @param params - Creation parameters
* @returns A new QualityMetrics instance
*/
static create(params: CreateQualityMetricsParams): QualityMetrics;
/**
* Creates a composite ID for the aggregate
*/
private static createId;
/**
* Gets the project key
*/
get projectKey(): ProjectKey;
/**
* Gets the repository ID
*/
get repositoryId(): GraphQLNodeId;
/**
* Gets the metric configuration
*/
get configuration(): Readonly<MetricConfiguration>;
/**
* Gets the current metric value
*/
get currentValue(): MetricValue | null;
/**
* Gets the metric history
*/
get history(): ReadonlyArray<MetricHistoryEntry>;
/**
* Gets the last update timestamp
*/
get lastUpdated(): Date;
/**
* Checks if the metric is currently compliant with its threshold
*/
get isCompliant(): boolean;
/**
* Gets the current threshold status
*/
get thresholdStatus(): ThresholdStatus;
/**
* Updates the metric threshold
*
* @param threshold - New threshold value or null to remove
*/
updateThreshold(threshold: ThresholdValue | null): void;
/**
* Updates the metric configuration
*
* @param params - Configuration update parameters
*/
updateConfiguration(params: UpdateMetricConfigParams): void;
/**
* Records a new measurement
*
* @param params - Measurement parameters
*/
recordMeasurement(params: RecordMeasurementParams): void;
/**
* Evaluates compliance at a specific point in time
*
* @param value - The value to evaluate
* @returns Whether the value meets the threshold
*/
evaluateCompliance(value: number): boolean;
/**
* Gets the trend over a specified period
*
* @param periodDays - Number of days to analyze
* @returns Trend information or null if insufficient data
*/
getTrend(periodDays?: number): MetricTrend | null;
/**
* Reconstructs QualityMetrics from persisted data
*
* @param data - Persisted metrics data
* @returns A reconstructed QualityMetrics instance
*/
static fromPersistence(data: {
id: string;
projectKey: ProjectKey;
repositoryId: GraphQLNodeId;
configuration: MetricConfiguration;
currentValue: MetricValue | null;
history: MetricHistoryEntry[];
lastUpdated: Date;
}): QualityMetrics;
/**
* Converts the metrics to a persistence-friendly format
*/
toPersistence(): {
id: string;
projectKey: ProjectKey;
repositoryId: GraphQLNodeId;
configuration: MetricConfiguration;
currentValue: MetricValue | null;
history: MetricHistoryEntry[];
lastUpdated: Date;
};
}