@application-kit/observability 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +62 -18
  3. package/dist/cjs/cqrs/cqrs-logger.d.ts +1 -1
  4. package/dist/cjs/cqrs/cqrs-logger.js +1 -1
  5. package/dist/cjs/cqrs/index.d.ts +0 -2
  6. package/dist/cjs/cqrs/index.js +0 -2
  7. package/dist/cjs/health/cli/health-cli-options.interface.d.ts +3 -0
  8. package/dist/cjs/health/cli/health-cli.d.ts +13 -0
  9. package/dist/cjs/health/cli/health-cli.js +56 -0
  10. package/dist/cjs/health/cli/health-cli.module.d.ts +5 -0
  11. package/dist/cjs/health/cli/health-cli.module.js +23 -0
  12. package/dist/cjs/health/cli/index.d.ts +3 -0
  13. package/dist/cjs/health/cli/index.js +19 -0
  14. package/dist/cjs/health/graphql/health-check.type.d.ts +3 -0
  15. package/dist/cjs/health/graphql/health-check.type.js +24 -0
  16. package/dist/cjs/health/graphql/health-graphql.module.d.ts +5 -0
  17. package/dist/cjs/health/graphql/health-graphql.module.js +26 -0
  18. package/dist/cjs/health/graphql/health.resolver.d.ts +11 -0
  19. package/dist/cjs/health/graphql/health.resolver.js +55 -0
  20. package/dist/cjs/health/graphql/index.d.ts +3 -0
  21. package/dist/cjs/health/graphql/index.js +19 -0
  22. package/dist/cjs/health/health-checks.d.ts +10 -0
  23. package/dist/cjs/health/health-checks.js +53 -0
  24. package/dist/cjs/health/health-http.module.d.ts +5 -0
  25. package/dist/cjs/health/health-http.module.js +26 -0
  26. package/dist/cjs/health/health-module-options.interface.d.ts +9 -0
  27. package/dist/cjs/health/health-module-options.interface.js +2 -0
  28. package/dist/cjs/health/health.config.d.ts +8 -0
  29. package/dist/cjs/health/health.config.js +39 -0
  30. package/dist/cjs/health/health.controller.d.ts +14 -0
  31. package/dist/cjs/health/health.controller.js +78 -0
  32. package/dist/cjs/health/health.environment.d.ts +5 -0
  33. package/dist/cjs/health/health.environment.js +38 -0
  34. package/dist/cjs/health/health.module.d.ts +5 -0
  35. package/dist/cjs/health/health.module.js +28 -0
  36. package/dist/cjs/health/index.d.ts +8 -0
  37. package/dist/cjs/health/index.js +24 -0
  38. package/dist/cjs/health/migrations.health-indicator.d.ts +9 -0
  39. package/dist/cjs/health/migrations.health-indicator.js +40 -0
  40. package/dist/cjs/logging/index.d.ts +8 -0
  41. package/dist/cjs/logging/index.js +24 -0
  42. package/dist/cjs/logging/infrastructure-paths.d.ts +4 -0
  43. package/dist/cjs/logging/infrastructure-paths.js +9 -0
  44. package/dist/cjs/logging/logger.environment.d.ts +4 -0
  45. package/dist/cjs/logging/logger.environment.js +24 -0
  46. package/dist/cjs/logging/observability-logger.interface.js +2 -0
  47. package/dist/cjs/logging/pino-logger-options.interface.d.ts +5 -0
  48. package/dist/cjs/logging/pino-logger-options.interface.js +2 -0
  49. package/dist/cjs/logging/pino-logger.config.d.ts +15 -0
  50. package/dist/cjs/logging/pino-logger.config.js +104 -0
  51. package/dist/cjs/logging/resolve-request-id.d.ts +4 -0
  52. package/dist/cjs/logging/resolve-request-id.js +10 -0
  53. package/dist/cjs/logging/resolve-support-id.d.ts +3 -0
  54. package/dist/cjs/logging/resolve-support-id.js +8 -0
  55. package/dist/cjs/metrics/index.d.ts +3 -0
  56. package/dist/cjs/metrics/index.js +3 -0
  57. package/dist/cjs/metrics/metrics-hooks.d.ts +2 -0
  58. package/dist/cjs/metrics/metrics-hooks.js +37 -0
  59. package/dist/cjs/metrics/metrics-http.module.d.ts +5 -0
  60. package/dist/cjs/metrics/metrics-http.module.js +29 -0
  61. package/dist/cjs/metrics/metrics.controller.d.ts +7 -0
  62. package/dist/cjs/metrics/metrics.controller.js +42 -0
  63. package/dist/cjs/shared/active-span-context.d.ts +2 -0
  64. package/dist/cjs/shared/active-span-context.js +9 -0
  65. package/dist/cjs/shared/with-class-decorator.d.ts +2 -0
  66. package/dist/cjs/shared/with-class-decorator.js +14 -0
  67. package/dist/esm/cqrs/cqrs-logger.d.ts +1 -1
  68. package/dist/esm/cqrs/cqrs-logger.js +1 -1
  69. package/dist/esm/cqrs/index.d.ts +0 -2
  70. package/dist/esm/cqrs/index.js +0 -2
  71. package/dist/esm/health/cli/health-cli-options.interface.d.ts +3 -0
  72. package/dist/esm/health/cli/health-cli.d.ts +13 -0
  73. package/dist/esm/health/cli/health-cli.js +52 -0
  74. package/dist/esm/health/cli/health-cli.module.d.ts +5 -0
  75. package/dist/esm/health/cli/health-cli.module.js +20 -0
  76. package/dist/esm/health/cli/index.d.ts +3 -0
  77. package/dist/esm/health/cli/index.js +3 -0
  78. package/dist/esm/health/graphql/health-check.type.d.ts +3 -0
  79. package/dist/esm/health/graphql/health-check.type.js +21 -0
  80. package/dist/esm/health/graphql/health-graphql.module.d.ts +5 -0
  81. package/dist/esm/health/graphql/health-graphql.module.js +23 -0
  82. package/dist/esm/health/graphql/health.resolver.d.ts +11 -0
  83. package/dist/esm/health/graphql/health.resolver.js +52 -0
  84. package/dist/esm/health/graphql/index.d.ts +3 -0
  85. package/dist/esm/health/graphql/index.js +3 -0
  86. package/dist/esm/health/health-checks.d.ts +10 -0
  87. package/dist/esm/health/health-checks.js +50 -0
  88. package/dist/esm/health/health-http.module.d.ts +5 -0
  89. package/dist/esm/health/health-http.module.js +23 -0
  90. package/dist/esm/health/health-module-options.interface.d.ts +9 -0
  91. package/dist/esm/health/health-module-options.interface.js +1 -0
  92. package/dist/esm/health/health.config.d.ts +8 -0
  93. package/dist/esm/health/health.config.js +36 -0
  94. package/dist/esm/health/health.controller.d.ts +14 -0
  95. package/dist/esm/health/health.controller.js +75 -0
  96. package/dist/esm/health/health.environment.d.ts +5 -0
  97. package/dist/esm/health/health.environment.js +34 -0
  98. package/dist/esm/health/health.module.d.ts +5 -0
  99. package/dist/esm/health/health.module.js +25 -0
  100. package/dist/esm/health/index.d.ts +8 -0
  101. package/dist/esm/health/index.js +8 -0
  102. package/dist/esm/health/migrations.health-indicator.d.ts +9 -0
  103. package/dist/esm/health/migrations.health-indicator.js +37 -0
  104. package/dist/esm/logging/index.d.ts +8 -0
  105. package/dist/esm/logging/index.js +8 -0
  106. package/dist/esm/logging/infrastructure-paths.d.ts +4 -0
  107. package/dist/esm/logging/infrastructure-paths.js +5 -0
  108. package/dist/esm/logging/logger.environment.d.ts +4 -0
  109. package/dist/esm/logging/logger.environment.js +20 -0
  110. package/dist/esm/logging/observability-logger.interface.js +1 -0
  111. package/dist/esm/logging/pino-logger-options.interface.d.ts +5 -0
  112. package/dist/esm/logging/pino-logger-options.interface.js +1 -0
  113. package/dist/esm/logging/pino-logger.config.d.ts +15 -0
  114. package/dist/esm/logging/pino-logger.config.js +99 -0
  115. package/dist/esm/logging/resolve-request-id.d.ts +4 -0
  116. package/dist/esm/logging/resolve-request-id.js +6 -0
  117. package/dist/esm/logging/resolve-support-id.d.ts +3 -0
  118. package/dist/esm/logging/resolve-support-id.js +4 -0
  119. package/dist/esm/metrics/index.d.ts +3 -0
  120. package/dist/esm/metrics/index.js +3 -0
  121. package/dist/esm/metrics/metrics-hooks.d.ts +2 -0
  122. package/dist/esm/metrics/metrics-hooks.js +33 -0
  123. package/dist/esm/metrics/metrics-http.module.d.ts +5 -0
  124. package/dist/esm/metrics/metrics-http.module.js +26 -0
  125. package/dist/esm/metrics/metrics.controller.d.ts +7 -0
  126. package/dist/esm/metrics/metrics.controller.js +39 -0
  127. package/dist/esm/shared/active-span-context.d.ts +2 -0
  128. package/dist/esm/shared/active-span-context.js +5 -0
  129. package/dist/esm/shared/with-class-decorator.d.ts +2 -0
  130. package/dist/esm/shared/with-class-decorator.js +10 -0
  131. package/package.json +111 -5
  132. /package/dist/cjs/{cqrs/observability-logger.interface.js → health/cli/health-cli-options.interface.js} +0 -0
  133. /package/dist/cjs/{cqrs → logging}/constants.d.ts +0 -0
  134. /package/dist/cjs/{cqrs → logging}/constants.js +0 -0
  135. /package/dist/cjs/{cqrs → logging}/observability-logger.interface.d.ts +0 -0
  136. /package/dist/esm/{cqrs/observability-logger.interface.js → health/cli/health-cli-options.interface.js} +0 -0
  137. /package/dist/esm/{cqrs → logging}/constants.d.ts +0 -0
  138. /package/dist/esm/{cqrs → logging}/constants.js +0 -0
  139. /package/dist/esm/{cqrs → logging}/observability-logger.interface.d.ts +0 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MetricsHttpModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const with_class_decorator_js_1 = require("../shared/with-class-decorator.js");
