@vidavidorra/bunyan-pretty-stream 2.0.6 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,9 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { Options } from './options';
|
3
|
-
import {
|
4
|
-
declare class PrettyStream extends
|
5
|
-
readable: boolean;
|
6
|
-
writable: boolean;
|
3
|
+
import { Transform, TransformCallback } from 'stream';
|
4
|
+
declare class PrettyStream extends Transform {
|
7
5
|
private _formatter;
|
8
6
|
constructor(options?: Options);
|
9
|
-
|
10
|
-
end(): boolean;
|
7
|
+
_transform(chunk: any, encoding: BufferEncoding, done: TransformCallback): void;
|
11
8
|
}
|
12
9
|
export { PrettyStream };
|
@@ -1,33 +1,38 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.PrettyStream = void 0;
|
4
7
|
const options_1 = require("./options");
|
5
|
-
const formatter_1 = require("./formatter");
|
6
8
|
const stream_1 = require("stream");
|
7
9
|
const bunyan_record_1 = require("./bunyan-record");
|
10
|
+
const formatter_1 = require("./formatter");
|
11
|
+
const is_1 = __importDefault(require("@sindresorhus/is"));
|
8
12
|
const helpers_1 = require("./helpers");
|
9
|
-
class PrettyStream extends stream_1.
|
13
|
+
class PrettyStream extends stream_1.Transform {
|
10
14
|
constructor(options = {}) {
|
11
|
-
super();
|
12
|
-
this.readable = true;
|
13
|
-
this.writable = true;
|
15
|
+
super({ objectMode: true });
|
14
16
|
const validation = options_1.schema.validate(options);
|
15
17
|
if (!helpers_1.joi.isValid(validation, validation.value)) {
|
16
18
|
throw validation.error;
|
17
19
|
}
|
18
20
|
this._formatter = new formatter_1.Formatter(validation.value);
|
19
21
|
}
|
22
|
+
_transform(
|
20
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
21
|
-
|
22
|
-
if (
|
23
|
-
|
24
|
+
chunk, encoding, done) {
|
25
|
+
if (is_1.default.string(chunk)) {
|
26
|
+
this.push(this._formatter.format((0, bunyan_record_1.fromString)(chunk)));
|
27
|
+
done();
|
28
|
+
}
|
29
|
+
else if ((0, bunyan_record_1.isBunyanRecord)(chunk)) {
|
30
|
+
this.push(this._formatter.format(chunk));
|
31
|
+
done();
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
done(new Error('data MUST be a valid bunyan record'));
|
24
35
|
}
|
25
|
-
this.emit('data', this._formatter.format(chunk));
|
26
|
-
return true;
|
27
|
-
}
|
28
|
-
end() {
|
29
|
-
this.emit('end');
|
30
|
-
return true;
|
31
36
|
}
|
32
37
|
}
|
33
38
|
exports.PrettyStream = PrettyStream;
|
@@ -15,4 +15,5 @@ interface BunyanCoreRecord {
|
|
15
15
|
declare type BunyanRecord = BunyanCoreRecord & Record<string, unknown>;
|
16
16
|
declare function coreFields(): string[];
|
17
17
|
declare function isBunyanRecord(value: unknown): value is BunyanRecord;
|
18
|
-
|
18
|
+
declare function fromString(json: string): BunyanRecord;
|
19
|
+
export { BunyanRecord, coreFields, fromString, isBunyanRecord };
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.isBunyanRecord = exports.coreFields = void 0;
|
6
|
+
exports.isBunyanRecord = exports.fromString = exports.coreFields = void 0;
|
7
7
|
const is_1 = __importDefault(require("@sindresorhus/is"));
|
8
8
|
function coreFields() {
|
9
9
|
const record = {
|
@@ -38,3 +38,18 @@ function isBunyanRecord(value) {
|
|
38
38
|
(is_1.default.undefined(value.src.func) || is_1.default.string(value.src.func)))));
|
39
39
|
}
|
40
40
|
exports.isBunyanRecord = isBunyanRecord;
|
41
|
+
function fromString(json) {
|
42
|
+
const record = JSON.parse(json, (key, value) => {
|
43
|
+
if (key === 'time' &&
|
44
|
+
is_1.default.string(value) &&
|
45
|
+
/^((\+-)\d{2})?\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(value)) {
|
46
|
+
return new Date(value);
|
47
|
+
}
|
48
|
+
return value;
|
49
|
+
});
|
50
|
+
if (!isBunyanRecord(record)) {
|
51
|
+
throw new Error('string MUST be parsable to a valid Bunyan record');
|
52
|
+
}
|
53
|
+
return record;
|
54
|
+
}
|
55
|
+
exports.fromString = fromString;
|
package/dist/src/formatter.js
CHANGED
@@ -174,16 +174,21 @@ class Formatter {
|
|
174
174
|
return chalk_1.default.red(` (${formattedExtras.join(', ')})`);
|
175
175
|
}
|
176
176
|
formatDetails(message, details) {
|
177
|
-
const
|
177
|
+
const formatted = [];
|
178
178
|
if (!this.isSingleLine(message)) {
|
179
|
-
|
179
|
+
formatted.push(chalk_1.default.blue(this.indent(message, true)));
|
180
180
|
}
|
181
|
-
|
181
|
+
formatted.push(...Object.entries(details).map(([key, value]) => chalk_1.default.cyan(this.indent(`${key}: ${(0, json_stringify_pretty_compact_1.default)(value, {
|
182
182
|
indent: this._options.jsonIndent,
|
183
183
|
maxLength: 80,
|
184
184
|
})}`, true))));
|
185
|
-
const separator =
|
186
|
-
|
185
|
+
const separator = [
|
186
|
+
this._options.newLineCharacter,
|
187
|
+
this.indent('--', true),
|
188
|
+
this._options.newLineCharacter,
|
189
|
+
].join('');
|
190
|
+
const suffix = formatted.length > 0 ? this._options.newLineCharacter : '';
|
191
|
+
return `${formatted.join(separator)}${suffix}`;
|
187
192
|
}
|
188
193
|
isExtra(value) {
|
189
194
|
let stringifiedValue = JSON.stringify(value, undefined, 2);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vidavidorra/bunyan-pretty-stream",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.10",
|
4
4
|
"description": "Highly configurable Bunyan stream with pretty output.",
|
5
5
|
"main": "dist/src/index.js",
|
6
6
|
"types": "dist/src/index.d.ts",
|
@@ -53,43 +53,43 @@
|
|
53
53
|
"node": ">=14.0.0"
|
54
54
|
},
|
55
55
|
"devDependencies": {
|
56
|
-
"@commitlint/cli": "
|
57
|
-
"@jest/globals": "27.
|
58
|
-
"@semantic-release/changelog": "
|
59
|
-
"@semantic-release/exec": "
|
60
|
-
"@semantic-release/git": "
|
61
|
-
"@types/bunyan": "1.8.
|
56
|
+
"@commitlint/cli": "16.1.0",
|
57
|
+
"@jest/globals": "27.4.6",
|
58
|
+
"@semantic-release/changelog": "6.0.1",
|
59
|
+
"@semantic-release/exec": "6.0.3",
|
60
|
+
"@semantic-release/git": "10.0.1",
|
61
|
+
"@types/bunyan": "1.8.8",
|
62
62
|
"@types/clone": "2.1.1",
|
63
|
-
"@types/node": "
|
64
|
-
"@typescript-eslint/eslint-plugin": "
|
65
|
-
"@typescript-eslint/parser": "
|
66
|
-
"@vidavidorra/commitlint-config": "2.
|
63
|
+
"@types/node": "16.11.21",
|
64
|
+
"@typescript-eslint/eslint-plugin": "5.8.0",
|
65
|
+
"@typescript-eslint/parser": "5.8.0",
|
66
|
+
"@vidavidorra/commitlint-config": "3.2.3",
|
67
67
|
"bunyan": "*",
|
68
68
|
"bunyan-1.x": "npm:bunyan@1.8.15",
|
69
69
|
"bunyan-2.x": "npm:bunyan@2.0.5",
|
70
70
|
"clone": "2.1.2",
|
71
71
|
"dot-prop": "6.0.1",
|
72
|
-
"eslint": "
|
72
|
+
"eslint": "8.5.0",
|
73
73
|
"eslint-config-prettier": "8.3.0",
|
74
|
-
"eslint-plugin-jest": "
|
74
|
+
"eslint-plugin-jest": "25.3.0",
|
75
75
|
"eslint-plugin-json": "3.1.0",
|
76
76
|
"eslint-plugin-prettier": "4.0.0",
|
77
|
-
"husky": "
|
78
|
-
"jest": "27.
|
79
|
-
"lint-staged": "
|
77
|
+
"husky": "7.0.4",
|
78
|
+
"jest": "27.4.7",
|
79
|
+
"lint-staged": "12.3.1",
|
80
80
|
"npm-run-all": "4.1.5",
|
81
81
|
"pinst": "2.1.6",
|
82
|
-
"prettier": "2.
|
83
|
-
"semantic-release": "
|
84
|
-
"strip-ansi": "6.0.
|
85
|
-
"ts-jest": "27.
|
86
|
-
"typescript": "4.
|
82
|
+
"prettier": "2.5.1",
|
83
|
+
"semantic-release": "19.0.2",
|
84
|
+
"strip-ansi": "6.0.1",
|
85
|
+
"ts-jest": "27.1.3",
|
86
|
+
"typescript": "4.5.5"
|
87
87
|
},
|
88
88
|
"peerDependencies": {
|
89
89
|
"bunyan": "1.8.15"
|
90
90
|
},
|
91
91
|
"dependencies": {
|
92
|
-
"@sindresorhus/is": "4.
|
92
|
+
"@sindresorhus/is": "4.4.0",
|
93
93
|
"chalk": "4.1.2",
|
94
94
|
"joi": "17.4.2",
|
95
95
|
"json-stringify-pretty-compact": "3.0.0",
|