@visulima/pail 4.0.0-alpha.8 → 4.0.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 (145) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/LICENSE.md +270 -166
  3. package/README.md +53 -24
  4. package/dist/error.d.ts +95 -96
  5. package/dist/error.js +5 -76
  6. package/dist/index.browser.d.ts +568 -47
  7. package/dist/index.browser.js +19 -1499
  8. package/dist/index.server.d.ts +749 -65
  9. package/dist/index.server.js +32 -3179
  10. package/dist/middleware/elysia.d.ts +66 -63
  11. package/dist/middleware/elysia.js +1 -70
  12. package/dist/middleware/express.d.ts +74 -71
  13. package/dist/middleware/express.js +1 -29
  14. package/dist/middleware/fastify.d.ts +70 -67
  15. package/dist/middleware/fastify.js +1 -46
  16. package/dist/middleware/hono.d.ts +75 -72
  17. package/dist/middleware/hono.js +1 -33
  18. package/dist/middleware/next/handler.d.ts +102 -34
  19. package/dist/middleware/next/handler.js +1 -53
  20. package/dist/middleware/sveltekit.d.ts +101 -98
  21. package/dist/middleware/sveltekit.js +1 -43
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +1 -0
  26. package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +2 -0
  27. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  28. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CcDdPQSt.js +44 -0
  30. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  31. package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +62 -0
  32. package/dist/packem_shared/abstract-pretty-reporter-DrLBJ6ds.js +57 -0
  33. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +25 -0
  34. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  35. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  36. package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +47 -0
  37. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  38. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  39. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  40. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  41. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  42. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  43. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  44. package/dist/packem_shared/types.d-bWnqHJKL.d.ts +211 -0
  45. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  46. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  47. package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +717 -0
  48. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  49. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  50. package/dist/processor/caller/caller-processor.d.ts +50 -47
  51. package/dist/processor/caller/caller-processor.js +1 -59
  52. package/dist/processor/environment-processor.d.ts +114 -113
  53. package/dist/processor/environment-processor.js +1 -78
  54. package/dist/processor/message-formatter-processor.d.ts +59 -49
  55. package/dist/processor/message-formatter-processor.js +1 -713
  56. package/dist/processor/opentelemetry-processor.d.ts +70 -66
  57. package/dist/processor/opentelemetry-processor.js +1 -52
  58. package/dist/processor/redact-processor.d.ts +99 -41
  59. package/dist/processor/redact-processor.js +1 -30
  60. package/dist/processor/sampling-processor.d.ts +103 -101
  61. package/dist/processor/sampling-processor.js +1 -59
  62. package/dist/reporter/file/json-file-reporter.d.ts +109 -42
  63. package/dist/reporter/file/json-file-reporter.js +2 -136
  64. package/dist/reporter/http/abstract-http-reporter.d.ts +256 -211
  65. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  66. package/dist/reporter/http/http-reporter.d.ts +41 -36
  67. package/dist/reporter/http/http-reporter.edge-light.d.ts +487 -39
  68. package/dist/reporter/http/http-reporter.edge-light.js +2 -733
  69. package/dist/reporter/http/http-reporter.js +1 -13
  70. package/dist/reporter/json/index.browser.d.ts +98 -3
  71. package/dist/reporter/json/index.browser.js +1 -2
  72. package/dist/reporter/json/index.d.ts +53 -3
  73. package/dist/reporter/json/index.js +1 -2
  74. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  75. package/dist/reporter/pretty/index.browser.js +1 -1
  76. package/dist/reporter/pretty/index.d.ts +270 -2
  77. package/dist/reporter/pretty/index.js +1 -1
  78. package/dist/reporter/simple/simple-reporter.server.d.ts +215 -18
  79. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  80. package/dist/wide-event.d.ts +6 -300
  81. package/dist/wide-event.js +1 -281
  82. package/package.json +23 -38
  83. package/dist/constants.d.ts +0 -37
  84. package/dist/interactive/index.d.ts +0 -2
  85. package/dist/interactive/index.js +0 -2
  86. package/dist/interactive/interactive-manager.d.ts +0 -108
  87. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  88. package/dist/middleware/next/middleware.d.ts +0 -59
  89. package/dist/middleware/next/storage.d.ts +0 -14
  90. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  91. package/dist/middleware/shared/headers.d.ts +0 -14
  92. package/dist/middleware/shared/routes.d.ts +0 -30
  93. package/dist/middleware/shared/storage.d.ts +0 -29
  94. package/dist/packem_shared/AbstractJsonReporter-CGKHS8_M.js +0 -286
  95. package/dist/packem_shared/AbstractJsonReporter-DDjDkciI.js +0 -286
  96. package/dist/packem_shared/InteractiveManager-Cd6A14ZK.js +0 -172
  97. package/dist/packem_shared/InteractiveStreamHook-ePIURL_U.js +0 -133
  98. package/dist/packem_shared/JsonReporter-B3XX8GHN.js +0 -58
  99. package/dist/packem_shared/JsonReporter-p_BXg6Sj.js +0 -28
  100. package/dist/packem_shared/PrettyReporter-BYL3NrdA.js +0 -214
  101. package/dist/packem_shared/PrettyReporter-CvBn-hxP.js +0 -1459
  102. package/dist/packem_shared/Spinner-DIdVcfWq.js +0 -2183
  103. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +0 -2602
  104. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  105. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  106. package/dist/packem_shared/createPailError-B11aRfrT.js +0 -76
  107. package/dist/packem_shared/getBarChar-BWj1UrH3.js +0 -404
  108. package/dist/packem_shared/headers-Cp4uLtr4.js +0 -123
  109. package/dist/packem_shared/index-DnkF86LQ.js +0 -658
  110. package/dist/packem_shared/index-frijFf5m.js +0 -1252
  111. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  112. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  113. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  114. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  115. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  116. package/dist/pail.browser.d.ts +0 -412
  117. package/dist/pail.server.d.ts +0 -233
  118. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  119. package/dist/progress-bar.d.ts +0 -136
  120. package/dist/progress-bar.js +0 -404
  121. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  122. package/dist/reporter/http/utils/compression.d.ts +0 -7
  123. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  124. package/dist/reporter/http/utils/retry.d.ts +0 -27
  125. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  126. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  127. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  128. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  129. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  130. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  131. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  132. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  133. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  134. package/dist/reporter/utils/format-label.d.ts +0 -3
  135. package/dist/spinner.d.ts +0 -220
  136. package/dist/spinner.js +0 -2183
  137. package/dist/types.d.ts +0 -241
  138. package/dist/utils/ansi-escapes.d.ts +0 -4
  139. package/dist/utils/arrayify.d.ts +0 -2
  140. package/dist/utils/get-longest-badge.d.ts +0 -4
  141. package/dist/utils/get-longest-label.d.ts +0 -4
  142. package/dist/utils/merge-types.d.ts +0 -4
  143. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  144. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  145. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,172 +0,0 @@
