From 6051594a617a802fd45f312dcc12e024ff49cb4c Mon Sep 17 00:00:00 2001 From: Rodrigo Saboya Date: Wed, 12 Dec 2018 16:53:23 -0200 Subject: [PATCH] Adding types for hapi-pino. --- types/hapi-pino/hapi-pino-tests.ts | 44 ++++++++++++++++++++++++++++ types/hapi-pino/index.d.ts | 46 ++++++++++++++++++++++++++++++ types/hapi-pino/tsconfig.json | 23 +++++++++++++++ types/hapi-pino/tslint.json | 1 + 4 files changed, 114 insertions(+) create mode 100644 types/hapi-pino/hapi-pino-tests.ts create mode 100644 types/hapi-pino/index.d.ts create mode 100644 types/hapi-pino/tsconfig.json create mode 100644 types/hapi-pino/tslint.json diff --git a/types/hapi-pino/hapi-pino-tests.ts b/types/hapi-pino/hapi-pino-tests.ts new file mode 100644 index 0000000000..eb028d37ad --- /dev/null +++ b/types/hapi-pino/hapi-pino-tests.ts @@ -0,0 +1,44 @@ +import { Server } from 'hapi'; +import * as pino from 'pino'; +import * as HapiPino from 'hapi-pino'; + +const pinoLogger = pino(); + +const server = new Server(); + +server.register({ + plugin: HapiPino, + options: { + logPayload: false, + logRouteTags: false, + stream: process.stdout, + prettyPrint: process.env.NODE_ENV !== 'PRODUCTION', + levelTags: { + trace: 'trace', + debug: 'debug', + info: 'info', + warn: 'warn', + error: 'error' + }, + allTags: 'info', + serializers: { + req: (req: any) => console.log(req) + }, + instance: pinoLogger, + logEvents: false, + mergeHapiLogData: false, + ignorePaths: ['/testRoute'], + level: 'debug', + redact: ['test.property'] + } +}).then(() => { + server.logger().debug('using logger object directly'); + + server.route({ + method: 'GET', + path: '/', + handler: (request, h) => { + request.logger.debug('using logger directly'); + } + }); +}); diff --git a/types/hapi-pino/index.d.ts b/types/hapi-pino/index.d.ts new file mode 100644 index 0000000000..c3f61cbe8d --- /dev/null +++ b/types/hapi-pino/index.d.ts @@ -0,0 +1,46 @@ +// Type definitions for hapi-pino 5.2 +// Project: https://github.com/pinojs/hapi-pino#readme +// Definitions by: Rodrigo Saboya +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/// + +import { + Plugin, +} from 'hapi'; +import * as pino from 'pino'; + +declare module 'hapi' { +interface Server { + logger: () => pino.Logger; +} + +interface Request { + logger: pino.Logger; +} +} + +declare namespace HapiPino { + type LogLevels = 'trace' | 'debug' | 'info' | 'warn' | 'error'; + + interface Options { + logPayload?: boolean; + logRouteTags?: boolean; + stream?: NodeJS.WriteStream; + prettyPrint?: boolean; + levelTags?: { [key in LogLevels]: string }; + allTags?: LogLevels; + serializers?: { [key: string]: (param: any) => void}; + instance?: pino.Logger; + logEvents?: string[] | false | null; + mergeHapiLogData?: boolean; + ignorePaths?: string[]; + level?: LogLevels; + redact?: string[]; + } +} + +declare var HapiPino: Plugin; + +export = HapiPino; diff --git a/types/hapi-pino/tsconfig.json b/types/hapi-pino/tsconfig.json new file mode 100644 index 0000000000..044a1596b4 --- /dev/null +++ b/types/hapi-pino/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", + "hapi-pino-tests.ts" + ] +} diff --git a/types/hapi-pino/tslint.json b/types/hapi-pino/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hapi-pino/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }