From e70729bb8302ab6f31ca68ca21c24c2929c05290 Mon Sep 17 00:00:00 2001 From: Matthew Hintzke Date: Fri, 13 Dec 2019 11:51:27 -0800 Subject: [PATCH] Adding TypeScript support for "datadog-winston" (#37983) * Added typings for datadog-winston * Updated comments * Fixing comments which will also kick the Git checks * Apparently I can't have a PATCH in my version. I thought this was supposed to be the version of the JS package my types target * Ahh I see now, it is the version of the JS package, just with PATCH omitted * Updated library to use CommonJS style imports * Formatting * Fixing to not use a declare module * Fixing whitespace * Fixed typo * Adding options into a namespace so it can be referenced by consumer --- .../datadog-winston/datadog-winston-tests.ts | 12 +++++++++ types/datadog-winston/index.d.ts | 25 +++++++++++++++++++ types/datadog-winston/package.json | 6 +++++ types/datadog-winston/tsconfig.json | 23 +++++++++++++++++ types/datadog-winston/tslint.json | 1 + 5 files changed, 67 insertions(+) create mode 100644 types/datadog-winston/datadog-winston-tests.ts create mode 100644 types/datadog-winston/index.d.ts create mode 100644 types/datadog-winston/package.json create mode 100644 types/datadog-winston/tsconfig.json create mode 100644 types/datadog-winston/tslint.json diff --git a/types/datadog-winston/datadog-winston-tests.ts b/types/datadog-winston/datadog-winston-tests.ts new file mode 100644 index 0000000000..4795fee12a --- /dev/null +++ b/types/datadog-winston/datadog-winston-tests.ts @@ -0,0 +1,12 @@ +import DatadogWinston = require("datadog-winston"); + +const options: DatadogWinston.DatadogTransportOptions = { + apiKey: '', + ddsource: 'node.js', + ddtags: 'key:value', + hostname: 'hostname', + level: 'error', + service: 'service', +}; + +const logger = new DatadogWinston(options); diff --git a/types/datadog-winston/index.d.ts b/types/datadog-winston/index.d.ts new file mode 100644 index 0000000000..7816c66b42 --- /dev/null +++ b/types/datadog-winston/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for datadog-winston 1.0 +// Project: https://github.com/itsfadnis/datadog-winston +// Definitions by: Matt Hintzke +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +import * as Transport from "winston-transport"; + +declare namespace DatadogWinston { + interface DatadogTransportOptions extends Transport.TransportStreamOptions { + apiKey: string; + hostname?: string; + service?: string; + ddsource?: string; + ddtags?: string; + } +} + +declare class DatadogWinston extends Transport { + constructor(options: DatadogWinston.DatadogTransportOptions); + + log?(info: any, next: () => void): void; +} + +export = DatadogWinston; diff --git a/types/datadog-winston/package.json b/types/datadog-winston/package.json new file mode 100644 index 0000000000..ae2c526fc1 --- /dev/null +++ b/types/datadog-winston/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "winston-transport": "^4.3.0" + } +} diff --git a/types/datadog-winston/tsconfig.json b/types/datadog-winston/tsconfig.json new file mode 100644 index 0000000000..ef82da74e4 --- /dev/null +++ b/types/datadog-winston/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "datadog-winston-tests.ts" + ] +} diff --git a/types/datadog-winston/tslint.json b/types/datadog-winston/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/datadog-winston/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }