proactive-deps
Version:
A library for managing proactive dependency checks in Node.js applications.
72 lines • 3.07 kB
TypeScript
/**
* Represents the status of a dependency.
* @typedef {Object} DependencyStatus
* @property {string} name - The name of the dependency.
* @property {boolean} healthy - Indicates whether the dependency is healthy.
* @property {number} code - Status code (e.g., SUCCESS_STATUS_CODE, ERROR_STATUS_CODE, WARNING_STATUS_CODE).
* @property {string} status - Status message (e.g., SUCCESS_STATUS_MESSAGE, ERROR_STATUS_MESSAGE, WARNING_STATUS_MESSAGE).
* @property {Error} [error] - Optional error object if the check fails.
* @property {string} [errorMessage] - Optional error message if the check fails.
* @property {number} latencyMs - The latency of the dependency check in milliseconds.
* @property {string} lastChecked - The ISO timestamp of the last check.
* @property {string} [description] - Optional description of the dependency.
* @property {string} [impact] - Optional impact of the dependency on the system.
*/
export type DependencyStatus = {
name: string;
healthy: boolean;
code: number;
status: string;
error?: Error;
errorMessage?: string;
latencyMs: number;
lastChecked: string;
description: string;
impact: string;
};
/**
* Represents the result of a dependency check function.
*
* This can either be:
* - A single status code (number).
* - An object containing a status code and optional error details.
*
* @typedef {number | Object} DependencyCheckResult
* @property {number} code - Status code (e.g., SUCCESS_STATUS_CODE, ERROR_STATUS_CODE, WARNING_STATUS_CODE).
* @property {Error} [error] - Optional error object if the check fails.
* @property {string} [errorMessage] - Optional error message if the check fails.
*/
export type DependencyCheckResult = number | {
code: number;
error?: Error;
errorMessage?: string;
};
/**
* Represents a dependency to be monitored.
* @typedef {Object} DependencyCheck
* @property {string} name - The name of the dependency.
* @property {string} description - A description of the dependency.
* @property {string} impact - The impact of the dependency on the system, should it go down.
* @property {DependencyCheckFunction} check - A function that performs the dependency check and returns a result.
* @property {number} [cacheDurationMs] - Optional override duration (in milliseconds) to cache the dependency check result.
*/
export interface DependencyCheck {
name: string;
description: string;
impact: string;
check: () => Promise<DependencyCheckResult>;
cacheDurationMs?: number;
}
/**
* Configuration options for the DependencyMonitor.
* @typedef {Object} DependencyMonitorOptions
* @property {number} [cacheDurationMs] - Cache duration in milliseconds.
* @property {number} [refreshThresholdMs] - Refresh threshold in milliseconds.
* @property {number} [checkIntervalMs] - Interval for running dependency checks in milliseconds.
*/
export type DependencyMonitorOptions = {
cacheDurationMs?: number;
refreshThresholdMs?: number;
checkIntervalMs?: number;
};
//# sourceMappingURL=types.d.ts.map