mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
express-winston: Provides its own types (#39612)
This commit is contained in:
committed by
Jesse Trinity
parent
4f05aeed7e
commit
7eee597922
@@ -990,6 +990,12 @@
|
||||
"sourceRepoURL": "https://github.com/ctavan/express-validator",
|
||||
"asOfVersion": "3.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "express-winston",
|
||||
"typingsPackageName": "express-winston",
|
||||
"sourceRepoURL": "https://github.com/bithavoc/express-winston#readme",
|
||||
"asOfVersion": "4.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "extended-listbox",
|
||||
"typingsPackageName": "extended-listbox",
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
import expressWinston = require('express-winston');
|
||||
import * as winston from 'winston';
|
||||
import express = require('express');
|
||||
import { Format } from 'logform';
|
||||
|
||||
const app = express();
|
||||
|
||||
// Logger with all options
|
||||
app.use(expressWinston.logger({
|
||||
baseMeta: { foo: 'foo', nested: { bar: 'baz' } },
|
||||
bodyBlacklist: ['foo'],
|
||||
bodyWhitelist: ['bar'],
|
||||
colorize: true,
|
||||
dynamicMeta: (req, res, err) => ({ foo: 'bar' }),
|
||||
expressFormat: true,
|
||||
format: new Format(),
|
||||
ignoreRoute: (req, res) => true,
|
||||
ignoredRoutes: ['foo'],
|
||||
level: (req, res) => 'level',
|
||||
meta: true,
|
||||
metaField: 'metaField',
|
||||
msg: 'msg',
|
||||
requestFilter: (req, prop) => req[prop],
|
||||
requestWhitelist: ['foo', 'bar'],
|
||||
skip: (req, res) => false,
|
||||
statusLevels: ({ error: 'error', success: 'success', warn: 'warn' }),
|
||||
transports: [
|
||||
new winston.transports.Console({})
|
||||
]
|
||||
}));
|
||||
|
||||
// Logger with minimum options (transport)
|
||||
app.use(expressWinston.logger({
|
||||
transports: [
|
||||
new winston.transports.Console({})
|
||||
],
|
||||
}));
|
||||
|
||||
const logger = winston.createLogger();
|
||||
|
||||
// Logger with minimum options (winstonInstance)
|
||||
app.use(expressWinston.logger({
|
||||
winstonInstance: logger,
|
||||
}));
|
||||
|
||||
// Error Logger with all options
|
||||
app.use(expressWinston.errorLogger({
|
||||
baseMeta: { foo: 'foo', nested: { bar: 'baz' } },
|
||||
dynamicMeta: (req, res, err) => ({ foo: 'bar' }),
|
||||
format: new Format(),
|
||||
level: (req, res) => 'level',
|
||||
metaField: 'metaField',
|
||||
msg: 'msg',
|
||||
requestFilter: (req, prop) => true,
|
||||
requestWhitelist: ['foo', 'bar'],
|
||||
transports: [
|
||||
new winston.transports.Console({})
|
||||
]
|
||||
}));
|
||||
|
||||
// Error Logger with min options (transports)
|
||||
app.use(expressWinston.errorLogger({
|
||||
transports: [
|
||||
new winston.transports.Console({})
|
||||
],
|
||||
}));
|
||||
|
||||
// Error Logger with min options (winstonInstance)
|
||||
app.use(expressWinston.errorLogger({
|
||||
winstonInstance: logger,
|
||||
}));
|
||||
|
||||
// Request and error logger with function type msg
|
||||
app.use(expressWinston.logger({
|
||||
msg: (req, res) => `HTTP ${req.method} ${req.url} - ${res.statusCode}`,
|
||||
transports: [
|
||||
new winston.transports.Console({})
|
||||
],
|
||||
}));
|
||||
|
||||
app.use(expressWinston.errorLogger({
|
||||
msg: (req, res) => `HTTP ${req.method} ${req.url} - ${res.statusCode}`,
|
||||
winstonInstance: logger,
|
||||
}));
|
||||
|
||||
expressWinston.bodyBlacklist.push('potato');
|
||||
expressWinston.bodyWhitelist.push('apple');
|
||||
expressWinston.defaultRequestFilter = (req: expressWinston.FilterRequest, prop: string) => req[prop];
|
||||
expressWinston.defaultResponseFilter = (res: expressWinston.FilterResponse, prop: string) => res[prop];
|
||||
expressWinston.defaultSkip = () => true;
|
||||
expressWinston.ignoredRoutes.push('/ignored');
|
||||
expressWinston.responseWhitelist.push('body');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/user/register', (req, res, next) => {
|
||||
const expressWinstonReq = req as expressWinston.ExpressWinstonRequest;
|
||||
expressWinstonReq._routeWhitelists.body = ['username', 'email', 'age'];
|
||||
expressWinstonReq._routeWhitelists.req = ['userId'];
|
||||
expressWinstonReq._routeWhitelists.res = ['_headers'];
|
||||
});
|
||||
Vendored
-110
@@ -1,110 +0,0 @@
|
||||
// Type definitions for express-winston 3.0
|
||||
// Project: https://github.com/bithavoc/express-winston#readme
|
||||
// Definitions by: Alex Brick <https://github.com/bricka>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { ErrorRequestHandler, Handler, Request, Response } from 'express';
|
||||
import { Format } from 'logform';
|
||||
import * as winston from 'winston';
|
||||
import * as Transport from 'winston-transport';
|
||||
|
||||
export interface FilterRequest extends Request {
|
||||
[other: string]: any;
|
||||
}
|
||||
|
||||
export interface FilterResponse extends Response {
|
||||
[other: string]: any;
|
||||
}
|
||||
|
||||
export type DynamicMetaFunction = (req: Request, res: Response, err: Error) => object;
|
||||
export type DynamicLevelFunction = (req: Request, res: Response, err: Error) => string;
|
||||
export type RequestFilter = (req: FilterRequest, propName: string) => any;
|
||||
export type ResponseFilter = (res: FilterResponse, propName: string) => any;
|
||||
export type RouteFilter = (req: Request, res: Response) => boolean;
|
||||
export type MessageTemplate = string | ((req: Request, res: Response) => string);
|
||||
|
||||
export interface BaseLoggerOptions {
|
||||
baseMeta?: object;
|
||||
bodyBlacklist?: string[];
|
||||
bodyWhitelist?: string[];
|
||||
colorize?: boolean;
|
||||
dynamicMeta?: DynamicMetaFunction;
|
||||
expressFormat?: boolean;
|
||||
format?: Format;
|
||||
ignoreRoute?: RouteFilter;
|
||||
ignoredRoutes?: string[];
|
||||
level?: string | DynamicLevelFunction;
|
||||
meta?: boolean;
|
||||
metaField?: string;
|
||||
msg?: MessageTemplate;
|
||||
requestFilter?: RequestFilter;
|
||||
requestWhitelist?: string[];
|
||||
responseFilter?: ResponseFilter;
|
||||
responseWhitelist?: string[];
|
||||
skip?: RouteFilter;
|
||||
statusLevels?: {
|
||||
error?: string;
|
||||
success?: string;
|
||||
warn?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface LoggerOptionsWithTransports extends BaseLoggerOptions {
|
||||
transports: Transport[];
|
||||
}
|
||||
|
||||
export interface LoggerOptionsWithWinstonInstance extends BaseLoggerOptions {
|
||||
winstonInstance: winston.Logger;
|
||||
}
|
||||
|
||||
export type LoggerOptions = LoggerOptionsWithTransports | LoggerOptionsWithWinstonInstance;
|
||||
|
||||
export function logger(options: LoggerOptions): Handler;
|
||||
|
||||
export interface BaseErrorLoggerOptions {
|
||||
baseMeta?: object;
|
||||
dynamicMeta?: DynamicMetaFunction;
|
||||
format?: Format;
|
||||
level?: string | DynamicLevelFunction;
|
||||
metaField?: string;
|
||||
msg?: MessageTemplate;
|
||||
requestFilter?: RequestFilter;
|
||||
requestWhitelist?: string[];
|
||||
}
|
||||
|
||||
export interface ErrorLoggerOptionsWithTransports extends BaseErrorLoggerOptions {
|
||||
transports: Transport[];
|
||||
}
|
||||
|
||||
export interface ErrorLoggerOptionsWithWinstonInstance extends BaseErrorLoggerOptions {
|
||||
winstonInstance: winston.Logger;
|
||||
}
|
||||
|
||||
export type ErrorLoggerOptions = ErrorLoggerOptionsWithTransports | ErrorLoggerOptionsWithWinstonInstance;
|
||||
|
||||
export function errorLogger(options: ErrorLoggerOptions): ErrorRequestHandler;
|
||||
|
||||
export let requestWhitelist: string[];
|
||||
|
||||
export let bodyWhitelist: string[];
|
||||
|
||||
export let bodyBlacklist: string[];
|
||||
|
||||
export let responseWhitelist: string[];
|
||||
|
||||
export let ignoredRoutes: string[];
|
||||
|
||||
export let defaultRequestFilter: RequestFilter;
|
||||
|
||||
export let defaultResponseFilter: ResponseFilter;
|
||||
|
||||
export function defaultSkip(): boolean;
|
||||
|
||||
export interface ExpressWinstonRequest extends Request {
|
||||
_routeWhitelists: {
|
||||
body: string[];
|
||||
req: string[];
|
||||
res: string[];
|
||||
};
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"winston": "^3.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"express-winston-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user