Skip to content

Commit 319f662

Browse files
BrunnerLiviogergelyke
authored andcommitted
fix(typings): update types for 3.0.0
1 parent d07e527 commit 319f662

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

typings/express.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function onHealthCheck() {
1212
return Promise.resolve();
1313
}
1414

15-
terminus(http.createServer(app), {
15+
terminus.createTerminus(http.createServer(app), {
1616
logger: console.log,
1717
healthChecks: {
1818
"/healthcheck": () => Promise.resolve()

typings/index.d.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
declare module "@godaddy/terminus" {
22

3-
type HealthCheck = () => Promise<any>;
3+
export type HealthCheck = () => Promise<any>;
44

5-
interface HealthCheckMap {
5+
export class HealthCheckError extends Error {
6+
constructor(message: string, causes: any);
7+
public causes: string;
8+
}
9+
10+
export interface HealthCheckMap {
611
[key: string]: HealthCheck;
712
}
813

9-
interface TerminusOptions {
14+
export interface TerminusOptions {
1015
healthChecks?: HealthCheckMap;
1116
timeout?: number;
1217
signal?: string;
@@ -20,9 +25,8 @@ declare module "@godaddy/terminus" {
2025
onSigterm?: () => Promise<any>;
2126
}
2227

23-
type Terminus = <T>(server: T, options?: TerminusOptions) => T;
28+
export type Terminus = <T>(server: T, options?: TerminusOptions) => T;
2429

25-
const terminus: Terminus;
30+
export const createTerminus: Terminus;
2631

27-
export = terminus;
2832
}

typings/index.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as http from "http";
2-
import * as terminus from "@godaddy/terminus";
2+
import { createTerminus, HealthCheckError, HealthCheck, TerminusOptions } from "@godaddy/terminus";
33

4-
async function onSignal () {
4+
async function onSignal() {
55
console.log('server is starting cleanup');
66
return Promise.all([
77
// your clean logic, like closing database connections
88
]);
99
}
1010

11-
async function onShutdown () {
11+
async function onShutdown() {
1212
console.log('cleanup finished, server is shutting down');
1313
return Promise.resolve();
1414
}
@@ -17,14 +17,22 @@ const server = http.createServer((request, response) => {
1717
response.end('<html><body><h1>Hello, World!</h1></body></html>');
1818
})
1919

20-
terminus(server, {
20+
const healthcheck: HealthCheck = () => {
21+
const status = [{ status: 'up' }];
22+
const error = new HealthCheckError('Error', status);
23+
throw error;
24+
}
25+
26+
const options: TerminusOptions = {
2127
healthChecks: {
22-
"/healthcheck": () => Promise.resolve()
28+
"/healthcheck": healthcheck
2329
},
2430
timeout: 1000,
2531
onSignal,
2632
onShutdown,
2733
logger: console.log
28-
});
34+
};
35+
36+
createTerminus(server, options);
2937

3038
server.listen(3000);

typings/koa.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function onHealthCheck() {
1010
return Promise.resolve();
1111
}
1212

13-
terminus(server, {
13+
terminus.createTerminus(server, {
1414
logger: console.log,
1515
healthChecks: {
1616
"/healthcheck": () => Promise.resolve()

0 commit comments

Comments
 (0)