From 85de4c36158892ca3debd598ebcf77bfcf0748fd Mon Sep 17 00:00:00 2001 From: Steven McDowall Date: Wed, 29 Aug 2018 15:27:12 -0400 Subject: [PATCH 1/2] 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" } From 69990795c524ad2d860b7407c206468f0f8cd6c1 Mon Sep 17 00:00:00 2001 From: Steven McDowall Date: Mon, 3 Sep 2018 20:40:41 -0400 Subject: [PATCH 2/2] Next try! I think I have this figured out ?? --- types/koa-bunyan-logger/index.d.ts | 6 ++++-- types/koa-bunyan-logger/koa-bunyan-logger-tests.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/types/koa-bunyan-logger/index.d.ts b/types/koa-bunyan-logger/index.d.ts index 9e59f876e0..1cf77fec92 100644 --- a/types/koa-bunyan-logger/index.d.ts +++ b/types/koa-bunyan-logger/index.d.ts @@ -6,9 +6,11 @@ import { Middleware } from 'koa'; -import * as Logger from 'bunyan'; +import Logger = require('bunyan'); -export default function(logger?: Logger): Middleware; +export = koaBunyanLogger; + +declare function koaBunyanLogger(logger?: Logger): Middleware; // Extend the Koa context to add the logger.. declare module 'koa' { diff --git a/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts b/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts index 5f1bd1e263..daaf26b7a3 100644 --- a/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts +++ b/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts @@ -1,5 +1,5 @@ -import * as Koa from 'koa'; -import koaBunyanLogger from 'koa-bunyan-logger'; +import Koa = require('koa'); +import koaBunyanLogger = require('koa-bunyan-logger'); const app = new Koa(); app.use(koaBunyanLogger());