From 86f3c3d26c91638ef8069c70228275767869617e Mon Sep 17 00:00:00 2001 From: felix-hoc Date: Fri, 10 Aug 2018 10:44:01 +0200 Subject: [PATCH 1/6] Add types for winston-syslog v2.0.0, move existing types to v1/ --- types/winston-syslog/index.d.ts | 55 +++++++++++-------- types/winston-syslog/package.json | 2 +- types/winston-syslog/tsconfig.json | 4 +- types/winston-syslog/v1/index.d.ts | 25 +++++++++ types/winston-syslog/v1/package.json | 6 ++ types/winston-syslog/v1/tsconfig.json | 32 +++++++++++ types/winston-syslog/v1/tslint.json | 3 + .../winston-syslog/v1/winston-syslog-tests.ts | 35 ++++++++++++ types/winston-syslog/winston-syslog-tests.ts | 19 +++---- 9 files changed, 144 insertions(+), 37 deletions(-) create mode 100644 types/winston-syslog/v1/index.d.ts create mode 100644 types/winston-syslog/v1/package.json create mode 100644 types/winston-syslog/v1/tsconfig.json create mode 100644 types/winston-syslog/v1/tslint.json create mode 100644 types/winston-syslog/v1/winston-syslog-tests.ts diff --git a/types/winston-syslog/index.d.ts b/types/winston-syslog/index.d.ts index 816274ded8..bd0ee54cdf 100644 --- a/types/winston-syslog/index.d.ts +++ b/types/winston-syslog/index.d.ts @@ -1,25 +1,36 @@ -// Type definitions for winston-syslog 1.0 -// Project: https://github.com/indexzero/winston-syslog#readme -// Definitions by: Chris Barth +// Type definitions for winston-syslog v2.0.0 +// Project: https://github.com/winstonjs/winston-syslog +// Definitions by: Felix Hochgruber // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import * as winston from "winston"; -export interface SyslogTransportOptions extends winston.GenericTextTransportOptions { - host?: string; - port?: number; - path?: string; - protocol?: string; - pid?: number; - facility?: string; - localhost?: string; - type?: string; - app_name?: string; - eol?: string; -} -export class Syslog extends winston.Transport implements winston.TransportInstance { -} -declare module "winston" { - interface Transports { - Syslog: Syslog; - } +import * as Transport from 'winston-transport'; +import * as dgram from 'dgram'; +import * as net from 'net'; + +declare module 'winston-syslog' { + + export interface SyslogTransportOptions extends Transport.TransportStreamOptions { + host?: string; + port?: number; + path?: string; + protocol?: string; + pid?: number; + facility?: string; + localhost?: string; + type?: string; + app_name?: string; + eol?: string; + } + + interface SyslogTransportInstance extends Transport { + + producer: any; + socket: dgram.Socket | net.Socket; + + connect(callback: (err: (true | null)) => any): void; + + new(options?: SyslogTransportOptions): SyslogTransportInstance; + } } + +export const Syslog: SyslogTransportInstance; diff --git a/types/winston-syslog/package.json b/types/winston-syslog/package.json index 33e1a4f018..0aa4cf368f 100644 --- a/types/winston-syslog/package.json +++ b/types/winston-syslog/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "@types/winston": "^2.3.9" + "winston": "^3.0.0" } } diff --git a/types/winston-syslog/tsconfig.json b/types/winston-syslog/tsconfig.json index e11a89c680..2c0a6050a4 100644 --- a/types/winston-syslog/tsconfig.json +++ b/types/winston-syslog/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -21,4 +21,4 @@ "index.d.ts", "winston-syslog-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/winston-syslog/v1/index.d.ts b/types/winston-syslog/v1/index.d.ts new file mode 100644 index 0000000000..816274ded8 --- /dev/null +++ b/types/winston-syslog/v1/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for winston-syslog 1.0 +// Project: https://github.com/indexzero/winston-syslog#readme +// Definitions by: Chris Barth +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as winston from "winston"; +export interface SyslogTransportOptions extends winston.GenericTextTransportOptions { + host?: string; + port?: number; + path?: string; + protocol?: string; + pid?: number; + facility?: string; + localhost?: string; + type?: string; + app_name?: string; + eol?: string; +} +export class Syslog extends winston.Transport implements winston.TransportInstance { +} +declare module "winston" { + interface Transports { + Syslog: Syslog; + } +} diff --git a/types/winston-syslog/v1/package.json b/types/winston-syslog/v1/package.json new file mode 100644 index 0000000000..33e1a4f018 --- /dev/null +++ b/types/winston-syslog/v1/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "@types/winston": "^2.3.9" + } +} diff --git a/types/winston-syslog/v1/tsconfig.json b/types/winston-syslog/v1/tsconfig.json new file mode 100644 index 0000000000..610ded1b9b --- /dev/null +++ b/types/winston-syslog/v1/tsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "paths": { + "winston-syslog": [ + "winston-syslog/v1" + ], + "winston-syslog/*": [ + "winston-syslog/v1/*" + ] + }, + "noEmit": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "winston-syslog-tests.ts" + ] +} diff --git a/types/winston-syslog/v1/tslint.json b/types/winston-syslog/v1/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/winston-syslog/v1/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/winston-syslog/v1/winston-syslog-tests.ts b/types/winston-syslog/v1/winston-syslog-tests.ts new file mode 100644 index 0000000000..a08b80b045 --- /dev/null +++ b/types/winston-syslog/v1/winston-syslog-tests.ts @@ -0,0 +1,35 @@ +import winston = require('winston'); +import { SyslogTransportOptions } from 'winston-syslog'; + +const str = ""; +const bool = true; +const num = 1; +const obj: any = {}; + +const syslogOptions: SyslogTransportOptions = { + host: str, + port: num, + path: str, + protocol: str, + pid: num, + facility: str, + localhost: str, + type: str, + app_name: str, + eol: str, + json: bool, + colorize: bool, + colors: str, + prettyPrint: bool, + showLevel: bool, + label: str, + depth: num, +}; + +winston.add(winston.transports.Syslog, syslogOptions); + +const logger: winston.LoggerInstance = new (winston.Logger)({ + transports: [ + new (winston.transports.Syslog)(syslogOptions), + ] +}); diff --git a/types/winston-syslog/winston-syslog-tests.ts b/types/winston-syslog/winston-syslog-tests.ts index a08b80b045..66a4a71e17 100644 --- a/types/winston-syslog/winston-syslog-tests.ts +++ b/types/winston-syslog/winston-syslog-tests.ts @@ -1,5 +1,5 @@ import winston = require('winston'); -import { SyslogTransportOptions } from 'winston-syslog'; +import { Syslog, SyslogTransportOptions } from 'winston-syslog'; const str = ""; const bool = true; @@ -16,20 +16,15 @@ const syslogOptions: SyslogTransportOptions = { localhost: str, type: str, app_name: str, - eol: str, - json: bool, - colorize: bool, - colors: str, - prettyPrint: bool, - showLevel: bool, - label: str, - depth: num, + eol: str }; -winston.add(winston.transports.Syslog, syslogOptions); +const syslogTransport = new Syslog(syslogOptions); -const logger: winston.LoggerInstance = new (winston.Logger)({ +winston.add(syslogTransport); + +const logger: winston.Logger = winston.createLogger({ transports: [ - new (winston.transports.Syslog)(syslogOptions), + syslogTransport ] }); From cb332fb8495d401358b25ae31395bc630612b2f6 Mon Sep 17 00:00:00 2001 From: felix-hoc Date: Fri, 10 Aug 2018 11:24:46 +0200 Subject: [PATCH 2/6] Fix some linting issues. --- types/winston-syslog/index.d.ts | 40 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/types/winston-syslog/index.d.ts b/types/winston-syslog/index.d.ts index bd0ee54cdf..d1517cc957 100644 --- a/types/winston-syslog/index.d.ts +++ b/types/winston-syslog/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for winston-syslog v2.0.0 +// Type definitions for winston-syslog 2.0 // Project: https://github.com/winstonjs/winston-syslog // Definitions by: Felix Hochgruber // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -7,30 +7,26 @@ import * as Transport from 'winston-transport'; import * as dgram from 'dgram'; import * as net from 'net'; -declare module 'winston-syslog' { +export interface SyslogTransportOptions extends Transport.TransportStreamOptions { + host?: string; + port?: number; + path?: string; + protocol?: string; + pid?: number; + facility?: string; + localhost?: string; + type?: string; + app_name?: string; + eol?: string; +} - export interface SyslogTransportOptions extends Transport.TransportStreamOptions { - host?: string; - port?: number; - path?: string; - protocol?: string; - pid?: number; - facility?: string; - localhost?: string; - type?: string; - app_name?: string; - eol?: string; - } +export interface SyslogTransportInstance extends Transport { + producer: any; + socket: dgram.Socket | net.Socket; - interface SyslogTransportInstance extends Transport { + connect(callback: (err: (true | null)) => any): void; - producer: any; - socket: dgram.Socket | net.Socket; - - connect(callback: (err: (true | null)) => any): void; - - new(options?: SyslogTransportOptions): SyslogTransportInstance; - } + new(options?: SyslogTransportOptions): SyslogTransportInstance; } export const Syslog: SyslogTransportInstance; From 94bf96d4288b20ee56b58b6045c5273f9b447c9c Mon Sep 17 00:00:00 2001 From: felix-hoc Date: Fri, 10 Aug 2018 11:50:28 +0200 Subject: [PATCH 3/6] Disable no-misused-new linting rule, so we can stay in line with winston's conventions. See https://github.com/winstonjs/winston-mongodb/blob/master/lib/winston-mongodb.d.ts and https://github.com/winstonjs/winston-daily-rotate-file/blob/master/index.d.ts --- types/winston-syslog/tslint.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/winston-syslog/tslint.json b/types/winston-syslog/tslint.json index f93cf8562a..bf5a9b916f 100644 --- a/types/winston-syslog/tslint.json +++ b/types/winston-syslog/tslint.json @@ -1,3 +1,8 @@ { - "extends": "dtslint/dt.json" + "extends": "dtslint/dt.json", + "rules": { + // This allows to be in line with winston transport types. + // See https://github.com/winstonjs/winston-mongodb/blob/master/lib/winston-mongodb.d.ts and https://github.com/winstonjs/winston-daily-rotate-file/blob/master/index.d.ts + "no-misused-new": false + } } From 779fe35d1a51e3c0261587bc0a138c2bb5526fca Mon Sep 17 00:00:00 2001 From: felix-hoc Date: Tue, 21 Aug 2018 09:17:30 +0200 Subject: [PATCH 4/6] Update owners list. --- types/winston-syslog/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/winston-syslog/index.d.ts b/types/winston-syslog/index.d.ts index d1517cc957..b0409ad4c4 100644 --- a/types/winston-syslog/index.d.ts +++ b/types/winston-syslog/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for winston-syslog 2.0 // Project: https://github.com/winstonjs/winston-syslog -// Definitions by: Felix Hochgruber +// Definitions by: Chris Barth , Felix Hochgruber // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import * as Transport from 'winston-transport'; From d962f8b98f7b08c277a7a60722c852b4fea86a74 Mon Sep 17 00:00:00 2001 From: felix-hoc Date: Tue, 21 Aug 2018 13:20:15 +0200 Subject: [PATCH 5/6] Set Typescript version to 2.9 for old version (v1). --- types/winston-syslog/v1/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/winston-syslog/v1/index.d.ts b/types/winston-syslog/v1/index.d.ts index 816274ded8..b2d5ecfb90 100644 --- a/types/winston-syslog/v1/index.d.ts +++ b/types/winston-syslog/v1/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/indexzero/winston-syslog#readme // Definitions by: Chris Barth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.9 import * as winston from "winston"; export interface SyslogTransportOptions extends winston.GenericTextTransportOptions { From 65574e4f8c8e48f86012b03ef70fd8912f10b658 Mon Sep 17 00:00:00 2001 From: felix-hoc Date: Mon, 27 Aug 2018 10:48:57 +0200 Subject: [PATCH 6/6] Pin @types/winston in v1 to 2.3.9. --- types/winston-syslog/v1/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/winston-syslog/v1/package.json b/types/winston-syslog/v1/package.json index 33e1a4f018..a39b614c7e 100644 --- a/types/winston-syslog/v1/package.json +++ b/types/winston-syslog/v1/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "@types/winston": "^2.3.9" + "@types/winston": "2.3.9" } }