@tsed/terminus 7.0.0-alpha.2 → 7.0.0-beta.11
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/lib/cjs/TerminusModule.js +78 -0
- package/lib/cjs/TerminusModule.js.map +1 -0
- package/lib/cjs/decorators/health.js +34 -0
- package/lib/cjs/decorators/health.js.map +1 -0
- package/lib/cjs/decorators/shutdown.js +54 -0
- package/lib/cjs/decorators/shutdown.js.map +1 -0
- package/lib/cjs/index.js +12 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/TerminusSettings.js +3 -0
- package/lib/cjs/interfaces/TerminusSettings.js.map +1 -0
- package/lib/cjs/interfaces/interfaces.js +3 -0
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/esm/TerminusModule.js +75 -0
- package/lib/esm/TerminusModule.js.map +1 -0
- package/lib/esm/decorators/health.js +30 -0
- package/lib/esm/decorators/health.js.map +1 -0
- package/lib/esm/decorators/shutdown.js +47 -0
- package/lib/esm/decorators/shutdown.js.map +1 -0
- package/lib/esm/index.js +9 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/TerminusSettings.js +2 -0
- package/lib/esm/interfaces/TerminusSettings.js.map +1 -0
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/{TerminusModule.d.ts → types/TerminusModule.d.ts} +1 -1
- package/lib/{decorators → types/decorators}/health.d.ts +0 -0
- package/lib/{decorators → types/decorators}/shutdown.d.ts +0 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/{interfaces → types/interfaces}/TerminusSettings.d.ts +0 -0
- package/lib/{interfaces/index.d.ts → types/interfaces/interfaces.d.ts} +0 -1
- package/package.json +32 -22
- package/readme.md +26 -24
- package/tsconfig.compile.esm.json +12 -0
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -176
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -174
- package/lib/index.modern.js.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TerminusModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const terminus_1 = require("@godaddy/terminus");
|
|
6
|
+
const di_1 = require("@tsed/di");
|
|
7
|
+
const https_1 = tslib_1.__importDefault(require("https"));
|
|
8
|
+
const http_1 = tslib_1.__importDefault(require("http"));
|
|
9
|
+
let TerminusModule = class TerminusModule {
|
|
10
|
+
$onInit() {
|
|
11
|
+
this.mount();
|
|
12
|
+
}
|
|
13
|
+
mount() {
|
|
14
|
+
const { terminus } = this.configuration;
|
|
15
|
+
const terminusConfig = {
|
|
16
|
+
logger: this.injector.logger,
|
|
17
|
+
healthChecks: this.getHealths(),
|
|
18
|
+
onSignal: this.execShutdown("onSignal"),
|
|
19
|
+
onShutdown: this.execShutdown("onShutdown"),
|
|
20
|
+
beforeShutdown: this.execShutdown("beforeShutdown"),
|
|
21
|
+
onSendFailureDuringShutdown: this.execShutdown("onSendFailureDuringShutdown"),
|
|
22
|
+
...terminus
|
|
23
|
+
};
|
|
24
|
+
if (this.httpServer) {
|
|
25
|
+
(0, terminus_1.createTerminus)(this.httpServer, terminusConfig);
|
|
26
|
+
}
|
|
27
|
+
if (this.httpsServer) {
|
|
28
|
+
(0, terminus_1.createTerminus)(this.httpsServer, terminusConfig);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getProviders(name) {
|
|
32
|
+
return this.injector.getProviders().filter((provider) => {
|
|
33
|
+
return provider.store.get(name);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getStore(name) {
|
|
37
|
+
return this.injector
|
|
38
|
+
.getProviders()
|
|
39
|
+
.map((provider) => provider.store.get(name))
|
|
40
|
+
.filter((x) => !!x)
|
|
41
|
+
.flat();
|
|
42
|
+
}
|
|
43
|
+
getHealths() {
|
|
44
|
+
const healths = {};
|
|
45
|
+
this.getProviders("terminus").forEach((provider) => {
|
|
46
|
+
Object.keys(provider.store.get("terminus")).forEach((name) => {
|
|
47
|
+
healths[`${provider.path}${name}`] = provider.store.get("terminus")[name];
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return healths;
|
|
51
|
+
}
|
|
52
|
+
execShutdown(name) {
|
|
53
|
+
return async () => {
|
|
54
|
+
this.getStore(name).forEach((func) => func());
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
tslib_1.__decorate([
|
|
59
|
+
(0, di_1.Configuration)(),
|
|
60
|
+
tslib_1.__metadata("design:type", Object)
|
|
61
|
+
], TerminusModule.prototype, "configuration", void 0);
|
|
62
|
+
tslib_1.__decorate([
|
|
63
|
+
(0, di_1.Inject)(),
|
|
64
|
+
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
65
|
+
], TerminusModule.prototype, "injector", void 0);
|
|
66
|
+
tslib_1.__decorate([
|
|
67
|
+
(0, di_1.Inject)(http_1.default.Server),
|
|
68
|
+
tslib_1.__metadata("design:type", Object)
|
|
69
|
+
], TerminusModule.prototype, "httpServer", void 0);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, di_1.Inject)(https_1.default.Server),
|
|
72
|
+
tslib_1.__metadata("design:type", Object)
|
|
73
|
+
], TerminusModule.prototype, "httpsServer", void 0);
|
|
74
|
+
TerminusModule = tslib_1.__decorate([
|
|
75
|
+
(0, di_1.Module)()
|
|
76
|
+
], TerminusModule);
|
|
77
|
+
exports.TerminusModule = TerminusModule;
|
|
78
|
+
//# sourceMappingURL=TerminusModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerminusModule.js","sourceRoot":"","sources":["../../src/TerminusModule.ts"],"names":[],"mappings":";;;;AAAA,gDAAiD;AACjD,iCAAgF;AAChF,0DAA0B;AAC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C,CAAC,CAAC,CAAC,CAAC;aAClB,IAAI,EAAE,CAAC;IACZ,CAAC;IAEO,UAAU;QAChB,MAAM,OAAO,GAAsC,EAAE,CAAC;QAEtD,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC3D,OAAO,CAAC,GAAG,QAAQ,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;YAC5E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,YAAY,CAAC,IAAY;QAC/B,OAAO,KAAK,IAAI,EAAE;YAChB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAChD,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AAnEC;IADC,IAAA,kBAAa,GAAE;;qDACqB;AAGrC;IADC,IAAA,WAAM,GAAE;sCACS,oBAAe;gDAAC;AAGlC;IADC,IAAA,WAAM,EAAC,cAAI,CAAC,MAAM,CAAC;;kDACmB;AAGvC;IADC,IAAA,WAAM,EAAC,eAAK,CAAC,MAAM,CAAC;;mDACoB;AAX9B,cAAc;IAD1B,IAAA,WAAM,GAAE;GACI,cAAc,CAqE1B;AArEY,wCAAc","sourcesContent":["import {createTerminus} from \"@godaddy/terminus\";\nimport {Configuration, Inject, InjectorService, Module, OnInit} from \"@tsed/di\";\nimport Https from \"https\";\nimport Http from \"http\";\n\n@Module()\nexport class TerminusModule implements OnInit {\n @Configuration()\n private configuration: Configuration;\n\n @Inject()\n private injector: InjectorService;\n\n @Inject(Http.Server)\n private httpServer: Http.Server | null;\n\n @Inject(Https.Server)\n private httpsServer: Https.Server | null;\n\n public $onInit() {\n this.mount();\n }\n\n private mount() {\n const {terminus} = this.configuration;\n const terminusConfig = {\n logger: this.injector.logger as any,\n healthChecks: this.getHealths(),\n onSignal: this.execShutdown(\"onSignal\"),\n onShutdown: this.execShutdown(\"onShutdown\"),\n beforeShutdown: this.execShutdown(\"beforeShutdown\"),\n onSendFailureDuringShutdown: this.execShutdown(\"onSendFailureDuringShutdown\"),\n ...terminus\n };\n\n if (this.httpServer) {\n createTerminus(this.httpServer, terminusConfig);\n }\n\n if (this.httpsServer) {\n createTerminus(this.httpsServer, terminusConfig);\n }\n }\n\n private getProviders(name: string) {\n return this.injector.getProviders().filter((provider) => {\n return provider.store.get(name);\n });\n }\n\n private getStore(name: string) {\n return this.injector\n .getProviders()\n .map((provider) => provider.store.get(name))\n .filter((x) => !!x)\n .flat();\n }\n\n private getHealths() {\n const healths: {[k: string]: () => Promise<any>} = {};\n\n this.getProviders(\"terminus\").forEach((provider) => {\n Object.keys(provider.store.get(\"terminus\")).forEach((name) => {\n healths[`${provider.path}${name}`] = provider.store.get(\"terminus\")[name];\n });\n });\n\n return healths;\n }\n\n private execShutdown(name: string) {\n return async () => {\n this.getStore(name).forEach((func) => func());\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Health = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
/**
|
|
6
|
+
* Create a readiness / liveness checks.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Health } from "@tsed/terminus";
|
|
10
|
+
*
|
|
11
|
+
* @Controller("/mongo")
|
|
12
|
+
* class MongoCtrl {
|
|
13
|
+
* @Health("/health")
|
|
14
|
+
* health() {
|
|
15
|
+
* // Here check the mongo health
|
|
16
|
+
* return Promise.resolve();
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* @param name
|
|
21
|
+
* @decorator
|
|
22
|
+
* @terminus
|
|
23
|
+
*/
|
|
24
|
+
function Health(name) {
|
|
25
|
+
return (target, propertyKey, descriptor) => {
|
|
26
|
+
if (descriptor.value) {
|
|
27
|
+
core_1.Store.from(target).merge("terminus", {
|
|
28
|
+
[name]: descriptor.value
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.Health = Health;
|
|
34
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../../src/decorators/health.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAEjC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,MAAM,CAAC,IAAY;IACjC,OAAO,CAAW,MAAc,EAAE,WAAmB,EAAE,UAA6C,EAAE,EAAE;QACtG,IAAI,UAAU,CAAC,KAAK,EAAE;YACpB,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;gBACnC,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK;aACzB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC;AARD,wBAQC","sourcesContent":["import {Store} from \"@tsed/core\";\n\n/**\n * Create a readiness / liveness checks.\n *\n * ```ts\n * import { Health } from \"@tsed/terminus\";\n *\n * @Controller(\"/mongo\")\n * class MongoCtrl {\n * @Health(\"/health\")\n * health() {\n * // Here check the mongo health\n * return Promise.resolve();\n * }\n * }\n *\n * @param name\n * @decorator\n * @terminus\n */\nexport function Health(name: string): MethodDecorator {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n Store.from(target).merge(\"terminus\", {\n [name]: descriptor.value\n });\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnSendFailureDuringShutdown = exports.OnShutdown = exports.OnSignal = exports.BeforeShutdown = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
function register(name) {
|
|
6
|
+
return (target, propertyKey, descriptor) => {
|
|
7
|
+
if (descriptor.value) {
|
|
8
|
+
const store = core_1.Store.from(target);
|
|
9
|
+
const values = store.get(name) || [];
|
|
10
|
+
store.merge(name, [...values, descriptor.value]);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Listen the `beforeShutdown` terminus event.
|
|
16
|
+
*
|
|
17
|
+
* @decorator
|
|
18
|
+
* @terminus
|
|
19
|
+
*/
|
|
20
|
+
function BeforeShutdown() {
|
|
21
|
+
return register("beforeShutdown");
|
|
22
|
+
}
|
|
23
|
+
exports.BeforeShutdown = BeforeShutdown;
|
|
24
|
+
/**
|
|
25
|
+
* Listen the `onSignal` terminus event.
|
|
26
|
+
*
|
|
27
|
+
* @decorator
|
|
28
|
+
* @terminus
|
|
29
|
+
*/
|
|
30
|
+
function OnSignal() {
|
|
31
|
+
return register("onSignal");
|
|
32
|
+
}
|
|
33
|
+
exports.OnSignal = OnSignal;
|
|
34
|
+
/**
|
|
35
|
+
* Listen the `onShutdown` terminus event.
|
|
36
|
+
*
|
|
37
|
+
* @decorator
|
|
38
|
+
* @terminus
|
|
39
|
+
*/
|
|
40
|
+
function OnShutdown() {
|
|
41
|
+
return register("onShutdown");
|
|
42
|
+
}
|
|
43
|
+
exports.OnShutdown = OnShutdown;
|
|
44
|
+
/**
|
|
45
|
+
* Listen the `onSendFailureDuringShutdown` terminus event.
|
|
46
|
+
*
|
|
47
|
+
* @decorator
|
|
48
|
+
* @terminus
|
|
49
|
+
*/
|
|
50
|
+
function OnSendFailureDuringShutdown() {
|
|
51
|
+
return register("onSendFailureDuringShutdown");
|
|
52
|
+
}
|
|
53
|
+
exports.OnSendFailureDuringShutdown = OnSendFailureDuringShutdown;
|
|
54
|
+
//# sourceMappingURL=shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../../src/decorators/shutdown.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAEjC,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,CAAW,MAAc,EAAE,WAAmB,EAAE,UAA6C,EAAE,EAAE;QACtG,IAAI,UAAU,CAAC,KAAK,EAAE;YACpB,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAErC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;SAClD;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc;IAC5B,OAAO,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACpC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ;IACtB,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC;AAFD,4BAEC;AAED;;;;;GAKG;AACH,SAAgB,UAAU;IACxB,OAAO,QAAQ,CAAC,YAAY,CAAC,CAAC;AAChC,CAAC;AAFD,gCAEC;AAED;;;;;GAKG;AACH,SAAgB,2BAA2B;IACzC,OAAO,QAAQ,CAAC,6BAA6B,CAAC,CAAC;AACjD,CAAC;AAFD,kEAEC","sourcesContent":["import {Store} from \"@tsed/core\";\n\nfunction register(name: string) {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n const store = Store.from(target);\n const values = store.get(name) || [];\n\n store.merge(name, [...values, descriptor.value]);\n }\n };\n}\n\n/**\n * Listen the `beforeShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function BeforeShutdown(): MethodDecorator {\n return register(\"beforeShutdown\");\n}\n\n/**\n * Listen the `onSignal` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSignal(): MethodDecorator {\n return register(\"onSignal\");\n}\n\n/**\n * Listen the `onShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnShutdown(): MethodDecorator {\n return register(\"onShutdown\");\n}\n\n/**\n * Listen the `onSendFailureDuringShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSendFailureDuringShutdown(): MethodDecorator {\n return register(\"onSendFailureDuringShutdown\");\n}\n"]}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
tslib_1.__exportStar(require("./TerminusModule"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./decorators/health"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/shutdown"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./interfaces/TerminusSettings"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2DAAiC;AACjC,8DAAoC;AACpC,gEAAsC;AACtC,wEAA8C;AAC9C,kEAAwC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./TerminusModule\";\nexport * from \"./decorators/health\";\nexport * from \"./decorators/shutdown\";\nexport * from \"./interfaces/TerminusSettings\";\nexport * from \"./interfaces/interfaces\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerminusSettings.js","sourceRoot":"","sources":["../../../src/interfaces/TerminusSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {TerminusOptions} from \"@godaddy/terminus\";\n\nexport type TerminusSettings = Omit<\n TerminusOptions,\n \"healthChecks\" | \"onSignal\" | \"onSendFailureDuringShutdown\" | \"onShutdown\" | \"beforeShutdown\" | \"onSigterm\"\n>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {TerminusSettings} from \"./TerminusSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n terminus: TerminusSettings;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { createTerminus } from "@godaddy/terminus";
|
|
3
|
+
import { Configuration, Inject, InjectorService, Module } from "@tsed/di";
|
|
4
|
+
import Https from "https";
|
|
5
|
+
import Http from "http";
|
|
6
|
+
let TerminusModule = class TerminusModule {
|
|
7
|
+
$onInit() {
|
|
8
|
+
this.mount();
|
|
9
|
+
}
|
|
10
|
+
mount() {
|
|
11
|
+
const { terminus } = this.configuration;
|
|
12
|
+
const terminusConfig = {
|
|
13
|
+
logger: this.injector.logger,
|
|
14
|
+
healthChecks: this.getHealths(),
|
|
15
|
+
onSignal: this.execShutdown("onSignal"),
|
|
16
|
+
onShutdown: this.execShutdown("onShutdown"),
|
|
17
|
+
beforeShutdown: this.execShutdown("beforeShutdown"),
|
|
18
|
+
onSendFailureDuringShutdown: this.execShutdown("onSendFailureDuringShutdown"),
|
|
19
|
+
...terminus
|
|
20
|
+
};
|
|
21
|
+
if (this.httpServer) {
|
|
22
|
+
createTerminus(this.httpServer, terminusConfig);
|
|
23
|
+
}
|
|
24
|
+
if (this.httpsServer) {
|
|
25
|
+
createTerminus(this.httpsServer, terminusConfig);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getProviders(name) {
|
|
29
|
+
return this.injector.getProviders().filter((provider) => {
|
|
30
|
+
return provider.store.get(name);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getStore(name) {
|
|
34
|
+
return this.injector
|
|
35
|
+
.getProviders()
|
|
36
|
+
.map((provider) => provider.store.get(name))
|
|
37
|
+
.filter((x) => !!x)
|
|
38
|
+
.flat();
|
|
39
|
+
}
|
|
40
|
+
getHealths() {
|
|
41
|
+
const healths = {};
|
|
42
|
+
this.getProviders("terminus").forEach((provider) => {
|
|
43
|
+
Object.keys(provider.store.get("terminus")).forEach((name) => {
|
|
44
|
+
healths[`${provider.path}${name}`] = provider.store.get("terminus")[name];
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return healths;
|
|
48
|
+
}
|
|
49
|
+
execShutdown(name) {
|
|
50
|
+
return async () => {
|
|
51
|
+
this.getStore(name).forEach((func) => func());
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__decorate([
|
|
56
|
+
Configuration(),
|
|
57
|
+
__metadata("design:type", Object)
|
|
58
|
+
], TerminusModule.prototype, "configuration", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
Inject(),
|
|
61
|
+
__metadata("design:type", InjectorService)
|
|
62
|
+
], TerminusModule.prototype, "injector", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
Inject(Http.Server),
|
|
65
|
+
__metadata("design:type", Object)
|
|
66
|
+
], TerminusModule.prototype, "httpServer", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
Inject(Https.Server),
|
|
69
|
+
__metadata("design:type", Object)
|
|
70
|
+
], TerminusModule.prototype, "httpsServer", void 0);
|
|
71
|
+
TerminusModule = __decorate([
|
|
72
|
+
Module()
|
|
73
|
+
], TerminusModule);
|
|
74
|
+
export { TerminusModule };
|
|
75
|
+
//# sourceMappingURL=TerminusModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerminusModule.js","sourceRoot":"","sources":["../../src/TerminusModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAS,MAAM,UAAU,CAAC;AAChF,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,IAAa,cAAc,GAA3B,MAAa,cAAc;IAalB,OAAO;QACZ,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAEO,KAAK;QACX,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC,aAAa,CAAC;QACtC,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAa;YACnC,YAAY,EAAE,IAAI,CAAC,UAAU,EAAE;YAC/B,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;YACvC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YAC3C,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC;YACnD,2BAA2B,EAAE,IAAI,CAAC,YAAY,CAAC,6BAA6B,CAAC;YAC7E,GAAG,QAAQ;SACZ,CAAC;QAEF,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;SACjD;QAED,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,YAAY,CAAC,IAAY;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAA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,CAAC,IAAI,CAAC,MAAM,CAAC;;kDACmB;AAGvC;IADC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;;mDACoB;AAX9B,cAAc;IAD1B,MAAM,EAAE;GACI,cAAc,CAqE1B;SArEY,cAAc","sourcesContent":["import {createTerminus} from \"@godaddy/terminus\";\nimport {Configuration, Inject, InjectorService, Module, OnInit} from \"@tsed/di\";\nimport Https from \"https\";\nimport Http from \"http\";\n\n@Module()\nexport class TerminusModule implements OnInit {\n @Configuration()\n private configuration: Configuration;\n\n @Inject()\n private injector: InjectorService;\n\n @Inject(Http.Server)\n private httpServer: Http.Server | null;\n\n @Inject(Https.Server)\n private httpsServer: Https.Server | null;\n\n public $onInit() {\n this.mount();\n }\n\n private mount() {\n const {terminus} = this.configuration;\n const terminusConfig = {\n logger: this.injector.logger as any,\n healthChecks: this.getHealths(),\n onSignal: this.execShutdown(\"onSignal\"),\n onShutdown: this.execShutdown(\"onShutdown\"),\n beforeShutdown: this.execShutdown(\"beforeShutdown\"),\n onSendFailureDuringShutdown: this.execShutdown(\"onSendFailureDuringShutdown\"),\n ...terminus\n };\n\n if (this.httpServer) {\n createTerminus(this.httpServer, terminusConfig);\n }\n\n if (this.httpsServer) {\n createTerminus(this.httpsServer, terminusConfig);\n }\n }\n\n private getProviders(name: string) {\n return this.injector.getProviders().filter((provider) => {\n return provider.store.get(name);\n });\n }\n\n private getStore(name: string) {\n return this.injector\n .getProviders()\n .map((provider) => provider.store.get(name))\n .filter((x) => !!x)\n .flat();\n }\n\n private getHealths() {\n const healths: {[k: string]: () => Promise<any>} = {};\n\n this.getProviders(\"terminus\").forEach((provider) => {\n Object.keys(provider.store.get(\"terminus\")).forEach((name) => {\n healths[`${provider.path}${name}`] = provider.store.get(\"terminus\")[name];\n });\n });\n\n return healths;\n }\n\n private execShutdown(name: string) {\n return async () => {\n this.getStore(name).forEach((func) => func());\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* Create a readiness / liveness checks.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Health } from "@tsed/terminus";
|
|
7
|
+
*
|
|
8
|
+
* @Controller("/mongo")
|
|
9
|
+
* class MongoCtrl {
|
|
10
|
+
* @Health("/health")
|
|
11
|
+
* health() {
|
|
12
|
+
* // Here check the mongo health
|
|
13
|
+
* return Promise.resolve();
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* @param name
|
|
18
|
+
* @decorator
|
|
19
|
+
* @terminus
|
|
20
|
+
*/
|
|
21
|
+
export function Health(name) {
|
|
22
|
+
return (target, propertyKey, descriptor) => {
|
|
23
|
+
if (descriptor.value) {
|
|
24
|
+
Store.from(target).merge("terminus", {
|
|
25
|
+
[name]: descriptor.value
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../../src/decorators/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAEjC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,OAAO,CAAW,MAAc,EAAE,WAAmB,EAAE,UAA6C,EAAE,EAAE;QACtG,IAAI,UAAU,CAAC,KAAK,EAAE;YACpB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;gBACnC,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK;aACzB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\n\n/**\n * Create a readiness / liveness checks.\n *\n * ```ts\n * import { Health } from \"@tsed/terminus\";\n *\n * @Controller(\"/mongo\")\n * class MongoCtrl {\n * @Health(\"/health\")\n * health() {\n * // Here check the mongo health\n * return Promise.resolve();\n * }\n * }\n *\n * @param name\n * @decorator\n * @terminus\n */\nexport function Health(name: string): MethodDecorator {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n Store.from(target).merge(\"terminus\", {\n [name]: descriptor.value\n });\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
function register(name) {
|
|
3
|
+
return (target, propertyKey, descriptor) => {
|
|
4
|
+
if (descriptor.value) {
|
|
5
|
+
const store = Store.from(target);
|
|
6
|
+
const values = store.get(name) || [];
|
|
7
|
+
store.merge(name, [...values, descriptor.value]);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Listen the `beforeShutdown` terminus event.
|
|
13
|
+
*
|
|
14
|
+
* @decorator
|
|
15
|
+
* @terminus
|
|
16
|
+
*/
|
|
17
|
+
export function BeforeShutdown() {
|
|
18
|
+
return register("beforeShutdown");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Listen the `onSignal` terminus event.
|
|
22
|
+
*
|
|
23
|
+
* @decorator
|
|
24
|
+
* @terminus
|
|
25
|
+
*/
|
|
26
|
+
export function OnSignal() {
|
|
27
|
+
return register("onSignal");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Listen the `onShutdown` terminus event.
|
|
31
|
+
*
|
|
32
|
+
* @decorator
|
|
33
|
+
* @terminus
|
|
34
|
+
*/
|
|
35
|
+
export function OnShutdown() {
|
|
36
|
+
return register("onShutdown");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Listen the `onSendFailureDuringShutdown` terminus event.
|
|
40
|
+
*
|
|
41
|
+
* @decorator
|
|
42
|
+
* @terminus
|
|
43
|
+
*/
|
|
44
|
+
export function OnSendFailureDuringShutdown() {
|
|
45
|
+
return register("onSendFailureDuringShutdown");
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../../src/decorators/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAEjC,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,CAAW,MAAc,EAAE,WAAmB,EAAE,UAA6C,EAAE,EAAE;QACtG,IAAI,UAAU,CAAC,KAAK,EAAE;YACpB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAErC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;SAClD;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,QAAQ,CAAC,YAAY,CAAC,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B;IACzC,OAAO,QAAQ,CAAC,6BAA6B,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\n\nfunction register(name: string) {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n const store = Store.from(target);\n const values = store.get(name) || [];\n\n store.merge(name, [...values, descriptor.value]);\n }\n };\n}\n\n/**\n * Listen the `beforeShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function BeforeShutdown(): MethodDecorator {\n return register(\"beforeShutdown\");\n}\n\n/**\n * Listen the `onSignal` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSignal(): MethodDecorator {\n return register(\"onSignal\");\n}\n\n/**\n * Listen the `onShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnShutdown(): MethodDecorator {\n return register(\"onShutdown\");\n}\n\n/**\n * Listen the `onSendFailureDuringShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSendFailureDuringShutdown(): MethodDecorator {\n return register(\"onSendFailureDuringShutdown\");\n}\n"]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./TerminusModule.js";
|
|
5
|
+
export * from "./decorators/health.js";
|
|
6
|
+
export * from "./decorators/shutdown.js";
|
|
7
|
+
export * from "./interfaces/TerminusSettings.js";
|
|
8
|
+
export * from "./interfaces/interfaces.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./TerminusModule\";\nexport * from \"./decorators/health\";\nexport * from \"./decorators/shutdown\";\nexport * from \"./interfaces/TerminusSettings\";\nexport * from \"./interfaces/interfaces\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerminusSettings.js","sourceRoot":"","sources":["../../../src/interfaces/TerminusSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {TerminusOptions} from \"@godaddy/terminus\";\n\nexport type TerminusSettings = Omit<\n TerminusOptions,\n \"healthChecks\" | \"onSignal\" | \"onSendFailureDuringShutdown\" | \"onShutdown\" | \"beforeShutdown\" | \"onSigterm\"\n>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {TerminusSettings} from \"./TerminusSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n terminus: TerminusSettings;\n }\n }\n}\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,45 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/terminus",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.11",
|
|
4
4
|
"description": "Adds graceful shutdown and Kubernetes readiness / liveness checks for any HTTP applications.",
|
|
5
5
|
"author": "Romain Lenzotti",
|
|
6
6
|
"private": false,
|
|
7
7
|
"source": "./src/index.ts",
|
|
8
|
-
"main": "./lib/index.js",
|
|
9
|
-
"
|
|
8
|
+
"main": "./lib/cjs/index.js",
|
|
9
|
+
"module": "./lib/esm/index.js",
|
|
10
|
+
"typings": "./lib/types/index.d.ts",
|
|
10
11
|
"exports": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
12
|
+
"types": "./lib/types/index.d.ts",
|
|
13
|
+
"import": "./lib/esm/index.js",
|
|
14
|
+
"require": "./lib/cjs/index.js",
|
|
15
|
+
"default": "./lib/esm/index.js"
|
|
13
16
|
},
|
|
14
17
|
"scripts": {
|
|
15
|
-
"build": "
|
|
18
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
19
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
20
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
21
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
16
22
|
"start": "ts-node -r tsconfig-paths/register test/app/index.ts"
|
|
17
23
|
},
|
|
18
24
|
"dependencies": {
|
|
19
25
|
"@godaddy/terminus": "^4.7.1",
|
|
20
|
-
"tslib": "2.
|
|
26
|
+
"tslib": "2.3.1"
|
|
21
27
|
},
|
|
22
28
|
"devDependencies": {
|
|
23
|
-
"@tsed/
|
|
24
|
-
"@tsed/
|
|
25
|
-
"@tsed/
|
|
26
|
-
"@tsed/openspec": "7.0.0-alpha.2",
|
|
27
|
-
"@tsed/schema": "7.0.0-alpha.2"
|
|
29
|
+
"@tsed/core": "7.0.0-beta.11",
|
|
30
|
+
"@tsed/di": "7.0.0-beta.11",
|
|
31
|
+
"@tsed/schema": "7.0.0-beta.11"
|
|
28
32
|
},
|
|
29
33
|
"peerDependencies": {
|
|
30
|
-
"@tsed/
|
|
31
|
-
"@tsed/
|
|
32
|
-
"@tsed/
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
"@tsed/core": "^7.0.0-beta.11",
|
|
35
|
+
"@tsed/di": "^7.0.0-beta.11",
|
|
36
|
+
"@tsed/schema": "^7.0.0-beta.11"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@tsed/core": {
|
|
40
|
+
"optional": false
|
|
41
|
+
},
|
|
42
|
+
"@tsed/di": {
|
|
43
|
+
"optional": false
|
|
44
|
+
},
|
|
45
|
+
"@tsed/schema": {
|
|
46
|
+
"optional": false
|
|
47
|
+
}
|
|
35
48
|
},
|
|
36
49
|
"repository": "https://github.com/tsedio/tsed",
|
|
37
50
|
"bugs": {
|
|
38
51
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
39
52
|
},
|
|
40
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
41
|
-
"license": "MIT"
|
|
42
|
-
"publishConfig": {
|
|
43
|
-
"tag": "alpha"
|
|
44
|
-
}
|
|
53
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/third-parties/terminus",
|
|
54
|
+
"license": "MIT"
|
|
45
55
|
}
|
package/readme.md
CHANGED
|
@@ -43,10 +43,8 @@ Then import `@tsed/terminus` and add the following configuration in your `Server
|
|
|
43
43
|
import {Configuration} from "@tsed/common";
|
|
44
44
|
import "@tsed/terminus"; // import terminus Ts.ED module
|
|
45
45
|
import {resolve} from "path";
|
|
46
|
-
const rootDir = resolve(__dirname);
|
|
47
46
|
|
|
48
47
|
@Configuration({
|
|
49
|
-
rootDir,
|
|
50
48
|
terminus: {
|
|
51
49
|
// ... see Terminus configuration options on https://github.com/godaddy/terminus
|
|
52
50
|
}
|
|
@@ -59,27 +57,28 @@ export class Server {}
|
|
|
59
57
|
`terminus` configuration options waiting the same option description in the official Terminus documentation [here](https://github.com/godaddy/terminus).
|
|
60
58
|
The following the options are managed by the `@tsed/terminus` package:
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
- healthChecks
|
|
61
|
+
- onSignal
|
|
62
|
+
- onSendFailureDuringShutdown
|
|
63
|
+
- onShutdown
|
|
64
|
+
- beforeShutdown
|
|
65
|
+
- onSigterm
|
|
68
66
|
|
|
69
67
|
```typescript
|
|
70
68
|
export type TerminusSettings = Omit<
|
|
71
|
-
TerminusOptions,
|
|
72
|
-
"healthChecks" | "onSignal" | "onSendFailureDuringShutdown" | "onShutdown" | "beforeShutdown" | "onSigterm"
|
|
69
|
+
TerminusOptions,
|
|
70
|
+
"healthChecks" | "onSignal" | "onSendFailureDuringShutdown" | "onShutdown" | "beforeShutdown" | "onSigterm"
|
|
73
71
|
>;
|
|
74
72
|
```
|
|
75
73
|
|
|
76
74
|
## Usage
|
|
75
|
+
|
|
77
76
|
### Readiness / liveness checks
|
|
78
77
|
|
|
79
78
|
To create a readiness / liveness checks use the `@Health` decorator.
|
|
80
79
|
|
|
81
80
|
```ts
|
|
82
|
-
import {
|
|
81
|
+
import {Health} from "@tsed/terminus";
|
|
83
82
|
|
|
84
83
|
@Controller("/mongo")
|
|
85
84
|
class MongoCtrl {
|
|
@@ -91,27 +90,29 @@ class MongoCtrl {
|
|
|
91
90
|
}
|
|
92
91
|
```
|
|
93
92
|
|
|
94
|
-
You can also create an
|
|
93
|
+
You can also create an `HealthCheckError` when an error appear during your check.
|
|
95
94
|
|
|
96
95
|
```ts
|
|
97
|
-
import {
|
|
98
|
-
import {
|
|
96
|
+
import {Health} from "@tsed/terminus";
|
|
97
|
+
import {HealthCheckError} from "@godaddy/terminus";
|
|
99
98
|
|
|
100
99
|
@Controller("/redis")
|
|
101
100
|
class Redis {
|
|
102
101
|
@Health("/health")
|
|
103
102
|
health() {
|
|
104
103
|
// Here check the redis health
|
|
105
|
-
return Promise.reject(
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
return Promise.reject(
|
|
105
|
+
new HealthCheckError("failed", {
|
|
106
|
+
redis: "down"
|
|
107
|
+
})
|
|
108
|
+
);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
```
|
|
111
112
|
|
|
112
113
|
### Graceful shutdown
|
|
113
114
|
|
|
114
|
-
`@tsed/terminus` package give some decorators to handle Terminus hooks. These hooks allow you to adds graceful shutdown.
|
|
115
|
+
`@tsed/terminus` package give some decorators to handle Terminus hooks. These hooks allow you to adds graceful shutdown.
|
|
115
116
|
Here is the list of decorators:
|
|
116
117
|
|
|
117
118
|
- `BeforeShutdown`: Use this hook if you deploy your application with Kubernetes (see more details [here](https://github.com/godaddy/terminus#how-to-set-terminus-up-with-kubernetes)),
|
|
@@ -120,34 +121,36 @@ Here is the list of decorators:
|
|
|
120
121
|
- `OnSendFailureDuringShutdown`: called before sending each 503 during shutdowns.
|
|
121
122
|
|
|
122
123
|
**Example:**
|
|
124
|
+
|
|
123
125
|
```typescript
|
|
124
|
-
import {
|
|
126
|
+
import {BeforeShutdown, OnSendFailureDuringShutdown, OnShutdown, OnSignal} from "@tsed/terminus";
|
|
125
127
|
|
|
126
128
|
@Controller("/redis")
|
|
127
129
|
class RedisCtrl {
|
|
128
130
|
@BeforeShutdown()
|
|
129
131
|
beforeShutdow() {
|
|
130
|
-
console.log(
|
|
132
|
+
console.log("called before shutdown");
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
@OnSignal()
|
|
134
136
|
OnSignal() {
|
|
135
|
-
console.log(
|
|
137
|
+
console.log("called on signal");
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
@OnShutdown()
|
|
139
141
|
OnShutdown() {
|
|
140
|
-
console.log(
|
|
142
|
+
console.log("called on shutdown");
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
@OnSendFailureDuringShutdown()
|
|
144
146
|
OnSendFailureDuringShutdown() {
|
|
145
|
-
console.log(
|
|
147
|
+
console.log("on send failure during shutdown");
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
```
|
|
149
151
|
|
|
150
152
|
## Contributors
|
|
153
|
+
|
|
151
154
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
152
155
|
|
|
153
156
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
@@ -158,7 +161,6 @@ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com
|
|
|
158
161
|
|
|
159
162
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
160
163
|
|
|
161
|
-
|
|
162
164
|
## Sponsors
|
|
163
165
|
|
|
164
166
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
12
|
+
}
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
var core = require('@tsed/core');
|
|
2
|
-
var tslib = require('tslib');
|
|
3
|
-
var terminus = require('@godaddy/terminus');
|
|
4
|
-
var common = require('@tsed/common');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a readiness / liveness checks.
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { Health } from "@tsed/terminus";
|
|
11
|
-
*
|
|
12
|
-
* @Controller("/mongo")
|
|
13
|
-
* class MongoCtrl {
|
|
14
|
-
* @Health("/health")
|
|
15
|
-
* health() {
|
|
16
|
-
* // Here check the mongo health
|
|
17
|
-
* return Promise.resolve();
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* @param name
|
|
22
|
-
* @decorator
|
|
23
|
-
* @terminus
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
function Health(name) {
|
|
27
|
-
return (target, propertyKey, descriptor) => {
|
|
28
|
-
if (descriptor.value) {
|
|
29
|
-
core.Store.from(target).merge("terminus", {
|
|
30
|
-
[name]: descriptor.value
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function register(name) {
|
|
37
|
-
return (target, propertyKey, descriptor) => {
|
|
38
|
-
if (descriptor.value) {
|
|
39
|
-
const store = core.Store.from(target);
|
|
40
|
-
const values = store.get(name) || [];
|
|
41
|
-
store.merge(name, [...values, descriptor.value]);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Listen the `beforeShutdown` terminus event.
|
|
47
|
-
*
|
|
48
|
-
* @decorator
|
|
49
|
-
* @terminus
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function BeforeShutdown() {
|
|
54
|
-
return register("beforeShutdown");
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Listen the `onSignal` terminus event.
|
|
58
|
-
*
|
|
59
|
-
* @decorator
|
|
60
|
-
* @terminus
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
function OnSignal() {
|
|
64
|
-
return register("onSignal");
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Listen the `onShutdown` terminus event.
|
|
68
|
-
*
|
|
69
|
-
* @decorator
|
|
70
|
-
* @terminus
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
function OnShutdown() {
|
|
74
|
-
return register("onShutdown");
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Listen the `onSendFailureDuringShutdown` terminus event.
|
|
78
|
-
*
|
|
79
|
-
* @decorator
|
|
80
|
-
* @terminus
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
function OnSendFailureDuringShutdown() {
|
|
84
|
-
return register("onSendFailureDuringShutdown");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function _extends() {
|
|
88
|
-
_extends = Object.assign || function (target) {
|
|
89
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
90
|
-
var source = arguments[i];
|
|
91
|
-
|
|
92
|
-
for (var key in source) {
|
|
93
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
94
|
-
target[key] = source[key];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return target;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
return _extends.apply(this, arguments);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
exports.TerminusModule = class TerminusModule {
|
|
106
|
-
$onInit() {
|
|
107
|
-
this.mount(this.httpServer, this.httpsServer);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
mount(httpServer, httpsServer) {
|
|
111
|
-
const {
|
|
112
|
-
terminus: terminus$1
|
|
113
|
-
} = this.configuration;
|
|
114
|
-
|
|
115
|
-
const terminusConfig = _extends({
|
|
116
|
-
logger: this.injector.logger,
|
|
117
|
-
healthChecks: this.getHealths(),
|
|
118
|
-
onSignal: this.execShutdown("onSignal"),
|
|
119
|
-
onShutdown: this.execShutdown("onShutdown"),
|
|
120
|
-
beforeShutdown: this.execShutdown("beforeShutdown"),
|
|
121
|
-
onSendFailureDuringShutdown: this.execShutdown("onSendFailureDuringShutdown")
|
|
122
|
-
}, terminus$1);
|
|
123
|
-
|
|
124
|
-
if (httpServer) {
|
|
125
|
-
terminus.createTerminus(httpServer, terminusConfig);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (httpsServer) {
|
|
129
|
-
terminus.createTerminus(httpsServer, terminusConfig);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
getProviders(name) {
|
|
134
|
-
return this.injector.getProviders().filter(provider => {
|
|
135
|
-
return provider.store.get(name);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
getStore(name) {
|
|
140
|
-
return this.injector.getProviders().map(provider => provider.store.get(name)).filter(x => !!x).flat();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getHealths() {
|
|
144
|
-
const healths = {};
|
|
145
|
-
this.getProviders("terminus").forEach(provider => {
|
|
146
|
-
Object.keys(provider.store.get("terminus")).forEach(name => {
|
|
147
|
-
healths[`${provider.path}${name}`] = provider.store.get("terminus")[name];
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
return healths;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
execShutdown(name) {
|
|
154
|
-
return async () => {
|
|
155
|
-
this.getStore(name).forEach(func => func());
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
tslib.__decorate([common.Configuration(), tslib.__metadata("design:type", Object)], exports.TerminusModule.prototype, "configuration", void 0);
|
|
162
|
-
|
|
163
|
-
tslib.__decorate([common.Inject(), tslib.__metadata("design:type", common.InjectorService)], exports.TerminusModule.prototype, "injector", void 0);
|
|
164
|
-
|
|
165
|
-
tslib.__decorate([common.Inject(common.HttpServer), tslib.__metadata("design:type", Object)], exports.TerminusModule.prototype, "httpServer", void 0);
|
|
166
|
-
|
|
167
|
-
tslib.__decorate([common.Inject(common.HttpsServer), tslib.__metadata("design:type", Object)], exports.TerminusModule.prototype, "httpsServer", void 0);
|
|
168
|
-
|
|
169
|
-
exports.TerminusModule = tslib.__decorate([common.Module()], exports.TerminusModule);
|
|
170
|
-
|
|
171
|
-
exports.BeforeShutdown = BeforeShutdown;
|
|
172
|
-
exports.Health = Health;
|
|
173
|
-
exports.OnSendFailureDuringShutdown = OnSendFailureDuringShutdown;
|
|
174
|
-
exports.OnShutdown = OnShutdown;
|
|
175
|
-
exports.OnSignal = OnSignal;
|
|
176
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/decorators/health.ts","../src/decorators/shutdown.ts","../src/TerminusModule.ts"],"sourcesContent":["import {Store} from \"@tsed/core\";\n\n/**\n * Create a readiness / liveness checks.\n *\n * ```ts\n * import { Health } from \"@tsed/terminus\";\n *\n * @Controller(\"/mongo\")\n * class MongoCtrl {\n * @Health(\"/health\")\n * health() {\n * // Here check the mongo health\n * return Promise.resolve();\n * }\n * }\n *\n * @param name\n * @decorator\n * @terminus\n */\nexport function Health(name: string): MethodDecorator {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n Store.from(target).merge(\"terminus\", {\n [name]: descriptor.value\n });\n }\n };\n}\n","import {Store} from \"@tsed/core\";\n\nfunction register(name: string) {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n const store = Store.from(target);\n const values = store.get(name) || [];\n\n store.merge(name, [...values, descriptor.value]);\n }\n };\n}\n\n/**\n * Listen the `beforeShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function BeforeShutdown(): MethodDecorator {\n return register(\"beforeShutdown\");\n}\n\n/**\n * Listen the `onSignal` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSignal(): MethodDecorator {\n return register(\"onSignal\");\n}\n\n/**\n * Listen the `onShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnShutdown(): MethodDecorator {\n return register(\"onShutdown\");\n}\n\n/**\n * Listen the `onSendFailureDuringShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSendFailureDuringShutdown(): MethodDecorator {\n return register(\"onSendFailureDuringShutdown\");\n}\n","import {createTerminus} from \"@godaddy/terminus\";\nimport {Configuration, HttpServer, HttpsServer, Inject, InjectorService, Module, OnInit} from \"@tsed/common\";\n\n@Module()\nexport class TerminusModule implements OnInit {\n @Configuration()\n private configuration: Configuration;\n\n @Inject()\n private injector: InjectorService;\n\n @Inject(HttpServer)\n private httpServer: HttpServer;\n\n @Inject(HttpsServer)\n private httpsServer: HttpsServer;\n\n public $onInit() {\n this.mount(this.httpServer, this.httpsServer);\n }\n\n private mount(httpServer?: HttpServer, httpsServer?: HttpsServer) {\n const {terminus} = this.configuration;\n const terminusConfig = {\n logger: this.injector.logger as any,\n healthChecks: this.getHealths(),\n onSignal: this.execShutdown(\"onSignal\"),\n onShutdown: this.execShutdown(\"onShutdown\"),\n beforeShutdown: this.execShutdown(\"beforeShutdown\"),\n onSendFailureDuringShutdown: this.execShutdown(\"onSendFailureDuringShutdown\"),\n ...terminus\n };\n\n if (httpServer) {\n createTerminus(httpServer, terminusConfig);\n }\n\n if (httpsServer) {\n createTerminus(httpsServer, terminusConfig);\n }\n }\n\n private getProviders(name: string) {\n return this.injector.getProviders().filter((provider) => {\n return provider.store.get(name);\n });\n }\n\n private getStore(name: string) {\n return this.injector\n .getProviders()\n .map((provider) => provider.store.get(name))\n .filter((x) => !!x)\n .flat();\n }\n\n private getHealths() {\n const healths: {[k: string]: () => Promise<any>} = {};\n\n this.getProviders(\"terminus\").forEach((provider) => {\n Object.keys(provider.store.get(\"terminus\")).forEach((name) => {\n healths[`${provider.path}${name}`] = provider.store.get(\"terminus\")[name];\n });\n });\n\n return healths;\n }\n\n private execShutdown(name: string) {\n return async () => {\n this.getStore(name).forEach((func) => func());\n };\n }\n}\n"],"names":["Health","name","target","propertyKey","descriptor","value","Store","from","merge","register","store","values","get","BeforeShutdown","OnSignal","OnShutdown","OnSendFailureDuringShutdown","TerminusModule","$onInit","mount","httpServer","httpsServer","terminus","configuration","terminusConfig","logger","injector","healthChecks","getHealths","onSignal","execShutdown","onShutdown","beforeShutdown","onSendFailureDuringShutdown","createTerminus","getProviders","filter","provider","getStore","map","x","flat","healths","forEach","Object","keys","path","func","__decorate","Configuration","Inject","InjectorService","HttpServer","HttpsServer","Module"],"mappings":";;;;;AAEA;;;;;;;;;;;;;;;;;;;;SAmBgBA,OAAOC;AACrB,SAAO,CAAWC,MAAX,EAA2BC,WAA3B,EAAgDC,UAAhD;AACL,QAAIA,UAAU,CAACC,KAAf,EAAsB;AACpBC,MAAAA,UAAK,CAACC,IAAN,CAAWL,MAAX,EAAmBM,KAAnB,CAAyB,UAAzB,EAAqC;AACnC,SAACP,IAAD,GAAQG,UAAU,CAACC;AADgB,OAArC;AAGD;AACF,GAND;AAOD;;AC3BD,SAASI,QAAT,CAAkBR,IAAlB;AACE,SAAO,CAAWC,MAAX,EAA2BC,WAA3B,EAAgDC,UAAhD;AACL,QAAIA,UAAU,CAACC,KAAf,EAAsB;AACpB,Y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AGAJ,kBADCE,aAAM,CAACG,kBAAD,qGACP;;AAXWpC,sBAAc,qBAD1BqC,aAAM,KACMrC,uBAAA;;;;;;;;"}
|
package/lib/index.modern.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { Store } from '@tsed/core';
|
|
2
|
-
import { __decorate, __metadata } from 'tslib';
|
|
3
|
-
import { createTerminus } from '@godaddy/terminus';
|
|
4
|
-
import { Configuration, Inject, InjectorService, HttpServer, HttpsServer, Module } from '@tsed/common';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a readiness / liveness checks.
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { Health } from "@tsed/terminus";
|
|
11
|
-
*
|
|
12
|
-
* @Controller("/mongo")
|
|
13
|
-
* class MongoCtrl {
|
|
14
|
-
* @Health("/health")
|
|
15
|
-
* health() {
|
|
16
|
-
* // Here check the mongo health
|
|
17
|
-
* return Promise.resolve();
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* @param name
|
|
22
|
-
* @decorator
|
|
23
|
-
* @terminus
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
function Health(name) {
|
|
27
|
-
return (target, propertyKey, descriptor) => {
|
|
28
|
-
if (descriptor.value) {
|
|
29
|
-
Store.from(target).merge("terminus", {
|
|
30
|
-
[name]: descriptor.value
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function register(name) {
|
|
37
|
-
return (target, propertyKey, descriptor) => {
|
|
38
|
-
if (descriptor.value) {
|
|
39
|
-
const store = Store.from(target);
|
|
40
|
-
const values = store.get(name) || [];
|
|
41
|
-
store.merge(name, [...values, descriptor.value]);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Listen the `beforeShutdown` terminus event.
|
|
47
|
-
*
|
|
48
|
-
* @decorator
|
|
49
|
-
* @terminus
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function BeforeShutdown() {
|
|
54
|
-
return register("beforeShutdown");
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Listen the `onSignal` terminus event.
|
|
58
|
-
*
|
|
59
|
-
* @decorator
|
|
60
|
-
* @terminus
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
function OnSignal() {
|
|
64
|
-
return register("onSignal");
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Listen the `onShutdown` terminus event.
|
|
68
|
-
*
|
|
69
|
-
* @decorator
|
|
70
|
-
* @terminus
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
function OnShutdown() {
|
|
74
|
-
return register("onShutdown");
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Listen the `onSendFailureDuringShutdown` terminus event.
|
|
78
|
-
*
|
|
79
|
-
* @decorator
|
|
80
|
-
* @terminus
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
function OnSendFailureDuringShutdown() {
|
|
84
|
-
return register("onSendFailureDuringShutdown");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function _extends() {
|
|
88
|
-
_extends = Object.assign || function (target) {
|
|
89
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
90
|
-
var source = arguments[i];
|
|
91
|
-
|
|
92
|
-
for (var key in source) {
|
|
93
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
94
|
-
target[key] = source[key];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return target;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
return _extends.apply(this, arguments);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let TerminusModule = class TerminusModule {
|
|
106
|
-
$onInit() {
|
|
107
|
-
this.mount(this.httpServer, this.httpsServer);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
mount(httpServer, httpsServer) {
|
|
111
|
-
const {
|
|
112
|
-
terminus
|
|
113
|
-
} = this.configuration;
|
|
114
|
-
|
|
115
|
-
const terminusConfig = _extends({
|
|
116
|
-
logger: this.injector.logger,
|
|
117
|
-
healthChecks: this.getHealths(),
|
|
118
|
-
onSignal: this.execShutdown("onSignal"),
|
|
119
|
-
onShutdown: this.execShutdown("onShutdown"),
|
|
120
|
-
beforeShutdown: this.execShutdown("beforeShutdown"),
|
|
121
|
-
onSendFailureDuringShutdown: this.execShutdown("onSendFailureDuringShutdown")
|
|
122
|
-
}, terminus);
|
|
123
|
-
|
|
124
|
-
if (httpServer) {
|
|
125
|
-
createTerminus(httpServer, terminusConfig);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (httpsServer) {
|
|
129
|
-
createTerminus(httpsServer, terminusConfig);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
getProviders(name) {
|
|
134
|
-
return this.injector.getProviders().filter(provider => {
|
|
135
|
-
return provider.store.get(name);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
getStore(name) {
|
|
140
|
-
return this.injector.getProviders().map(provider => provider.store.get(name)).filter(x => !!x).flat();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getHealths() {
|
|
144
|
-
const healths = {};
|
|
145
|
-
this.getProviders("terminus").forEach(provider => {
|
|
146
|
-
Object.keys(provider.store.get("terminus")).forEach(name => {
|
|
147
|
-
healths[`${provider.path}${name}`] = provider.store.get("terminus")[name];
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
return healths;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
execShutdown(name) {
|
|
154
|
-
var _this = this;
|
|
155
|
-
|
|
156
|
-
return async function () {
|
|
157
|
-
_this.getStore(name).forEach(func => func());
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
__decorate([Configuration(), __metadata("design:type", Object)], TerminusModule.prototype, "configuration", void 0);
|
|
164
|
-
|
|
165
|
-
__decorate([Inject(), __metadata("design:type", InjectorService)], TerminusModule.prototype, "injector", void 0);
|
|
166
|
-
|
|
167
|
-
__decorate([Inject(HttpServer), __metadata("design:type", Object)], TerminusModule.prototype, "httpServer", void 0);
|
|
168
|
-
|
|
169
|
-
__decorate([Inject(HttpsServer), __metadata("design:type", Object)], TerminusModule.prototype, "httpsServer", void 0);
|
|
170
|
-
|
|
171
|
-
TerminusModule = __decorate([Module()], TerminusModule);
|
|
172
|
-
|
|
173
|
-
export { BeforeShutdown, Health, OnSendFailureDuringShutdown, OnShutdown, OnSignal, TerminusModule };
|
|
174
|
-
//# sourceMappingURL=index.modern.js.map
|
package/lib/index.modern.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/decorators/health.ts","../src/decorators/shutdown.ts","../src/TerminusModule.ts"],"sourcesContent":["import {Store} from \"@tsed/core\";\n\n/**\n * Create a readiness / liveness checks.\n *\n * ```ts\n * import { Health } from \"@tsed/terminus\";\n *\n * @Controller(\"/mongo\")\n * class MongoCtrl {\n * @Health(\"/health\")\n * health() {\n * // Here check the mongo health\n * return Promise.resolve();\n * }\n * }\n *\n * @param name\n * @decorator\n * @terminus\n */\nexport function Health(name: string): MethodDecorator {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n Store.from(target).merge(\"terminus\", {\n [name]: descriptor.value\n });\n }\n };\n}\n","import {Store} from \"@tsed/core\";\n\nfunction register(name: string) {\n return <Function>(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<Function>) => {\n if (descriptor.value) {\n const store = Store.from(target);\n const values = store.get(name) || [];\n\n store.merge(name, [...values, descriptor.value]);\n }\n };\n}\n\n/**\n * Listen the `beforeShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function BeforeShutdown(): MethodDecorator {\n return register(\"beforeShutdown\");\n}\n\n/**\n * Listen the `onSignal` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSignal(): MethodDecorator {\n return register(\"onSignal\");\n}\n\n/**\n * Listen the `onShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnShutdown(): MethodDecorator {\n return register(\"onShutdown\");\n}\n\n/**\n * Listen the `onSendFailureDuringShutdown` terminus event.\n *\n * @decorator\n * @terminus\n */\nexport function OnSendFailureDuringShutdown(): MethodDecorator {\n return register(\"onSendFailureDuringShutdown\");\n}\n","import {createTerminus} from \"@godaddy/terminus\";\nimport {Configuration, HttpServer, HttpsServer, Inject, InjectorService, Module, OnInit} from \"@tsed/common\";\n\n@Module()\nexport class TerminusModule implements OnInit {\n @Configuration()\n private configuration: Configuration;\n\n @Inject()\n private injector: InjectorService;\n\n @Inject(HttpServer)\n private httpServer: HttpServer;\n\n @Inject(HttpsServer)\n private httpsServer: HttpsServer;\n\n public $onInit() {\n this.mount(this.httpServer, this.httpsServer);\n }\n\n private mount(httpServer?: HttpServer, httpsServer?: HttpsServer) {\n const {terminus} = this.configuration;\n const terminusConfig = {\n logger: this.injector.logger as any,\n healthChecks: this.getHealths(),\n onSignal: this.execShutdown(\"onSignal\"),\n onShutdown: this.execShutdown(\"onShutdown\"),\n beforeShutdown: this.execShutdown(\"beforeShutdown\"),\n onSendFailureDuringShutdown: this.execShutdown(\"onSendFailureDuringShutdown\"),\n ...terminus\n };\n\n if (httpServer) {\n createTerminus(httpServer, terminusConfig);\n }\n\n if (httpsServer) {\n createTerminus(httpsServer, terminusConfig);\n }\n }\n\n private getProviders(name: string) {\n return this.injector.getProviders().filter((provider) => {\n return provider.store.get(name);\n });\n }\n\n private getStore(name: string) {\n return this.injector\n .getProviders()\n .map((provider) => provider.store.get(name))\n .filter((x) => !!x)\n .flat();\n }\n\n private getHealths() {\n const healths: {[k: string]: () => Promise<any>} = {};\n\n this.getProviders(\"terminus\").forEach((provider) => {\n Object.keys(provider.store.get(\"terminus\")).forEach((name) => {\n healths[`${provider.path}${name}`] = provider.store.get(\"terminus\")[name];\n });\n });\n\n return healths;\n }\n\n private execShutdown(name: string) {\n return async () => {\n this.getStore(name).forEach((func) => func());\n };\n }\n}\n"],"names":["Health","name","target","propertyKey","descriptor","value","Store","from","merge","register","store","values","get","BeforeShutdown","OnSignal","OnShutdown","OnSendFailureDuringShutdown","TerminusModule","$onInit","mount","httpServer","httpsServer","terminus","configuration","terminusConfig","logger","injector","healthChecks","getHealths","onSignal","execShutdown","onShutdown","beforeShutdown","onSendFailureDuringShutdown","createTerminus","getProviders","filter","provider","getStore","map","x","flat","healths","forEach","Object","keys","path","func","__decorate","Configuration","Inject","InjectorService","HttpServer","HttpsServer","Module"],"mappings":";;;;;AAEA;;;;;;;;;;;;;;;;;;;;SAmBgBA,OAAOC;AACrB,SAAO,CAAWC,MAAX,EAA2BC,WAA3B,EAAgDC,UAAhD;AACL,QAAIA,UAAU,CAACC,KAAf,EAAsB;AACpBC,MAAAA,KAAK,CAACC,IAAN,CAAWL,MAAX,EAAmBM,KAAnB,CAAyB,UAAzB,EAAqC;AACnC,SAACP,IAAD,GAAQG,UAAU,CAACC;AADgB,OAArC;AAGD;AACF,GAND;AAOD;;AC3BD,SAASI,QAAT,CAAkBR,IAAlB;AACE,SAAO,CAAWC,MAAX,EAA2BC,WAA3B,EAAgDC,UAAhD;AACL,QAAIA,UAAU,CAACC,KAAf,EAAsB;AACpB,YAAMK,KAAK,GAAGJ,KAAK,CAACC,IAAN,CAAWL,MAAX,CAAd;AACA,YAAMS,MAAM,GAAGD,KAAK,CAACE,GAAN,CAAUX,IAAV,KAAmB,EAAlC;AAEAS,MAAAA,KAAK,CAACF,KAAN,CAAYP,IAAZ,EAAkB,CAAC,GAAGU,MAAJ,EAAYP,UAAU,CAACC,KAAvB,CAAlB;AACD;AACF,GAPD;AAQD;AAED;;;;;;;;SAMgBQ;AACd,SAAOJ,QAAQ,CAAC,gBAAD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