@vidavidorra/bunyan-pretty-stream 3.0.17 → 4.0.0-beta.2

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.
Files changed (51) hide show
  1. package/LICENSE.md +70 -70
  2. package/dist/bunyan/core-fields.d.ts +6 -0
  3. package/dist/bunyan/core-fields.js +16 -0
  4. package/dist/bunyan/from-json-string.d.ts +3 -0
  5. package/dist/bunyan/from-json-string.js +17 -0
  6. package/dist/bunyan/index.d.ts +4 -0
  7. package/dist/bunyan/index.js +4 -0
  8. package/dist/bunyan/is-record.d.ts +3 -0
  9. package/dist/bunyan/is-record.js +17 -0
  10. package/dist/bunyan/record.d.ts +16 -0
  11. package/dist/bunyan/record.js +2 -0
  12. package/dist/bunyan-pretty-stream.d.ts +11 -0
  13. package/dist/bunyan-pretty-stream.js +25 -0
  14. package/dist/formatter/extra.d.ts +11 -0
  15. package/dist/formatter/extra.js +33 -0
  16. package/dist/formatter/extras.d.ts +7 -0
  17. package/dist/formatter/extras.js +18 -0
  18. package/dist/formatter/formatter.d.ts +25 -0
  19. package/dist/formatter/formatter.js +116 -0
  20. package/dist/formatter/index.d.ts +1 -0
  21. package/dist/formatter/index.js +2 -0
  22. package/dist/formatter/time.d.ts +11 -0
  23. package/dist/formatter/time.js +68 -0
  24. package/dist/helpers/normalise-path.d.ts +2 -0
  25. package/dist/helpers/normalise-path.js +9 -0
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.js +2 -0
  28. package/dist/{src/logger.d.ts → logger.d.ts} +2 -2
  29. package/dist/logger.js +2 -0
  30. package/dist/options.d.ts +332 -0
  31. package/dist/options.js +109 -0
  32. package/dist/parser/extras.d.ts +13 -0
  33. package/dist/parser/extras.js +47 -0
  34. package/dist/parser/parser.d.ts +22 -0
  35. package/dist/parser/parser.js +53 -0
  36. package/package.json +192 -45
  37. package/dist/src/bunyan-pretty-stream.d.ts +0 -10
  38. package/dist/src/bunyan-pretty-stream.js +0 -32
  39. package/dist/src/bunyan-record.d.ts +0 -19
  40. package/dist/src/bunyan-record.js +0 -55
  41. package/dist/src/formatter/extras.d.ts +0 -34
  42. package/dist/src/formatter/extras.js +0 -94
  43. package/dist/src/formatter/formatter.d.ts +0 -34
  44. package/dist/src/formatter/formatter.js +0 -200
  45. package/dist/src/formatter/index.d.ts +0 -2
  46. package/dist/src/formatter/index.js +0 -5
  47. package/dist/src/index.d.ts +0 -3
  48. package/dist/src/index.js +0 -5
  49. package/dist/src/logger.js +0 -2
  50. package/dist/src/options.d.ts +0 -151
  51. package/dist/src/options.js +0 -68
