From df625fba9ac07b52ccc3c8b422017842daeea016 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Fri, 30 Sep 2016 14:38:28 +0200 Subject: [PATCH] Add definitions for: "bunyan-config", "express-mung", "node-vitalsigns" and "memwatch-next" (#11285) * Add definition for "bunnymq". * Add definition for "strftime". * Add definitions for: "bunyan-config", "express-mung" and "node-vitalsigns". * Add definitions for: "bunyan-config", "express-mung" and "node-vitalsigns". * Add definition for "memwatch-next". * Fix project URL address. * Rename "node-vitalsigns" to "vitalsigns". * Update definitions. * Use {} instead of "Object" type. Remove unnecessary namespace for "memwatch-next" definition. Rewrite "bunyan-config" definition. * Replace "Object" by "{}". --- bunyan-config/bunyan-config-tests.ts | 41 ++++++ bunyan-config/bunyan-config.d.ts | 31 +++++ express-mung/express-mung-tests.ts | 9 ++ express-mung/express-mung.d.ts | 43 ++++++ memwatch-next/memwatch-next-tests.ts | 8 ++ memwatch-next/memwatch-next.d.ts | 71 ++++++++++ vitalsigns/vitalsigns-tests.ts | 25 ++++ vitalsigns/vitalsigns.d.ts | 192 +++++++++++++++++++++++++++ 8 files changed, 420 insertions(+) create mode 100644 bunyan-config/bunyan-config-tests.ts create mode 100644 bunyan-config/bunyan-config.d.ts create mode 100644 express-mung/express-mung-tests.ts create mode 100644 express-mung/express-mung.d.ts create mode 100644 memwatch-next/memwatch-next-tests.ts create mode 100644 memwatch-next/memwatch-next.d.ts create mode 100644 vitalsigns/vitalsigns-tests.ts create mode 100644 vitalsigns/vitalsigns.d.ts diff --git a/bunyan-config/bunyan-config-tests.ts b/bunyan-config/bunyan-config-tests.ts new file mode 100644 index 0000000000..6a15aff601 --- /dev/null +++ b/bunyan-config/bunyan-config-tests.ts @@ -0,0 +1,41 @@ +/// + +import * as bunyan from "bunyan"; +import bunyanConfig from "bunyan-config"; + +var jsonConfig = { + name: "myLogger", + streams: [{ + stream: "stdout" + }, { + stream: { name: "stderr" } + }, { + type: "raw", + stream: { + name: "bunyan-logstash", + params: { + host: "localhost", + port: 5005 + } + } + }, { + type: "raw", + stream: { + name: "bunyan-redis", + params: { + host: "localhost", + port: 6379 + } + } + }], serializers: { + req: "bunyan:stdSerializers.req", + fromNodeModules: "someNodeModule", + fromNodeModulesWithProps: "someNodeModule:a.b.c", + custom: "./lib/customSerializers:custom", + another: "./lib/anotherSerializer", + absolutePath: "/path/to/serializer:xyz" + } +}; + +var config = bunyanConfig(jsonConfig); +var logger = require("bunyan").createLogger(bunyanConfig); diff --git a/bunyan-config/bunyan-config.d.ts b/bunyan-config/bunyan-config.d.ts new file mode 100644 index 0000000000..68a095b9b8 --- /dev/null +++ b/bunyan-config/bunyan-config.d.ts @@ -0,0 +1,31 @@ +// Type definitions for bunyan-config 0.2.0 +// Project: https://github.com/LSEducation/bunyan-config +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "bunyan-config" { + import * as bunyan from "bunyan"; + + /** + * Configuration. + * @interface + */ + interface Configuration { + name: string; + streams?: bunyan.Stream[]; + level?: string | number; + stream?: NodeJS.WritableStream; + serializers?: {}; + src?: boolean; + } + + /** + * Constructor. + * @param {Configuration} [jsonConfig] A JSON configuration. + * @return {LoggerOptions} A logger options. + */ + function bunyanConfig(jsonConfig?: Configuration): bunyan.LoggerOptions; + export default bunyanConfig; +} diff --git a/express-mung/express-mung-tests.ts b/express-mung/express-mung-tests.ts new file mode 100644 index 0000000000..c4ab59f0e6 --- /dev/null +++ b/express-mung/express-mung-tests.ts @@ -0,0 +1,9 @@ +/// + +import { Request, Response } from "express"; +import * as mung from "express-mung"; + +function redact(body: Object, req: Request, res: Response) { +    return body; +} +mung.json(redact); diff --git a/express-mung/express-mung.d.ts b/express-mung/express-mung.d.ts new file mode 100644 index 0000000000..6dfee7d557 --- /dev/null +++ b/express-mung/express-mung.d.ts @@ -0,0 +1,43 @@ +// Type definitions for express-mung 0.4.2 +// Project: https://github.com/richardschneider/express-mung +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +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) => {}; + + /** + * Transform the JSON body of the response. + * @param {Transform} fn A transformation function. + * @return {any} The body. + */ + export function json(fn: Transform): any; + + /** + * Transform the JSON body of the response. + * @param {Transform} fn A transformation function. + * @return {any} The body. + */ + export function jsonAsync(fn: Transform): PromiseLike; + + /** + * Transform the HTTP headers of the response. + * @param {Transform} fn A transformation function. + * @return {any} The body. + */ + export function headers(fn: TransformHeader): any; + + /** + * Transform the HTTP headers of the response. + * @param {Transform} fn A transformation function. + * @return {any} The body. + */ + export function headersAsync(fn: TransformHeader): PromiseLike; +} diff --git a/memwatch-next/memwatch-next-tests.ts b/memwatch-next/memwatch-next-tests.ts new file mode 100644 index 0000000000..231c702f00 --- /dev/null +++ b/memwatch-next/memwatch-next-tests.ts @@ -0,0 +1,8 @@ +/// + +import * as memwatch from "memwatch-next"; + +memwatch.on('leak', function (info) { }); + +var hd = new memwatch.HeapDiff(); +var diff = hd.end(); \ No newline at end of file diff --git a/memwatch-next/memwatch-next.d.ts b/memwatch-next/memwatch-next.d.ts new file mode 100644 index 0000000000..aba3dfebcc --- /dev/null +++ b/memwatch-next/memwatch-next.d.ts @@ -0,0 +1,71 @@ +// Type definitions for memwatch-next 0.3.0 +// Project: https://github.com/marcominetti/node-memwatch +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "memwatch-next" { + type EventCallback = (data: LeakInformation | StatsInformation | Object) => void; + + /** + * Compare the state of your heap between two points in time, telling you what has been allocated, and what has been released. + * @class + */ + export class HeapDiff { + /** + * Compute the diff. + */ + end: () => void; + } + + /** + * Stats information. + * @interface + */ + export interface StatsInformation { + current_base: number; + estimated_base: number; + heap_compactions: number; + max: number; + min: number; + num_full_gc: number; + num_inc_gc: number; + usage_trend: number; + } + + /** + * Leak information. + * @interface + */ + export interface LeakInformation { + /** + * End date. + * @type {Date} + */ + end: Date, + + /** + * Growth. + * @type {number} + */ + growth: number; + + /** + * Reason leak. + * @type {string} + */ + reason: string; + + /** + * Start date. + * @type {Date} + */ + start: Date; + } + + /** + * Subscribe to a event. + * @param {string} eventName A event name. + * @param {EventCallback} callback A callback; + */ + export function on(eventName: string, callback: EventCallback): void; +} \ No newline at end of file diff --git a/vitalsigns/vitalsigns-tests.ts b/vitalsigns/vitalsigns-tests.ts new file mode 100644 index 0000000000..1e22dec433 --- /dev/null +++ b/vitalsigns/vitalsigns-tests.ts @@ -0,0 +1,25 @@ +/// + +import VitalSigns = require("vitalsigns"); + +var vitals = new VitalSigns(); + +vitals.monitor('cpu'); +vitals.monitor('mem', {units: 'MB'}); +vitals.monitor('tick'); + +vitals.unhealthyWhen('cpu', 'usage').equals(100); +vitals.unhealthyWhen('tick', 'maxMs').greaterThan(500); + +vitals.monitor({ + connections: () => new Object() +}, {name: 'game'}); + +var vitals = new VitalSigns({ + autoCheck: 5000, + httpHealthy: 200, + httpUnhealthy: 503 +}); + +vitals.monitor('cpu', {name: 'foo'}); +vitals.unhealthyWhen('foo', 'bar').not.greaterThan(5); diff --git a/vitalsigns/vitalsigns.d.ts b/vitalsigns/vitalsigns.d.ts new file mode 100644 index 0000000000..c74a42f08a --- /dev/null +++ b/vitalsigns/vitalsigns.d.ts @@ -0,0 +1,192 @@ +// Type definitions for vitalsigns 0.4.3 +// Project: https://github.com/TomFrost/node-vitalsigns +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "vitalsigns" { + namespace vitalsigns { + /** + * Contraint. + * @interface + */ + export interface Constraint { + /** + * The comparator to use when comparing the field's value with the constraint value. + * Valid comparators are: 'equal', 'greater', and 'less'. + * @type {string} + */ + comparator: string; + + /** + * The name of the field to be constrained. + * @type {string} + */ + field: string; + + /** + * The name of the monitor containing the field to be constrained. + * @type {string} + */ + monitor: string; + + /** + * true to negate the outcome of the comparison; false or omitted to use the comparison result. + * @type {boolean} + */ + negate?: boolean; + + /** + * The value against which the field should be compared. + * @type {any} + */ + value: any; + } + + /** + * Constraint wrapper. + * @interface + */ + export interface ConstraintWrapper { + equals?: (num: number) => ConstraintWrapper; + + greaterThan?: (num: number) => ConstraintWrapper; + + lessThan?: (num: number) => ConstraintWrapper; + + not?: ConstraintWrapper; + } + + /** + * Options. + * @interface + */ + export interface Options { + /** + * Number of milliseconds to wait between automatic health checks. + * @type {number|boolean} + */ + autoCheck?: number | boolean; + + /** + * HTTP response code to send back in the VitalSigns. + * @type {number} + */ + httpHealthy?: number; + + /** + * HTTP response code to send back in the VitalSigns. + * @type {number} + */ + httpUnhealthy?: number; + } + + export interface Monitor { + /** + * Connections. + * @type {any} + */ + connections: any; + } + + /** + * Monitor field. + * @interface + */ + export interface MonitorField { + /** + * Name. + * @type {string} + */ + name?: string; + + /** + * Units. + * @type {string} + */ + units?: string; + } + + /** + * Report options. + * @interface + */ + interface ReportOptions { + /** + * true to flatten the report object down to a single level by concatenating nested key names; false to keep the default hierarchical format. + * @type {boolean} + */ + flatten?: boolean; + + /** + * If flatten is true, this string will be used to separate key names when they are concatenated together. + * @type {boolean} + */ + separator?: string; + } + } + + /** + * VitalSigns instance. + */ + class VitalSigns { + /** + * Constructor. + * @constructors + * @param {Options} [options] Options. + */ + constructor (options?: vitalsigns.Options); + + /** + * Pushes a health constraint onto this instance's constraint array. + * Health constraints define scenarios in which VitalSigns will consider the application to be in an unhealthy state. + * @param {} constraint A constraint. + */ + addConstraint(): void; + + /** + * Destroys this VitalSigns instance. + */ + destroy(): void; + + /** + * 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. + */ + getFailed(): Array; + + /** + * Gets a report of all monitors, their fields, and the values of those fields, compiled into Javascript object form. Additionally, a 'healthy' field is + * attached. This field will be boolean true if all health constraints passed; false otherwise. + * @param {ReportOptions} [options] A mapping of options to customize this report. + * @return {Object} The full health report. + */ + getReport(options?: vitalsigns.ReportOptions): Object; + + /** + * 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 + * a human-readable failure message, which can be retrieved with {@link #getFailed}. + * @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; + + /** + * Registers monitor. + * @param {string} monitorName A monitor name. + * @param {MonitorField} [field] Options. + */ + monitor(monitor: string | vitalsigns.Monitor | Object, field?: vitalsigns.MonitorField): void; + + /** + * Defines a new health constraint in a chainable, more easily readable format. + * When called with the monitor name and field name of concern, a wrapper is + * returned that allows the constraint to be built out with function calls. + * @param {string} monitorName A monitor name. + * @param {string} fieldName A field name. + * @return {ConstraintWrapper} The constraint wrapper. + */ + unhealthyWhen: (monitorName: string, fieldName: string) => vitalsigns.ConstraintWrapper; + } + + export = VitalSigns; +}