12
+ const graphql_metrics_js_1 = require("./graphql-metrics.js");
13
+ const http_metrics_js_1 = require("./http-metrics.js");
14
+ const metrics_controller_js_1 = require("./metrics.controller.js");
15
+ const metrics_registry_js_1 = require("./metrics.registry.js");
16
+ let MetricsHttpModule = class MetricsHttpModule {
17
+ static forRoot(options = {}) {
18
+ return {
19
+ controllers: [(0, with_class_decorator_js_1.withClassDecorator)(metrics_controller_js_1.MetricsController, options.publicRoute)],
20
+ exports: [graphql_metrics_js_1.GraphqlMetrics, http_metrics_js_1.HttpMetrics, metrics_registry_js_1.MetricsRegistry],
21
+ module: this,
22
+ providers: [graphql_metrics_js_1.GraphqlMetrics, http_metrics_js_1.HttpMetrics, metrics_registry_js_1.MetricsRegistry],
23
+ };
24
+ }
25
+ };
26
+ exports.MetricsHttpModule = MetricsHttpModule;
27
+ exports.MetricsHttpModule = MetricsHttpModule = __decorate([
28
+ (0, common_1.Module)({})
29
+ ], MetricsHttpModule);
@@ -0,0 +1,7 @@
1
+ import type { FastifyReply } from 'fastify';
2
+ import { MetricsRegistry } from './metrics.registry.js';
3
+ export declare class MetricsController {
4
+ private readonly metricsRegistry;
5
+ constructor(metricsRegistry: MetricsRegistry);
6
+ scrape(reply: FastifyReply): Promise<string>;
7
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MetricsController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const infrastructure_paths_js_1 = require("../logging/infrastructure-paths.js");
18
+ const metrics_registry_js_1 = require("./metrics.registry.js");
19
+ let MetricsController = class MetricsController {
20
+ metricsRegistry;
21
+ constructor(metricsRegistry) {
22
+ this.metricsRegistry = metricsRegistry;
23
+ }
24
+ async scrape(reply) {
25
+ void reply.header('Content-Type', this.metricsRegistry.contentType);
26
+ return this.metricsRegistry.render();
27
+ }
28
+ };
29
+ exports.MetricsController = MetricsController;
30
+ __decorate([
31
+ (0, common_1.Get)(),
32
+ (0, common_1.Header)('Cache-Control', 'no-store'),
33
+ __param(0, (0, common_1.Res)({ passthrough: true })),
34
+ __metadata("design:type", Function),
35
+ __metadata("design:paramtypes", [Object]),
36
+ __metadata("design:returntype", Promise)
37
+ ], MetricsController.prototype, "scrape", null);
38
+ exports.MetricsController = MetricsController = __decorate([
39
+ (0, common_1.Controller)(infrastructure_paths_js_1.METRICS_ROUTE),
40
+ __param(0, (0, common_1.Inject)(metrics_registry_js_1.MetricsRegistry)),
41
+ __metadata("design:paramtypes", [metrics_registry_js_1.MetricsRegistry])
42
+ ], MetricsController);
@@ -0,0 +1,2 @@
1
+ import type { SpanContext } from '@opentelemetry/api';
2
+ export declare const activeSpanContext: () => SpanContext | undefined;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.activeSpanContext = void 0;
4
+ const api_1 = require("@opentelemetry/api");
5
+ const activeSpanContext = () => {
6
+ const spanContext = api_1.trace.getActiveSpan()?.spanContext();
7
+ return spanContext !== undefined && (0, api_1.isSpanContextValid)(spanContext) ? spanContext : undefined;
8
+ };
9
+ exports.activeSpanContext = activeSpanContext;
@@ -0,0 +1,2 @@
1
+ import type { Type } from '@nestjs/common';
2
+ export declare const withClassDecorator: <T extends Type>(base: T, decorator: ClassDecorator | undefined) => T;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withClassDecorator = void 0;
4
+ const withClassDecorator = (base, decorator) => {
5
+ if (decorator === undefined) {
6
+ return base;
7
+ }
8
+ const decorated = class extends base {
9
+ };
10
+ Object.defineProperty(decorated, 'name', { value: base.name });
11
+ decorator(decorated);
12
+ return decorated;
13
+ };
14
+ exports.withClassDecorator = withClassDecorator;
@@ -1,6 +1,6 @@
1
1
  import { OnApplicationBootstrap } from '@nestjs/common';
2
2
  import { CommandBus, QueryBus } from '@nestjs/cqrs';
3
- import type { ObservabilityLoggerInterface } from './observability-logger.interface.js';
3
+ import type { ObservabilityLoggerInterface } from '../logging/observability-logger.interface.js';
4
4
  export declare class CqrsLogger implements OnApplicationBootstrap {
5
5
  private readonly commandBus;
6
6
  private readonly queryBus;
@@ -13,7 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  import { Inject, Injectable } from '@nestjs/common';
14
14
  import { CommandBus, QueryBus } from '@nestjs/cqrs';
15
15
  import { performance } from 'node:perf_hooks';
16
- import { OBSERVABILITY_LOGGER } from './constants.js';
16
+ import { OBSERVABILITY_LOGGER } from '../logging/constants.js';
17
17
  const KIND_COMMAND = 'command';
18
18
  const KIND_QUERY = 'query';
19
19
  let CqrsLogger = class CqrsLogger {
@@ -1,4 +1,2 @@
1
- export * from './constants.js';
2
1
  export * from './cqrs-logger.js';
3
2
  export * from './cqrs-logger.module.js';
4
- export * from './observability-logger.interface.js';
@@ -1,4 +1,2 @@
1
- export * from './constants.js';
2
1
  export * from './cqrs-logger.js';
3
2
  export * from './cqrs-logger.module.js';
4
- export * from './observability-logger.interface.js';
@@ -0,0 +1,3 @@
1
+ export interface HealthCliOptionsInterface {
2
+ readonly command: string;
3
+ }
@@ -0,0 +1,13 @@
1
+ import type { Type } from '@nestjs/common';
2
+ import { HealthCheckService } from '@nestjs/terminus';
3
+ import type { ObservabilityLoggerInterface } from '../../logging/observability-logger.interface.js';
4
+ import type { HealthCliOptionsInterface } from './health-cli-options.interface.js';
5
+ import { HealthChecks } from '../health-checks.js';
6
+ export declare class HealthCliCommands {
7
+ private readonly health;
8
+ private readonly logger;
9
+ private readonly healthChecks;
10
+ constructor(health: HealthCheckService, logger: ObservabilityLoggerInterface, healthChecks: HealthChecks);
11
+ getHealth(): Promise<void>;
12
+ }
13
+ export declare const createHealthCli: (options: HealthCliOptionsInterface) => Type<HealthCliCommands>;
@@ -0,0 +1,52 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject, ServiceUnavailableException } from '@nestjs/common';
14
+ import { HealthCheckService } from '@nestjs/terminus';
15
+ import { Command, Console } from 'nestjs-console';
16
+ import { OBSERVABILITY_LOGGER } from '../../logging/constants.js';
17
+ import { withClassDecorator } from '../../shared/with-class-decorator.js';
18
+ import { HealthChecks } from '../health-checks.js';
19
+ let HealthCliCommands = class HealthCliCommands {
20
+ health;
21
+ logger;
22
+ healthChecks;
23
+ constructor(health, logger, healthChecks) {
24
+ this.health = health;
25
+ this.logger = logger;
26
+ this.healthChecks = healthChecks;
27
+ }
28
+ async getHealth() {
29
+ try {
30
+ const healthResult = await this.health.check(this.healthChecks.build());
31
+ this.logger.info({ healthResult }, healthResult.status);
32
+ }
33
+ catch (error) {
34
+ const healthResult = error instanceof ServiceUnavailableException ? error.getResponse() : 'unknown';
35
+ this.logger.error({ healthResult }, 'error');
36
+ }
37
+ }
38
+ };
39
+ __decorate([
40
+ Command({ command: 'health' }),
41
+ __metadata("design:type", Function),
42
+ __metadata("design:paramtypes", []),
43
+ __metadata("design:returntype", Promise)
44
+ ], HealthCliCommands.prototype, "getHealth", null);
45
+ HealthCliCommands = __decorate([
46
+ __param(0, Inject(HealthCheckService)),
47
+ __param(1, Inject(OBSERVABILITY_LOGGER)),
48
+ __param(2, Inject(HealthChecks)),
49
+ __metadata("design:paramtypes", [HealthCheckService, Object, HealthChecks])
50
+ ], HealthCliCommands);
51
+ export { HealthCliCommands };
52
+ export const createHealthCli = (options) => withClassDecorator(HealthCliCommands, Console({ command: options.command }));
@@ -0,0 +1,5 @@
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { HealthCliOptionsInterface } from './health-cli-options.interface.js';
3
+ export declare class HealthCliModule {
4
+ static forRoot(options: HealthCliOptionsInterface): DynamicModule;
5
+ }
@@ -0,0 +1,20 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Module } from '@nestjs/common';
8
+ import { createHealthCli } from './health-cli.js';
9
+ let HealthCliModule = class HealthCliModule {
10
+ static forRoot(options) {
11
+ return {
12
+ module: this,
13
+ providers: [createHealthCli(options)],
14
+ };
15
+ }
16
+ };
17
+ HealthCliModule = __decorate([
18
+ Module({})
19
+ ], HealthCliModule);
20
+ export { HealthCliModule };
@@ -0,0 +1,3 @@
1
+ export * from './health-cli.js';
2
+ export * from './health-cli-options.interface.js';
3
+ export * from './health-cli.module.js';
@@ -0,0 +1,3 @@
1
+ export * from './health-cli.js';
2
+ export * from './health-cli-options.interface.js';
3
+ export * from './health-cli.module.js';
@@ -0,0 +1,3 @@
1
+ export declare class HealthCheckType {
2
+ status: string;
3
+ }
@@ -0,0 +1,21 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Field, ObjectType } from '@nestjs/graphql';
11
+ let HealthCheckType = class HealthCheckType {
12
+ status;
13
+ };
14
+ __decorate([
15
+ Field(() => String),
16
+ __metadata("design:type", String)
17
+ ], HealthCheckType.prototype, "status", void 0);
18
+ HealthCheckType = __decorate([
19
+ ObjectType('HealthCheck')
20
+ ], HealthCheckType);
21
+ export { HealthCheckType };
@@ -0,0 +1,5 @@
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { HealthCarrierOptionsInterface } from '../health-module-options.interface.js';
3
+ export declare class HealthGraphqlModule {
4
+ static forRoot(options?: HealthCarrierOptionsInterface): DynamicModule;
5
+ }
@@ -0,0 +1,23 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { applyDecorators, Module } from '@nestjs/common';
8
+ import { Resolver } from '@nestjs/graphql';
9
+ import { withClassDecorator } from '../../shared/with-class-decorator.js';
10
+ import { HealthResolver } from './health.resolver.js';
11
+ let HealthGraphqlModule = class HealthGraphqlModule {
12
+ static forRoot(options = {}) {
13
+ const consumerDecorators = options.publicRoute === undefined ? [] : [options.publicRoute];
14
+ return {
15
+ module: this,
16
+ providers: [withClassDecorator(HealthResolver, applyDecorators(Resolver(), ...consumerDecorators))],
17
+ };
18
+ }
19
+ };
20
+ HealthGraphqlModule = __decorate([
21
+ Module({})
22
+ ], HealthGraphqlModule);
23
+ export { HealthGraphqlModule };
@@ -0,0 +1,11 @@
1
+ import { HealthCheckService } from '@nestjs/terminus';
2
+ import type { ObservabilityLoggerInterface } from '../../logging/observability-logger.interface.js';
3
+ import { HealthChecks } from '../health-checks.js';
4
+ import { HealthCheckType } from './health-check.type.js';
5
+ export declare class HealthResolver {
6
+ private readonly healthCheck;
7
+ private readonly logger;
8
+ private readonly healthChecks;
9
+ constructor(healthCheck: HealthCheckService, logger: ObservabilityLoggerInterface, healthChecks: HealthChecks);
10
+ health(): Promise<HealthCheckType>;
11
+ }
@@ -0,0 +1,52 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject } from '@nestjs/common';
14
+ import { Query, Resolver } from '@nestjs/graphql';
15
+ import { HealthCheckService } from '@nestjs/terminus';
16
+ import { OBSERVABILITY_LOGGER } from '../../logging/constants.js';
17
+ import { HealthChecks } from '../health-checks.js';
18
+ import { HealthCheckType } from './health-check.type.js';
19
+ let HealthResolver = class HealthResolver {
20
+ healthCheck;
21
+ logger;
22
+ healthChecks;
23
+ constructor(healthCheck, logger, healthChecks) {
24
+ this.healthCheck = healthCheck;
25
+ this.logger = logger;
26
+ this.healthChecks = healthChecks;
27
+ }
28
+ async health() {
29
+ try {
30
+ const health = await this.healthCheck.check(this.healthChecks.build());
31
+ return { status: health.status };
32
+ }
33
+ catch (error) {
34
+ this.logger.error({ err: error }, 'GraphQL health check failed');
35
+ return { status: 'error' };
36
+ }
37
+ }
38
+ };
39
+ __decorate([
40
+ Query(() => HealthCheckType),
41
+ __metadata("design:type", Function),
42
+ __metadata("design:paramtypes", []),
43
+ __metadata("design:returntype", Promise)
44
+ ], HealthResolver.prototype, "health", null);
45
+ HealthResolver = __decorate([
46
+ Resolver({ isAbstract: true }),
47
+ __param(0, Inject(HealthCheckService)),
48
+ __param(1, Inject(OBSERVABILITY_LOGGER)),
49
+ __param(2, Inject(HealthChecks)),
50
+ __metadata("design:paramtypes", [HealthCheckService, Object, HealthChecks])
51
+ ], HealthResolver);
52
+ export { HealthResolver };
@@ -0,0 +1,3 @@
1
+ export * from './health-check.type.js';
2
+ export * from './health-graphql.module.js';
3
+ export * from './health.resolver.js';
@@ -0,0 +1,3 @@
1
+ export * from './health-check.type.js';
2
+ export * from './health-graphql.module.js';
3
+ export * from './health.resolver.js';
@@ -0,0 +1,10 @@
1
+ import { DiskHealthIndicator, HealthIndicatorFunction, MemoryHealthIndicator, TypeOrmHealthIndicator } from '@nestjs/terminus';
2
+ import { HealthConfig } from './health.config.js';
3
+ export declare class HealthChecks {
4
+ private readonly database;
5
+ private readonly memory;
6
+ private readonly disk;
7
+ private readonly config;
8
+ constructor(database: TypeOrmHealthIndicator, memory: MemoryHealthIndicator, disk: DiskHealthIndicator, config: HealthConfig);
9
+ build(): HealthIndicatorFunction[];
10
+ }
@@ -0,0 +1,50 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject, Injectable } from '@nestjs/common';
14
+ import { DiskHealthIndicator, MemoryHealthIndicator, TypeOrmHealthIndicator, } from '@nestjs/terminus';
15
+ import { HealthConfig } from './health.config.js';
16
+ let HealthChecks = class HealthChecks {
17
+ database;
18
+ memory;
19
+ disk;
20
+ config;
21
+ constructor(database, memory, disk, config) {
22
+ this.database = database;
23
+ this.memory = memory;
24
+ this.disk = disk;
25
+ this.config = config;
26
+ }
27
+ build() {
28
+ return [
29
+ async () => this.database.pingCheck('typeorm'),
30
+ async () => this.memory.checkHeap('memory_heap', this.config.memoryHeapBytes),
31
+ async () => this.memory.checkRSS('memory_rss', this.config.memoryRssBytes),
32
+ async () => this.disk.checkStorage('disk', {
33
+ path: '/',
34
+ thresholdPercent: this.config.diskThresholdPercent,
35
+ }),
36
+ ];
37
+ }
38
+ };
39
+ HealthChecks = __decorate([
40
+ Injectable(),
41
+ __param(0, Inject(TypeOrmHealthIndicator)),
42
+ __param(1, Inject(MemoryHealthIndicator)),
43
+ __param(2, Inject(DiskHealthIndicator)),
44
+ __param(3, Inject(HealthConfig)),
45
+ __metadata("design:paramtypes", [TypeOrmHealthIndicator,
46
+ MemoryHealthIndicator,
47
+ DiskHealthIndicator,
48
+ HealthConfig])
49
+ ], HealthChecks);
50
+ export { HealthChecks };
@@ -0,0 +1,5 @@
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { HealthCarrierOptionsInterface } from './health-module-options.interface.js';
3
+ export declare class HealthHttpModule {
4
+ static forRoot(options?: HealthCarrierOptionsInterface): DynamicModule;
5
+ }
@@ -0,0 +1,23 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Module } from '@nestjs/common';
8
+ import { withClassDecorator } from '../shared/with-class-decorator.js';
9
+ import { HealthController } from './health.controller.js';
10
+ import { MigrationsHealthIndicator } from './migrations.health-indicator.js';
11
+ let HealthHttpModule = class HealthHttpModule {
12
+ static forRoot(options = {}) {
13
+ return {
14
+ controllers: [withClassDecorator(HealthController, options.publicRoute)],
15
+ module: this,
16
+ providers: [MigrationsHealthIndicator],
17
+ };
18
+ }
19
+ };
20
+ HealthHttpModule = __decorate([
21
+ Module({})
22
+ ], HealthHttpModule);
23
+ export { HealthHttpModule };
@@ -0,0 +1,9 @@
1
+ import type { ModuleMetadata } from '@nestjs/common';
2
+ import type { TerminusModuleOptions } from '@nestjs/terminus';
3
+ export interface HealthCarrierOptionsInterface {
4
+ readonly publicRoute?: ClassDecorator;
5
+ }
6
+ export interface HealthModuleOptionsInterface {
7
+ readonly imports?: ModuleMetadata['imports'];
8
+ readonly terminus?: TerminusModuleOptions;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { HealthEnvironment } from './health.environment.js';
2
+ export declare class HealthConfig {
3
+ private readonly environment;
4
+ get diskThresholdPercent(): number;
5
+ get memoryHeapBytes(): number;
6
+ get memoryRssBytes(): number;
7
+ constructor(environment: HealthEnvironment);
8
+ }
@@ -0,0 +1,36 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject, Injectable } from '@nestjs/common';
14
+ import { HealthEnvironment } from './health.environment.js';
15
+ const BYTES_IN_MEGABYTE = 1024 * 1024;
16
+ let HealthConfig = class HealthConfig {
17
+ environment;
18
+ get diskThresholdPercent() {
19
+ return this.environment.HEALTH_DISK_THRESHOLD_PERCENT;
20
+ }
21
+ get memoryHeapBytes() {
22
+ return this.environment.HEALTH_MEMORY_HEAP_MB * BYTES_IN_MEGABYTE;
23
+ }
24
+ get memoryRssBytes() {
25
+ return this.environment.HEALTH_MEMORY_RSS_MB * BYTES_IN_MEGABYTE;
26
+ }
27
+ constructor(environment) {
28
+ this.environment = environment;
29
+ }
30
+ };
31
+ HealthConfig = __decorate([
32
+ Injectable(),
33
+ __param(0, Inject(HealthEnvironment)),
34
+ __metadata("design:paramtypes", [HealthEnvironment])
35
+ ], HealthConfig);
36
+ export { HealthConfig };
@@ -0,0 +1,14 @@
1
+ import type { HealthCheckResult } from '@nestjs/terminus';
2
+ import { HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus';
3
+ import { HealthChecks } from './health-checks.js';
4
+ import { MigrationsHealthIndicator } from './migrations.health-indicator.js';
5
+ export declare class HealthController {
6
+ private readonly health;
7
+ private readonly database;
8
+ private readonly migrations;
9
+ private readonly healthChecks;
10
+ constructor(health: HealthCheckService, database: TypeOrmHealthIndicator, migrations: MigrationsHealthIndicator, healthChecks: HealthChecks);
11
+ check(): Promise<HealthCheckResult>;
12
+ live(): Promise<HealthCheckResult>;
13
+ ready(): Promise<HealthCheckResult>;
14
+ }
@@ -0,0 +1,75 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { runAsInfrastructureQuery } from '@application-kit/typeorm/logging';
14
+ import { Controller, Get, Inject } from '@nestjs/common';
15
+ import { HealthCheck, HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus';
16
+ import { HEALTH_ROUTE } from '../logging/infrastructure-paths.js';
17
+ import { HealthChecks } from './health-checks.js';
18
+ import { MigrationsHealthIndicator } from './migrations.health-indicator.js';
19
+ let HealthController = class HealthController {
20
+ health;
21
+ database;
22
+ migrations;
23
+ healthChecks;
24
+ constructor(health, database, migrations, healthChecks) {
25
+ this.health = health;
26
+ this.database = database;
27
+ this.migrations = migrations;
28
+ this.healthChecks = healthChecks;
29
+ }
30
+ async check() {
31
+ return runAsInfrastructureQuery(async () => this.health.check(this.healthChecks.build()));
32
+ }
33
+ async live() {
34
+ return this.health.check([]);
35
+ }
36
+ async ready() {
37
+ return runAsInfrastructureQuery(async () => this.health.check([
38
+ async () => this.database.pingCheck('typeorm'),
39
+ async () => this.migrations.isUpToDate('migrations'),
40
+ ]));
41
+ }
42
+ };
43
+ __decorate([
44
+ Get(),
45
+ HealthCheck(),
46
+ __metadata("design:type", Function),
47
+ __metadata("design:paramtypes", []),
48
+ __metadata("design:returntype", Promise)
49
+ ], HealthController.prototype, "check", null);
50
+ __decorate([
51
+ Get('live'),
52
+ HealthCheck(),
53
+ __metadata("design:type", Function),
54
+ __metadata("design:paramtypes", []),
55
+ __metadata("design:returntype", Promise)
56
+ ], HealthController.prototype, "live", null);
57
+ __decorate([
58
+ Get('ready'),
59
+ HealthCheck(),
60
+ __metadata("design:type", Function),
61
+ __metadata("design:paramtypes", []),
62
+ __metadata("design:returntype", Promise)
63
+ ], HealthController.prototype, "ready", null);
64
+ HealthController = __decorate([
65
+ Controller(HEALTH_ROUTE),
66
+ __param(0, Inject(HealthCheckService)),
67
+ __param(1, Inject(TypeOrmHealthIndicator)),
68
+ __param(2, Inject(MigrationsHealthIndicator)),
69
+ __param(3, Inject(HealthChecks)),
70
+ __metadata("design:paramtypes", [HealthCheckService,
71
+ TypeOrmHealthIndicator,
72
+ MigrationsHealthIndicator,
73
+ HealthChecks])
74
+ ], HealthController);
75
+ export { HealthController };