@visulima/pail 3.1.0 → 3.2.0

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 (76) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE.md +1 -408
  3. package/README.md +298 -0
  4. package/dist/index.browser.d.ts +3 -3
  5. package/dist/index.browser.js +12 -1
  6. package/dist/index.server.d.ts +8 -5
  7. package/dist/index.server.js +535 -2
  8. package/dist/interactive/index.js +2 -1
  9. package/dist/object-tree.js +89 -2
  10. package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
  11. package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
  12. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
  13. package/dist/packem_shared/JsonReporter-BqWsVkHP.js +60 -0
  14. package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
  15. package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
  16. package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
  17. package/dist/packem_shared/{abstract-json-reporter-CPsNkpz8.d.ts → abstract-json-reporter-DiyVyU0j.d.ts} +1 -1
  18. package/dist/packem_shared/{abstract-pretty-reporter-DB2G-qlI.d.ts → abstract-pretty-reporter-BbOWXMCs.d.ts} +1 -1
  19. package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
  20. package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
  21. package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
  22. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
  23. package/dist/packem_shared/index-BomQ3E6J.js +650 -0
  24. package/dist/packem_shared/index-DqKWykfa.js +1146 -0
  25. package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
  26. package/dist/packem_shared/{pail.browser-CmWcqnn9.d.ts → pail.browser-By9KjOH7.d.ts} +8 -3
  27. package/dist/packem_shared/pail.browser-CPDOE_d1.js +1427 -0
  28. package/dist/packem_shared/{types-DVzG8TWL.d.ts → types-D3ycu8-x.d.ts} +1 -1
  29. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
  30. package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
  31. package/dist/processor/caller/caller-processor.d.ts +1 -1
  32. package/dist/processor/caller/caller-processor.js +59 -1
  33. package/dist/processor/message-formatter-processor.d.ts +1 -1
  34. package/dist/processor/message-formatter-processor.js +67 -1
  35. package/dist/processor/opentelemetry-processor.d.ts +19 -0
  36. package/dist/processor/opentelemetry-processor.js +52 -0
  37. package/dist/processor/redact-processor.d.ts +1 -1
  38. package/dist/processor/redact-processor.js +30 -1
  39. package/dist/progress-bar.js +404 -1
  40. package/dist/reporter/file/json-file-reporter.d.ts +2 -2
  41. package/dist/reporter/file/json-file-reporter.js +136 -4
  42. package/dist/reporter/http/abstract-http-reporter.d.ts +102 -0
  43. package/dist/reporter/http/abstract-http-reporter.js +435 -0
  44. package/dist/reporter/http/http-reporter.d.ts +13 -0
  45. package/dist/reporter/http/http-reporter.edge-light.d.ts +168 -0
  46. package/dist/reporter/http/http-reporter.edge-light.js +651 -0
  47. package/dist/reporter/http/http-reporter.js +13 -0
  48. package/dist/reporter/json/index.browser.d.ts +2 -2
  49. package/dist/reporter/json/index.browser.js +2 -1
  50. package/dist/reporter/json/index.d.ts +2 -2
  51. package/dist/reporter/json/index.js +2 -1
  52. package/dist/reporter/pretty/index.browser.d.ts +2 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +2 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +2 -2
  57. package/dist/reporter/simple/simple-reporter.server.js +186 -8
  58. package/dist/spinner.js +2150 -1
  59. package/package.json +53 -3
  60. package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
  61. package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
  62. package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
  63. package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
  64. package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
  65. package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
  66. package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
  67. package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
  68. package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
  69. package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
  70. package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
  71. package/dist/packem_shared/index-CysYvHXs.js +0 -8
  72. package/dist/packem_shared/index-D9hWq9ka.js +0 -1
  73. package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
  74. package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
  75. package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
  76. package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
