From a1b491689140719119b09ff7d8ff2abca3aa6c48 Mon Sep 17 00:00:00 2001 From: Elliott Campbell <51933617+ElliottCampbellJHA@users.noreply.github.com> Date: Mon, 9 Sep 2019 12:46:25 -0500 Subject: [PATCH] Add type declarations for [bristol] logger (#38042) * [bristol] Added types for bristol logger * [bristol] made recommended changes for most common use cases --- types/bristol/bristol-tests.ts | 17 ++++++++++++++++ types/bristol/index.d.ts | 36 ++++++++++++++++++++++++++++++++++ types/bristol/tsconfig.json | 23 ++++++++++++++++++++++ types/bristol/tslint.json | 1 + 4 files changed, 77 insertions(+) create mode 100644 types/bristol/bristol-tests.ts create mode 100644 types/bristol/index.d.ts create mode 100644 types/bristol/tsconfig.json create mode 100644 types/bristol/tslint.json diff --git a/types/bristol/bristol-tests.ts b/types/bristol/bristol-tests.ts new file mode 100644 index 0000000000..e1a155a85f --- /dev/null +++ b/types/bristol/bristol-tests.ts @@ -0,0 +1,17 @@ +import bristol = require('bristol'); + +bristol.addTarget('console'); +bristol.info('Things be working.', {}); + +bristol.addTarget('console').withFormatter('human'); +bristol.debug('Hello, world', { code: 404 }); + +const uhoh = { + code: 500, + error: { + message: 'Something broke', + reason: 'idk why though', + }, +}; + +bristol.error('Something went wrong', uhoh); diff --git a/types/bristol/index.d.ts b/types/bristol/index.d.ts new file mode 100644 index 0000000000..0753e55864 --- /dev/null +++ b/types/bristol/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for bristol 0.4 +// Project: https://github.com/TomFrost/Bristol +// Definitions by: Eric Heikes +// Elliott Campbell +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// Caveat: Currently, .d.ts files are unable to handle this package fully +// as it requires both class and namespace be exported. + +interface LogError { + message?: string; + reason?: any; + stack?: any; +} + +interface LogData { + code?: number; + id?: string; + path?: string; + error?: LogError; + data?: any; +} + +declare class Bristol { + addTarget(target: any, opts?: any): any; + withFormatter(formatter: string): any; + withLowestSeverity(severity: string): any; + info(message: string, data: LogData): any; + warn(message: string, data: LogData): any; + error(message: string, data: LogData): any; + debug(message: string, data: LogData): any; +} + +declare const bristol: Bristol; + +export = bristol; diff --git a/types/bristol/tsconfig.json b/types/bristol/tsconfig.json new file mode 100644 index 0000000000..650c167ed0 --- /dev/null +++ b/types/bristol/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "bristol-tests.ts" + ] +} diff --git a/types/bristol/tslint.json b/types/bristol/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/bristol/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }