@goodie-ts/health
v0.6.0
Published
Health check indicators and aggregation for goodie-ts
Readme
@goodie-ts/health
Health check indicators and aggregation for goodie-ts. Auto-discovers HealthIndicator subclasses and aggregates their results.
Install
pnpm add @goodie-ts/healthOverview
Extend HealthIndicator to define custom health checks. The plugin auto-wires a HealthAggregator that collects all indicators and reports a combined status.
Define a Health Indicator
import { Singleton } from '@goodie-ts/decorators';
import { HealthIndicator, HealthResult } from '@goodie-ts/health';
@Singleton()
class DatabaseHealthIndicator extends HealthIndicator {
readonly name = 'database';
constructor(private database: Database) {}
async check(): Promise<HealthResult> {
try {
await this.database.kysely.selectFrom('pg_catalog.pg_tables').execute();
return { status: 'UP' };
} catch (error) {
return { status: 'DOWN', details: { error: String(error) } };
}
}
}Use the Aggregator
import { Singleton } from '@goodie-ts/decorators';
import { HealthAggregator } from '@goodie-ts/health';
@Singleton()
class HealthController {
constructor(private health: HealthAggregator) {}
async check() {
const result = await this.health.checkAll();
// { status: 'UP', indicators: { database: { status: 'UP' }, uptime: { status: 'UP', details: { ... } } } }
return result;
}
}Built-in Indicators
- UptimeHealthIndicator — always included, reports application uptime in milliseconds and start time
Aggregation Behavior
- All indicators run in parallel via
Promise.allSettled - Overall status is
DOWNif any indicator reportsDOWNor throws - Thrown errors are caught and reported as
DOWNwith error details
Setup
Health beans are auto-discovered from beans.json — no manual plugin registration needed:
import { diPlugin } from '@goodie-ts/vite-plugin';
export default defineConfig({
plugins: [diPlugin()],
});