@tsed/terminus 6.87.2 → 6.90.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/lib/{TerminusModule.d.ts → cjs/TerminusModule.d.ts} +0 -0
- package/lib/cjs/TerminusModule.js +76 -0
- package/lib/cjs/TerminusModule.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/health.d.ts +0 -0
- package/lib/cjs/decorators/health.js +34 -0
- package/lib/cjs/decorators/health.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/shutdown.d.ts +0 -0
- package/lib/cjs/decorators/shutdown.js +54 -0
- package/lib/cjs/decorators/shutdown.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +8 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/TerminusSettings.d.ts +0 -0
- package/lib/cjs/interfaces/TerminusSettings.js +3 -0
- package/lib/cjs/interfaces/TerminusSettings.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
- package/lib/cjs/interfaces/index.js +5 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/esm/TerminusModule.js +73 -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 +5 -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/index.js +2 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/types/TerminusModule.d.ts +13 -0
- package/lib/types/decorators/health.d.ts +20 -0
- package/lib/types/decorators/shutdown.d.ts +28 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/interfaces/TerminusSettings.d.ts +2 -0
- package/lib/types/interfaces/index.d.ts +9 -0
- package/package.json +20 -16
- package/tsconfig.compile.esm.json +23 -0
- 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
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
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 common_1 = require("@tsed/common");
|
|
7
|
+
let TerminusModule = class TerminusModule {
|
|
8
|
+
$onInit() {
|
|
9
|
+
this.mount(this.httpServer, this.httpsServer);
|
|
10
|
+
}
|
|
11
|
+
mount(httpServer, httpsServer) {
|
|
12
|
+
const { terminus } = this.configuration;
|
|
13
|
+
const terminusConfig = {
|
|
14
|
+
logger: this.injector.logger,
|
|
15
|
+
healthChecks: this.getHealths(),
|
|
16
|
+
onSignal: this.execShutdown("onSignal"),
|
|
17
|
+
onShutdown: this.execShutdown("onShutdown"),
|
|
18
|
+
beforeShutdown: this.execShutdown("beforeShutdown"),
|
|
19
|
+
onSendFailureDuringShutdown: this.execShutdown("onSendFailureDuringShutdown"),
|
|
20
|
+
...terminus
|
|
21
|
+
};
|
|
22
|
+
if (httpServer) {
|
|
23
|
+
(0, terminus_1.createTerminus)(httpServer, terminusConfig);
|
|
24
|
+
}
|
|
25
|
+
if (httpsServer) {
|
|
26
|
+
(0, terminus_1.createTerminus)(httpsServer, terminusConfig);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
getProviders(name) {
|
|
30
|
+
return this.injector.getProviders().filter((provider) => {
|
|
31
|
+
return provider.store.get(name);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getStore(name) {
|
|
35
|
+
return this.injector
|
|
36
|
+
.getProviders()
|
|
37
|
+
.map((provider) => provider.store.get(name))
|
|
38
|
+
.filter((x) => !!x)
|
|
39
|
+
.flat();
|
|
40
|
+
}
|
|
41
|
+
getHealths() {
|
|
42
|
+
const healths = {};
|
|
43
|
+
this.getProviders("terminus").forEach((provider) => {
|
|
44
|
+
Object.keys(provider.store.get("terminus")).forEach((name) => {
|
|
45
|
+
healths[`${provider.path}${name}`] = provider.store.get("terminus")[name];
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return healths;
|
|
49
|
+
}
|
|
50
|
+
execShutdown(name) {
|
|
51
|
+
return async () => {
|
|
52
|
+
this.getStore(name).forEach((func) => func());
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
(0, tslib_1.__decorate)([
|
|
57
|
+
(0, common_1.Configuration)(),
|
|
58
|
+
(0, tslib_1.__metadata)("design:type", Object)
|
|
59
|
+
], TerminusModule.prototype, "configuration", void 0);
|
|
60
|
+
(0, tslib_1.__decorate)([
|
|
61
|
+
(0, common_1.Inject)(),
|
|
62
|
+
(0, tslib_1.__metadata)("design:type", common_1.InjectorService)
|
|
63
|
+
], TerminusModule.prototype, "injector", void 0);
|
|
64
|
+
(0, tslib_1.__decorate)([
|
|
65
|
+
(0, common_1.Inject)(common_1.HttpServer),
|
|
66
|
+
(0, tslib_1.__metadata)("design:type", Object)
|
|
67
|
+
], TerminusModule.prototype, "httpServer", void 0);
|
|
68
|
+
(0, tslib_1.__decorate)([
|
|
69
|
+
(0, common_1.Inject)(common_1.HttpsServer),
|
|
70
|
+
(0, tslib_1.__metadata)("design:type", Object)
|
|
71
|
+
], TerminusModule.prototype, "httpsServer", void 0);
|
|
72
|
+
TerminusModule = (0, tslib_1.__decorate)([
|
|
73
|
+
(0, common_1.Module)()
|
|
74
|
+
], TerminusModule);
|
|
75
|
+
exports.TerminusModule = TerminusModule;
|
|
76
|
+
//# sourceMappingURL=TerminusModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerminusModule.js","sourceRoot":"","sources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,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aAC3C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,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,sBAAa,GAAE;;qDACqB;AAGrC;IADC,IAAA,eAAM,GAAE;2CACS,wBAAe;gDAAC;AAGlC;IADC,IAAA,eAAM,EAAC,mBAAU,CAAC;;kDACY;AAG/B;IADC,IAAA,eAAM,EAAC,oBAAW,CAAC;;mDACa;AAXtB,cAAc;IAD1B,IAAA,eAAM,GAAE;GACI,cAAc,CAqE1B;AArEY,wCAAc","sourcesContent":["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"]}
|
|
File without changes
|
|
@@ -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"]}
|
|
File without changes
|
|
@@ -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"]}
|
|
File without changes
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./decorators/health"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./decorators/shutdown"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./interfaces"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./TerminusModule"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAoC;AACpC,qEAAsC;AACtC,4DAA6B;AAC7B,gEAAiC","sourcesContent":["export * from \"./decorators/health\";\nexport * from \"./decorators/shutdown\";\nexport * from \"./interfaces\";\nexport * from \"./TerminusModule\";\n"]}
|
|
File without changes
|
|
@@ -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"]}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAUA,kEAAmC","sourcesContent":["import {TerminusSettings} from \"./TerminusSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n terminus: TerminusSettings;\n }\n }\n}\n\nexport * from \"./TerminusSettings\";\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { createTerminus } from "@godaddy/terminus";
|
|
3
|
+
import { Configuration, HttpServer, HttpsServer, Inject, InjectorService, Module } from "@tsed/common";
|
|
4
|
+
let TerminusModule = class TerminusModule {
|
|
5
|
+
$onInit() {
|
|
6
|
+
this.mount(this.httpServer, this.httpsServer);
|
|
7
|
+
}
|
|
8
|
+
mount(httpServer, httpsServer) {
|
|
9
|
+
const { terminus } = this.configuration;
|
|
10
|
+
const terminusConfig = {
|
|
11
|
+
logger: this.injector.logger,
|
|
12
|
+
healthChecks: this.getHealths(),
|
|
13
|
+
onSignal: this.execShutdown("onSignal"),
|
|
14
|
+
onShutdown: this.execShutdown("onShutdown"),
|
|
15
|
+
beforeShutdown: this.execShutdown("beforeShutdown"),
|
|
16
|
+
onSendFailureDuringShutdown: this.execShutdown("onSendFailureDuringShutdown"),
|
|
17
|
+
...terminus
|
|
18
|
+
};
|
|
19
|
+
if (httpServer) {
|
|
20
|
+
createTerminus(httpServer, terminusConfig);
|
|
21
|
+
}
|
|
22
|
+
if (httpsServer) {
|
|
23
|
+
createTerminus(httpsServer, terminusConfig);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getProviders(name) {
|
|
27
|
+
return this.injector.getProviders().filter((provider) => {
|
|
28
|
+
return provider.store.get(name);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
getStore(name) {
|
|
32
|
+
return this.injector
|
|
33
|
+
.getProviders()
|
|
34
|
+
.map((provider) => provider.store.get(name))
|
|
35
|
+
.filter((x) => !!x)
|
|
36
|
+
.flat();
|
|
37
|
+
}
|
|
38
|
+
getHealths() {
|
|
39
|
+
const healths = {};
|
|
40
|
+
this.getProviders("terminus").forEach((provider) => {
|
|
41
|
+
Object.keys(provider.store.get("terminus")).forEach((name) => {
|
|
42
|
+
healths[`${provider.path}${name}`] = provider.store.get("terminus")[name];
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return healths;
|
|
46
|
+
}
|
|
47
|
+
execShutdown(name) {
|
|
48
|
+
return async () => {
|
|
49
|
+
this.getStore(name).forEach((func) => func());
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
__decorate([
|
|
54
|
+
Configuration(),
|
|
55
|
+
__metadata("design:type", Object)
|
|
56
|
+
], TerminusModule.prototype, "configuration", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
Inject(),
|
|
59
|
+
__metadata("design:type", InjectorService)
|
|
60
|
+
], TerminusModule.prototype, "injector", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
Inject(HttpServer),
|
|
63
|
+
__metadata("design:type", Object)
|
|
64
|
+
], TerminusModule.prototype, "httpServer", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
Inject(HttpsServer),
|
|
67
|
+
__metadata("design:type", Object)
|
|
68
|
+
], TerminusModule.prototype, "httpsServer", void 0);
|
|
69
|
+
TerminusModule = __decorate([
|
|
70
|
+
Module()
|
|
71
|
+
], TerminusModule);
|
|
72
|
+
export { TerminusModule };
|
|
73
|
+
//# 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,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAS,MAAM,cAAc,CAAC;AAG7G,IAAa,cAAc,GAA3B,MAAa,cAAc;IAalB,OAAO;QACZ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,UAAuB,EAAE,WAAyB;QAC9D,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,UAAU,EAAE;YACd,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;SAC5C;QAED,IAAI,WAAW,EAAE;YACf,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;SAC7C;IACH,CAAC;IAEO,YAAY,CAAC,IAAY;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE;YACtD,OAAO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WAAW,CAAC;;mDACa;AAXtB,cAAc;IAD1B,MAAM,EAAE;GACI,cAAc,CAqE1B;SArEY,cAAc","sourcesContent":["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"]}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from \"./decorators/health\";\nexport * from \"./decorators/shutdown\";\nexport * from \"./interfaces\";\nexport * from \"./TerminusModule\";\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":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAUA,cAAc,oBAAoB,CAAC","sourcesContent":["import {TerminusSettings} from \"./TerminusSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n terminus: TerminusSettings;\n }\n }\n}\n\nexport * from \"./TerminusSettings\";\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OnInit } from "@tsed/common";
|
|
2
|
+
export declare class TerminusModule implements OnInit {
|
|
3
|
+
private configuration;
|
|
4
|
+
private injector;
|
|
5
|
+
private httpServer;
|
|
6
|
+
private httpsServer;
|
|
7
|
+
$onInit(): void;
|
|
8
|
+
private mount;
|
|
9
|
+
private getProviders;
|
|
10
|
+
private getStore;
|
|
11
|
+
private getHealths;
|
|
12
|
+
private execShutdown;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a readiness / liveness checks.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { Health } from "@tsed/terminus";
|
|
6
|
+
*
|
|
7
|
+
* @Controller("/mongo")
|
|
8
|
+
* class MongoCtrl {
|
|
9
|
+
* @Health("/health")
|
|
10
|
+
* health() {
|
|
11
|
+
* // Here check the mongo health
|
|
12
|
+
* return Promise.resolve();
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* @param name
|
|
17
|
+
* @decorator
|
|
18
|
+
* @terminus
|
|
19
|
+
*/
|
|
20
|
+
export declare function Health(name: string): MethodDecorator;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listen the `beforeShutdown` terminus event.
|
|
3
|
+
*
|
|
4
|
+
* @decorator
|
|
5
|
+
* @terminus
|
|
6
|
+
*/
|
|
7
|
+
export declare function BeforeShutdown(): MethodDecorator;
|
|
8
|
+
/**
|
|
9
|
+
* Listen the `onSignal` terminus event.
|
|
10
|
+
*
|
|
11
|
+
* @decorator
|
|
12
|
+
* @terminus
|
|
13
|
+
*/
|
|
14
|
+
export declare function OnSignal(): MethodDecorator;
|
|
15
|
+
/**
|
|
16
|
+
* Listen the `onShutdown` terminus event.
|
|
17
|
+
*
|
|
18
|
+
* @decorator
|
|
19
|
+
* @terminus
|
|
20
|
+
*/
|
|
21
|
+
export declare function OnShutdown(): MethodDecorator;
|
|
22
|
+
/**
|
|
23
|
+
* Listen the `onSendFailureDuringShutdown` terminus event.
|
|
24
|
+
*
|
|
25
|
+
* @decorator
|
|
26
|
+
* @terminus
|
|
27
|
+
*/
|
|
28
|
+
export declare function OnSendFailureDuringShutdown(): MethodDecorator;
|
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/terminus",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.90.0",
|
|
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
|
-
"typings": "./lib/index.d.ts",
|
|
8
|
+
"main": "./lib/cjs/index.js",
|
|
9
|
+
"typings": "./lib/types/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"types": "./lib/types/index.d.ts",
|
|
12
|
+
"import": "./lib/esm/index.js",
|
|
13
|
+
"require": "./lib/cjs/index.js",
|
|
14
|
+
"default": "./lib/esm/index.js"
|
|
13
15
|
},
|
|
14
16
|
"scripts": {
|
|
15
|
-
"build": "
|
|
17
|
+
"build": "yarn run build:esm && yarn run build:cjs",
|
|
18
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
16
20
|
"start": "ts-node -r tsconfig-paths/register test/app/index.ts"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
@@ -20,18 +24,18 @@
|
|
|
20
24
|
"tslib": "2.2.0"
|
|
21
25
|
},
|
|
22
26
|
"devDependencies": {
|
|
23
|
-
"@tsed/common": "6.
|
|
24
|
-
"@tsed/core": "6.
|
|
25
|
-
"@tsed/di": "6.
|
|
26
|
-
"@tsed/openspec": "6.
|
|
27
|
-
"@tsed/schema": "6.
|
|
27
|
+
"@tsed/common": "6.90.0",
|
|
28
|
+
"@tsed/core": "6.90.0",
|
|
29
|
+
"@tsed/di": "6.90.0",
|
|
30
|
+
"@tsed/openspec": "6.90.0",
|
|
31
|
+
"@tsed/schema": "6.90.0"
|
|
28
32
|
},
|
|
29
33
|
"peerDependencies": {
|
|
30
|
-
"@tsed/common": "^6.
|
|
31
|
-
"@tsed/core": "^6.
|
|
32
|
-
"@tsed/di": "^6.
|
|
33
|
-
"@tsed/openspec": "^6.
|
|
34
|
-
"@tsed/schema": "^6.
|
|
34
|
+
"@tsed/common": "^6.90.0",
|
|
35
|
+
"@tsed/core": "^6.90.0",
|
|
36
|
+
"@tsed/di": "^6.90.0",
|
|
37
|
+
"@tsed/openspec": "^6.90.0",
|
|
38
|
+
"@tsed/schema": "^6.90.0"
|
|
35
39
|
},
|
|
36
40
|
"repository": "https://github.com/tsedio/tsed",
|
|
37
41
|
"bugs": {
|
|
@@ -0,0 +1,23 @@
|
|
|
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": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"test",
|
|
14
|
+
"lib",
|
|
15
|
+
"benchmark",
|
|
16
|
+
"coverage",
|
|
17
|
+
"spec",
|
|
18
|
+
"**/*.benchmark.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"keys",
|
|
21
|
+
"jest.config.js"
|
|
22
|
+
]
|
|
23
|
+
}
|
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,YAAMK,KAAK,GAAGJ,UAAK,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,CAAf;AACD;AAED;;;;;;;SAMgBK;AACd,SAAOL,QAAQ,CAAC,UAAD,CAAf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AAD,IAAcA,QAAQ,CAAC3B,KAAT,CAAeE,GAAf,CAAmBX,IAAnB,CAFd,EAGJmC,MAHI,CAGII,CAAD,IAAO,CAAC,CAACA,CAHZ,EAIJC,IAJI,EAAP;AAKD;;AAEOb,EAAAA,UAAU;AAChB,UAAMc,OAAO,GAAsC,EAAnD;AAEA,SAAKP,YAAL,CAAkB,UAAlB,EAA8BQ,OAA9B,CAAuCN,QAAD;AACpCO,MAAAA,MAAM,CAACC,IAAP,CAAYR,QAAQ,CAAC3B,KAAT,CAAeE,GAAf,CAAmB,UAAnB,CAAZ,EAA4C+B,OAA5C,CAAqD1C,IAAD;AAClDyC,QAAAA,OAAO,IAAIL,QAAQ,CAACS,OAAO7C,MAApB,CAAP,GAAqCoC,QAAQ,CAAC3B,KAAT,CAAeE,GAAf,CAAmB,UAAnB,EAA+BX,IAA/B,CAArC;AACD,OAFD;AAGD,KAJD;AAMA,WAAOyC,OAAP;AACD;;AAEOZ,EAAAA,YAAY,CAAC7B,IAAD;AAClB,WAAO;AACL,WAAKqC,QAAL,CAAcrC,IAAd,EAAoB0C,OAApB,CAA6BI,IAAD,IAAUA,IAAI,EAA1C;AACD,KAFD;AAGD;;;;AAlEDC,kBADCC,oBAAa,wGACd;;AAGAD,kBADCE,aAAM,oCACWC,+EAAlB;;AAGAH,kBADCE,aAAM,CAACE,iBAAD,oGACP;;AAGAJ,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,CAAf;AACD;AAED;;;;;;;SAMgBK;AACd,SAAOL,QAAQ,CAAC,UAAD,CAAf;AACD;AAED;;;;;;;SAMgBM;AACd,SAAON,QAAQ,CAAC,YAAD,CAAf;AACD;AAED;;;;;;;SAMgBO;AACd,SAAOP,QAAQ,CAAC,6BAAD,CAAf;AACD;;;;;;;;;;;;;;;;;;;;IC/CYQ,cAAc,GAA3B,MAAaA,cAAb;AAaSC,EAAAA,OAAO;AACZ,SAAKC,KAAL,CAAW,KAAKC,UAAhB,EAA4B,KAAKC,WAAjC;AACD;;AAEOF,EAAAA,KAAK,CAACC,UAAD,EAA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