Files
interfaces/ts/data/checks/index.ts

118 lines
3.0 KiB
TypeScript

import type { TStatusType, TCheckResultStatus, TCheckLastResult } from '../types.js';
// ============================================
// Execution Timing (used by check runners)
// ============================================
export interface TExecutionTiming {
plannedTime: number;
timeStarted: number;
timeEnded: number;
duration: number;
}
// Re-export for backward compatibility
export type { TCheckResultStatus };
// ============================================
// Check Configuration Base Interface
// ============================================
/**
* Base interface for all check configurations.
* Extended by discriminated variants.
*/
export interface ICheckBase {
id: string;
name: string;
description?: string;
enabled: boolean;
intervalMs?: number;
lastRun?: number;
lastResult?: TCheckLastResult;
}
// ============================================
// Discriminated Check Variants (Configuration)
// ============================================
/**
* Assumption check - assumes a status without active verification
*/
export interface IAssumptionCheckConfig extends ICheckBase {
checkType: 'assumption';
assumedStatus: TStatusType;
domain?: string;
title?: string;
statusCode?: string;
}
/**
* Function check - calls a URL and validates response
*/
export interface IFunctionCheckConfig extends ICheckBase {
checkType: 'function';
functionUrl: string;
domain?: string;
expectedStatusCode?: number;
timeoutMs?: number;
headers?: Record<string, string>;
}
/**
* PWA check - validates Progressive Web App criteria
*/
export interface IPwaCheckConfig extends ICheckBase {
checkType: 'pwa';
targetUrl: string;
domain?: string;
lighthouseThreshold?: number;
categories?: ('performance' | 'accessibility' | 'best-practices' | 'seo')[];
}
/**
* PageRank check - validates search engine ranking
*/
export interface IPageRankCheckConfig extends ICheckBase {
checkType: 'pagerank';
targetUrl: string;
domain?: string;
searchTerm: string;
minimumRank?: number;
checkGoogle?: boolean;
checkBing?: boolean;
googleMinRank?: number;
bingMinRank?: number;
}
// ============================================
// Union Type (for UI and generic handling)
// ============================================
/**
* Union of all check configuration types.
* Use `checkType` discriminant for type narrowing.
*
* @example
* function handleCheck(check: TCheckConfig) {
* if (check.checkType === 'function') {
* console.log(check.functionUrl); // TypeScript knows this exists
* }
* }
*/
export type TCheckConfig =
| IAssumptionCheckConfig
| IFunctionCheckConfig
| IPwaCheckConfig
| IPageRankCheckConfig;
// ============================================
// Execution Interfaces (Runtime Data)
// ============================================
// Keep existing execution interfaces for backward compatibility
export * from './assumption.check.js';
export * from './function.check.js';
export * from './pagerank.check.js';
export * from './pwa.check.js';