1
- import { t as terminalSize, w as wordWrap, W as WrapMode } from './index-frijFf5m.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 };
@@ -1,133 +0,0 @@
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
- const {
21
- StringDecoder
22
- } = __cjs_getBuiltinModule("node:string_decoder");
23
-
24
- const ESC = "\x1B[";
25
- const eraseLine = `${ESC}2K`;
26
- const cursorLeft = `${ESC}G`;
27
- const cursorUp = (count = 1) => `${ESC + count}A`;
28
- const cursorHide = `${ESC}?25l`;
29
- const cursorShow = `${ESC}?25h`;
30
- const eraseLines = (count) => {
31
- let clear = "";
32
- for (let index = 0; index < count; index++) {
33
- clear += eraseLine + (index < count - 1 ? cursorUp() : "");
34
- }
35
- if (count) {
36
- clear += cursorLeft;
37
- }
38
- return clear;
39
- };
40
-
41
- class InteractiveStreamHook {
42
- /** Constant indicating the stream write operation was successful */
43
- static DRAIN = true;
44
- #decoder = new StringDecoder();
45
- #history = [];
46
- #method;
47
- #stream;
48
- /**
49
- * Creates a new InteractiveStreamHook for the given stream.
50
- * @param stream The Node.js WriteStream to hook into (usually stdout or stderr)
51
- */
52
- constructor(stream) {
53
- this.#method = stream.write;
54
- this.#stream = stream;
55
- }
56
- /**
57
- * Activates the stream hook.
58
- *
59
- * When active, all writes to the stream are captured in history instead of
60
- * being written immediately. This allows for interactive features like
61
- * progress bars that can update dynamically.
62
- */
63
- active() {
64
- this.write(cursorHide);
65
- this.#stream.write = (data, ...arguments_) => {
66
- const callback = arguments_.at(-1);
67
- this.#history.push(
68
- // prettier-ignore
69
- this.#decoder.write(
70
- typeof data === "string" ? Buffer.from(data, typeof arguments_[0] === "string" ? arguments_[0] : void 0) : Buffer.from(data)
71
- )
72
- );
73
- if (typeof callback === "function") {
74
- callback();
75
- }
76
- return InteractiveStreamHook.DRAIN;
77
- };
78
- }
79
- /**
80
- * Erases the specified number of lines from the terminal.
81
- *
82
- * Uses ANSI escape sequences to remove lines from the current cursor position
83
- * upwards, which is useful for clearing previous output in interactive applications.
84
- * @param count Number of lines to erase (including the current line)
85
- */
86
- erase(count) {
87
- if (count > 0) {
88
- this.write(eraseLines(count + 1));
89
- }
90
- }
91
- /**
92
- * Deactivates the stream hook and replays captured output.
93
- *
94
- * Restores normal stream operation and outputs all captured history.
95
- * Optionally adds a newline separator before replaying the history.
96
- * @param separateHistory Whether to add a newline before replaying history
97
- */
98
- inactive(separateHistory = false) {
99
- if (this.#history.length > 0) {
100
- if (separateHistory) {
101
- this.write("\n");
102
- }
103
- this.#history.forEach((element) => {
104
- this.write(element);
105
- });
106
- this.#history = [];
107
- }
108
- this.renew();
109
- }
110
- /**
111
- * Renews the stream hook state.
112
- *
113
- * Restores the original stream write method and shows the cursor.
114
- * This is typically called when temporarily suspending interactive mode.
115
- */
116
- renew() {
117
- this.#stream.write = this.#method;
118
- this.write(cursorShow);
119
- }
120
- /**
121
- * Writes a message directly to the underlying stream.
122
- *
123
- * Bypasses the hook mechanism and writes directly using the original
124
- * stream write method. Useful for writing control sequences or
125
- * messages that should not be captured in history.
126
- * @param message The message to write to the stream
127
- */
128
- write(message) {
129
- this.#method.apply(this.#stream, [message]);
130
- }
131
- }
132
-
133
- export { InteractiveStreamHook as default };
@@ -1,58 +0,0 @@
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-CGKHS8_M.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
- setStdout(stdout_) {
33
- this.#stdout = stdout_;
34
- }
35
- /**
36
- * Sets the stderr stream for the reporter.
37
- * @param stderr_ The writable stream to use for stderr output
38
- */
39
- setStderr(stderr_) {
40
- this.#stderr = stderr_;
41
- }
42
- /**
43
- * Outputs the JSON message to the appropriate stream.
44
- *
45
- * Routes error and warning level messages to stderr, others to stdout.
46
- * @param message The JSON-formatted log message
47
- * @param logLevel The log level determining which stream to use
48
- * @protected
49
- */
50
- // eslint-disable-next-line no-underscore-dangle
51
- _log(message, logLevel) {
52
- const stream = ["error", "warn"].includes(logLevel) ? this.#stderr : this.#stdout;
53
- writeStream(`${message}
54
- `, stream);
55
- }
56
- }
57
-
58
- export { JsonReporter as default };
@@ -1,28 +0,0 @@
1
- import { AbstractJsonReporter } from './AbstractJsonReporter-DDjDkciI.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 };
@@ -1,214 +0,0 @@
1
- import colorize, { grey, white, underline, bold } from '@visulima/colorize/browser';
2
- import { f as format, g as getLongestLabel } from './index-DnkF86LQ.js';
3
- import { L as LOG_TYPES, E as EMPTY_SYMBOL } from './constants-omsTHUWB.js';
4
- import { w as writeConsoleLogBasedOnLevel } from './write-console-log-based-on-level-DBmRYXpj.js';
5
-
6
- const getLongestBadge = (types) => {
7
- const badges = Object.keys(types).map((x) => types[x].badge ?? "");
8
- if (badges.length === 0) {
9
- return "";
10
- }
11
- return badges.reduce((x, y) => x.length > y.length ? x : y);
12
- };
13
-
14
- const dateFormatter = (date) => [date.getHours(), date.getMinutes(), date.getSeconds()].map((n) => String(n).padStart(2, "0")).join(":");
15
- class AbstractPrettyReporter {
16
- /** Styling options for pretty formatting */
17
- styles;
18
- /** Logger type configurations for styling */
19
- loggerTypes;
20
- /**
21
- * Creates a new AbstractPrettyReporter instance.
22
- * @param options Styling options for pretty formatting
23
- * @protected
24
- */
25
- constructor(options) {
26
- this.styles = {
27
- bold: {
28
- label: false
29
- },
30
- dateFormatter,
31
- underline: {
32
- label: false,
33
- message: false,
34
- prefix: false,
35
- suffix: false
36
- },
37
- uppercase: {
38
- label: false
39
- },
40
- ...options
41
- };
42
- this.loggerTypes = LOG_TYPES;
43
- }
44
- /**
45
- * Sets the logger types configuration for styling.
46
- * @param types Logger type configurations with colors and labels
47
- */
48
- setLoggerTypes(types) {
49
- this.loggerTypes = types;
50
- }
51
- }
52
-
53
- class PrettyReporter extends AbstractPrettyReporter {
54
- /**
55
- * Creates a new Browser Pretty Reporter instance.
56
- * @param options Styling options for pretty formatting
57
- */
58
- constructor(options = {}) {
59
- super({
60
- uppercase: {
61
- label: true,
62
- ...options.uppercase
63
- },
64
- ...options
65
- });
66
- }
67
- // eslint-disable-next-line sonarjs/cognitive-complexity
68
- log(meta) {
69
- const isNotBrowser = typeof globalThis.window !== "undefined" && typeof globalThis.document !== "undefined";
70
- const consoleLogFunction = writeConsoleLogBasedOnLevel(meta.type.level);
71
- const { badge, context, date, error, groups, label, message, prefix, repeated, scope, suffix, type } = meta;
72
- const { color } = this.loggerTypes[type.name];
73
- const colorized = color ? colorize[color] : white;
74
- const items = [];
75
- if (isNotBrowser && groups.length > 0) {
76
- const groupSpaces = groups.map(() => " ").join("");
77
- const cGroup = grey(`[${groups.at(-1)}]`);
78
- items.push(format(groupSpaces + cGroup[0], cGroup.slice(1)));
79
- }
80
- if (date) {
81
- const cDate = grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date));
82
- if (isNotBrowser) {
83
- items.push(format(cDate[0], cDate.slice(1)));
84
- } else {
85
- items.push([`${cDate[0]} `, ...cDate.slice(1)]);
86
- }
87
- }
88
- if (badge) {
89
- const cBadge = colorized(badge);
90
- if (isNotBrowser) {
91
- items.push(format(cBadge[0], cBadge.slice(1)));
92
- } else {
93
- items.push([`${cBadge[0]} `, ...cBadge.slice(1)]);
94
- }
95
- } else {
96
- const longestBadge = getLongestBadge(this.loggerTypes);
97
- if (longestBadge.length > 0) {
98
- const cBadgePlaceholder = grey(".".repeat(longestBadge.length));
99
- if (isNotBrowser) {
100
- items.push(format(`${cBadgePlaceholder[0]} `, cBadgePlaceholder.slice(1)));
101
- } else {
102
- items.push([`${cBadgePlaceholder[0]} `, ...cBadgePlaceholder.slice(1)]);
103
- }
104
- }
105
- }
106
- const longestLabel = getLongestLabel(this.loggerTypes);
107
- let repeatedMessage;
108
- if (repeated) {
109
- const cRepeated = white(`[${repeated}x]`);
110
- repeatedMessage = isNotBrowser ? format(cRepeated[0], cRepeated.slice(1)) : [cRepeated[0], ...cRepeated.slice(1)];
111
- }
112
- if (label) {
113
- const cLabel = colorized(this.#formatLabel(label));
114
- if (isNotBrowser) {
115
- items.push(format(cLabel[0], cLabel.slice(1)));
116
- } else {
117
- items.push([cLabel[0], ...cLabel.slice(1)]);
118
- }
119
- if (repeatedMessage) {
120
- items.push(repeatedMessage);
121
- }
122
- let lengthDiff = longestLabel.length - label.length;
123
- if (repeated) {
124
- lengthDiff -= String(repeated).length + 3;
125
- } else {
126
- lengthDiff += 1;
127
- }
128
- if (lengthDiff > 0) {
129
- const cLabelSpacer = grey(".".repeat(lengthDiff));
130
- if (isNotBrowser) {
131
- items.push(format(cLabelSpacer[0], cLabelSpacer.slice(1)));
132
- } else {
133
- items.push([` ${cLabelSpacer[0]}`, ...cLabelSpacer.slice(1)]);
134
- }
135
- }
136
- } else {
137
- const cSpacer = grey(".".repeat(longestLabel.length + 1));
138
- if (isNotBrowser) {
139
- items.push(format(cSpacer[0], cSpacer.slice(1)));
140
- } else {
141
- items.push([cSpacer[0], ...cSpacer.slice(1)]);
142
- }
143
- }
144
- if (Array.isArray(scope) && scope.length > 0) {
145
- const cScope = grey(`[${scope.join(" > ")}]`);
146
- if (isNotBrowser) {
147
- items.push(format(cScope[0], cScope.slice(1)));
148
- } else {
149
- items.push([cScope[0], ...cScope.slice(1)]);
150
- }
151
- }
152
- if (prefix) {
153
- const cPrefix = grey(
154
- `${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}] `
155
- );
156
- if (isNotBrowser) {
157
- items.push(format(cPrefix[0], cPrefix.slice(1)));
158
- } else {
159
- items.push([cPrefix[0], ...cPrefix.slice(1)]);
160
- }
161
- }
162
- if (message !== EMPTY_SYMBOL) {
163
- items.push(message);
164
- }
165
- if (context) {
166
- items.push(...context);
167
- }
168
- if (error) {
169
- items.push(error, "\n\n");
170
- }
171
- if (suffix) {
172
- const cSuffix = grey(this.styles.underline.suffix ? underline(suffix) : suffix);
173
- if (isNotBrowser) {
174
- items.push(format(`
175
- ${cSuffix[0]}`, cSuffix.slice(1)));
176
- } else {
177
- items.push([`
178
- ${cSuffix[0]}`, ...cSuffix.slice(1)]);
179
- }
180
- }
181
- if (isNotBrowser) {
182
- consoleLogFunction(...items);
183
- } else {
184
- let logMessage = "";
185
- const css = [];
186
- const arguments_ = [];
187
- for (const value of items) {
188
- if (Array.isArray(value) && value.length > 1 && value[0].includes("%c")) {
189
- logMessage += value[0];
190
- css.push(...value.slice(1));
191
- } else {
192
- arguments_.push(value);
193
- }
194
- }
195
- consoleLogFunction(`${logMessage}%c`, ...css, "", ...arguments_);
196
- }
197
- }
198
- /**
199
- * Formats a label according to styling options.
200
- * @param label The label to format
201
- * @returns The formatted label string
202
- * @private
203
- */
204
- #formatLabel(label) {
205
- let formattedLabel = this.styles.uppercase.label ? label.toUpperCase() : label;
206
- formattedLabel = this.styles.underline.label ? underline(formattedLabel) : formattedLabel;
207
- if (this.styles.bold.label) {
208
- formattedLabel = bold(formattedLabel);
209
- }
210
- return formattedLabel;
211
- }
212
- }
213
-
214
- export { PrettyReporter as default };