43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import { ApiProperty } from '@nestjs/swagger';
|
|
|
|
/** API 总体健康只区分可服务与不可服务,依赖禁用不等同于故障。 */
|
|
export type HealthStatus = 'healthy' | 'unavailable';
|
|
/** 单项依赖额外允许 disabled,用于尚未启用但符合当前配置的组件。 */
|
|
export type DependencyStatus = HealthStatus | 'disabled';
|
|
|
|
/** 单项依赖健康契约只暴露安全摘要,不返回地址、账号或底层异常。 */
|
|
export class DependencyHealthDto {
|
|
@ApiProperty({ type: String, enum: ['healthy', 'unavailable', 'disabled'] })
|
|
status!: DependencyStatus;
|
|
|
|
@ApiProperty({ type: String })
|
|
detail!: string;
|
|
}
|
|
|
|
/** 健康响应固定列出三类基础设施,便于运维区分故障和计划内禁用。 */
|
|
export class HealthDependenciesDto {
|
|
@ApiProperty({ type: () => DependencyHealthDto })
|
|
redis!: DependencyHealthDto;
|
|
|
|
@ApiProperty({ type: () => DependencyHealthDto })
|
|
mysql!: DependencyHealthDto;
|
|
|
|
@ApiProperty({ type: () => DependencyHealthDto })
|
|
rocketMq!: DependencyHealthDto;
|
|
}
|
|
|
|
/** API 健康端点的版本化 HTTP DTO,也是 OpenAPI 单向发布源。 */
|
|
export class HealthResponseDto {
|
|
@ApiProperty({ type: String, enum: ['healthy', 'unavailable'] })
|
|
status!: HealthStatus;
|
|
|
|
@ApiProperty({ type: String, enum: ['api'] })
|
|
process!: 'api';
|
|
|
|
@ApiProperty({ type: String, format: 'date-time' })
|
|
checkedAt!: string;
|
|
|
|
@ApiProperty({ type: () => HealthDependenciesDto })
|
|
dependencies!: HealthDependenciesDto;
|
|
}
|