diff --git a/types/koa-bunyan-logger/index.d.ts b/types/koa-bunyan-logger/index.d.ts new file mode 100644 index 0000000000..1cf77fec92 --- /dev/null +++ b/types/koa-bunyan-logger/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for koa-bunyan-logger 2.0 +// Project: https://github.com/koajs/bunyan-logger +// Definitions by: Steven McDowall +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { Middleware } from 'koa'; + +import Logger = require('bunyan'); + +export = koaBunyanLogger; + +declare function koaBunyanLogger(logger?: Logger): Middleware; + +// Extend the Koa context to add the logger.. +declare module 'koa' { + // tslint:disable-next-line: interface-name + interface BaseContext { + log: Logger; + } +} diff --git a/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts b/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts new file mode 100644 index 0000000000..daaf26b7a3 --- /dev/null +++ b/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts @@ -0,0 +1,12 @@ +import Koa = require('koa'); +import koaBunyanLogger = require('koa-bunyan-logger'); + +const app = new Koa(); +app.use(koaBunyanLogger()); + +app.use(async (ctx, next) => { + ctx.log.info('Got a request from %s for %s', ctx.request.ip, ctx.path); + await next(); +}); + +app.listen(8000); diff --git a/types/koa-bunyan-logger/tsconfig.json b/types/koa-bunyan-logger/tsconfig.json new file mode 100644 index 0000000000..67657f2ec2 --- /dev/null +++ b/types/koa-bunyan-logger/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "koa-bunyan-logger-tests.ts" + ] +} diff --git a/types/koa-bunyan-logger/tslint.json b/types/koa-bunyan-logger/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/koa-bunyan-logger/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }