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
This commit is contained in:
Simcha Wood
2020-01-31 15:13:19 -08:00
committed by GitHub
parent df90a9baed
commit 6880eeb060
5 changed files with 106 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
// Type definitions for winston-loggly-bulk 3.0
// Project: https://github.com/loggly/winston-loggly-bulk
// Definitions by: Simcha Wood <https://github.com/SimchaWood>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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;
+6
View File
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"winston": "^3.0.0"
}
}
+17
View File
@@ -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"]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
@@ -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