Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change interface to class in exported types #2157

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/// <reference types="node" />

import * as NodeJSStream from "stream";
import * as NodeJSStream from 'stream';

import * as logform from 'logform';
import * as Transport from 'winston-transport';
Expand All @@ -19,7 +19,8 @@ declare namespace winston {
export import transports = Transports;
export import transport = Transport;

interface ExceptionHandler {
class ExceptionHandler {
constructor(logger: Logger);
logger: Logger;
handlers: Map<any, any>;
catcher: Function | boolean;
Expand All @@ -30,11 +31,10 @@ declare namespace winston {
getProcessInfo(): object;
getOsInfo(): object;
getTrace(err: Error): object;

new(logger: Logger): ExceptionHandler;
}

interface RejectionHandler {

class RejectionHandler {
constructor(logger: Logger);
logger: Logger;
handlers: Map<any, any>;
catcher: Function | boolean;
Expand All @@ -45,8 +45,6 @@ declare namespace winston {
getProcessInfo(): object;
getOsInfo(): object;
getTrace(err: Error): object;

new(logger: Logger): RejectionHandler;
}

interface QueryOptions {
Expand All @@ -55,25 +53,30 @@ declare namespace winston {
start?: number;
from?: Date;
until?: Date;
order?: "asc" | "desc";
order?: 'asc' | 'desc';
fields: any;
}

interface Profiler {
class Profiler {
logger: Logger;
start: Number;
done(info?: any): boolean;
}

type LogCallback = (error?: any, level?: string, message?: string, meta?: any) => void;
type LogCallback = (
error?: any,
level?: string,
message?: string,
meta?: any
) => void;

interface LogEntry {
level: string;
message: string;
[optionName: string]: any;
}

interface LogMethod {
interface LogMethod {
(level: string, message: string, callback: LogCallback): Logger;
(level: string, message: string, meta: any, callback: LogCallback): Logger;
(level: string, message: string, ...meta: any[]): Logger;
Expand Down Expand Up @@ -103,7 +106,9 @@ declare namespace winston {
rejectionHandlers?: any;
}

interface Logger extends NodeJSStream.Transform {
class Logger extends NodeJSStream.Transform {
constructor(options?: LoggerOptions);

silent: boolean;
format: logform.Format;
levels: Config.AbstractConfigSetLevels;
Expand Down Expand Up @@ -141,7 +146,10 @@ declare namespace winston {
warning: LeveledLogMethod;
notice: LeveledLogMethod;

query(options?: QueryOptions, callback?: (err: Error, results: any) => void): any;
query(
options?: QueryOptions,
callback?: (err: Error, results: any) => void
): any;
stream(options?: any): NodeJS.ReadableStream;

startTimer(): Profiler;
Expand All @@ -158,11 +166,9 @@ declare namespace winston {
isVerboseEnabled(): boolean;
isDebugEnabled(): boolean;
isSillyEnabled(): boolean;

new(options?: LoggerOptions): Logger;
}

interface Container {
class Container {
loggers: Map<string, Logger>;
options: LoggerOptions;

Expand All @@ -171,13 +177,10 @@ declare namespace winston {
has(id: string): boolean;
close(id?: string): void;

new(options?: LoggerOptions): Container;
constructor(options?: LoggerOptions);
}

let version: string;
let ExceptionHandler: ExceptionHandler;
let RejectionHandler: RejectionHandler;
let Container: Container;
let loggers: Container;

let addColors: (target: Config.AbstractConfigSetColors) => any;
Expand All @@ -194,7 +197,10 @@ declare namespace winston {

// Other pass-through methods routed to the default logger.
let log: LogMethod;
let query: (options?: QueryOptions, callback?: (err: Error, results: any) => void) => any;
let query: (
options?: QueryOptions,
callback?: (err: Error, results: any) => void
) => any;
let stream: (options?: any) => NodeJS.ReadableStream;
let add: (transport: Transport) => Logger;
let remove: (transport: Transport) => Logger;
Expand Down