@@ -0,0 +1,204 @@
1
+ import { E as EMPTY_SYMBOL } from './constants-DfDr4MHC.js';
2
+
3
+ function isPlainObject(value) {
4
+ if (typeof value !== "object" || value === null) {
5
+ return false;
6
+ }
7
+ const prototype = Object.getPrototypeOf(value);
8
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
9
+ }
10
+
11
+ const ErrorProto = Object.create(
12
+ {},
13
+ {
14
+ cause: {
15
+ enumerable: true,
16
+ value: void 0,
17
+ writable: true
18
+ },
19
+ code: {
20
+ enumerable: true,
21
+ value: void 0,
22
+ writable: true
23
+ },
24
+ errors: {
25
+ enumerable: true,
26
+ value: void 0,
27
+ writable: true
28
+ },
29
+ message: {
30
+ enumerable: true,
31
+ value: void 0,
32
+ writable: true
33
+ },
34
+ name: {
35
+ enumerable: true,
36
+ value: void 0,
37
+ writable: true
38
+ },
39
+ stack: {
40
+ enumerable: true,
41
+ value: void 0,
42
+ writable: true
43
+ }
44
+ }
45
+ );
46
+ const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
47
+ const toJSON = (from) => {
48
+ toJsonWasCalled.add(from);
49
+ const json = from.toJSON();
50
+ toJsonWasCalled.delete(from);
51
+ return json;
52
+ };
53
+ const serializeValue = (value, seen, depth, options) => {
54
+ if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
55
+ return "[object Buffer]";
56
+ }
57
+ if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
58
+ return "[object Stream]";
59
+ }
60
+ if (value instanceof Error) {
61
+ if (seen.includes(value)) {
62
+ return "[Circular]";
63
+ }
64
+ depth += 1;
65
+ return _serialize(value, options, seen, depth);
66
+ }
67
+ if (options.useToJSON && typeof value.toJSON === "function") {
68
+ return value.toJSON();
69
+ }
70
+ if (typeof value === "object" && value instanceof Date) {
71
+ return value.toISOString();
72
+ }
73
+ if (typeof value === "function") {
74
+ return `[Function: ${value.name || "anonymous"}]`;
75
+ }
76
+ if (isPlainObject(value)) {
77
+ depth += 1;
78
+ if (options.maxDepth && depth >= options.maxDepth) {
79
+ return {};
80
+ }
81
+ const plainObject = {};
82
+ for (const key in value) {
83
+ plainObject[key] = serializeValue(value[key], seen, depth, options);
84
+ }
85
+ return plainObject;
86
+ }
87
+ try {
88
+ return value;
89
+ } catch {
90
+ return "[Not Available]";
91
+ }
92
+ };
93
+ const _serialize = (error, options, seen, depth) => {
94
+ seen.push(error);
95
+ if (options.maxDepth === 0) {
96
+ return {};
97
+ }
98
+ if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
99
+ return toJSON(error);
100
+ }
101
+ const protoError = Object.create(ErrorProto);
102
+ protoError.name = Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name;
103
+ protoError.message = error.message;
104
+ protoError.stack = error.stack;
105
+ if (Array.isArray(error.errors)) {
106
+ const aggregateErrors = [];
107
+ for (const aggregateError of error.errors) {
108
+ if (!(aggregateError instanceof Error)) {
109
+ throw new TypeError("All errors in the 'errors' property must be instances of Error");
110
+ }
111
+ if (seen.includes(aggregateError)) {
112
+ protoError.errors = [];
113
+ return protoError;
114
+ }
115
+ aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
116
+ }
117
+ protoError.errors = aggregateErrors;
118
+ }
119
+ if (error.cause instanceof Error && !seen.includes(error.cause)) {
120
+ protoError.cause = _serialize(error.cause, options, seen, depth);
121
+ }
122
+ for (const key in error) {
123
+ if (protoError[key] === void 0) {
124
+ const value = error[key];
125
+ protoError[key] = serializeValue(value, seen, depth, options);
126
+ }
127
+ }
128
+ if (Array.isArray(options.exclude) && options.exclude.length > 0) {
129
+ for (const key of options.exclude) {
130
+ try {
131
+ delete protoError[key];
132
+ } catch {
133
+ }
134
+ }
135
+ }
136
+ return protoError;
137
+ };
138
+ const serialize = (error, options = {}) => _serialize(
139
+ error,
140
+ {
141
+ exclude: options.exclude ?? [],
142
+ maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
143
+ useToJSON: options.useToJSON ?? false
144
+ },
145
+ [],
146
+ 0
147
+ );
148
+
149
+ class AbstractJsonReporter {
150
+ /** Custom stringify function for object serialization */
151
+ stringify;
152
+ /** Error serialization options */
153
+ errorOptions;
154
+ /**
155
+ * Creates a new AbstractJsonReporter instance.
156
+ * @param options Configuration options for JSON formatting and error handling
157
+ */
158
+ constructor(options = {}) {
159
+ this.errorOptions = options.error ?? {};
160
+ }
161
+ /**
162
+ * Sets a custom stringify function for object serialization.
163
+ * @param function_ The stringify function to use for serialization
164
+ */
165
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
166
+ setStringify(function_) {
167
+ this.stringify = function_;
168
+ }
169
+ // eslint-disable-next-line sonarjs/cognitive-complexity
170
+ log(meta) {
171
+ const { context, error, file, message, type, ...rest } = meta;
172
+ if (rest.label) {
173
+ rest.label = rest.label.trim();
174
+ }
175
+ if (file) {
176
+ rest.file = `${file.name}:${file.line}${file.column ? `:${file.column}` : ""}`;
177
+ }
178
+ if (message === EMPTY_SYMBOL) {
179
+ rest.message = void 0;
180
+ } else {
181
+ rest.message = message;
182
+ }
183
+ if (error) {
184
+ rest.error = serialize(error, this.errorOptions);
185
+ }
186
+ if (context) {
187
+ const newContext = [];
188
+ for (const item of context) {
189
+ if (item === EMPTY_SYMBOL) {
190
+ continue;
191
+ }
192
+ if (item instanceof Error) {
193
+ newContext.push(serialize(item, this.errorOptions));
194
+ } else {
195
+ newContext.push(item);
196
+ }
197
+ }
198
+ rest.context = newContext;
199
+ }
200
+ this._log(this.stringify(rest), type.level);
201
+ }
202
+ }
203
+
204
+ export { AbstractJsonReporter };
@@ -0,0 +1,172 @@
1
+ import { t as terminalSize, w as wordWrap, W as WrapMode } from './index-DqKWykfa.js';
2
+
3
+ class InteractiveManager {
4
+ #stream;
5
+ #isActive = false;
6
+ #isSuspended = false;
7
+ #lastLength = 0;
8
+ #outside = 0;
9
+ /**
10
+ * Creates a new InteractiveManager with the given stream hooks.
11
+ * @param stdout Hook for stdout stream
12
+ * @param stderr Hook for stderr stream
13
+ */
14
+ constructor(stdout, stderr) {
15
+ this.#stream = {
16
+ stderr,
17
+ stdout
18
+ };
19
+ }
20
+ /**
21
+ * Last printed rows count.
22
+ *
23
+ * Tracks the number of rows that were last written to the terminal.
24
+ * Used internally for managing cursor positioning and output updates.
25
+ */
26
+ get lastLength() {
27
+ return this.#lastLength;
28
+ }
29
+ /**
30
+ * Rows count outside editable area.
31
+ *
32
+ * Tracks the number of rows that extend beyond the current terminal height.
33
+ * Used for managing scrolling and ensuring all output remains visible.
34
+ */
35
+ get outside() {
36
+ return this.#outside;
37
+ }
38
+ /**
39
+ * Hook activity status.
40
+ *
41
+ * Indicates whether the interactive hooks are currently active.
42
+ * When true, streams are being intercepted for interactive output.
43
+ */
44
+ get isHooked() {
45
+ return this.#isActive;
46
+ }
47
+ /**
48
+ * Suspend status for active hooks.
49
+ *
50
+ * Indicates whether interactive mode is temporarily suspended.
51
+ * When suspended, external output can be written without interference.
52
+ */
53
+ get isSuspended() {
54
+ return this.#isSuspended;
55
+ }
56
+ /**
57
+ * Removes lines from the terminal output.
58
+ *
59
+ * Erases the specified number of lines from the bottom of the output,
60
+ * moving the cursor up and clearing the lines. Useful for removing
61
+ * previous interactive output before displaying new content.
62
+ * @param stream The stream to erase lines from ("stdout" or "stderr")
63
+ * @param count Number of lines to remove (defaults to lastLength)
64
+ * @throws {TypeError} If the specified stream is not available
65
+ */
66
+ erase(stream, count = this.#lastLength) {
67
+ if (this.#stream[stream] === void 0) {
68
+ throw new TypeError(`Stream "${stream}" is not available`);
69
+ }
70
+ this.#stream[stream].erase(count);
71
+ }
72
+ /**
73
+ * Hook stdout and stderr streams.
74
+ * @returns Success status
75
+ */
76
+ hook() {
77
+ if (!this.#isActive) {
78
+ Object.values(this.#stream).forEach((hook) => hook.active());
79
+ this.#clear(true);
80
+ }
81
+ return this.#isActive;
82
+ }
83
+ /**
84
+ * Resume suspend hooks.
85
+ * @param stream Stream to resume
86
+ * @param eraseRowCount erase output rows count
87
+ */
88
+ resume(stream, eraseRowCount) {
89
+ if (this.#isSuspended) {
90
+ this.#isSuspended = false;
91
+ if (eraseRowCount) {
92
+ this.erase(stream, eraseRowCount);
93
+ }
94
+ this.#lastLength = 0;
95
+ Object.values(this.#stream).forEach((hook) => hook.active());
96
+ }
97
+ }
98
+ /**
99
+ * Suspend active hooks for external output.
100
+ * @param stream Stream to suspend
101
+ * @param erase erase output
102
+ */
103
+ suspend(stream, erase = true) {
104
+ if (!this.#isSuspended) {
105
+ this.#isSuspended = true;
106
+ if (erase) {
107
+ this.erase(stream);
108
+ }
109
+ Object.values(this.#stream).forEach((hook) => hook.renew());
110
+ }
111
+ }
112
+ /**
113
+ * Unhooks both stdout and stderr streams and print their story of logs.
114
+ * @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
115
+ * @returns Success status
116
+ */
117
+ unhook(separateHistory = true) {
118
+ if (this.#isActive) {
119
+ Object.values(this.#stream).forEach((hook) => hook.inactive(separateHistory));
120
+ this.#clear();
121
+ }
122
+ return !this.#isActive;
123
+ }
124
+ /**
125
+ * Update output.
126
+ * @param stream Stream to write to
127
+ * @param rows Text lines to write to standard output
128
+ * @param from Index of the line starting from which the contents of the terminal are being overwritten
129
+ */
130
+ update(stream, rows, from = 0) {
131
+ if (rows.length > 0) {
132
+ if (this.#stream[stream] === void 0) {
133
+ throw new TypeError(`Stream "${stream}" is not available`);
134
+ }
135
+ const hook = this.#stream[stream];
136
+ const { columns: width, rows: height } = terminalSize();
137
+ const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));
138
+ const actualLength = this.lastLength - position;
139
+ const outside = Math.max(actualLength - height, this.outside);
140
+ let output = rows.reduce(
141
+ (accumulator, row) => [
142
+ ...accumulator,
143
+ wordWrap(row, {
144
+ trim: false,
145
+ width,
146
+ wrapMode: WrapMode.STRICT_WIDTH
147
+ })
148
+ ],
149
+ []
150
+ );
151
+ if (height <= actualLength) {
152
+ hook.erase(height);
153
+ if (position < outside) {
154
+ output = output.slice(outside - position + 1);
155
+ }
156
+ } else if (actualLength) {
157
+ hook.erase(actualLength);
158
+ }
159
+ hook.write(`${output.join("\n")}
160
+ `);
161
+ this.#lastLength = outside ? outside + output.length + 1 : output.length;
162
+ this.#outside = Math.max(this.lastLength - height, this.outside);
163
+ }
164
+ }
165
+ #clear(status = false) {
166
+ this.#isActive = status;
167
+ this.#lastLength = 0;
168
+ this.#outside = 0;
169
+ }
170
+ }
171
+
172
+ export { InteractiveManager as default };
@@ -0,0 +1,21 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+
21
+ export { I as default } from './interactive-stream-hook-DG4BtN12.js';
@@ -0,0 +1,60 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const {
8
+ stdout,
9
+ stderr
10
+ } = __cjs_getProcess;
11
+ import { w as writeStream } from './write-stream-BG8fhcs3.js';
12
+ import { AbstractJsonReporter } from './AbstractJsonReporter-intFdT_A.js';
13
+
14
+ class JsonReporter extends AbstractJsonReporter {
15
+ /** Standard output stream */
16
+ #stdout;
17
+ /** Standard error stream */
18
+ #stderr;
19
+ /**
20
+ * Creates a new Server JSON Reporter instance.
21
+ * @param options Configuration options for JSON formatting
22
+ */
23
+ constructor(options = {}) {
24
+ super(options);
25
+ this.#stdout = stdout;
26
+ this.#stderr = stderr;
27
+ }
28
+ /**
29
+ * Sets the stdout stream for the reporter.
30
+ * @param stdout_ The writable stream to use for stdout output
31
+ */
32
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
33
+ setStdout(stdout_) {
34
+ this.#stdout = stdout_;
35
+ }
36
+ /**
37
+ * Sets the stderr stream for the reporter.
38
+ * @param stderr_ The writable stream to use for stderr output
39
+ */
40
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
41
+ setStderr(stderr_) {
42
+ this.#stderr = stderr_;
43
+ }
44
+ /**
45
+ * Outputs the JSON message to the appropriate stream.
46
+ *
47
+ * Routes error and warning level messages to stderr, others to stdout.
48
+ * @param message The JSON-formatted log message
49
+ * @param logLevel The log level determining which stream to use
50
+ * @protected
51
+ */
52
+ // eslint-disable-next-line no-underscore-dangle
53
+ _log(message, logLevel) {
54
+ const stream = ["error", "warn"].includes(logLevel) ? this.#stderr : this.#stdout;
55
+ writeStream(`${message}
56
+ `, stream);
57
+ }
58
+ }
59
+
60
+ export { JsonReporter as default };
@@ -0,0 +1,28 @@
1
+ import { AbstractJsonReporter } from './AbstractJsonReporter-intFdT_A.js';
2
+ import { w as writeConsoleLogBasedOnLevel } from './write-console-log-based-on-level-DBmRYXpj.js';
3
+
4
+ class JsonReporter extends AbstractJsonReporter {
5
+ /**
6
+ * Creates a new Browser JSON Reporter instance.
7
+ * @param options Configuration options for JSON formatting
8
+ */
9
+ constructor(options = {}) {
10
+ super(options);
11
+ }
12
+ /**
13
+ * Outputs the JSON message to the browser console.
14
+ *
15
+ * Uses the appropriate console method based on the log level
16
+ * (console.log, console.error, console.warn, etc.).
17
+ * @param message The JSON-formatted log message
18
+ * @param logLevel The log level determining which console method to use
19
+ * @protected
20
+ */
21
+ // eslint-disable-next-line class-methods-use-this, no-underscore-dangle
22
+ _log(message, logLevel) {
23
+ const consoleLogFunction = writeConsoleLogBasedOnLevel(logLevel);
24
+ consoleLogFunction(message);
25
+ }
26
+ }
27
+
28
+ export { JsonReporter as default };
@@ -0,0 +1,222 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const {
8
+ stdout,
9
+ stderr
10
+ } = __cjs_getProcess;
11
+ import colorize, { red, greenBright, cyan, green, grey, white, bgGrey, underline } from '@visulima/colorize';
12
+ import { d as defaultInspectorConfig, f as formatLabel, i as inspect, r as renderError } from './format-label-Btft2KGP.js';
13
+ import { t as terminalSize, g as getStringWidth, w as wordWrap, W as WrapMode } from './index-DqKWykfa.js';
14
+ import { E as EMPTY_SYMBOL } from './constants-DfDr4MHC.js';
15
+ import { A as AbstractPrettyReporter, g as getLongestBadge } from './abstract-pretty-reporter-DMPDCslJ.js';
16
+ import { g as getLongestLabel } from './get-longest-label-C9PWeyKq.js';
17
+ import { w as writeStream } from './write-stream-BG8fhcs3.js';
18
+
19
+ const pailFileFilter = (line) => !/[\\/]pail[\\/]dist/.test(line);
20
+ class PrettyReporter extends AbstractPrettyReporter {
21
+ #stdout;
22
+ #stderr;
23
+ #interactiveManager;
24
+ #interactive = false;
25
+ #inspectOptions;
26
+ #errorOptions;
27
+ /**
28
+ * Creates a new Server Pretty Reporter instance.
29
+ * @param options Configuration options for styling, error rendering, and object inspection
30
+ */
31
+ constructor(options = {}) {
32
+ const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
33
+ super({
34
+ uppercase: {
35
+ label: true,
36
+ ...rest.uppercase
37
+ },
38
+ ...rest
39
+ });
40
+ this.#inspectOptions = { ...defaultInspectorConfig, ...inspectOptions };
41
+ this.#errorOptions = {
42
+ ...errorOptions,
43
+ color: {
44
+ fileLine: green,
45
+ hint: cyan,
46
+ marker: red,
47
+ message: red,
48
+ method: greenBright,
49
+ title: red
50
+ }
51
+ };
52
+ this.#stdout = stdout;
53
+ this.#stderr = stderr;
54
+ }
55
+ /**
56
+ * Sets the stdout stream for the reporter.
57
+ * @param stdout_ The writable stream to use for standard output
58
+ */
59
+ setStdout(stdout_) {
60
+ this.#stdout = stdout_;
61
+ }
62
+ /**
63
+ * Sets the stderr stream for the reporter.
64
+ * @param stderr_ The writable stream to use for error output
65
+ */
66
+ setStderr(stderr_) {
67
+ this.#stderr = stderr_;
68
+ }
69
+ /**
70
+ * Sets the interactive manager for handling interactive output.
71
+ * @param manager The interactive manager instance, or undefined to disable
72
+ */
73
+ setInteractiveManager(manager) {
74
+ this.#interactiveManager = manager;
75
+ }
76
+ /**
77
+ * Enables or disables interactive mode.
78
+ * @param interactive Whether to enable interactive terminal features
79
+ */
80
+ setIsInteractive(interactive) {
81
+ this.#interactive = interactive;
82
+ }
83
+ log(meta) {
84
+ this._log(this._formatMessage(meta), meta.type.level);
85
+ }
86
+ // eslint-disable-next-line sonarjs/cognitive-complexity, no-underscore-dangle
87
+ _formatMessage(data) {
88
+ const { columns } = terminalSize();
89
+ let size = columns;
90
+ if (typeof this.styles.messageLength === "number") {
91
+ size = this.styles.messageLength;
92
+ }
93
+ const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
94
+ const { color } = this.loggerTypes[type.name];
95
+ const colorized = color ? colorize[color] : white;
96
+ const groupSpaces = groups.map(() => " ").join("");
97
+ const items = [];
98
+ if (groups.length > 0) {
99
+ items.push(`${groupSpaces + grey(`[${groups.at(-1)}]`)} `);
100
+ }
101
+ if (date) {
102
+ items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
103
+ }
104
+ if (badge) {
105
+ items.push(colorized(badge));
106
+ } else {
107
+ const longestBadge = getLongestBadge(this.loggerTypes);
108
+ if (longestBadge.length > 0) {
109
+ items.push(`${grey(".".repeat(longestBadge.length))} `);
110
+ }
111
+ }
112
+ const longestLabel = getLongestLabel(this.loggerTypes);
113
+ if (label) {
114
+ const longestLabelWidth = getStringWidth(longestLabel);
115
+ const labelWidth = getStringWidth(label);
116
+ items.push(`${colorized(formatLabel(label, this.styles))} `, grey(".".repeat(Math.max(0, longestLabelWidth - labelWidth))));
117
+ } else {
118
+ items.push(grey(".".repeat(longestLabel.length + 2)));
119
+ }
120
+ if (repeated) {
121
+ items.push(`${bgGrey.white(`[${repeated}x]`)} `);
122
+ }
123
+ if (Array.isArray(scope) && scope.length > 0) {
124
+ items.push(` ${grey(`[${scope.join(" > ")}]`)} `);
125
+ }
126
+ if (prefix) {
127
+ items.push(
128
+ `${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `
129
+ );
130
+ }
131
+ const titleSize = getStringWidth(items.join(" "));
132
+ if (file) {
133
+ const fileMessage = file.name + (file.line ? `:${file.line}` : "");
134
+ const fileMessageSize = getStringWidth(fileMessage);
135
+ if (fileMessageSize + titleSize + 2 > size) {
136
+ items.push(grey(` ${fileMessage}`));
137
+ } else {
138
+ const dots = Math.max(0, size - titleSize - fileMessageSize - 2);
139
+ items.push(grey(`${".".repeat(dots)} ${fileMessage}`));
140
+ }
141
+ } else {
142
+ items.push(grey(".".repeat(Math.max(0, size - titleSize - 1))));
143
+ }
144
+ if (items.length > 0) {
145
+ items.push("\n\n");
146
+ }
147
+ if (message !== EMPTY_SYMBOL) {
148
+ const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
149
+ items.push(
150
+ groupSpaces + wordWrap(formattedMessage, {
151
+ trim: false,
152
+ width: size - 3,
153
+ wrapMode: WrapMode.STRICT_WIDTH
154
+ })
155
+ );
156
+ }
157
+ if (context) {
158
+ let hasError = false;
159
+ items.push(
160
+ ...context.map((value) => {
161
+ if (value instanceof Error) {
162
+ hasError = true;
163
+ return `
164
+
165
+ ${renderError(value, {
166
+ ...this.#errorOptions,
167
+ filterStacktrace: pailFileFilter,
168
+ prefix: groupSpaces
169
+ })}`;
170
+ }
171
+ if (typeof value === "object") {
172
+ return ` ${inspect(value, this.#inspectOptions)}`;
173
+ }
174
+ const newValue = (hasError ? "\n\n" : " ") + value;
175
+ hasError = false;
176
+ return newValue;
177
+ })
178
+ );
179
+ }
180
+ if (error) {
181
+ items.push(
182
+ renderError(error, {
183
+ ...this.#errorOptions,
184
+ filterStacktrace: pailFileFilter,
185
+ prefix: groupSpaces
186
+ })
187
+ );
188
+ }
189
+ if (traceError) {
190
+ items.push(
191
+ `
192
+
193
+ ${renderError(traceError, {
194
+ ...this.#errorOptions,
195
+ filterStacktrace: pailFileFilter,
196
+ hideErrorCauseCodeView: true,
197
+ hideErrorCodeView: true,
198
+ hideErrorErrorsCodeView: true,
199
+ hideMessage: true,
200
+ prefix: groupSpaces
201
+ })}`
202
+ );
203
+ }
204
+ if (suffix) {
205
+ items.push("\n", groupSpaces + grey(this.styles.underline.suffix ? underline(suffix) : suffix));
206
+ }
207
+ return items.join("");
208
+ }
209
+ // eslint-disable-next-line no-underscore-dangle
210
+ _log(message, logLevel) {
211
+ const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
212
+ const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
213
+ if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
214
+ this.#interactiveManager.update(streamType, message.split("\n"), 0);
215
+ } else {
216
+ writeStream(`${message}
217
+ `, stream);
218
+ }
219
+ }
220
+ }
221
+
222
+ export { PrettyReporter };