@vidavidorra/bunyan-pretty-stream 2.0.10 → 3.0.1

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,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Options } from './options';
3
2
  import { Transform, TransformCallback } from 'stream';
3
+ import { Options } from './options';
4
4
  declare class PrettyStream extends Transform {
5
5
  private _formatter;
6
6
  constructor(options?: Options);
@@ -4,20 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PrettyStream = void 0;
7
- const options_1 = require("./options");
8
7
  const stream_1 = require("stream");
9
8
  const bunyan_record_1 = require("./bunyan-record");
10
9
  const formatter_1 = require("./formatter");
11
10
  const is_1 = __importDefault(require("@sindresorhus/is"));
12
- const helpers_1 = require("./helpers");
13
11
  class PrettyStream extends stream_1.Transform {
14
12
  constructor(options = {}) {
15
13
  super({ objectMode: true });
16
- const validation = options_1.schema.validate(options);
17
- if (!helpers_1.joi.isValid(validation, validation.value)) {
18
- throw validation.error;
19
- }
20
- this._formatter = new formatter_1.Formatter(validation.value);
14
+ this._formatter = new formatter_1.Formatter(options);
21
15
  }
22
16
  _transform(
23
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
@@ -0,0 +1,34 @@
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 };
@@ -0,0 +1,93 @@
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' || typeof value === 'function') {
31
+ return false;
32
+ }
33
+ const extra = this.formatExtra(key, value);
34
+ if (extra.key.length > this._maxLength.key ||
35
+ extra.value.length > this._maxLength.value ||
36
+ this.lengthAfterAdding(extra.formatted) > this._maxLength.total) {
37
+ return false;
38
+ }
39
+ this.add(extra.formatted);
40
+ return true;
41
+ }
42
+ format() {
43
+ if (this._extras.length === 0) {
44
+ return '';
45
+ }
46
+ return [
47
+ this.options.start,
48
+ this._extras.join(this.options.separator),
49
+ this.options.end,
50
+ ].join('');
51
+ }
52
+ formatExtra(key, value) {
53
+ const stringifiedKey = this.stringify(key);
54
+ const stringifiedValue = this.stringify(value);
55
+ const formatted = [
56
+ stringifiedKey,
57
+ this.options.keyValueSeparator,
58
+ stringifiedValue,
59
+ ].join('');
60
+ return {
61
+ formatted,
62
+ key: stringifiedKey,
63
+ value: stringifiedValue,
64
+ };
65
+ }
66
+ lengthAfterAdding(formattedExtra) {
67
+ let length = this._length + formattedExtra.length;
68
+ if (this._length === 0) {
69
+ length += this.options.start.length + this.options.end.length;
70
+ }
71
+ else if (this._extras.length >= 1) {
72
+ length += this.options.separator.length;
73
+ }
74
+ return length;
75
+ }
76
+ add(formattedExtra) {
77
+ this._extras.push(formattedExtra);
78
+ this._length = this.lengthAfterAdding(formattedExtra);
79
+ }
80
+ stringify(value) {
81
+ if (typeof value === 'string' &&
82
+ value.length > 0 &&
83
+ !this.containsWhitespace(value) &&
84
+ !value.includes(this.options.keyValueSeparator)) {
85
+ return value;
86
+ }
87
+ return JSON.stringify(value);
88
+ }
89
+ containsWhitespace(value) {
90
+ return /\s/.test(value);
91
+ }
92
+ }
93
+ exports.Extras = Extras;
@@ -1,19 +1,21 @@
1
- import { BunyanRecord } from './bunyan-record';
2
- import { MergedOptions } from './options';
1
+ import { BunyanRecord } from '../bunyan-record';
2
+ import { Options } from '../options';
3
+ import { Extras } from './extras';
3
4
  import moment from 'moment';
4
5
  interface ParsedRecord extends Pick<BunyanRecord, 'level' | 'name' | 'hostname' | 'pid'> {
5
6
  version: BunyanRecord['v'];
6
7
  time: moment.Moment;
7
8
  message: BunyanRecord['msg'];
8
9
  source: BunyanRecord['src'];
9
- extras: Record<string, any>;
10
- details: Record<string, any>;
10
+ extras: Extras;
11
+ details: Record<string, unknown>;
11
12
  }
