@sailboat-computer/validation
Version:
Validation framework for sailboat computer v3
78 lines • 3.28 kB
TypeScript
/**
* Base validation rule implementation
*/
import { ValidationRule, ValidationResult, ValidationContext, RawSensorData, AlertSeverityType } from '../types';
/**
* Abstract base class for validation rules
*/
export declare abstract class BaseValidationRule implements ValidationRule {
readonly name: string;
readonly description: string;
readonly category: 'physical' | 'operational' | 'quality';
readonly severity: AlertSeverityType;
constructor(name: string, description: string, category: 'physical' | 'operational' | 'quality', severity: AlertSeverityType);
/**
* Abstract validation method to be implemented by subclasses
*/
abstract validate(data: RawSensorData, context: ValidationContext): ValidationResult;
/**
* Abstract applicability check to be implemented by subclasses
*/
abstract isApplicable(data: RawSensorData): boolean;
/**
* Get rule configuration (can be overridden by subclasses)
*/
getConfiguration(): Record<string, any>;
/**
* Helper method to create a validation result
*/
protected createResult(passed: boolean, message?: string, details?: Record<string, any>): ValidationResult;
/**
* Helper method to check if a numeric value is within range
*/
protected isInRange(value: number, min: number, max: number, inclusive?: boolean): boolean;
/**
* Helper method to check rate of change
*/
protected checkRateOfChange(currentValue: number, previousValue: number, timeDeltaSeconds: number, maxRatePerSecond: number): boolean;
/**
* Helper method to get previous sensor data from context
*/
protected getPreviousData(data: RawSensorData, context: ValidationContext, maxAgeSeconds?: number): RawSensorData | undefined;
/**
* Helper method to extract numeric value from sensor data
*/
protected extractNumericValue(data: RawSensorData): number | null;
/**
* Helper method to check if sensor type matches expected types
*/
protected matchesSensorType(data: RawSensorData, expectedTypes: string[]): boolean;
/**
* Helper method to get operational context priority
*/
protected getContextPriority(context: ValidationContext): number;
}
/**
* Range validation rule for numeric sensor values
*/
export declare class RangeValidationRule extends BaseValidationRule {
private minValue;
private maxValue;
private sensorTypes;
constructor(name: string, description: string, minValue: number, maxValue: number, sensorTypes: string[], severity?: AlertSeverityType);
validate(data: RawSensorData, context: ValidationContext): ValidationResult;
isApplicable(data: RawSensorData): boolean;
getConfiguration(): Record<string, any>;
}
/**
* Rate of change validation rule
*/
export declare class RateOfChangeRule extends BaseValidationRule {
private maxRatePerSecond;
private sensorTypes;
constructor(name: string, description: string, maxRatePerSecond: number, sensorTypes: string[], severity?: AlertSeverityType);
validate(data: RawSensorData, context: ValidationContext): ValidationResult;
isApplicable(data: RawSensorData): boolean;
getConfiguration(): Record<string, any>;
}
//# sourceMappingURL=base-rule.d.ts.map