@carlonicora/nestjs-neo4jsonapi 1.19.0 → 1.21.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.
- package/README.md +115 -0
- package/dist/core/core.module.d.ts.map +1 -1
- package/dist/core/core.module.js +6 -2
- package/dist/core/core.module.js.map +1 -1
- package/dist/core/health/controllers/health.controller.d.ts +65 -0
- package/dist/core/health/controllers/health.controller.d.ts.map +1 -0
- package/dist/core/health/controllers/health.controller.js +125 -0
- package/dist/core/health/controllers/health.controller.js.map +1 -0
- package/dist/core/health/health.module.d.ts +3 -0
- package/dist/core/health/health.module.d.ts.map +1 -0
- package/dist/core/health/health.module.js +28 -0
- package/dist/core/health/health.module.js.map +1 -0
- package/dist/core/health/index.d.ts +7 -0
- package/dist/core/health/index.d.ts.map +1 -0
- package/dist/core/health/index.js +23 -0
- package/dist/core/health/index.js.map +1 -0
- package/dist/core/health/indicators/disk.health.d.ts +9 -0
- package/dist/core/health/indicators/disk.health.d.ts.map +1 -0
- package/dist/core/health/indicators/disk.health.js +145 -0
- package/dist/core/health/indicators/disk.health.js.map +1 -0
- package/dist/core/health/indicators/neo4j.health.d.ts +9 -0
- package/dist/core/health/indicators/neo4j.health.d.ts.map +1 -0
- package/dist/core/health/indicators/neo4j.health.js +49 -0
- package/dist/core/health/indicators/neo4j.health.js.map +1 -0
- package/dist/core/health/indicators/redis.health.d.ts +9 -0
- package/dist/core/health/indicators/redis.health.d.ts.map +1 -0
- package/dist/core/health/indicators/redis.health.js +59 -0
- package/dist/core/health/indicators/redis.health.js.map +1 -0
- package/dist/core/health/indicators/s3.health.d.ts +12 -0
- package/dist/core/health/indicators/s3.health.d.ts.map +1 -0
- package/dist/core/health/indicators/s3.health.js +118 -0
- package/dist/core/health/indicators/s3.health.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/foundations/stripe/__tests__/fixtures/stripe.fixtures.d.ts.map +1 -1
- package/dist/foundations/stripe/__tests__/fixtures/stripe.fixtures.js +6 -0
- package/dist/foundations/stripe/__tests__/fixtures/stripe.fixtures.js.map +1 -1
- package/dist/scripts/generate-module/generator.js.map +1 -1
- package/dist/scripts/generate-module/transformers/import-resolver.d.ts.map +1 -1
- package/dist/scripts/generate-module/transformers/import-resolver.js +3 -1
- package/dist/scripts/generate-module/transformers/import-resolver.js.map +1 -1
- package/dist/scripts/generate-module/types/template-data.interface.d.ts +1 -1
- package/dist/scripts/generate-module/types/template-data.interface.d.ts.map +1 -1
- package/dist/scripts/generate-module/utils/module-registrar.d.ts +1 -1
- package/dist/scripts/generate-module/utils/module-registrar.d.ts.map +1 -1
- package/dist/scripts/generate-module/utils/module-registrar.js +105 -29
- package/dist/scripts/generate-module/utils/module-registrar.js.map +1 -1
- package/dist/scripts/generate-module/validators/json-schema-validator.d.ts.map +1 -1
- package/dist/scripts/generate-module/validators/json-schema-validator.js +10 -7
- package/dist/scripts/generate-module/validators/json-schema-validator.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ A comprehensive NestJS foundation package providing JSON:API compliant APIs, Neo
|
|
|
13
13
|
- [Company-User Model (B2B & B2C)](#company-user-model-b2b--b2c)
|
|
14
14
|
- [Required Configuration Files](#required-configuration-files)
|
|
15
15
|
- [Core Modules](#core-modules)
|
|
16
|
+
- [Health Check Endpoints](#health-check-endpoints)
|
|
16
17
|
- [Foundation Modules](#foundation-modules)
|
|
17
18
|
- [AI Agents](#ai-agents)
|
|
18
19
|
- [Security & Authentication](#security--authentication)
|
|
@@ -902,6 +903,120 @@ The library includes 18 core infrastructure modules:
|
|
|
902
903
|
| `MigratorModule` | Database migrations |
|
|
903
904
|
| `AppModeModule` | Application mode (API/Worker) |
|
|
904
905
|
| `DebugModule` | Debugging utilities |
|
|
906
|
+
| `HealthModule` | Health check endpoints for liveness/readiness |
|
|
907
|
+
|
|
908
|
+
## Health Check Endpoints
|
|
909
|
+
|
|
910
|
+
The package includes built-in health check endpoints using `@nestjs/terminus` for container orchestration and load balancer integration. Rate limiting is automatically disabled for all health endpoints.
|
|
911
|
+
|
|
912
|
+
### Endpoints
|
|
913
|
+
|
|
914
|
+
| Endpoint | Purpose | Checks |
|
|
915
|
+
|----------|---------|--------|
|
|
916
|
+
| `GET /health` | Full health status | Neo4j, Redis, S3, Disk |
|
|
917
|
+
| `GET /health/live` | Liveness probe | None (process running) |
|
|
918
|
+
| `GET /health/ready` | Readiness probe | Neo4j, Redis |
|
|
919
|
+
|
|
920
|
+
### Full Health Check: GET /health
|
|
921
|
+
|
|
922
|
+
Returns detailed status of all dependencies. Use for monitoring dashboards.
|
|
923
|
+
|
|
924
|
+
**Response when healthy (200 OK):**
|
|
925
|
+
```json
|
|
926
|
+
{
|
|
927
|
+
"status": "ok",
|
|
928
|
+
"info": {
|
|
929
|
+
"neo4j": { "status": "up", "message": "Neo4j connection healthy" },
|
|
930
|
+
"redis": { "status": "up", "message": "Redis connection healthy" },
|
|
931
|
+
"storage": { "status": "up", "message": "aws storage connection healthy" },
|
|
932
|
+
"disk": { "status": "up", "message": "Disk space healthy", "free": "50.00 GB" }
|
|
933
|
+
},
|
|
934
|
+
"error": {},
|
|
935
|
+
"details": { ... }
|
|
936
|
+
}
|
|
937
|
+
```
|
|
938
|
+
|
|
939
|
+
### Liveness Probe: GET /health/live
|
|
940
|
+
|
|
941
|
+
Indicates if the application process is running. Does NOT check external dependencies.
|
|
942
|
+
|
|
943
|
+
**Use for Kubernetes livenessProbe:** If this fails, the container should be restarted.
|
|
944
|
+
|
|
945
|
+
**Response (200 OK):**
|
|
946
|
+
```json
|
|
947
|
+
{
|
|
948
|
+
"status": "ok",
|
|
949
|
+
"info": {},
|
|
950
|
+
"error": {},
|
|
951
|
+
"details": {}
|
|
952
|
+
}
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
### Readiness Probe: GET /health/ready
|
|
956
|
+
|
|
957
|
+
Indicates if the application can accept traffic. Checks critical dependencies (Neo4j, Redis).
|
|
958
|
+
|
|
959
|
+
**Use for Kubernetes readinessProbe:** If this fails, traffic should be routed elsewhere.
|
|
960
|
+
|
|
961
|
+
**Response when healthy (200 OK):**
|
|
962
|
+
```json
|
|
963
|
+
{
|
|
964
|
+
"status": "ok",
|
|
965
|
+
"info": {
|
|
966
|
+
"neo4j": { "status": "up", "message": "Neo4j connection healthy" },
|
|
967
|
+
"redis": { "status": "up", "message": "Redis connection healthy" }
|
|
968
|
+
},
|
|
969
|
+
"error": {},
|
|
970
|
+
"details": { ... }
|
|
971
|
+
}
|
|
972
|
+
```
|
|
973
|
+
|
|
974
|
+
**Response when unhealthy (503 Service Unavailable):**
|
|
975
|
+
```json
|
|
976
|
+
{
|
|
977
|
+
"status": "error",
|
|
978
|
+
"info": {
|
|
979
|
+
"redis": { "status": "up", "message": "Redis connection healthy" }
|
|
980
|
+
},
|
|
981
|
+
"error": {
|
|
982
|
+
"neo4j": { "status": "down", "message": "Connection refused" }
|
|
983
|
+
},
|
|
984
|
+
"details": { ... }
|
|
985
|
+
}
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
### Kubernetes Configuration Example
|
|
989
|
+
|
|
990
|
+
```yaml
|
|
991
|
+
apiVersion: v1
|
|
992
|
+
kind: Pod
|
|
993
|
+
spec:
|
|
994
|
+
containers:
|
|
995
|
+
- name: api
|
|
996
|
+
livenessProbe:
|
|
997
|
+
httpGet:
|
|
998
|
+
path: /health/live
|
|
999
|
+
port: 3000
|
|
1000
|
+
initialDelaySeconds: 10
|
|
1001
|
+
periodSeconds: 10
|
|
1002
|
+
readinessProbe:
|
|
1003
|
+
httpGet:
|
|
1004
|
+
path: /health/ready
|
|
1005
|
+
port: 3000
|
|
1006
|
+
initialDelaySeconds: 5
|
|
1007
|
+
periodSeconds: 5
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
### Health Indicators
|
|
1011
|
+
|
|
1012
|
+
The module includes four health indicators:
|
|
1013
|
+
|
|
1014
|
+
| Indicator | Timeout | What it checks |
|
|
1015
|
+
|-----------|---------|----------------|
|
|
1016
|
+
| `Neo4jHealthIndicator` | 3s | Executes `RETURN 1` query |
|
|
1017
|
+
| `RedisHealthIndicator` | 3s | Connection status + PING |
|
|
1018
|
+
| `S3HealthIndicator` | 5s | Bucket access (HeadBucket) |
|
|
1019
|
+
| `DiskHealthIndicator` | - | Free space ≥ 1GB or 10% |
|
|
905
1020
|
|
|
906
1021
|
## Foundation Modules
|
|
907
1022
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.module.d.ts","sourceRoot":"","sources":["../../src/core/core.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"core.module.d.ts","sourceRoot":"","sources":["../../src/core/core.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4B,MAAM,gBAAgB,CAAC;AA6GzE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAEa,UAAU;IACrB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,aAAa;CAW3D"}
|
package/dist/core/core.module.js
CHANGED
|
@@ -15,6 +15,7 @@ const passport_1 = require("@nestjs/passport");
|
|
|
15
15
|
// Import all core modules
|
|
16
16
|
const blocknote_module_1 = require("./blocknote/blocknote.module");
|
|
17
17
|
const cache_module_1 = require("./cache/cache.module");
|
|
18
|
+
const health_module_1 = require("./health/health.module");
|
|
18
19
|
const cors_module_1 = require("./cors/cors.module");
|
|
19
20
|
const debug_module_1 = require("./debug/debug.module");
|
|
20
21
|
const email_module_1 = require("./email/email.module");
|
|
@@ -71,9 +72,11 @@ function getCoreModules(queueIds = []) {
|
|
|
71
72
|
neo4j_module_1.Neo4JModule,
|
|
72
73
|
redis_module_1.RedisModule,
|
|
73
74
|
cache_module_1.CacheModule,
|
|
74
|
-
// 3.
|
|
75
|
+
// 3. Health module - needs Neo4j and Redis for health checks
|
|
76
|
+
health_module_1.HealthModule,
|
|
77
|
+
// 4. Queue module - uses ConfigService for Redis, explicit queue IDs for registration
|
|
75
78
|
queue_module_1.QueueModule.forRootWithQueues(queueIds),
|
|
76
|
-
//
|
|
79
|
+
// 5. Services using external connections
|
|
77
80
|
email_module_1.EmailModule.forRoot(),
|
|
78
81
|
websocket_module_1.WebsocketModule,
|
|
79
82
|
llm_module_1.LLMModule,
|
|
@@ -97,6 +100,7 @@ function getCoreModuleExports() {
|
|
|
97
100
|
email_module_1.EmailModule,
|
|
98
101
|
cors_module_1.CorsModule,
|
|
99
102
|
version_module_1.VersionModule,
|
|
103
|
+
health_module_1.HealthModule,
|
|
100
104
|
websocket_module_1.WebsocketModule,
|
|
101
105
|
llm_module_1.LLMModule,
|
|
102
106
|
blocknote_module_1.BlockNoteModule,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.module.js","sourceRoot":"","sources":["../../src/core/core.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,2CAA6D;AAC7D,qCAAwC;AACxC,+CAAkD;AAGlD,0BAA0B;AAC1B,mEAA+D;AAC/D,uDAAmD;AACnD,oDAAgD;AAChD,uDAAmD;AACnD,uDAAmD;AACnD,6DAAyD;AACzD,iDAA6C;AAC7C,6DAAyD;AACzD,gEAA4D;AAC5D,uDAAmD;AACnD,uDAAmD;AACnD,uDAAmD;AACnD,gEAA4D;AAC5D,6DAAyD;AACzD,6DAAyD;AACzD,mEAA+D;AAE/D;;;;;;;;;;;;;;GAcG;AACH,SAAS,cAAc,CAAC,WAAqB,EAAE;IAC7C,OAAO;QACL,iEAAiE;QACjE,eAAS,CAAC,aAAa,CAAC;YACtB,OAAO,EAA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O,EAAE,cAAc,CAAC,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAC;YAChD,SAAS;YACT,OAAO,EAAE,CAAC,GAAG,oBAAoB,EAAE,CAAC;YACpC,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF,CAAA;AAfY,gCAAU;qBAAV,UAAU;IAFtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAetB"}
|
|
1
|
+
{"version":3,"file":"core.module.js","sourceRoot":"","sources":["../../src/core/core.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,2CAA6D;AAC7D,qCAAwC;AACxC,+CAAkD;AAGlD,0BAA0B;AAC1B,mEAA+D;AAC/D,uDAAmD;AACnD,0DAAsD;AACtD,oDAAgD;AAChD,uDAAmD;AACnD,uDAAmD;AACnD,6DAAyD;AACzD,iDAA6C;AAC7C,6DAAyD;AACzD,gEAA4D;AAC5D,uDAAmD;AACnD,uDAAmD;AACnD,uDAAmD;AACnD,gEAA4D;AAC5D,6DAAyD;AACzD,6DAAyD;AACzD,mEAA+D;AAE/D;;;;;;;;;;;;;;GAcG;AACH,SAAS,cAAc,CAAC,WAAqB,EAAE;IAC7C,OAAO;QACL,iEAAiE;QACjE,eAAS,CAAC,aAAa,CAAC;YACtB,OAAO,EAAE,CAAC,qBAAY,CAAC;YACvB,MAAM,EAAE,CAAC,sBAAa,CAAC;YACvB,UAAU,EAAE,CAAC,aAAiD,EAAE,EAAE;gBAChE,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,CAAqB,KAAK,CAAC,CAAC;gBACzD,OAAO;oBACL,MAAM,EAAE,GAAG,EAAE,MAAM;oBACnB,WAAW,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,SAAgB,EAAE;iBAClD,CAAC;YACJ,CAAC;SACF,CAAC;QACF,yBAAc;QACd,kDAAkD;QAClD,gCAAc;QACd,wBAAU,CAAC,OAAO,EAAE;QACpB,8BAA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us";
|
|
2
|
+
import { Neo4jHealthIndicator } from "../indicators/neo4j.health";
|
|
3
|
+
import { RedisHealthIndicator } from "../indicators/redis.health";
|
|
4
|
+
import { S3HealthIndicator } from "../indicators/s3.health";
|
|
5
|
+
import { DiskHealthIndicator } from "../indicators/disk.health";
|
|
6
|
+
/**
|
|
7
|
+
* Health Check Controller
|
|
8
|
+
*
|
|
9
|
+
* Provides health check endpoints for monitoring and orchestration.
|
|
10
|
+
* All endpoints are PUBLIC (no authentication required).
|
|
11
|
+
* Rate limiting is disabled for health endpoints.
|
|
12
|
+
*
|
|
13
|
+
* Endpoints:
|
|
14
|
+
* - GET /health - Full health status with all dependency checks
|
|
15
|
+
* - GET /health/live - Liveness probe (process is running)
|
|
16
|
+
* - GET /health/ready - Readiness probe (can accept traffic)
|
|
17
|
+
*/
|
|
18
|
+
export declare class HealthController {
|
|
19
|
+
private health;
|
|
20
|
+
private neo4jHealth;
|
|
21
|
+
private redisHealth;
|
|
22
|
+
private s3Health;
|
|
23
|
+
private diskHealth;
|
|
24
|
+
constructor(health: HealthCheckService, neo4jHealth: Neo4jHealthIndicator, redisHealth: RedisHealthIndicator, s3Health: S3HealthIndicator, diskHealth: DiskHealthIndicator);
|
|
25
|
+
/**
|
|
26
|
+
* Full health check endpoint
|
|
27
|
+
*
|
|
28
|
+
* Checks all dependencies and returns detailed status.
|
|
29
|
+
* Use for monitoring dashboards and detailed health analysis.
|
|
30
|
+
*
|
|
31
|
+
* @returns HealthCheckResult with status of all dependencies
|
|
32
|
+
* - HTTP 200: All dependencies healthy
|
|
33
|
+
* - HTTP 503: One or more dependencies unhealthy
|
|
34
|
+
*/
|
|
35
|
+
check(): Promise<HealthCheckResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Liveness probe endpoint
|
|
38
|
+
*
|
|
39
|
+
* Indicates if the application process is running.
|
|
40
|
+
* Does NOT check external dependencies.
|
|
41
|
+
*
|
|
42
|
+
* Use for Kubernetes livenessProbe:
|
|
43
|
+
* - If this fails, container should be restarted
|
|
44
|
+
*
|
|
45
|
+
* @returns HealthCheckResult
|
|
46
|
+
* - HTTP 200: Process is alive
|
|
47
|
+
*/
|
|
48
|
+
liveness(): Promise<HealthCheckResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Readiness probe endpoint
|
|
51
|
+
*
|
|
52
|
+
* Indicates if the application can accept traffic.
|
|
53
|
+
* Checks critical dependencies (Neo4j, Redis).
|
|
54
|
+
*
|
|
55
|
+
* Use for Kubernetes readinessProbe:
|
|
56
|
+
* - If this fails, traffic should be routed elsewhere
|
|
57
|
+
* - Container should NOT be restarted
|
|
58
|
+
*
|
|
59
|
+
* @returns HealthCheckResult
|
|
60
|
+
* - HTTP 200: Ready to accept traffic
|
|
61
|
+
* - HTTP 503: Not ready (dependency unavailable)
|
|
62
|
+
*/
|
|
63
|
+
readiness(): Promise<HealthCheckResult>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=health.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.controller.d.ts","sourceRoot":"","sources":["../../../../src/core/health/controllers/health.controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,qBAEa,gBAAgB;IAEzB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,UAAU;gBAJV,MAAM,EAAE,kBAAkB,EAC1B,WAAW,EAAE,oBAAoB,EACjC,WAAW,EAAE,oBAAoB,EACjC,QAAQ,EAAE,iBAAiB,EAC3B,UAAU,EAAE,mBAAmB;IAGzC;;;;;;;;;OASG;IAGG,KAAK,IAAI,OAAO,CAAC,iBAAiB,CAAC;IASzC;;;;;;;;;;;OAWG;IAGG,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAM5C;;;;;;;;;;;;;OAaG;IAGG,SAAS,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAI9C"}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HealthController = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
15
|
+
const terminus_1 = require("@nestjs/terminus");
|
|
16
|
+
const neo4j_health_1 = require("../indicators/neo4j.health");
|
|
17
|
+
const redis_health_1 = require("../indicators/redis.health");
|
|
18
|
+
const s3_health_1 = require("../indicators/s3.health");
|
|
19
|
+
const disk_health_1 = require("../indicators/disk.health");
|
|
20
|
+
/**
|
|
21
|
+
* Health Check Controller
|
|
22
|
+
*
|
|
23
|
+
* Provides health check endpoints for monitoring and orchestration.
|
|
24
|
+
* All endpoints are PUBLIC (no authentication required).
|
|
25
|
+
* Rate limiting is disabled for health endpoints.
|
|
26
|
+
*
|
|
27
|
+
* Endpoints:
|
|
28
|
+
* - GET /health - Full health status with all dependency checks
|
|
29
|
+
* - GET /health/live - Liveness probe (process is running)
|
|
30
|
+
* - GET /health/ready - Readiness probe (can accept traffic)
|
|
31
|
+
*/
|
|
32
|
+
let HealthController = class HealthController {
|
|
33
|
+
constructor(health, neo4jHealth, redisHealth, s3Health, diskHealth) {
|
|
34
|
+
this.health = health;
|
|
35
|
+
this.neo4jHealth = neo4jHealth;
|
|
36
|
+
this.redisHealth = redisHealth;
|
|
37
|
+
this.s3Health = s3Health;
|
|
38
|
+
this.diskHealth = diskHealth;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Full health check endpoint
|
|
42
|
+
*
|
|
43
|
+
* Checks all dependencies and returns detailed status.
|
|
44
|
+
* Use for monitoring dashboards and detailed health analysis.
|
|
45
|
+
*
|
|
46
|
+
* @returns HealthCheckResult with status of all dependencies
|
|
47
|
+
* - HTTP 200: All dependencies healthy
|
|
48
|
+
* - HTTP 503: One or more dependencies unhealthy
|
|
49
|
+
*/
|
|
50
|
+
async check() {
|
|
51
|
+
return this.health.check([
|
|
52
|
+
() => this.neo4jHealth.isHealthy("neo4j"),
|
|
53
|
+
() => this.redisHealth.isHealthy("redis"),
|
|
54
|
+
() => this.s3Health.isHealthy("storage"),
|
|
55
|
+
() => this.diskHealth.isHealthy("disk"),
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Liveness probe endpoint
|
|
60
|
+
*
|
|
61
|
+
* Indicates if the application process is running.
|
|
62
|
+
* Does NOT check external dependencies.
|
|
63
|
+
*
|
|
64
|
+
* Use for Kubernetes livenessProbe:
|
|
65
|
+
* - If this fails, container should be restarted
|
|
66
|
+
*
|
|
67
|
+
* @returns HealthCheckResult
|
|
68
|
+
* - HTTP 200: Process is alive
|
|
69
|
+
*/
|
|
70
|
+
async liveness() {
|
|
71
|
+
// Liveness only checks if process is running
|
|
72
|
+
// No external dependency checks
|
|
73
|
+
return this.health.check([]);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Readiness probe endpoint
|
|
77
|
+
*
|
|
78
|
+
* Indicates if the application can accept traffic.
|
|
79
|
+
* Checks critical dependencies (Neo4j, Redis).
|
|
80
|
+
*
|
|
81
|
+
* Use for Kubernetes readinessProbe:
|
|
82
|
+
* - If this fails, traffic should be routed elsewhere
|
|
83
|
+
* - Container should NOT be restarted
|
|
84
|
+
*
|
|
85
|
+
* @returns HealthCheckResult
|
|
86
|
+
* - HTTP 200: Ready to accept traffic
|
|
87
|
+
* - HTTP 503: Not ready (dependency unavailable)
|
|
88
|
+
*/
|
|
89
|
+
async readiness() {
|
|
90
|
+
// Readiness checks critical dependencies needed to handle requests
|
|
91
|
+
return this.health.check([() => this.neo4jHealth.isHealthy("neo4j"), () => this.redisHealth.isHealthy("redis")]);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.HealthController = HealthController;
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, common_1.Get)(),
|
|
97
|
+
(0, terminus_1.HealthCheck)(),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", []),
|
|
100
|
+
__metadata("design:returntype", Promise)
|
|
101
|
+
], HealthController.prototype, "check", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, common_1.Get)("live"),
|
|
104
|
+
(0, terminus_1.HealthCheck)(),
|
|
105
|
+
__metadata("design:type", Function),
|
|
106
|
+
__metadata("design:paramtypes", []),
|
|
107
|
+
__metadata("design:returntype", Promise)
|
|
108
|
+
], HealthController.prototype, "liveness", null);
|
|
109
|
+
__decorate([
|
|
110
|
+
(0, common_1.Get)("ready"),
|
|
111
|
+
(0, terminus_1.HealthCheck)(),
|
|
112
|
+
__metadata("design:type", Function),
|
|
113
|
+
__metadata("design:paramtypes", []),
|
|
114
|
+
__metadata("design:returntype", Promise)
|
|
115
|
+
], HealthController.prototype, "readiness", null);
|
|
116
|
+
exports.HealthController = HealthController = __decorate([
|
|
117
|
+
(0, common_1.Controller)("health"),
|
|
118
|
+
(0, throttler_1.SkipThrottle)(),
|
|
119
|
+
__metadata("design:paramtypes", [terminus_1.HealthCheckService,
|
|
120
|
+
neo4j_health_1.Neo4jHealthIndicator,
|
|
121
|
+
redis_health_1.RedisHealthIndicator,
|
|
122
|
+
s3_health_1.S3HealthIndicator,
|
|
123
|
+
disk_health_1.DiskHealthIndicator])
|
|
124
|
+
], HealthController);
|
|
125
|
+
//# sourceMappingURL=health.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../../../src/core/health/controllers/health.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,iDAAiD;AACjD,+CAAsF;AACtF,6DAAkE;AAClE,6DAAkE;AAClE,uDAA4D;AAC5D,2DAAgE;AAEhE;;;;;;;;;;;GAWG;AAGI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YACU,MAA0B,EAC1B,WAAiC,EACjC,WAAiC,EACjC,QAA2B,EAC3B,UAA+B;QAJ/B,WAAM,GAAN,MAAM,CAAoB;QAC1B,gBAAW,GAAX,WAAW,CAAsB;QACjC,gBAAW,GAAX,WAAW,CAAsB;QACjC,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,eAAU,GAAV,UAAU,CAAqB;IACtC,CAAC;IAEJ;;;;;;;;;OASG;IAGG,AAAN,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACvB,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC;YACzC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC;YACzC,GA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|
|
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.HealthModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const terminus_1 = require("@nestjs/terminus");
|
|
12
|
+
const health_controller_1 = require("./controllers/health.controller");
|
|
13
|
+
const neo4j_health_1 = require("./indicators/neo4j.health");
|
|
14
|
+
const redis_health_1 = require("./indicators/redis.health");
|
|
15
|
+
const s3_health_1 = require("./indicators/s3.health");
|
|
16
|
+
const disk_health_1 = require("./indicators/disk.health");
|
|
17
|
+
let HealthModule = class HealthModule {
|
|
18
|
+
};
|
|
19
|
+
exports.HealthModule = HealthModule;
|
|
20
|
+
exports.HealthModule = HealthModule = __decorate([
|
|
21
|
+
(0, common_1.Module)({
|
|
22
|
+
imports: [terminus_1.TerminusModule],
|
|
23
|
+
controllers: [health_controller_1.HealthController],
|
|
24
|
+
providers: [neo4j_health_1.Neo4jHealthIndicator, redis_health_1.RedisHealthIndicator, s3_health_1.S3HealthIndicator, disk_health_1.DiskHealthIndicator],
|
|
25
|
+
exports: [neo4j_health_1.Neo4jHealthIndicator, redis_health_1.RedisHealthIndicator, s3_health_1.S3HealthIndicator, disk_health_1.DiskHealthIndicator],
|
|
26
|
+
})
|
|
27
|
+
], HealthModule);
|
|
28
|
+
//# sourceMappingURL=health.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.module.js","sourceRoot":"","sources":["../../../src/core/health/health.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAAkD;AAClD,uEAAmE;AACnE,4DAAiE;AACjE,4DAAiE;AACjE,sDAA2D;AAC3D,0DAA+D;AAQxD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IANxB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,yBAAc,CAAC;QACzB,WAAW,EAAE,CAAC,oCAAgB,CAAC;QAC/B,SAAS,EAAE,CAAC,mCAAoB,EAAE,mCAAoB,EAAE,6BAAiB,EAAE,iCAAmB,CAAC;QAC/F,OAAO,EAAE,CAAC,mCAAoB,EAAE,mCAAoB,EAAE,6BAAiB,EAAE,iCAAmB,CAAC;KAC9F,CAAC;GACW,YAAY,CAAG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./controllers/health.controller";
|
|
2
|
+
export * from "./indicators/neo4j.health";
|
|
3
|
+
export * from "./indicators/redis.health";
|
|
4
|
+
export * from "./indicators/s3.health";
|
|
5
|
+
export * from "./indicators/disk.health";
|
|
6
|
+
export * from "./health.module";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/health/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./controllers/health.controller"), exports);
|
|
18
|
+
__exportStar(require("./indicators/neo4j.health"), exports);
|
|
19
|
+
__exportStar(require("./indicators/redis.health"), exports);
|
|
20
|
+
__exportStar(require("./indicators/s3.health"), exports);
|
|
21
|
+
__exportStar(require("./indicators/disk.health"), exports);
|
|
22
|
+
__exportStar(require("./health.module"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/health/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAgD;AAChD,4DAA0C;AAC1C,4DAA0C;AAC1C,yDAAuC;AACvC,2DAAyC;AACzC,kDAAgC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HealthIndicator, HealthIndicatorResult } from "@nestjs/terminus";
|
|
2
|
+
export declare class DiskHealthIndicator extends HealthIndicator {
|
|
3
|
+
private readonly MIN_FREE_BYTES;
|
|
4
|
+
private readonly MIN_FREE_PERCENTAGE;
|
|
5
|
+
isHealthy(key: string): Promise<HealthIndicatorResult>;
|
|
6
|
+
private getDiskStats;
|
|
7
|
+
private formatBytes;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=disk.health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disk.health.d.ts","sourceRoot":"","sources":["../../../../src/core/health/indicators/disk.health.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAoB,MAAM,kBAAkB,CAAC;AAW5F,qBACa,mBAAoB,SAAQ,eAAe;IAEtD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAsB;IACrD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAM;IAEpC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;YA2C9C,YAAY;IA4C1B,OAAO,CAAC,WAAW;CAYpB"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.DiskHealthIndicator = void 0;
|
|
43
|
+
const common_1 = require("@nestjs/common");
|
|
44
|
+
const terminus_1 = require("@nestjs/terminus");
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const os = __importStar(require("os"));
|
|
47
|
+
let DiskHealthIndicator = class DiskHealthIndicator extends terminus_1.HealthIndicator {
|
|
48
|
+
constructor() {
|
|
49
|
+
super(...arguments);
|
|
50
|
+
// Minimum free space threshold: 1GB or 10% of total, whichever is smaller
|
|
51
|
+
this.MIN_FREE_BYTES = 1024 * 1024 * 1024; // 1GB
|
|
52
|
+
this.MIN_FREE_PERCENTAGE = 10; // 10%
|
|
53
|
+
}
|
|
54
|
+
async isHealthy(key) {
|
|
55
|
+
try {
|
|
56
|
+
const stats = await this.getDiskStats();
|
|
57
|
+
const minRequiredByPercentage = (stats.total * this.MIN_FREE_PERCENTAGE) / 100;
|
|
58
|
+
const threshold = Math.min(this.MIN_FREE_BYTES, minRequiredByPercentage);
|
|
59
|
+
const isHealthy = stats.free >= threshold;
|
|
60
|
+
if (!isHealthy) {
|
|
61
|
+
throw new terminus_1.HealthCheckError("Disk space critically low", this.getStatus(key, false, {
|
|
62
|
+
message: `Low disk space: ${this.formatBytes(stats.free)} free (${(100 - stats.usedPercentage).toFixed(1)}%)`,
|
|
63
|
+
total: this.formatBytes(stats.total),
|
|
64
|
+
free: this.formatBytes(stats.free),
|
|
65
|
+
used: this.formatBytes(stats.used),
|
|
66
|
+
usedPercentage: `${stats.usedPercentage.toFixed(1)}%`,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
return this.getStatus(key, true, {
|
|
70
|
+
message: "Disk space healthy",
|
|
71
|
+
total: this.formatBytes(stats.total),
|
|
72
|
+
free: this.formatBytes(stats.free),
|
|
73
|
+
used: this.formatBytes(stats.used),
|
|
74
|
+
usedPercentage: `${stats.usedPercentage.toFixed(1)}%`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof terminus_1.HealthCheckError) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
82
|
+
throw new terminus_1.HealthCheckError("Disk health check failed", this.getStatus(key, false, {
|
|
83
|
+
message: errorMessage,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async getDiskStats() {
|
|
88
|
+
// Get the root path based on OS
|
|
89
|
+
const checkPath = os.platform() === "win32" ? "C:\\" : "/";
|
|
90
|
+
return new Promise((resolve) => {
|
|
91
|
+
// Use statvfs-like approach for Unix systems
|
|
92
|
+
if (os.platform() !== "win32") {
|
|
93
|
+
try {
|
|
94
|
+
const stats = fs.statfsSync(checkPath);
|
|
95
|
+
const total = stats.bsize * stats.blocks;
|
|
96
|
+
const free = stats.bsize * stats.bfree;
|
|
97
|
+
const used = total - free;
|
|
98
|
+
resolve({
|
|
99
|
+
total,
|
|
100
|
+
free,
|
|
101
|
+
used,
|
|
102
|
+
usedPercentage: (used / total) * 100,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// Fallback: use os module for basic memory info as indicator
|
|
107
|
+
const totalMem = os.totalmem();
|
|
108
|
+
const freeMem = os.freemem();
|
|
109
|
+
resolve({
|
|
110
|
+
total: totalMem,
|
|
111
|
+
free: freeMem,
|
|
112
|
+
used: totalMem - freeMem,
|
|
113
|
+
usedPercentage: ((totalMem - freeMem) / totalMem) * 100,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// For Windows, use a different approach or return system memory
|
|
119
|
+
const totalMem = os.totalmem();
|
|
120
|
+
const freeMem = os.freemem();
|
|
121
|
+
resolve({
|
|
122
|
+
total: totalMem,
|
|
123
|
+
free: freeMem,
|
|
124
|
+
used: totalMem - freeMem,
|
|
125
|
+
usedPercentage: ((totalMem - freeMem) / totalMem) * 100,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
formatBytes(bytes) {
|
|
131
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
132
|
+
let unitIndex = 0;
|
|
133
|
+
let size = bytes;
|
|
134
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
135
|
+
size /= 1024;
|
|
136
|
+
unitIndex++;
|
|
137
|
+
}
|
|
138
|
+
return `${size.toFixed(2)} ${units[unitIndex]}`;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
exports.DiskHealthIndicator = DiskHealthIndicator;
|
|
142
|
+
exports.DiskHealthIndicator = DiskHealthIndicator = __decorate([
|
|
143
|
+
(0, common_1.Injectable)()
|
|
144
|
+
], DiskHealthIndicator);
|
|
145
|
+
//# sourceMappingURL=disk.health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disk.health.js","sourceRoot":"","sources":["../../../../src/core/health/indicators/disk.health.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA4F;AAC5F,uCAAyB;AACzB,uCAAyB;AAUlB,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,0BAAe;IAAjD;;QACL,0EAA0E;QACzD,mBAAc,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM;QAC3C,wBAAmB,GAAG,EAAE,CAAC,CAAC,MAAM;IAqGnD,CAAC;IAnGC,KAAK,CAAC,SAAS,CAAC,GAAW;QACzB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YAExC,MAAM,uBAAuB,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,GAAG,CAAC;YAC/E,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,uBAAuB,CAAC,CAAC;YAEzE,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,IAAI,SAAS,CAAC;YAE1C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,MAAM,IAAI,2BAAgB,CACxB,2BAA2B,EAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE;oBACzB,OAAO,EAAE,mBAAmB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;oBAC7G,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC;oBACpC,IAAI,EAAE,IAA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AAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,IAAI,GAAG,KAAK,CAAC;QAEjB,OAAO,IAAI,IAAI,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpD,IAAI,IAAI,IAAI,CAAC;YACb,SAAS,EAAE,CAAC;QACd,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;IAClD,CAAC;CACF,CAAA;AAxGY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;GACA,mBAAmB,CAwG/B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HealthIndicator, HealthIndicatorResult } from "@nestjs/terminus";
|
|
2
|
+
import { Neo4jService } from "../../neo4j/services/neo4j.service";
|
|
3
|
+
export declare class Neo4jHealthIndicator extends HealthIndicator {
|
|
4
|
+
private readonly neo4jService;
|
|
5
|
+
private readonly TIMEOUT_MS;
|
|
6
|
+
constructor(neo4jService: Neo4jService);
|
|
7
|
+
isHealthy(key: string): Promise<HealthIndicatorResult>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=neo4j.health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neo4j.health.d.ts","sourceRoot":"","sources":["../../../../src/core/health/indicators/neo4j.health.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAoB,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,qBACa,oBAAqB,SAAQ,eAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,YAAY;IAFzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;gBAEN,YAAY,EAAE,YAAY;IAIjD,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CA0B7D"}
|