12
13
  declare class Formatter {
13
14
  private readonly _options;
14
15
  private readonly _regex;
16
+ private readonly _internalOptions;
15
17
  private readonly _levels;
16
- constructor(options: MergedOptions);
18
+ constructor(options: Options);
17
19
  parse(record: BunyanRecord): ParsedRecord;
18
20
  format(record: BunyanRecord): string;
19
21
  formatTime(time: ParsedRecord['time']): string;
@@ -25,7 +27,6 @@ declare class Formatter {
25
27
  formatMessage(message: ParsedRecord['message']): string;
26
28
  formatExtras(extras: ParsedRecord['extras']): string;
27
29
  formatDetails(message: ParsedRecord['message'], details: ParsedRecord['details']): string;
28
- isExtra(value: unknown): boolean;
29
30
  isSingleLine(string: string): boolean;
30
31
  containsWhitespace(string: string): boolean;
31
32
  indent(input: string, leading?: boolean): string;
@@ -4,7 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Formatter = void 0;
7
- const bunyan_record_1 = require("./bunyan-record");
7
+ const bunyan_record_1 = require("../bunyan-record");
8
+ const options_1 = require("../options");
9
+ const extras_1 = require("./extras");
8
10
  const bunyan_1 = __importDefault(require("bunyan"));
9
11
  const chalk_1 = __importDefault(require("chalk"));
10
12
  const is_1 = __importDefault(require("@sindresorhus/is"));
@@ -29,8 +31,15 @@ class Formatter {
29
31
  newLine: /\r\n|\r|\n/,
30
32
  whitespace: /\s/,
31
33
  };
32
- options.basePath = path_1.default.normalize(options.basePath);
33
- this._options = options;
34
+ this._internalOptions = {
35
+ timeFormat: {
36
+ short: 'HH:mm:ss.SSS',
37
+ long: 'YYYY-MM-DD[T]HH:mm:ss.SSS',
38
+ },
39
+ };
40
+ const parsedOptions = options_1.schema.parse(options);
41
+ parsedOptions.basePath = path_1.default.normalize(parsedOptions.basePath);
42
+ this._options = parsedOptions;
34
43
  this._levels = {
35
44
  [bunyan_1.default.levelFromName.trace]: chalk_1.default.gray('TRACE'),
36
45
  [bunyan_1.default.levelFromName.debug]: chalk_1.default.blue('DEBUG'),
@@ -50,7 +59,7 @@ class Formatter {
50
59
  time: (0, moment_1.default)(record.time),
51
60
  message: record.msg,
52
61
  source: record.src,
53
- extras: {},
62
+ extras: new extras_1.Extras(this._options.extras.maxLength),
54
63
  details: sanitise(record),
55
64
  };
56
65
  Object.keys(parsed.details).forEach((key) => {
@@ -58,26 +67,20 @@ class Formatter {
58
67
  delete parsed.details[key];
59
68
  }
60
69
  });
61
- if (!this._options.enable.extras) {
70
+ if (!this._options.show.extras) {
62
71
  return parsed;
63
72
  }
64
- const extras = parsed.details[this._options.extrasKey];
65
- if (this._options.extrasKey !== '' && is_1.default.nonEmptyObject(extras)) {
66
- Object.entries(parsed.details[this._options.extrasKey]).forEach(([key, value]) => {
67
- if (this.isExtra(value)) {
68
- parsed.extras[key] = value;
69
- delete parsed.details[this._options.extrasKey][key];
70
- }
71
- });
72
- }
73
- else if (this._options.extrasKey === '') {
74
- Object.entries(parsed.details).forEach(([key, value]) => {
75
- if (this.isExtra(value)) {
76
- parsed.extras[key] = value;
77
- delete parsed.details[key];
78
- }
79
- });
73
+ const leftOvers = is_1.default.undefined(this._options.extras.key)
74
+ ? parsed.details
75
+ : parsed.details[this._options.extras.key];
76
+ if (!is_1.default.nonEmptyObject(leftOvers)) {
77
+ return parsed;
80
78
  }
79
+ Object.entries(leftOvers).forEach(([key, value]) => {
80
+ if (parsed.extras.parseAndAdd(key, value)) {
81
+ delete leftOvers[key];
82
+ }
83
+ });
81
84
  return parsed;
82
85
  }
83
86
  format(record) {
@@ -97,15 +100,15 @@ class Formatter {
97
100
  ].join('');
98
101
  }
99
102
  formatTime(time) {
100
- if (!this._options.enable.time) {
103
+ if (!this._options.show.time) {
101
104
  return '';
102
105
  }
103
106
  let format = this._options.time.format;
104
107
  if (this._options.time.type === 'short') {
105
- format = this._options.time.formats.short;
108
+ format = this._internalOptions.timeFormat.short;
106
109
  }
107
110
  else if (this._options.time.type === 'long') {
108
- format = this._options.time.formats.long;
111
+ format = this._internalOptions.timeFormat.long;
109
112
  }
110
113
  if (!this._options.time.local) {
111
114
  time.utc();
@@ -114,34 +117,34 @@ class Formatter {
114
117
  return `[${time.format(format)}]`;
115
118
  }
116
119
  formatLevel(level) {
117
- const prefix = this._options.enable.time ? ' ' : '';
120
+ const prefix = this._options.show.time ? ' ' : '';
118
121
  return `${prefix}${this._levels[level]}`;
119
122
  }
120
123
  formatName(name) {
121
- if (!this._options.enable.name) {
124
+ if (!this._options.show.name) {
122
125
  return '';
123
126
  }
124
127
  return ` ${name}`;
125
128
  }
126
129
  formatPid(pid) {
127
- if (!this._options.enable.pid) {
130
+ if (!this._options.show.pid) {
128
131
  return '';
129
132
  }
130
- const prefix = this._options.enable.name ? '/' : ' ';
133
+ const prefix = this._options.show.name ? '/' : ' ';
131
134
  return `${prefix}${pid}`;
132
135
  }
133
136
  formatHostname(hostname) {
134
- if (!this._options.enable.hostname) {
137
+ if (!this._options.show.hostname) {
135
138
  return '';
136
139
  }
137
140
  return [
138
141
  ' ',
139
- this._options.enable.name || this._options.enable.pid ? 'on ' : '',
142
+ this._options.show.name || this._options.show.pid ? 'on ' : '',
140
143
  hostname,
141
144
  ].join('');
142
145
  }
143
146
  formatSource(source) {
144
- if (!this._options.enable.source || is_1.default.undefined(source)) {
147
+ if (!this._options.show.source || is_1.default.undefined(source)) {
145
148
  return '';
146
149
  }
147
150
  const file = path_1.default.relative(this._options.basePath, source.file);
@@ -159,19 +162,8 @@ class Formatter {
159
162
  return chalk_1.default.blue(` ${message}`);
160
163
  }
161
164
  formatExtras(extras) {
162
- const entries = Object.entries(extras);
163
- if (entries.length === 0) {
164
- return '';
165
- }
166
- const formattedExtras = entries.map(([key, value]) => {
167
- if (is_1.default.string(value) &&
168
- !this.containsWhitespace(value) &&
169
- value.length > 0) {
170
- return `${key}=${value}`;
171
- }
172
- return `${key}=${JSON.stringify(value)}`;
173
- });
174
- return chalk_1.default.red(` (${formattedExtras.join(', ')})`);
165
+ const formattedExtras = extras.format();
166
+ return formattedExtras.length === 0 ? '' : chalk_1.default.red(` ${formattedExtras}`);
175
167
  }
176
168
  formatDetails(message, details) {
177
169
  const formatted = [];
@@ -179,7 +171,7 @@ class Formatter {
179
171
  formatted.push(chalk_1.default.blue(this.indent(message, true)));
180
172
  }
181
173
  formatted.push(...Object.entries(details).map(([key, value]) => chalk_1.default.cyan(this.indent(`${key}: ${(0, json_stringify_pretty_compact_1.default)(value, {
182
- indent: this._options.jsonIndent,
174
+ indent: this._options.indent.json,
183
175
  maxLength: 80,
184
176
  })}`, true))));
185
177
  const separator = [
@@ -190,14 +182,6 @@ class Formatter {
190
182
  const suffix = formatted.length > 0 ? this._options.newLineCharacter : '';
191
183
  return `${formatted.join(separator)}${suffix}`;
192
184
  }
193
- isExtra(value) {
194
- let stringifiedValue = JSON.stringify(value, undefined, 2);
195
- if (is_1.default.string(value)) {
196
- stringifiedValue = value;
197
- }
198
- return (this.isSingleLine(stringifiedValue) &&
199
- stringifiedValue.length <= this._options.extrasMaxValueLength);
200
- }
201
185
  isSingleLine(string) {
202
186
  return !this._regex.newLine.test(string);
203
187
  }
@@ -205,7 +189,7 @@ class Formatter {
205
189
  return this._regex.whitespace.test(string);
206
190
  }
207
191
  indent(input, leading = false) {
208
- const indentation = ' '.repeat(this._options.indent);
192
+ const indentation = ' '.repeat(this._options.indent.details);
209
193
  const prefix = leading ? indentation : '';
210
194
  const formatted = input
211
195
  .split(this._regex.newLine)
@@ -0,0 +1,2 @@
1
+ import { Formatter } from './formatter';
2
+ export { Formatter };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Formatter = void 0;
4
+ const formatter_1 = require("./formatter");
5
+ Object.defineProperty(exports, "Formatter", { enumerable: true, get: function () { return formatter_1.Formatter; } });
@@ -1,47 +1,151 @@
1
- interface Options {
2
- enable?: {
3
- time?: boolean;
4
- name?: boolean;
5
- hostname?: boolean;
6
- pid?: boolean;
7
- source?: boolean;
8
- extras?: boolean;
9
- };
10
- extrasKey?: string;
11
- indent?: number;
12
- jsonIndent?: number;
13
- basePath?: string;
14
- newLineCharacter?: '\r' | '\n' | '\r\n';
15
- time?: {
16
- type?: 'short' | 'long' | 'format';
1
+ import { z } from 'zod';
2
+ declare const schema: z.ZodObject<{
3
+ show: z.ZodDefault<z.ZodObject<{
4
+ time: z.ZodDefault<z.ZodBoolean>;
5
+ name: z.ZodDefault<z.ZodBoolean>;
6
+ hostname: z.ZodDefault<z.ZodBoolean>;
7
+ pid: z.ZodDefault<z.ZodBoolean>;
8
+ source: z.ZodDefault<z.ZodBoolean>;
9
+ extras: z.ZodDefault<z.ZodBoolean>;
10
+ }, "strict", z.ZodTypeAny, {
11
+ source: boolean;
12
+ name: boolean;
13
+ time: boolean;
14
+ hostname: boolean;
15
+ pid: boolean;
16
+ extras: boolean;
17
+ }, {
18
+ source?: boolean | undefined;
19
+ name?: boolean | undefined;
20
+ time?: boolean | undefined;
21
+ hostname?: boolean | undefined;
22
+ pid?: boolean | undefined;
23
+ extras?: boolean | undefined;
24
+ }>>;
25
+ extras: z.ZodDefault<z.ZodObject<{
26
+ key: z.ZodOptional<z.ZodString>;
27
+ maxLength: z.ZodDefault<z.ZodObject<{
28
+ key: z.ZodDefault<z.ZodNumber>;
29
+ value: z.ZodDefault<z.ZodNumber>;
30
+ total: z.ZodDefault<z.ZodNumber>;
31
+ }, "strict", z.ZodTypeAny, {
32
+ key: number;
33
+ total: number;
34
+ value: number;
35
+ }, {
36
+ key?: number | undefined;
37
+ total?: number | undefined;
38
+ value?: number | undefined;
39
+ }>>;
40
+ }, "strict", z.ZodTypeAny, {
41
+ key?: string | undefined;
42
+ maxLength: {
43
+ key: number;
44
+ total: number;
45
+ value: number;
46
+ };
47
+ }, {
48
+ key?: string | undefined;
49
+ maxLength?: {
50
+ key?: number | undefined;
51
+ total?: number | undefined;
52
+ value?: number | undefined;
53
+ } | undefined;
54
+ }>>;
55
+ indent: z.ZodDefault<z.ZodObject<{
56
+ details: z.ZodDefault<z.ZodNumber>;
57
+ json: z.ZodDefault<z.ZodNumber>;
58
+ }, "strict", z.ZodTypeAny, {
59
+ details: number;
60
+ json: number;
61
+ }, {
62
+ details?: number | undefined;
63
+ json?: number | undefined;
64
+ }>>;
65
+ basePath: z.ZodDefault<z.ZodString>;
66
+ newLineCharacter: z.ZodDefault<z.ZodEnum<["\r", "\n", "\r\n"]>>;
67
+ time: z.ZodDefault<z.ZodObject<{
68
+ type: z.ZodDefault<z.ZodEnum<["short", "long", "format"]>>;
17
69
  /**
18
70
  * Display local time instead of UTC.
19
71
  */
20
- local?: boolean;
72
+ local: z.ZodDefault<z.ZodBoolean>;
21
73
  /**
22
74
  * Time format as specified by the `Moment.js` [format options](
23
75
  * https://momentjs.com/docs/#/displaying/format/).
24
76
  *
25
77
  * @note The time zone, `Z` or `ZZ`, should be omitted as `Z` is
26
78
  * automatically to the format if the time is UTC.
27
- * @note The `Z` display suffix for UTC times is automatically added to the
28
- * format and should be omitted.
79
+ * @note The `Z` display suffix for UTC times is automatically added to
80
+ * the format and should be omitted.
29
81
  */
30
- format?: string;
82
+ format: z.ZodDefault<z.ZodString>;
83
+ }, "strict", z.ZodTypeAny, {
84
+ type: "long" | "short" | "format";
85
+ format: string;
86
+ local: boolean;
87
+ }, {
88
+ type?: "long" | "short" | "format" | undefined;
89
+ format?: string | undefined;
90
+ local?: boolean | undefined;
91
+ }>>;
92
+ }, "strict", z.ZodTypeAny, {
93
+ show: {
94
+ source: boolean;
95
+ name: boolean;
96
+ time: boolean;
97
+ hostname: boolean;
98
+ pid: boolean;
99
+ extras: boolean;
31
100
  };
32
- }
33
- interface InternalOptions {
34
- extrasMaxValueLength: number;
35
101
  time: {
36
- formats: {
37
- short: string;
38
- long: string;
102
+ type: "long" | "short" | "format";
103
+ format: string;
104
+ local: boolean;
105
+ };
106
+ extras: {
107
+ key?: string | undefined;
108
+ maxLength: {
109
+ key: number;
110
+ total: number;
111
+ value: number;
39
112
  };
40
113
  };
41
- }
42
- declare type DeepRequired<T> = {
43
- [P in keyof T]-?: DeepRequired<T[P]>;
44
- };
45
- declare type MergedOptions = DeepRequired<Options & InternalOptions>;
46
- declare const schema: import("joi").ObjectSchema<any>;
47
- export { Options, InternalOptions, MergedOptions, schema };
114
+ indent: {
115
+ details: number;
116
+ json: number;
117
+ };
118
+ basePath: string;
119
+ newLineCharacter: "\r" | "\n" | "\r\n";
120
+ }, {
121
+ show?: {
122
+ source?: boolean | undefined;
123
+ name?: boolean | undefined;
124
+ time?: boolean | undefined;
125
+ hostname?: boolean | undefined;
126
+ pid?: boolean | undefined;
127
+ extras?: boolean | undefined;
128
+ } | undefined;
129
+ time?: {
130
+ type?: "long" | "short" | "format" | undefined;
131
+ format?: string | undefined;
132
+ local?: boolean | undefined;
133
+ } | undefined;
134
+ extras?: {
135
+ key?: string | undefined;
136
+ maxLength?: {
137
+ key?: number | undefined;
138
+ total?: number | undefined;
139
+ value?: number | undefined;
140
+ } | undefined;
141
+ } | undefined;
142
+ indent?: {
143
+ details?: number | undefined;
144
+ json?: number | undefined;
145
+ } | undefined;
146
+ basePath?: string | undefined;
147
+ newLineCharacter?: "\r" | "\n" | "\r\n" | undefined;
148
+ }>;
149
+ declare type Options = z.input<typeof schema>;
150
+ declare type ParsedOptions = z.infer<typeof schema>;
151
+ export { Options, ParsedOptions, schema };
@@ -2,42 +2,67 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schema = void 0;
4
4
  const bunyan_record_1 = require("./bunyan-record");
5
- const helpers_1 = require("./helpers");
6
- const schema = helpers_1.joi.object().keys({
7
- enable: helpers_1.joi
8
- .object()
9
- .keys({
10
- time: helpers_1.joi.boolean().default(true),
11
- name: helpers_1.joi.boolean().default(false),
12
- hostname: helpers_1.joi.boolean().default(false),
13
- pid: helpers_1.joi.boolean().default(false),
14
- source: helpers_1.joi.boolean().default(false),
15
- extras: helpers_1.joi.boolean().default(true),
5
+ const zod_1 = require("zod");
6
+ const schema = zod_1.z
7
+ .object({
8
+ show: zod_1.z
9
+ .object({
10
+ time: zod_1.z.boolean().default(true),
11
+ name: zod_1.z.boolean().default(false),
12
+ hostname: zod_1.z.boolean().default(false),
13
+ pid: zod_1.z.boolean().default(false),
14
+ source: zod_1.z.boolean().default(false),
15
+ extras: zod_1.z.boolean().default(true),
16
16
  })
17
- .default(),
18
- extrasKey: helpers_1.joi
19
- .string()
20
- .disallow(...(0, bunyan_record_1.coreFields)(), '')
21
- .default(''),
22
- indent: helpers_1.joi.number().integer().min(0).default(4),
23
- jsonIndent: helpers_1.joi.number().integer().min(0).default(2),
24
- basePath: helpers_1.joi.string().default('/'),
25
- newLineCharacter: helpers_1.joi.string().valid('\r', '\n', '\r\n').default('\n'),
26
- extrasMaxValueLength: helpers_1.joi.number().integer().positive().default(50),
27
- time: helpers_1.joi
28
- .object()
29
- .keys({
30
- local: helpers_1.joi.boolean().default(false),
31
- type: helpers_1.joi.string().valid('short', 'long', 'format').default('long'),
32
- format: helpers_1.joi.string().default('YYYY-MM-DD[T]HH:mm:ss.SSS'),
33
- formats: helpers_1.joi
34
- .object()
35
- .keys({
36
- short: helpers_1.joi.string().default('HH:mm:ss.SSS'),
37
- long: helpers_1.joi.string().default('YYYY-MM-DD[T]HH:mm:ss.SSS'),
17
+ .strict()
18
+ .default({}),
19
+ extras: zod_1.z
20
+ .object({
21
+ key: zod_1.z
22
+ .string()
23
+ .min(1)
24
+ .regex(new RegExp(`^((?!(${(0, bunyan_record_1.coreFields)().join('|')})).)*$`))
25
+ .optional(),
26
+ maxLength: zod_1.z
27
+ .object({
28
+ key: zod_1.z.number().int().positive().default(20),
29
+ value: zod_1.z.number().int().positive().default(50),
30
+ total: zod_1.z.number().int().positive().default(500),
38
31
  })
39
- .default(),
32
+ .strict()
33
+ .default({}),
40
34
  })
41
- .default(),
42
- });
35
+ .strict()
36
+ .default({}),
37
+ indent: zod_1.z
38
+ .object({
39
+ details: zod_1.z.number().int().nonnegative().default(4),
40
+ json: zod_1.z.number().int().nonnegative().default(2),
41
+ })
42
+ .strict()
43
+ .default({}),
44
+ basePath: zod_1.z.string().min(1).default('/'),
45
+ newLineCharacter: zod_1.z.enum(['\r', '\n', '\r\n']).default('\n'),
46
+ time: zod_1.z
47
+ .object({
48
+ type: zod_1.z.enum(['short', 'long', 'format']).default('long'),
49
+ /**
50
+ * Display local time instead of UTC.
51
+ */
52
+ local: zod_1.z.boolean().default(false),
53
+ /**
54
+ * Time format as specified by the `Moment.js` [format options](
55
+ * https://momentjs.com/docs/#/displaying/format/).
56
+ *
57
+ * @note The time zone, `Z` or `ZZ`, should be omitted as `Z` is
58
+ * automatically to the format if the time is UTC.
59
+ * @note The `Z` display suffix for UTC times is automatically added to
60
+ * the format and should be omitted.
61
+ */
62
+ format: zod_1.z.string().min(1).default('YYYY-MM-DD[T]HH:mm:ss.SSS'),
63
+ })
64
+ .strict()
65
+ .default({}),
66
+ })
67
+ .strict();
43
68
  exports.schema = schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vidavidorra/bunyan-pretty-stream",
3
- "version": "2.0.10",
3
+ "version": "3.0.1",
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",
@@ -11,9 +11,7 @@
11
11
  "dist/src/**/!(*.test).{js,d.ts}"
12
12
  ],
13
13
  "scripts": {
14
- "_postinstall": "husky install .github/husky",
15
- "prepublishOnly": "pinst --disable",
16
- "postpublish": "pinst --enable",
14
+ "prepare": "husky install .github/husky",
17
15
  "lint": "run-p format:check lint-es",
18
16
  "lint:fix": "run-s format lint-es:fix",
19
17
  "lint-es": "eslint --ext .ts,.tsx,.js,.jsx,.json .",
@@ -53,46 +51,45 @@
53
51
  "node": ">=14.0.0"
54
52
  },
55
53
  "devDependencies": {
56
- "@commitlint/cli": "16.1.0",
57
- "@jest/globals": "27.4.6",
54
+ "@commitlint/cli": "16.2.3",
55
+ "@jest/globals": "27.5.1",
58
56
  "@semantic-release/changelog": "6.0.1",
59
57
  "@semantic-release/exec": "6.0.3",
60
58
  "@semantic-release/git": "10.0.1",
61
59
  "@types/bunyan": "1.8.8",
62
60
  "@types/clone": "2.1.1",
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",
61
+ "@types/node": "16.11.26",
62
+ "@typescript-eslint/eslint-plugin": "5.17.0",
63
+ "@typescript-eslint/parser": "5.17.0",
64
+ "@vidavidorra/commitlint-config": "3.2.5",
67
65
  "bunyan": "*",
68
66
  "bunyan-1.x": "npm:bunyan@1.8.15",
69
67
  "bunyan-2.x": "npm:bunyan@2.0.5",
70
68
  "clone": "2.1.2",
71
69
  "dot-prop": "6.0.1",
72
- "eslint": "8.5.0",
73
- "eslint-config-prettier": "8.3.0",
74
- "eslint-plugin-jest": "25.3.0",
70
+ "eslint": "8.12.0",
71
+ "eslint-config-prettier": "8.5.0",
72
+ "eslint-plugin-jest": "26.1.3",
75
73
  "eslint-plugin-json": "3.1.0",
76
74
  "eslint-plugin-prettier": "4.0.0",
77
75
  "husky": "7.0.4",
78
- "jest": "27.4.7",
79
- "lint-staged": "12.3.1",
76
+ "jest": "27.5.1",
77
+ "lint-staged": "12.3.7",
80
78
  "npm-run-all": "4.1.5",
81
- "pinst": "2.1.6",
82
- "prettier": "2.5.1",
79
+ "prettier": "2.6.2",
83
80
  "semantic-release": "19.0.2",
84
81
  "strip-ansi": "6.0.1",
85
- "ts-jest": "27.1.3",
86
- "typescript": "4.5.5"
82
+ "ts-jest": "27.1.4",
83
+ "typescript": "4.6.3"
87
84
  },
88
85
  "peerDependencies": {
89
86
  "bunyan": "1.8.15"
90
87
  },
91
88
  "dependencies": {
92
- "@sindresorhus/is": "4.4.0",
89
+ "@sindresorhus/is": "4.6.0",
93
90
  "chalk": "4.1.2",
94
- "joi": "17.4.2",
95
91
  "json-stringify-pretty-compact": "3.0.0",
96
- "moment": "2.29.1"
92
+ "moment": "2.29.1",
93
+ "zod": "3.14.4"
97
94
  }
98
95
  }
@@ -1,2 +0,0 @@
1
- import { Joi, joi } from './joi';
2
- export { Joi, joi };
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.joi = exports.Joi = void 0;
4
- const joi_1 = require("./joi");
5
- Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return joi_1.Joi; } });
6
- Object.defineProperty(exports, "joi", { enumerable: true, get: function () { return joi_1.joi; } });
@@ -1,6 +0,0 @@
1
- import BaseJoi from 'joi';
2
- interface Joi extends BaseJoi.Root {
3
- isValid<T>(validation: BaseJoi.ValidationResult, value: unknown): value is T;
4
- }
5
- declare const joi: Joi;
6
- export { joi, BaseJoi as Joi };
@@ -1,13 +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.Joi = exports.joi = void 0;
7
- const joi_1 = __importDefault(require("joi"));
8
- exports.Joi = joi_1.default;
9
- function isValid(validation, value) {
10
- return validation.error === undefined;
11
- }
12
- const joi = { ...joi_1.default, isValid };
13
- exports.joi = joi;