package/package.json CHANGED
@@ -1,33 +1,26 @@
1
1
  {
2
2
  "name": "@vidavidorra/bunyan-pretty-stream",
3
- "version": "3.0.17",
4
- "description": "Highly configurable Bunyan stream with pretty output.",
5
- "main": "dist/src/index.js",
6
- "types": "dist/src/index.d.ts",
3
+ "version": "4.0.0-beta.2",
4
+ "description": "Highly configurable Bunyan stream with pretty output",
5
+ "type": "module",
6
+ "exports": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
7
8
  "publishConfig": {
8
9
  "access": "public"
9
10
  },
10
11
  "files": [
11
- "dist/src/**/!(*.test).{js,d.ts}"
12
+ "./dist/**/!(*.test).{js,d.ts}"
12
13
  ],
13
14
  "scripts": {
14
15
  "prepare": "husky install .github/husky",
15
- "lint": "run-p format:check lint-es",
16
- "lint:fix": "run-s format lint-es:fix",
17
- "lint-es": "eslint --ext .ts,.tsx,.js,.jsx,.json .",
18
- "lint-es:file": "eslint --ext .ts,.tsx,.js,.jsx,.json",
19
- "lint-es:fix": "eslint --ext .ts,.tsx,.js,.jsx,.json --fix .",
20
- "lint-es:file:fix": "eslint --ext .ts,.tsx,.js,.jsx,.json --fix",
21
- "format": "prettier --ignore-path .eslintignore --write \"**/*.{js,jsx,vue,ts,css,less,scss,html,htm,json,md,markdown,yml,yaml}\"",
22
- "format:check": "prettier --ignore-path .eslintignore --check \"**/*.{js,jsx,vue,ts,css,less,scss,html,htm,json,md,markdown,yml,yaml}\"",
23
- "format:file": "prettier --write",
16
+ "lint": "run-p format:check xo",
17
+ "lint:fix": "run-p format 'xo -- --fix'",
18
+ "format:check": "prettier --ignore-path .gitignore --check \"**/*.{vue,css,less,scss,html,htm,json,md,markdown,yml,yaml}\" --loglevel warn",
19
+ "format": "prettier --ignore-path .gitignore --write \"**/*.{vue,css,less,scss,html,htm,json,md,markdown,yml,yaml}\" --loglevel warn",
20
+ "xo": "xo",
24
21
  "build": "tsc",
25
22
  "build:check": "tsc --noEmit",
26
- "build:clean-first": "run-s clean build",
27
- "clean": "rm -rf ./dist",
28
- "test": "jest",
29
- "test:ci": "jest --ci --verbose --coverage",
30
- "test:staged": "jest --passWithNoTests --findRelatedTests $(git diff --staged --name-only)"
23
+ "test": "c8 ava"
31
24
  },
32
25
  "repository": {
33
26
  "type": "git",
@@ -48,48 +41,202 @@
48
41
  },
49
42
  "homepage": "https://github.com/vidavidorra/bunyan-pretty-stream#readme",
50
43
  "engines": {
51
- "node": ">=14.0.0"
44
+ "node": ">=18"
52
45
  },
53
46
  "devDependencies": {
54
- "@commitlint/cli": "17.4.2",
55
- "@jest/globals": "29.4.2",
47
+ "@ava/typescript": "3.0.1",
48
+ "@commitlint/cli": "17.4.4",
56
49
  "@semantic-release/changelog": "6.0.2",
57
50
  "@semantic-release/exec": "6.0.3",
58
51
  "@semantic-release/git": "10.0.1",
59
52
  "@types/bunyan": "1.8.8",
60
- "@types/clone": "2.1.1",
61
- "@types/node": "18.13.0",
62
- "@typescript-eslint/eslint-plugin": "5.51.0",
63
- "@typescript-eslint/parser": "5.51.0",
64
- "@vidavidorra/commitlint-config": "4.0.10",
53
+ "@types/luxon": "3.2.0",
54
+ "@types/node": "18.14.1",
55
+ "@vidavidorra/commitlint-config": "4.0.12",
56
+ "ava": "5.2.0",
65
57
  "bunyan": "*",
66
58
  "bunyan-1.x": "npm:bunyan@1.8.15",
67
59
  "bunyan-2.x": "npm:bunyan@2.0.5",
68
- "clone": "2.1.2",
69
- "dot-prop": "6.0.1",
70
- "eslint": "8.33.0",
71
- "eslint-config-prettier": "8.6.0",
72
- "eslint-plugin-jest": "27.2.1",
73
- "eslint-plugin-json": "3.1.0",
74
- "eslint-plugin-prettier": "4.2.1",
60
+ "c8": "7.13.0",
61
+ "chalk": "5.2.0",
62
+ "deepmerge": "4.3.0",
63
+ "dot-prop": "7.2.0",
75
64
  "husky": "8.0.3",
76
- "jest": "29.4.2",
77
- "lint-staged": "13.1.1",
65
+ "lint-staged": "13.1.2",
78
66
  "npm-run-all": "4.1.5",
79
67
  "prettier": "2.8.4",
80
- "semantic-release": "19.0.5",
81
- "strip-ansi": "6.0.1",
82
- "ts-jest": "29.0.5",
83
- "typescript": "4.9.5"
68
+ "semantic-release": "20.1.0",
69
+ "strip-ansi": "7.0.1",
70
+ "typescript": "4.9.5",
71
+ "xo": "0.53.1"
84
72
  },
85
73
  "peerDependencies": {
86
- "bunyan": "1.8.15"
74
+ "bunyan": ">=1.8.15 <3"
87
75
  },
88
76
  "dependencies": {
89
- "@sindresorhus/is": "4.6.0",
90
- "chalk": "4.1.2",
91
- "json-stringify-pretty-compact": "3.0.0",
92
- "moment": "2.29.4",
77
+ "@sindresorhus/is": "5.3.0",
78
+ "json-stringify-pretty-compact": "4.0.0",
79
+ "luxon": "3.2.1",
93
80
  "zod": "3.20.6"
81
+ },
82
+ "ava": {
83
+ "files": [
84
+ "!worktrees",
85
+ "src/**/*.test.ts"
86
+ ],
87
+ "typescript": {
88
+ "rewritePaths": {
89
+ "src/": "dist/"
90
+ },
91
+ "compile": "tsc"
92
+ }
93
+ },
94
+ "c8": {
95
+ "include": [
96
+ "dist/**/*.js"
97
+ ],
98
+ "reporter": [
99
+ "cobertura",
100
+ "html",
101
+ "lcovonly",
102
+ "text-summary"
103
+ ]
104
+ },
105
+ "xo": {
106
+ "prettier": true,
107
+ "rules": {
108
+ "object-curly-spacing": "off"
109
+ },
110
+ "space": true
111
+ },
112
+ "commitlint": {
113
+ "extends": [
114
+ "@vidavidorra"
115
+ ]
116
+ },
117
+ "prettier": {
118
+ "singleQuote": true,
119
+ "trailingComma": "all"
120
+ },
121
+ "release": {
122
+ "branches": [
123
+ "main",
124
+ {
125
+ "name": "beta",
126
+ "prerelease": true
127
+ }
128
+ ],
129
+ "plugins": [
130
+ [
131
+ "@semantic-release/commit-analyzer",
132
+ {
133
+ "releaseRules": [
134
+ {
135
+ "type": "perf",
136
+ "release": "patch"
137
+ },
138
+ {
139
+ "type": "revert",
140
+ "release": "patch"
141
+ },
142
+ {
143
+ "type": "docs",
144
+ "release": "patch"
145
+ },
146
+ {
147
+ "type": "chore",
148
+ "release": false
149
+ },
150
+ {
151
+ "type": "refactor",
152
+ "release": "patch"
153
+ },
154
+ {
155
+ "type": "test",
156
+ "release": "patch"
157
+ },
158
+ {
159
+ "type": "build",
160
+ "release": "patch"
161
+ },
162
+ {
163
+ "type": "ci",
164
+ "release": "patch"
165
+ }
166
+ ]
167
+ }
168
+ ],
169
+ "@semantic-release/release-notes-generator",
170
+ "@semantic-release/changelog",
171
+ [
172
+ "@semantic-release/exec",
173
+ {
174
+ "prepareCmd": "prettier --write CHANGELOG.md"
175
+ }
176
+ ],
177
+ [
178
+ "@semantic-release/npm",
179
+ {
180
+ "tarballDir": "dist"
181
+ }
182
+ ],
183
+ "@semantic-release/git",
184
+ [
185
+ "@semantic-release/github",
186
+ {
187
+ "assets": "dist/*.tgz"
188
+ }
189
+ ]
190
+ ],
191
+ "preset": "conventionalcommits",
192
+ "presetConfig": {
193
+ "types": [
194
+ {
195
+ "type": "feat",
196
+ "section": "Features"
197
+ },
198
+ {
199
+ "type": "fix",
200
+ "section": "Bug Fixes"
201
+ },
202
+ {
203
+ "type": "perf",
204
+ "section": "Performance Improvements"
205
+ },
206
+ {
207
+ "type": "revert",
208
+ "section": "Reverts"
209
+ },
210
+ {
211
+ "type": "docs",
212
+ "section": "Documentation"
213
+ },
214
+ {
215
+ "type": "style",
216
+ "section": "Styles"
217
+ },
218
+ {
219
+ "type": "chore",
220
+ "section": "Miscellaneous Chores",
221
+ "hidden": true
222
+ },
223
+ {
224
+ "type": "refactor",
225
+ "section": "Code Refactoring"
226
+ },
227
+ {
228
+ "type": "test",
229
+ "section": "Tests"
230
+ },
231
+ {
232
+ "type": "build",
233
+ "section": "Build System"
234
+ },
235
+ {
236
+ "type": "ci",
237
+ "section": "Continuous Integration"
238
+ }
239
+ ]
240
+ }
94
241
  }
95
242
  }
@@ -1,10 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Transform, TransformCallback } from 'stream';
4
- import { Options } from './options';
5
- declare class PrettyStream extends Transform {
6
- private _formatter;
7
- constructor(options?: Options);
8
- _transform(chunk: any, encoding: BufferEncoding, done: TransformCallback): void;
9
- }
10
- export { PrettyStream };
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PrettyStream = void 0;
7
- const stream_1 = require("stream");
8
- const bunyan_record_1 = require("./bunyan-record");
9
- const formatter_1 = require("./formatter");
10
- const is_1 = __importDefault(require("@sindresorhus/is"));
11
- class PrettyStream extends stream_1.Transform {
12
- constructor(options = {}) {
13
- super({ objectMode: true });
14
- this._formatter = new formatter_1.Formatter(options);
15
- }
16
- _transform(
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
18
- chunk, encoding, done) {
19
- if (is_1.default.string(chunk)) {
20
- this.push(this._formatter.format((0, bunyan_record_1.fromString)(chunk)));
21
- done();
22
- }
23
- else if ((0, bunyan_record_1.isBunyanRecord)(chunk)) {
24
- this.push(this._formatter.format(chunk));
25
- done();
26
- }
27
- else {
28
- done(new Error('data MUST be a valid bunyan record'));
29
- }
30
- }
31
- }
32
- exports.PrettyStream = PrettyStream;
@@ -1,19 +0,0 @@
1
- interface BunyanCoreRecord {
2
- v: number;
3
- level: number;
4
- name: string;
5
- hostname: string;
6
- pid: number;
7
- time: Date;
8
- msg: string;
9
- src?: {
10
- file: string;
11
- line: number;
12
- func?: string;
13
- };
14
- }
15
- type BunyanRecord = BunyanCoreRecord & Record<string, unknown>;
16
- declare function coreFields(): string[];
17
- declare function isBunyanRecord(value: unknown): value is BunyanRecord;
18
- declare function fromString(json: string): BunyanRecord;
19
- export { BunyanRecord, coreFields, fromString, isBunyanRecord };
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isBunyanRecord = exports.fromString = exports.coreFields = void 0;
7
- const is_1 = __importDefault(require("@sindresorhus/is"));
8
- function coreFields() {
9
- const record = {
10
- v: 0,
11
- level: 0,
12
- name: '',
13
- hostname: '',
14
- pid: 0,
15
- time: new Date(0),
16
- msg: '',
17
- src: {
18
- file: '',
19
- line: 0,
20
- func: '',
21
- },
22
- };
23
- return Object.keys(record);
24
- }
25
- exports.coreFields = coreFields;
26
- function isBunyanRecord(value) {
27
- return (is_1.default.plainObject(value) &&
28
- is_1.default.number(value.v) &&
29
- is_1.default.number(value.level) &&
30
- is_1.default.string(value.name) &&
31
- is_1.default.string(value.hostname) &&
32
- is_1.default.number(value.pid) &&
33
- is_1.default.date(value.time) &&
34
- is_1.default.string(value.msg) &&
35
- (is_1.default.undefined(value.src) ||
36
- (is_1.default.plainObject(value.src) &&
37
- is_1.default.number(value.src.line) &&
38
- (is_1.default.undefined(value.src.func) || is_1.default.string(value.src.func)))));
39
- }
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;
@@ -1,34 +0,0 @@
1
- import { ParsedOptions } from '../options';
2
- declare class Extras {
3
- readonly options: {
4
- readonly keyValueSeparator: "=";
5
- readonly separator: ", ";
6
- readonly start: "(";
7
- readonly end: ")";
8
- };
9
- private readonly _maxLength;
10
- private _extras;
11
- private _length;
12
- constructor(maxLength: ParsedOptions['extras']['maxLength']);
13
- get length(): number;
14
- get extras(): string[];
15
- /**
16
- * Parse a key-value pair and add to the extras if it is a valid extra.
17
- *
18
- * @param key
19
- * @param value
20
- * @returns `true` if the key-value was valid and is added, false otherwise.
21
- */
22
- parseAndAdd(key: string, value: unknown): boolean;
23
- format(): string;
24
- formatExtra(key: string, value: unknown): {
25
- formatted: string;
26
- key: string;
27
- value: string;
28
- };
29
- private lengthAfterAdding;
30
- private add;
31
- private stringify;
32
- private containsWhitespace;
33
- }
34
- export { Extras };
@@ -1,94 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Extras = void 0;
4
- class Extras {
5
- constructor(maxLength) {
6
- this.options = {
7
- keyValueSeparator: '=',
8
- separator: ', ',
9
- start: '(',
10
- end: ')',
11
- };
12
- this._maxLength = maxLength;
13
- this._length = 0;
14
- this._extras = [];
15
- }
16
- get length() {
17
- return this._length;
18
- }
19
- get extras() {
20
- return this._extras;
21
- }
22
- /**
23
- * Parse a key-value pair and add to the extras if it is a valid extra.
24
- *
25
- * @param key
26
- * @param value
27
- * @returns `true` if the key-value was valid and is added, false otherwise.
28
- */
29
- parseAndAdd(key, value) {
30
- if ((typeof value === 'object' && value !== null) ||
31
- typeof value === 'function') {
32
- return false;
33
- }
34
- const extra = this.formatExtra(key, value);
35
- if (extra.key.length > this._maxLength.key ||
36
- extra.value.length > this._maxLength.value ||
37
- this.lengthAfterAdding(extra.formatted) > this._maxLength.total) {
38
- return false;
39
- }
40
- this.add(extra.formatted);
41
- return true;
42
- }
43
- format() {
44
- if (this._extras.length === 0) {
45
- return '';
46
- }
47
- return [
48
- this.options.start,
49
- this._extras.join(this.options.separator),
50
- this.options.end,
51
- ].join('');
52
- }
53
- formatExtra(key, value) {
54
- const stringifiedKey = this.stringify(key);
55
- const stringifiedValue = this.stringify(value);
56
- const formatted = [
57
- stringifiedKey,
58
- this.options.keyValueSeparator,
59
- stringifiedValue,
60
- ].join('');
61
- return {
62
- formatted,
63
- key: stringifiedKey,
64
- value: stringifiedValue,
65
- };
66
- }
67
- lengthAfterAdding(formattedExtra) {
68
- let length = this._length + formattedExtra.length;
69
- if (this._length === 0) {
70
- length += this.options.start.length + this.options.end.length;
71
- }
72
- else if (this._extras.length >= 1) {
73
- length += this.options.separator.length;
74
- }
75
- return length;
76
- }
77
- add(formattedExtra) {
78
- this._extras.push(formattedExtra);
79
- this._length = this.lengthAfterAdding(formattedExtra);
80
- }
81
- stringify(value) {
82
- if (typeof value === 'string' &&
83
- value.length > 0 &&
84
- !this.containsWhitespace(value) &&
85
- !value.includes(this.options.keyValueSeparator)) {
86
- return value;
87
- }
88
- return JSON.stringify(value);
89
- }
90
- containsWhitespace(value) {
91
- return /\s/.test(value);
92
- }
93
- }
94
- exports.Extras = Extras;
@@ -1,34 +0,0 @@
1
- import { BunyanRecord } from '../bunyan-record';
2
- import { Options } from '../options';
3
- import { Extras } from './extras';
4
- import moment from 'moment';
5
- interface ParsedRecord extends Pick<BunyanRecord, 'level' | 'name' | 'hostname' | 'pid'> {
6
- version: BunyanRecord['v'];
7
- time: moment.Moment;
8
- message: BunyanRecord['msg'];
9
- source: BunyanRecord['src'];
10
- extras: Extras;
11
- details: Record<string, unknown>;
12
- }
13
- declare class Formatter {
14
- private readonly _options;
15
- private readonly _regex;
16
- private readonly _internalOptions;
17
- private readonly _levels;
18
- constructor(options: Options);
19
- parse(record: BunyanRecord): ParsedRecord;
20
- format(record: BunyanRecord): string;
21
- formatTime(time: ParsedRecord['time']): string;
22
- formatLevel(level: ParsedRecord['level']): string;
23
- formatName(name: ParsedRecord['name']): string;
24
- formatPid(pid: ParsedRecord['pid']): string;
25
- formatHostname(hostname: ParsedRecord['hostname']): string;
26
- formatSource(source: ParsedRecord['source']): string;
27
- formatMessage(message: ParsedRecord['message']): string;
28
- formatExtras(extras: ParsedRecord['extras']): string;
29
- formatDetails(message: ParsedRecord['message'], details: ParsedRecord['details']): string;
30
- isSingleLine(string: string): boolean;
31
- containsWhitespace(string: string): boolean;
32
- indent(input: string, leading?: boolean): string;
33
- }
34
- export { ParsedRecord, Formatter };