From a12da99962194847264da457678a274f6cc2e7db Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Tue, 30 Oct 2018 10:45:23 +0100 Subject: [PATCH 1/4] Add sonic-boom package --- types/sonic-boom/index.d.ts | 50 ++++++++++++++++++++++++++++ types/sonic-boom/sonic-boom-tests.ts | 19 +++++++++++ types/sonic-boom/tsconfig.json | 23 +++++++++++++ types/sonic-boom/tslint.json | 1 + 4 files changed, 93 insertions(+) create mode 100644 types/sonic-boom/index.d.ts create mode 100644 types/sonic-boom/sonic-boom-tests.ts create mode 100644 types/sonic-boom/tsconfig.json create mode 100644 types/sonic-boom/tslint.json diff --git a/types/sonic-boom/index.d.ts b/types/sonic-boom/index.d.ts new file mode 100644 index 0000000000..eca15c0cb7 --- /dev/null +++ b/types/sonic-boom/index.d.ts @@ -0,0 +1,50 @@ +// Type definitions for sonic-boom 0.6 +// Project: https://github.com/mcollina/sonic-boom.git +// Definitions by: Alex Ferrando +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { EventEmitter } from 'events'; + +export = SonicBoom + +declare class SonicBoom extends EventEmitter { + /** + * @param [fileDescriptor] File path or numerical file descriptor + * relative protocol is enabled. Default: process.stdout + * @returns a new sonic-boom instance + */ + constructor(fileDescriptor: String | Number) + + /** + * Writes the string to the file. It will return false to signal the producer to slow down. + */ + write(string: String): void; + + /** + * Writes the current buffer to the file if a write was not in progress. + * Do nothing if minLength is zero or if it is already writing. + */ + flush(): void; + + /** + * Reopen the file in place, useful for log rotation. + */ + reopen(file: String): void; + + /** + * Flushes the buffered data synchronously. This is a costly operation. + */ + flushSync(): void; + + /** + * Closes the stream, the data will be flushed down asynchronously + */ + end(): void; + + /** + * Closes the stream immediately, the data is not flushed. + */ + destroy(): void; +} diff --git a/types/sonic-boom/sonic-boom-tests.ts b/types/sonic-boom/sonic-boom-tests.ts new file mode 100644 index 0000000000..a819ec635f --- /dev/null +++ b/types/sonic-boom/sonic-boom-tests.ts @@ -0,0 +1,19 @@ + +import SonicBoom = require('sonic-boom') +const sonic = new SonicBoom(1) + +sonic.write('hello sonic\n') + +sonic.flush() + +sonic.flushSync() + +sonic.end() + +sonic.destroy() + + + + + + diff --git a/types/sonic-boom/tsconfig.json b/types/sonic-boom/tsconfig.json new file mode 100644 index 0000000000..46c62493b0 --- /dev/null +++ b/types/sonic-boom/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", + "sonic-boom-tests.ts" + ] +} diff --git a/types/sonic-boom/tslint.json b/types/sonic-boom/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sonic-boom/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 0dca0edc490b77aac03a1d201b8314b2ce6d775d Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Tue, 30 Oct 2018 10:46:34 +0100 Subject: [PATCH 2/4] Bump pino to 5.8 This commit also adresses breaking changes that were not reflected when upgrading from pino 4 to 5. Such changes include: - Remove extreme option - Remove pretty option - Remove slowtime - Add extreme function - Add destination function --- types/pino/index.d.ts | 45 ++++++++++++++++------------------------ types/pino/pino-tests.ts | 9 -------- 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/types/pino/index.d.ts b/types/pino/index.d.ts index 75f045af01..925c1c1824 100644 --- a/types/pino/index.d.ts +++ b/types/pino/index.d.ts @@ -1,9 +1,10 @@ -// Type definitions for pino 5.6 +// Type definitions for pino 5.8 // Project: https://github.com/pinojs/pino.git // Definitions by: Peter Snider // BendingBender // Christian Rackerseder // GP +// Alex Ferrando // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -12,6 +13,7 @@ import * as stream from 'stream'; import * as http from 'http'; import { EventEmitter } from 'events'; +import SonicBoom = require('sonic-boom') export = P; @@ -20,7 +22,7 @@ export = P; * relative protocol is enabled. Default: process.stdout * @returns a new logger instance. */ -declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream): P.Logger; +declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream | SonicBoom): P.Logger; /** * @param [options]: an options object @@ -28,7 +30,7 @@ declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream. * relative protocol is enabled. Default: process.stdout * @returns a new logger instance. */ -declare function P(options: P.LoggerOptions, stream: stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream): P.Logger; +declare function P(options: P.LoggerOptions, stream: stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream | SonicBoom): P.Logger; declare namespace P { /** @@ -75,11 +77,6 @@ declare namespace P { * The default time function for Pino. Returns a string like `,"time":1493426328206`. */ epochTime: TimeFn; - /** - * Returns an ISO formatted string like `,"time":"2017-04-29T004749.354Z"`. It is highly recommended that you avoid this function. - * It incurs a significant performance penalty. - */ - slowTime: TimeFn; /** * Returns an empty string. This function is used when the `timestamp` option is set to `false`. */ @@ -87,12 +84,19 @@ declare namespace P { }; /** - * Provides access to the CLI log prettifier as an API. - * This can also be enabled via the constructor by setting the `prettyPrint` option to either `true` or a configuration object described in this section. - * @param [options]: an options object - * @returns A transform stream to be used as input for the constructor. - */ - function pretty(options?: PrettyOptions): stream.Transform; + *Create a Pino Destination instance: a stream-like object with significantly more throughput (over 30%) than a standard Node.js stream. + * @param [fileDescriptor]: File path or numerical file descriptor, by default 1 + * @returns A Sonic-Boom stream to be used as destination for the pino function + */ + function destination(fileDescriptor?: String | Number): SonicBoom; + + /** + *Create an extreme mode destination. This yields an additional 60% performance boost. + * There are trade-offs that should be understood before usage. + * @param [fileDescriptor]: File path or numerical file descriptor, by default 1 + * @returns A Sonic-Boom stream to be used as destination for the pino function + */ + function extreme(fileDescriptor?: String | Number): SonicBoom; interface LevelMapping { /** @@ -128,19 +132,6 @@ declare namespace P { * Caution: any sort of formatted time will significantly slow down Pino's performance. */ timestamp?: TimeFn | false; - /** - * @deprecated - * This option is scheduled to be removed in Pino 5.0.0. Use `timestamp: pino.stdTimeFunctions.slowTime` instead. - * Outputs ISO time stamps ('2016-03-09T15:18:53.889Z') instead of Epoch time stamps (1457536759176). - * WARNING: This option carries a 25% performance drop, we recommend using default Epoch timestamps and transforming logs after if required. - * The pino -t command will do this for you (see CLI). Default: `false`. - */ - slowtime?: boolean; - /** - * Enables extreme mode, yields an additional 60% performance (from 250ms down to 100ms per 10000 ops). - * There are trade-off's should be understood before usage. See Extreme mode explained. Default: `false`. - */ - extreme?: boolean; /** * One of the supported levels or `silent` to disable logging. Any other value defines a custom level and * requires supplying a level value via `levelVal`. Default: 'info'. diff --git a/types/pino/pino-tests.ts b/types/pino/pino-tests.ts index cec8f658fb..609cac121f 100644 --- a/types/pino/pino-tests.ts +++ b/types/pino/pino-tests.ts @@ -22,15 +22,6 @@ const log2: pino.Logger = pino({ } }); -const pretty = pino.pretty(); -pretty.pipe(process.stdout); -const log3 = pino({ - name: 'app', - safe: true -}, pretty); -log3.child({widget: 'foo'}).info('hello'); -log3.child({widget: 'bar'}).warn('hello 2'); - pino({ browser: { write(o) { From e39959930827a5df9d9ffba60ff60be68c75a06c Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Tue, 30 Oct 2018 12:11:58 +0100 Subject: [PATCH 3/4] Fix styling issues in sonic-boom --- types/sonic-boom/index.d.ts | 8 ++++---- types/sonic-boom/sonic-boom-tests.ts | 21 +++++++-------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/types/sonic-boom/index.d.ts b/types/sonic-boom/index.d.ts index eca15c0cb7..292770bd0d 100644 --- a/types/sonic-boom/index.d.ts +++ b/types/sonic-boom/index.d.ts @@ -7,7 +7,7 @@ import { EventEmitter } from 'events'; -export = SonicBoom +export = SonicBoom; declare class SonicBoom extends EventEmitter { /** @@ -15,12 +15,12 @@ declare class SonicBoom extends EventEmitter { * relative protocol is enabled. Default: process.stdout * @returns a new sonic-boom instance */ - constructor(fileDescriptor: String | Number) + constructor(fileDescriptor: string | number) /** * Writes the string to the file. It will return false to signal the producer to slow down. */ - write(string: String): void; + write(string: string): void; /** * Writes the current buffer to the file if a write was not in progress. @@ -31,7 +31,7 @@ declare class SonicBoom extends EventEmitter { /** * Reopen the file in place, useful for log rotation. */ - reopen(file: String): void; + reopen(file: string): void; /** * Flushes the buffered data synchronously. This is a costly operation. diff --git a/types/sonic-boom/sonic-boom-tests.ts b/types/sonic-boom/sonic-boom-tests.ts index a819ec635f..a3beb06d0c 100644 --- a/types/sonic-boom/sonic-boom-tests.ts +++ b/types/sonic-boom/sonic-boom-tests.ts @@ -1,19 +1,12 @@ +import SonicBoom = require('sonic-boom'); +const sonic = new SonicBoom(1); -import SonicBoom = require('sonic-boom') -const sonic = new SonicBoom(1) - -sonic.write('hello sonic\n') - -sonic.flush() - -sonic.flushSync() - -sonic.end() - -sonic.destroy() - - +sonic.write('hello sonic\n'); +sonic.flush(); +sonic.flushSync(); +sonic.end(); +sonic.destroy(); From 760c7cf2cbc8e8fc06d4ff178c229c55e2e54a42 Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Tue, 30 Oct 2018 12:20:57 +0100 Subject: [PATCH 4/4] Fix style issues for pino --- types/pino/index.d.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/types/pino/index.d.ts b/types/pino/index.d.ts index 925c1c1824..4392d09ae9 100644 --- a/types/pino/index.d.ts +++ b/types/pino/index.d.ts @@ -13,7 +13,7 @@ import * as stream from 'stream'; import * as http from 'http'; import { EventEmitter } from 'events'; -import SonicBoom = require('sonic-boom') +import SonicBoom = require('sonic-boom'); export = P; @@ -84,19 +84,19 @@ declare namespace P { }; /** - *Create a Pino Destination instance: a stream-like object with significantly more throughput (over 30%) than a standard Node.js stream. - * @param [fileDescriptor]: File path or numerical file descriptor, by default 1 - * @returns A Sonic-Boom stream to be used as destination for the pino function - */ - function destination(fileDescriptor?: String | Number): SonicBoom; + * Create a Pino Destination instance: a stream-like object with significantly more throughput (over 30%) than a standard Node.js stream. + * @param [fileDescriptor]: File path or numerical file descriptor, by default 1 + * @returns A Sonic-Boom stream to be used as destination for the pino function + */ + function destination(fileDescriptor?: string | number): SonicBoom; /** - *Create an extreme mode destination. This yields an additional 60% performance boost. - * There are trade-offs that should be understood before usage. - * @param [fileDescriptor]: File path or numerical file descriptor, by default 1 - * @returns A Sonic-Boom stream to be used as destination for the pino function - */ - function extreme(fileDescriptor?: String | Number): SonicBoom; + * Create an extreme mode destination. This yields an additional 60% performance boost. + * There are trade-offs that should be understood before usage. + * @param [fileDescriptor]: File path or numerical file descriptor, by default 1 + * @returns A Sonic-Boom stream to be used as destination for the pino function + */ + function extreme(fileDescriptor?: string | number): SonicBoom; interface LevelMapping { /**