@nestjs-redis/health-indicator
Version:
A comprehensive Redis health indicator for NestJS applications using the Terminus health check library
61 lines (60 loc) • 1.7 kB
JavaScript
;
// DISCLAIMER: This file is a modified version of the original file from
// @nestjs/terminus package to remove the dependency on it.
Object.defineProperty(exports, "__esModule", { value: true });
exports.HealthIndicatorSession = exports.HealthIndicatorService = void 0;
/**
* Helper service which can be used to create health indicator results
* @publicApi
*/
class HealthIndicatorService {
check(key) {
return new HealthIndicatorSession(key);
}
}
exports.HealthIndicatorService = HealthIndicatorService;
/**
* Indicate the health of a health indicator with the given key
*
* @publicApi
*/
class HealthIndicatorSession {
constructor(key) {
this.key = key;
}
down(data) {
let additionalData = {};
if (typeof data === 'string') {
additionalData = { message: data };
}
else if (typeof data === 'object') {
additionalData = data;
}
const detail = {
status: 'down',
...additionalData,
};
return {
[this.key]: detail,
// TypeScript does not infer this.key as Key correctly.
};
}
up(data) {
let additionalData = {};
if (typeof data === 'string') {
additionalData = { message: data };
}
else if (typeof data === 'object') {
additionalData = data;
}
const detail = {
status: 'up',
...additionalData,
};
return {
[this.key]: detail,
// TypeScript does not infer this.key as Key correctly.
};
}
}
exports.HealthIndicatorSession = HealthIndicatorSession;