From 85de4c36158892ca3debd598ebcf77bfcf0748fd Mon Sep 17 00:00:00 2001 From: Steven McDowall Date: Wed, 29 Aug 2018 15:27:12 -0400 Subject: [PATCH] Attempt number 2 for PR Ok -- cleaned up a lot of stuff -- but lost my master branch etc. so started over. Sorry! --- types/koa-bunyan-logger/index.d.ts | 19 +++++++++++++++ .../koa-bunyan-logger-tests.ts | 12 ++++++++++ types/koa-bunyan-logger/tsconfig.json | 23 +++++++++++++++++++ types/koa-bunyan-logger/tslint.json | 1 + 4 files changed, 55 insertions(+) create mode 100644 types/koa-bunyan-logger/index.d.ts create mode 100644 types/koa-bunyan-logger/koa-bunyan-logger-tests.ts create mode 100644 types/koa-bunyan-logger/tsconfig.json create mode 100644 types/koa-bunyan-logger/tslint.json diff --git a/types/koa-bunyan-logger/index.d.ts b/types/koa-bunyan-logger/index.d.ts new file mode 100644 index 0000000000..9e59f876e0 --- /dev/null +++ b/types/koa-bunyan-logger/index.d.ts @@ -0,0 +1,19 @@ +// 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 * as Logger from 'bunyan'; + +export default function(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..5f1bd1e263 --- /dev/null +++ b/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts @@ -0,0 +1,12 @@ +import * as Koa from 'koa'; +import koaBunyanLogger from '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" }