From 6880eeb0608ba5c0d167fdf2de7063240dcc9b1e Mon Sep 17 00:00:00 2001 From: Simcha Wood <31593126+SimchaWood@users.noreply.github.com> Date: Fri, 31 Jan 2020 18:13:19 -0500 Subject: [PATCH] Add types package for winston-loggly-bulk (#41994) * Add types for winston-loggly-bulk * Fix tsconfig.json * Fix Loggly class and update tslint.json * Fixed tsconfig.json and adjusted exports * Fix for failing tests * Add needed extend to Loggly class --- types/winston-loggly-bulk/index.d.ts | 55 +++++++++++++++++++ types/winston-loggly-bulk/package.json | 6 ++ types/winston-loggly-bulk/tsconfig.json | 17 ++++++ types/winston-loggly-bulk/tslint.json | 3 + .../winston-loggly-bulk-tests.ts | 25 +++++++++ 5 files changed, 106 insertions(+) create mode 100644 types/winston-loggly-bulk/index.d.ts create mode 100644 types/winston-loggly-bulk/package.json create mode 100644 types/winston-loggly-bulk/tsconfig.json create mode 100644 types/winston-loggly-bulk/tslint.json create mode 100644 types/winston-loggly-bulk/winston-loggly-bulk-tests.ts diff --git a/types/winston-loggly-bulk/index.d.ts b/types/winston-loggly-bulk/index.d.ts new file mode 100644 index 0000000000..e98e710875 --- /dev/null +++ b/types/winston-loggly-bulk/index.d.ts @@ -0,0 +1,55 @@ +// Type definitions for winston-loggly-bulk 3.0 +// Project: https://github.com/loggly/winston-loggly-bulk +// Definitions by: Simcha Wood +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Url } from 'url'; +import TransportStream = require('winston-transport'); + +export interface BufferOptions { + size: number; + retriesInMilliseconds: number; +} + +export interface LogglyOptions extends TransportStream.TransportStreamOptions { + auth?: { + username: string; + password: string; + } | null; + bufferOptions?: BufferOptions; + isBulk?: boolean; + json?: boolean; + networkErrorOnConsole?: boolean; + proxy?: null | string | Url; + stripColors?: boolean; + subdomain: string; + tags?: string[]; + timestamp?: boolean; + token: string; +} + +export class Loggly extends TransportStream { + constructor(options?: LogglyOptions); + + extend(destination: any, source: any): any; + + extractContext(obj: any): any; + + formatQuery(query: any): any; + + formatResults(results: any, _options: any): any; + + log(meta: any, callback: any): any; + + loglify(obj: any): any; + + query(options: any, callback: any): any; + + sanitizeLogs(logs: any): any; + + stream(maybeOptions: any): any; +} + +export function flushLogsAndExit(): void; diff --git a/types/winston-loggly-bulk/package.json b/types/winston-loggly-bulk/package.json new file mode 100644 index 0000000000..0aa4cf368f --- /dev/null +++ b/types/winston-loggly-bulk/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "winston": "^3.0.0" + } +} diff --git a/types/winston-loggly-bulk/tsconfig.json b/types/winston-loggly-bulk/tsconfig.json new file mode 100644 index 0000000000..31ee511a93 --- /dev/null +++ b/types/winston-loggly-bulk/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "esModuleInterop": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "forceConsistentCasingInFileNames": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true + }, + "files": ["index.d.ts", "winston-loggly-bulk-tests.ts"] +} diff --git a/types/winston-loggly-bulk/tslint.json b/types/winston-loggly-bulk/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/winston-loggly-bulk/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/winston-loggly-bulk/winston-loggly-bulk-tests.ts b/types/winston-loggly-bulk/winston-loggly-bulk-tests.ts new file mode 100644 index 0000000000..a2be0e6db2 --- /dev/null +++ b/types/winston-loggly-bulk/winston-loggly-bulk-tests.ts @@ -0,0 +1,25 @@ +import { Loggly, flushLogsAndExit } from 'winston-loggly-bulk'; + +const loggly = new Loggly({ + auth: { + username: 'user', + password: 'guest', + }, + bufferOptions: { + size: 500, + retriesInMilliseconds: 30000, + }, + isBulk: false, + json: true, + networkErrorOnConsole: false, + proxy: 'www.example.com', + stripColors: true, + subdomain: 'my_subdomain', + tags: ['NodeJS'], + timestamp: true, + token: 'mysupersecrettoken', +}); + +loggly; // $ExpectType Loggly + +flushLogsAndExit(); // $ExpectType void