From e35513ae8fe0209e86eb72958efc3f9fc5c80eda Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 3 Oct 2016 15:05:12 +0200 Subject: [PATCH] Fix export for "bunyan-config" and improve definitions (#11653) * Fix export for "bunyan-config". * Update definitions. Replace "Object" to "{}" type. Add "express" property in "VitalSigns" class. --- bunyan-config/bunyan-config-tests.ts | 2 +- bunyan-config/bunyan-config.d.ts | 2 +- express-mung/express-mung.d.ts | 4 ++-- vitalsigns/vitalsigns-tests.ts | 10 +++++++--- vitalsigns/vitalsigns.d.ts | 16 +++++++++++++--- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bunyan-config/bunyan-config-tests.ts b/bunyan-config/bunyan-config-tests.ts index 6a15aff601..71d22ee2a4 100644 --- a/bunyan-config/bunyan-config-tests.ts +++ b/bunyan-config/bunyan-config-tests.ts @@ -1,7 +1,7 @@ /// import * as bunyan from "bunyan"; -import bunyanConfig from "bunyan-config"; +import bunyanConfig = require("bunyan-config"); var jsonConfig = { name: "myLogger", diff --git a/bunyan-config/bunyan-config.d.ts b/bunyan-config/bunyan-config.d.ts index 68a095b9b8..fb68702aee 100644 --- a/bunyan-config/bunyan-config.d.ts +++ b/bunyan-config/bunyan-config.d.ts @@ -27,5 +27,5 @@ declare module "bunyan-config" { * @return {LoggerOptions} A logger options. */ function bunyanConfig(jsonConfig?: Configuration): bunyan.LoggerOptions; - export default bunyanConfig; + export = bunyanConfig; } diff --git a/express-mung/express-mung.d.ts b/express-mung/express-mung.d.ts index 6dfee7d557..6f9a844c7a 100644 --- a/express-mung/express-mung.d.ts +++ b/express-mung/express-mung.d.ts @@ -10,8 +10,8 @@ declare module "express-mung" { import { Request, Response } from "express"; import * as http from "http"; - type Transform = (body: {}, request: Request, response: Response) => {}; - type TransformHeader = (body: http.IncomingMessage, request: Request, response: Response) => {}; + type Transform = (body: {}, request: Request, response: Response) => any; + type TransformHeader = (body: http.IncomingMessage, request: Request, response: Response) => any; /** * Transform the JSON body of the response. diff --git a/vitalsigns/vitalsigns-tests.ts b/vitalsigns/vitalsigns-tests.ts index 1e22dec433..8136dfcfbd 100644 --- a/vitalsigns/vitalsigns-tests.ts +++ b/vitalsigns/vitalsigns-tests.ts @@ -1,11 +1,12 @@ /// +import * as express from "express"; import VitalSigns = require("vitalsigns"); var vitals = new VitalSigns(); vitals.monitor('cpu'); -vitals.monitor('mem', {units: 'MB'}); +vitals.monitor('mem', { units: 'MB' }); vitals.monitor('tick'); vitals.unhealthyWhen('cpu', 'usage').equals(100); @@ -13,7 +14,7 @@ vitals.unhealthyWhen('tick', 'maxMs').greaterThan(500); vitals.monitor({ connections: () => new Object() -}, {name: 'game'}); +}, { name: 'game' }); var vitals = new VitalSigns({ autoCheck: 5000, @@ -21,5 +22,8 @@ var vitals = new VitalSigns({ httpUnhealthy: 503 }); -vitals.monitor('cpu', {name: 'foo'}); +vitals.monitor('cpu', { name: 'foo' }); vitals.unhealthyWhen('foo', 'bar').not.greaterThan(5); + +var app = express(); +app.get('/health', vitals.express); diff --git a/vitalsigns/vitalsigns.d.ts b/vitalsigns/vitalsigns.d.ts index c74a42f08a..f58a88962d 100644 --- a/vitalsigns/vitalsigns.d.ts +++ b/vitalsigns/vitalsigns.d.ts @@ -3,7 +3,11 @@ // Definitions by: Cyril Schumacher // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + declare module "vitalsigns" { + import { RequestHandler } from "express"; + namespace vitalsigns { /** * Contraint. @@ -148,6 +152,12 @@ declare module "vitalsigns" { */ destroy(): void; + /** + * Gets a request handler. + * @type {RequestHandler} + */ + express: RequestHandler; + /** * Retrieves an array of human-readable messages that define the specific health constraints that failed when running the last health check. * @returns {Array} An array of failure messages. @@ -160,7 +170,7 @@ declare module "vitalsigns" { * @param {ReportOptions} [options] A mapping of options to customize this report. * @return {Object} The full health report. */ - getReport(options?: vitalsigns.ReportOptions): Object; + getReport(options?: vitalsigns.ReportOptions): {}; /** * Generates a health report and checks each health constraint against it. Any constraints that fail will be added to the 'failed' array in the form of @@ -168,14 +178,14 @@ declare module "vitalsigns" { * @param {Object} [report] A report object on which to run the health constraints. If omitted, this function will generate a health report automatically. * @return {boolean} true if all health constraints passed; false otherwise. */ - isHealthy(report?: Object): boolean; + isHealthy(report?: {}): boolean; /** * Registers monitor. * @param {string} monitorName A monitor name. * @param {MonitorField} [field] Options. */ - monitor(monitor: string | vitalsigns.Monitor | Object, field?: vitalsigns.MonitorField): void; + monitor(monitor: string | vitalsigns.Monitor | {}, field?: vitalsigns.MonitorField): void; /** * Defines a new health constraint in a chainable, more easily readable format.