@jadermme/orus-core
Version:
ORUS Core Framework - Universal framework for 6 Pillars assessment, domain-agnostic
165 lines • 4.31 kB
TypeScript
/**
* ORUS Core - Validation Functions
*
* Pure functions for validating pillar and assessment data structures.
* Ensures data integrity and catches inconsistencies early.
*
* @remarks
* All validators:
* - Are pure functions (no side effects)
* - Return validation results (not throw errors)
* - Provide actionable error messages
* - Support both runtime and compile-time checking
*/
import type { PillarAssessment, SixPillarsAssessment } from '../types/assessment.js';
/**
* Validation result
*/
export interface ValidationResult {
/**
* Whether validation passed
*/
isValid: boolean;
/**
* Error messages (if any)
*/
errors: string[];
/**
* Warning messages (non-blocking issues)
*/
warnings: string[];
}
/**
* Validation error with context
*/
export interface ValidationError {
/**
* Field that failed validation
*/
field: string;
/**
* Error message
*/
message: string;
/**
* Current (invalid) value
*/
value: unknown;
/**
* Expected value or format
*/
expected?: string;
}
/**
* Validates a pillar ID
*
* @param pillarId - Pillar ID to validate
* @returns Validation result
*
* @remarks
* - Pure function: deterministic validation
* - Checks against valid PillarId enum values
*
* @example
* ```typescript
* validatePillarId('PILLAR_1') // => { isValid: true, ... }
* validatePillarId('INVALID') // => { isValid: false, ... }
* ```
*/
export declare function validatePillarId(pillarId: string): ValidationResult;
/**
* Validates a pillar assessment
*
* @param pillar - Pillar assessment to validate
* @param strict - Enable strict mode (additional checks)
* @returns Validation result
*
* @remarks
* - Pure function: deterministic validation
* - Checks all core fields and their constraints
* - Strict mode validates score-status consistency
* - Detects stale data (lastUpdated > 90 days ago)
*
* @example
* ```typescript
* const result = validatePillarAssessment(pillar, true);
*
* if (!result.isValid) {
* console.error('Validation errors:', result.errors);
* }
*
* if (result.warnings.length > 0) {
* console.warn('Warnings:', result.warnings);
* }
* ```
*/
export declare function validatePillarAssessment(pillar: PillarAssessment, strict?: boolean): ValidationResult;
/**
* Validates a complete six pillars assessment
*
* @param assessment - Assessment to validate
* @param strict - Enable strict mode
* @returns Validation result
*
* @remarks
* - Pure function: deterministic validation
* - Validates structure, all pillars, and overall consistency
* - Checks that all 6 pillars are present
* - Validates overall score calculation
*
* @example
* ```typescript
* const result = validateSixPillarsAssessment(assessment, true);
*
* if (!result.isValid) {
* console.error('Assessment has errors:', result.errors);
* // Do not save or use this assessment
* }
* ```
*/
export declare function validateSixPillarsAssessment(assessment: SixPillarsAssessment, strict?: boolean): ValidationResult;
/**
* Quick validation (non-strict, for runtime checks)
*
* @param assessment - Assessment to validate
* @returns Whether assessment is valid (ignores warnings)
*
* @remarks
* - Pure function: simple boolean check
* - Useful for conditional logic and guards
* - Does not provide detailed error messages
*
* @example
* ```typescript
* if (isValidAssessment(assessment)) {
* // Safe to use assessment
* saveToDB(assessment);
* }
* ```
*/
export declare function isValidAssessment(assessment: SixPillarsAssessment): boolean;
/**
* Creates a validation error object
*
* @param field - Field name
* @param message - Error message
* @param value - Current value
* @param expected - Expected value/format
* @returns Validation error object
*
* @remarks
* - Pure function: factory for consistent error objects
* - Useful for building custom validators
*
* @example
* ```typescript
* const error = createValidationError(
* 'score',
* 'Score out of range',
* 15,
* '0-10'
* );
* ```
*/
export declare function createValidationError(field: string, message: string, value: unknown, expected?: string): ValidationError;
//# sourceMappingURL=validators.d.ts.map