@visulima/pail 4.0.0-alpha.10 → 4.0.0-alpha.12

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 (106) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE.md +143 -931
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +2 -2
  6. package/dist/index.server.d.ts +722 -65
  7. package/dist/index.server.js +27 -410
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/elysia.js +2 -2
  10. package/dist/middleware/express.d.ts +73 -71
  11. package/dist/middleware/express.js +1 -1
  12. package/dist/middleware/fastify.d.ts +69 -67
  13. package/dist/middleware/fastify.js +2 -2
  14. package/dist/middleware/hono.d.ts +74 -72
  15. package/dist/middleware/next/handler.d.ts +101 -34
  16. package/dist/middleware/sveltekit.d.ts +100 -98
  17. package/dist/object-tree.d.ts +67 -70
  18. package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
  19. package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
  20. package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
  21. package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
  22. package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-CIbrmjUV.js} +2 -4
  23. package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-CNJEO9g7.js} +1250 -15
  24. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  25. package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CkqCt5hg.js} +2300 -2298
  26. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  27. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  28. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  29. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  30. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  31. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  32. package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
  33. package/dist/processor/caller/caller-processor.d.ts +49 -47
  34. package/dist/processor/caller/caller-processor.js +1 -1
  35. package/dist/processor/environment-processor.d.ts +113 -113
  36. package/dist/processor/message-formatter-processor.d.ts +51 -49
  37. package/dist/processor/message-formatter-processor.js +2 -2
  38. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  39. package/dist/processor/redact-processor.d.ts +60 -41
  40. package/dist/processor/sampling-processor.d.ts +102 -101
  41. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  42. package/dist/reporter/file/json-file-reporter.js +1 -1
  43. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  44. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  45. package/dist/reporter/http/http-reporter.d.ts +40 -36
  46. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  47. package/dist/reporter/http/http-reporter.edge-light.js +1 -5
  48. package/dist/reporter/json/index.browser.d.ts +99 -3
  49. package/dist/reporter/json/index.browser.js +2 -2
  50. package/dist/reporter/json/index.d.ts +51 -3
  51. package/dist/reporter/json/index.js +2 -2
  52. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +219 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  57. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  58. package/dist/wide-event.d.ts +5 -300
  59. package/dist/wide-event.js +3 -2
  60. package/package.json +9 -21
  61. package/dist/constants.d.ts +0 -37
  62. package/dist/interactive/index.d.ts +0 -2
  63. package/dist/interactive/index.js +0 -2
  64. package/dist/interactive/interactive-manager.d.ts +0 -108
  65. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  66. package/dist/middleware/next/middleware.d.ts +0 -59
  67. package/dist/middleware/next/storage.d.ts +0 -14
  68. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  69. package/dist/middleware/shared/headers.d.ts +0 -14
  70. package/dist/middleware/shared/routes.d.ts +0 -30
  71. package/dist/middleware/shared/storage.d.ts +0 -29
  72. package/dist/packem_shared/InteractiveManager-CowYA3Hx.js +0 -178
  73. package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
  74. package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
  75. package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
  76. package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
  77. package/dist/pail.browser.d.ts +0 -412
  78. package/dist/pail.server.d.ts +0 -233
  79. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  80. package/dist/progress-bar.d.ts +0 -145
  81. package/dist/progress-bar.js +0 -459
  82. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  83. package/dist/reporter/http/utils/compression.d.ts +0 -7
  84. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  85. package/dist/reporter/http/utils/retry.d.ts +0 -27
  86. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  87. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  88. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  89. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  90. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  91. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  92. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  93. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  94. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  95. package/dist/reporter/utils/format-label.d.ts +0 -3
  96. package/dist/spinner.d.ts +0 -220
  97. package/dist/spinner.js +0 -2183
  98. package/dist/types.d.ts +0 -241
  99. package/dist/utils/ansi-escapes.d.ts +0 -4
  100. package/dist/utils/arrayify.d.ts +0 -2
  101. package/dist/utils/get-longest-badge.d.ts +0 -4
  102. package/dist/utils/get-longest-label.d.ts +0 -4
  103. package/dist/utils/merge-types.d.ts +0 -4
  104. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  105. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  106. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,145 +0,0 @@
1
- import type InteractiveManager from "./interactive/interactive-manager.d.ts";
2
- export type ProgressBarStyle = "shades_classic" | "shades_grey" | "rect" | "filled" | "solid" | "ascii" | "braille" | "custom";
3
- export interface ProgressBarOptions {
4
- barCompleteChar?: string | string[];
5
- barGlue?: string;
6
- barIncompleteChar?: string | string[];
7
- current?: number;
8
- format?: string;
9
- fps?: number;
10
- peak?: number;
11
- peakChar?: string;
12
- roundedCaps?: boolean;
13
- style?: ProgressBarStyle;
14
- total: number;
15
- width?: number;
16
- }
17
- export interface SingleBarOptions extends ProgressBarOptions {
18
- format?: string;
19
- }
20
- export interface MultiBarOptions {
21
- barCompleteChar?: string | string[];
22
- barGlue?: string;
23
- barIncompleteChar?: string | string[];
24
- composite?: boolean;
25
- format?: string;
26
- fps?: number;
27
- style?: ProgressBarStyle;
28
- }
29
- export interface ProgressBarPayload {
30
- [key: string]: string | number | boolean;
31
- }
32
- /**
33
- * Gets the appropriate bar character based on style and completion state.
34
- * @param char Custom character override
35
- * @param style Progress bar style to use
36
- * @param complete Whether to get completed or incomplete character
37
- * @returns The appropriate character for the given style
38
- */
39
- export declare const getBarChar: (char: string | undefined, style: ProgressBarStyle, complete?: boolean) => string;
40
- export declare const applyStyleToOptions: <T extends ProgressBarOptions | MultiBarOptions>(options: T) => T;
41
- export declare class ProgressBar {
42
- protected options: ProgressBarOptions;
43
- protected current: number;
44
- private startTime;
45
- private interactiveManager?;
46
- private isActive;
47
- private payload?;
48
- /**
49
- * Creates a new progress bar instance.
50
- * @param options Configuration options for the progress bar
51
- * @param interactiveManager Optional interactive manager for rendering
52
- * @param payload Optional initial payload data for format placeholders
53
- */
54
- constructor(options: ProgressBarOptions, interactiveManager?: InteractiveManager, payload?: ProgressBarPayload);
55
- /**
56
- * Updates the progress bar to a new value.
57
- * @param current The current progress value
58
- * @param payload Optional payload data to merge with existing data
59
- */
60
- update(current: number, payload?: ProgressBarPayload): void;
61
- /**
62
- * Sets the peak marker position.
63
- * @param peak The peak value (in the same scale as total)
64
- */
65
- setPeak(peak: number): void;
66
- /**
67
- * Increments the progress bar by a specified step.
68
- * @param step Amount to increment (default: 1)
69
- * @param payload Optional payload data to merge with existing data
70
- */
71
- increment(step?: number, payload?: ProgressBarPayload): void;
72
- /**
73
- * Renders the progress bar as a formatted string.
74
- * @returns Formatted progress bar string with all placeholders replaced
75
- */
76
- render(): string;
77
- /**
78
- * Starts the progress bar.
79
- * @param total Optional total value to set
80
- * @param startValue Optional starting value
81
- * @param payload Optional initial payload data
82
- */
83
- start(total?: number, startValue?: number, payload?: ProgressBarPayload): void;
84
- /**
85
- * Stops the progress bar and cleanup.
86
- */
87
- stop(): void;
88
- private calculatePeakPosition;
89
- private calculateETA;
90
- }
91
- export declare class MultiBarInstance extends ProgressBar {
92
- private multiBar;
93
- constructor(multiBar: MultiProgressBar, options: ProgressBarOptions, payload?: ProgressBarPayload);
94
- update(current: number, payload?: ProgressBarPayload): void;
95
- getBarState(): {
96
- char: string;
97
- current: number;
98
- total: number;
99
- };
100
- }
101
- export declare class MultiProgressBar {
102
- private bars;
103
- private options;
104
- private interactiveManager?;
105
- private isActive;
106
- private nextBarId;
107
- private composite;
108
- private barColors;
109
- /**
110
- * Creates a new multi progress bar manager.
111
- * @param options Configuration options for the progress bars
112
- * @param interactiveManager Optional interactive manager for rendering
113
- */
114
- constructor(options?: MultiBarOptions, interactiveManager?: InteractiveManager);
115
- /**
116
- * Creates a new progress bar within this multi-bar manager.
117
- * @param total Total value for the progress bar
118
- * @param current Starting current value (default: 0)
119
- * @param payload Optional initial payload data for format placeholders
120
- * @returns The created progress bar instance
121
- */
122
- create(total: number, current?: number, payload?: ProgressBarPayload): ProgressBar;
123
- /**
124
- * Removes a progress bar from the manager.
125
- * @param bar The progress bar instance to remove
126
- * @returns True if the bar was removed, false if not found
127
- */
128
- remove(bar: ProgressBar): boolean;
129
- /**
130
- * Renders all progress bars.
131
- */
132
- renderAll(): void;
133
- /**
134
- * Sets or removes a color function for a specific bar.
135
- * @param bar The progress bar instance to color (must be from this MultiProgressBar)
136
- * @param color Color function or undefined to remove color
137
- */
138
- setBarColor(bar: MultiBarInstance, color: ((text: string) => string) | undefined): void;
139
- /**
140
- * Stops all progress bars and cleanup.
141
- */
142
- stop(): void;
143
- private renderComposite;
144
- private getCompositeChar;
145
- }
@@ -1,459 +0,0 @@
1
- const CHAR_GRADIENTS = {
2
- braille: ["⣿", "⡷", "⢾", "⠤"],
3
- default: ["█", "▓", "▒", "░"],
4
- rect: ["▬", "▮", "▯", "▭"]
5
- };
6
- const BRAILLE_FULL = "⣿";
7
- const BRAILLE_CAP_LEFT = "⢾";
8
- const BRAILLE_CAP_RIGHT = "⡷";
9
- const BRAILLE_EMPTY = "⠤";
10
- const BAR_REGEX = /\[([^[\]]*)\]/u;
11
- const getBarChar = (char, style, complete = true) => {
12
- if (char) {
13
- return char;
14
- }
15
- switch (style) {
16
- case "ascii": {
17
- return complete ? "#" : "-";
18
- }
19
- case "braille": {
20
- return complete ? BRAILLE_FULL : BRAILLE_EMPTY;
21
- }
22
- case "filled": {
23
- return complete ? "█" : " ";
24
- }
25
- case "rect": {
26
- return complete ? "▬" : "▭";
27
- }
28
- case "shades_classic": {
29
- return complete ? "█" : "░";
30
- }
31
- case "shades_grey": {
32
- return complete ? "▓" : "░";
33
- }
34
- case "solid": {
35
- return complete ? "█" : " ";
36
- }
37
- default: {
38
- return complete ? "█" : "░";
39
- }
40
- }
41
- };
42
- const applyStyleToOptions = (options) => {
43
- if (!options.style) {
44
- return options;
45
- }
46
- const { style } = options;
47
- const result = { ...options };
48
- result.barCompleteChar ??= getBarChar(void 0, style, true);
49
- result.barIncompleteChar ??= getBarChar(void 0, style, false);
50
- result.barGlue ??= "";
51
- return result;
52
- };
53
- class ProgressBar {
54
- options;
55
- current;
56
- startTime;
57
- interactiveManager;
58
- isActive = false;
59
- payload;
60
- /**
61
- * Creates a new progress bar instance.
62
- * @param options Configuration options for the progress bar
63
- * @param interactiveManager Optional interactive manager for rendering
64
- * @param payload Optional initial payload data for format placeholders
65
- */
66
- constructor(options, interactiveManager, payload) {
67
- const isCompleteArray = Array.isArray(options.barCompleteChar);
68
- const isIncompleteArray = Array.isArray(options.barIncompleteChar);
69
- const isGradientMode = isCompleteArray || isIncompleteArray;
70
- const effectiveStyle = options.style ?? "shades_classic";
71
- const completeChar = isCompleteArray ? options.barCompleteChar : getBarChar(options.barCompleteChar, effectiveStyle);
72
- const incompleteChar = isIncompleteArray ? options.barIncompleteChar : getBarChar(options.barIncompleteChar, effectiveStyle, false);
73
- this.options = {
74
- barCompleteChar: completeChar,
75
- barIncompleteChar: incompleteChar,
76
- current: 0,
77
- fps: 10,
78
- width: 40,
79
- ...options
80
- };
81
- if (isGradientMode) {
82
- if (!Array.isArray(this.options.barCompleteChar)) {
83
- this.options.barCompleteChar = [this.options.barCompleteChar];
84
- }
85
- if (!Array.isArray(this.options.barIncompleteChar)) {
86
- this.options.barIncompleteChar = [this.options.barIncompleteChar];
87
- }
88
- }
89
- this.current = this.options.current ?? 0;
90
- this.startTime = Date.now();
91
- this.interactiveManager = interactiveManager;
92
- this.payload = payload;
93
- }
94
- /**
95
- * Updates the progress bar to a new value.
96
- * @param current The current progress value
97
- * @param payload Optional payload data to merge with existing data
98
- */
99
- update(current, payload) {
100
- this.current = Math.min(current, this.options.total);
101
- if (payload) {
102
- this.payload = { ...this.payload, ...payload };
103
- }
104
- if (this.interactiveManager && this.isActive) {
105
- const progressBar = this.render();
106
- this.interactiveManager.update("stdout", [progressBar]);
107
- }
108
- }
109
- /**
110
- * Sets the peak marker position.
111
- * @param peak The peak value (in the same scale as total)
112
- */
113
- setPeak(peak) {
114
- this.options.peak = peak;
115
- }
116
- /**
117
- * Increments the progress bar by a specified step.
118
- * @param step Amount to increment (default: 1)
119
- * @param payload Optional payload data to merge with existing data
120
- */
121
- increment(step = 1, payload) {
122
- this.update(this.current + step, payload);
123
- }
124
- /**
125
- * Renders the progress bar as a formatted string.
126
- * @returns Formatted progress bar string with all placeholders replaced
127
- */
128
- // eslint-disable-next-line sonarjs/cognitive-complexity
129
- render() {
130
- const total = this.options.total > 0 ? this.options.total : 1;
131
- const width = Math.max(0, this.options.width ?? 40);
132
- const percentage = Math.max(0, Math.min(100, Math.round(this.current / total * 100)));
133
- const filled = Math.max(0, Math.min(width, Math.round(this.current / total * width)));
134
- const empty = width - filled;
135
- let bar;
136
- const useCaps = this.options.roundedCaps === true || this.options.roundedCaps === void 0 && this.options.style === "braille";
137
- if (Array.isArray(this.options.barCompleteChar) || Array.isArray(this.options.barIncompleteChar)) {
138
- const completeChars = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar : void 0;
139
- const incompleteChars = Array.isArray(this.options.barIncompleteChar) ? this.options.barIncompleteChar : void 0;
140
- const completeChar = completeChars?.[completeChars.length - 1] ?? (typeof this.options.barCompleteChar === "string" ? this.options.barCompleteChar : "█");
141
- const incompleteChar = incompleteChars?.[0] ?? (typeof this.options.barIncompleteChar === "string" ? this.options.barIncompleteChar : "░");
142
- const completeLength = completeChars?.length ?? 1;
143
- const progressRatio = this.current / total;
144
- const totalSteps = width * completeLength;
145
- const currentStep = Math.round(progressRatio * totalSteps);
146
- const fractional = currentStep % completeLength;
147
- let barContent = "";
148
- for (let i = 0; i < width; i += 1) {
149
- if (i < filled) {
150
- const isGradientBoundary = i === filled - 1 && fractional > 0 && completeChars;
151
- barContent += isGradientBoundary ? completeChars[Math.max(0, fractional - 1)] ?? completeChar : completeChar;
152
- } else {
153
- barContent += incompleteChar;
154
- }
155
- }
156
- bar = barContent;
157
- } else {
158
- const completeChar = typeof this.options.barCompleteChar === "string" ? this.options.barCompleteChar : "█";
159
- const incompleteChar = typeof this.options.barIncompleteChar === "string" ? this.options.barIncompleteChar : "░";
160
- const peakPos = this.calculatePeakPosition(width, total, filled);
161
- const peakChar = this.options.peakChar ?? completeChar;
162
- if (peakPos === void 0) {
163
- bar = completeChar.repeat(filled) + incompleteChar.repeat(empty);
164
- } else {
165
- let barContent = "";
166
- for (let i = 0; i < width; i += 1) {
167
- if (i === peakPos) {
168
- barContent += peakChar;
169
- } else if (i < filled) {
170
- barContent += completeChar;
171
- } else {
172
- barContent += incompleteChar;
173
- }
174
- }
175
- bar = barContent;
176
- }
177
- }
178
- if (useCaps && width >= 2) {
179
- const chars = [...bar];
180
- chars[0] = BRAILLE_CAP_LEFT;
181
- chars[chars.length - 1] = BRAILLE_CAP_RIGHT;
182
- bar = chars.join("");
183
- }
184
- let format = this.options.format ?? "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}";
185
- if (this.payload) {
186
- const entries = Object.entries(this.payload);
187
- for (let i = 0; i < entries.length; i += 1) {
188
- const [k, v] = entries[i];
189
- format = format.replaceAll(`{${k}}`, String(v));
190
- }
191
- }
192
- const eta = this.calculateETA();
193
- return format.replaceAll("{bar}", bar).replaceAll("{percentage}", String(percentage)).replaceAll("{value}", String(this.current)).replaceAll("{total}", String(this.options.total)).replaceAll("{eta}", String(eta));
194
- }
195
- /**
196
- * Starts the progress bar.
197
- * @param total Optional total value to set
198
- * @param startValue Optional starting value
199
- * @param payload Optional initial payload data
200
- */
201
- start(total, startValue, payload) {
202
- if (total !== void 0) {
203
- this.options.total = total;
204
- }
205
- if (startValue !== void 0) {
206
- this.current = startValue;
207
- }
208
- this.startTime = Date.now();
209
- this.isActive = true;
210
- if (this.interactiveManager) {
211
- this.interactiveManager.hook();
212
- this.update(this.current, payload);
213
- }
214
- }
215
- /**
216
- * Stops the progress bar and cleanup.
217
- */
218
- stop() {
219
- this.isActive = false;
220
- if (this.interactiveManager) {
221
- this.interactiveManager.unhook(false);
222
- }
223
- }
224
- calculatePeakPosition(width, total, filled) {
225
- const { peak } = this.options;
226
- if (peak === void 0 || peak <= 0) {
227
- return void 0;
228
- }
229
- let peakPos = Math.max(0, Math.min(width - 1, Math.floor(peak / total * width)));
230
- if (peakPos < filled - 1) {
231
- peakPos = filled - 1;
232
- }
233
- return peakPos;
234
- }
235
- calculateETA() {
236
- if (this.current === 0) {
237
- return 0;
238
- }
239
- const elapsed = (Date.now() - this.startTime) / 1e3;
240
- if (elapsed < 0.1) {
241
- return 0;
242
- }
243
- const rate = this.current / elapsed;
244
- const remaining = this.options.total - this.current;
245
- return Math.round(remaining / rate);
246
- }
247
- }
248
- class MultiBarInstance extends ProgressBar {
249
- multiBar;
250
- constructor(multiBar, options, payload) {
251
- super(options, void 0, payload);
252
- this.multiBar = multiBar;
253
- }
254
- update(current, payload) {
255
- super.update(current, payload);
256
- this.multiBar.renderAll();
257
- }
258
- getBarState() {
259
- const completeChar = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar.at(-1) : getBarChar(this.options.barCompleteChar, this.options.style ?? "shades_classic", true);
260
- return {
261
- char: completeChar ?? "█",
262
- current: this.current,
263
- total: this.options.total
264
- };
265
- }
266
- }
267
- class MultiProgressBar {
268
- bars = /* @__PURE__ */ new Map();
269
- options;
270
- interactiveManager;
271
- isActive = false;
272
- nextBarId = 0;
273
- composite = false;
274
- barColors = /* @__PURE__ */ new Map();
275
- /**
276
- * Creates a new multi progress bar manager.
277
- * @param options Configuration options for the progress bars
278
- * @param interactiveManager Optional interactive manager for rendering
279
- */
280
- constructor(options = {}, interactiveManager) {
281
- this.options = {
282
- barCompleteChar: getBarChar(void 0, "shades_classic"),
283
- barIncompleteChar: getBarChar(void 0, "shades_classic", false),
284
- composite: false,
285
- format: "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}",
286
- fps: 10,
287
- ...options
288
- };
289
- this.composite = this.options.composite ?? false;
290
- this.interactiveManager = interactiveManager;
291
- }
292
- /**
293
- * Creates a new progress bar within this multi-bar manager.
294
- * @param total Total value for the progress bar
295
- * @param current Starting current value (default: 0)
296
- * @param payload Optional initial payload data for format placeholders
297
- * @returns The created progress bar instance
298
- */
299
- create(total, current = 0, payload) {
300
- const barId = `bar_${String(this.nextBarId++)}`;
301
- const bar = new MultiBarInstance(
302
- this,
303
- {
304
- barCompleteChar: this.options.barCompleteChar,
305
- barIncompleteChar: this.options.barIncompleteChar,
306
- current,
307
- format: this.options.format,
308
- fps: this.options.fps,
309
- total,
310
- width: 40
311
- },
312
- payload
313
- );
314
- this.bars.set(barId, bar);
315
- if (!this.isActive && this.interactiveManager) {
316
- this.interactiveManager.hook();
317
- this.isActive = true;
318
- this.renderAll();
319
- }
320
- return bar;
321
- }
322
- /**
323
- * Removes a progress bar from the manager.
324
- * @param bar The progress bar instance to remove
325
- * @returns True if the bar was removed, false if not found
326
- */
327
- remove(bar) {
328
- for (const [id, existingBar] of this.bars.entries()) {
329
- if (existingBar === bar) {
330
- this.bars.delete(id);
331
- if (this.bars.size === 0) {
332
- if (this.interactiveManager) {
333
- this.interactiveManager.unhook(false);
334
- }
335
- this.isActive = false;
336
- } else {
337
- this.renderAll();
338
- }
339
- return true;
340
- }
341
- }
342
- return false;
343
- }
344
- /**
345
- * Renders all progress bars.
346
- */
347
- renderAll() {
348
- if (!this.interactiveManager || !this.isActive) {
349
- return;
350
- }
351
- const lines = [];
352
- if (this.composite) {
353
- const barsArray = [...this.bars.values()];
354
- if (barsArray.length > 0) {
355
- const compositeOutput = this.renderComposite(barsArray);
356
- lines.push(compositeOutput);
357
- }
358
- } else {
359
- for (const bar of this.bars.values()) {
360
- lines.push(bar.render());
361
- }
362
- }
363
- this.interactiveManager.update("stdout", lines);
364
- }
365
- /**
366
- * Sets or removes a color function for a specific bar.
367
- * @param bar The progress bar instance to color (must be from this MultiProgressBar)
368
- * @param color Color function or undefined to remove color
369
- */
370
- setBarColor(bar, color) {
371
- for (const instance of this.bars.values()) {
372
- if (instance === bar) {
373
- if (color) {
374
- this.barColors.set(instance, color);
375
- } else {
376
- this.barColors.delete(instance);
377
- }
378
- break;
379
- }
380
- }
381
- }
382
- /**
383
- * Stops all progress bars and cleanup.
384
- */
385
- // eslint-disable-next-line sonarjs/no-identical-functions
386
- stop() {
387
- this.isActive = false;
388
- if (this.interactiveManager) {
389
- this.interactiveManager.unhook(false);
390
- }
391
- }
392
- renderComposite(bars) {
393
- if (bars.length === 0) {
394
- return "";
395
- }
396
- const firstBar = bars[0];
397
- if (!firstBar) {
398
- return "";
399
- }
400
- const output = firstBar.render();
401
- const barMatch = BAR_REGEX.exec(output);
402
- if (!barMatch?.[1]) {
403
- return output;
404
- }
405
- const width = barMatch[1].length;
406
- const grid = Array.from({ length: width }, () => []);
407
- bars.forEach((bar, index) => {
408
- const state = bar.getBarState();
409
- const filled = Math.round(state.current / state.total * width);
410
- for (let i = 0; i < width; i += 1) {
411
- if (i < filled) {
412
- grid[i]?.push(index);
413
- }
414
- }
415
- });
416
- const composite = Array.from({ length: width }, (_, i) => this.getCompositeChar(bars, grid[i])).join("");
417
- return output.replace(BAR_REGEX, `[${composite}]`);
418
- }
419
- getCompositeChar(bars, stack) {
420
- if (!stack || stack.length === 0) {
421
- const defaultBar = bars[0];
422
- return defaultBar?.getBarState().char ?? "█";
423
- }
424
- let gradientKey;
425
- if (this.options.style === "rect") {
426
- gradientKey = "rect";
427
- } else if (this.options.style === "braille") {
428
- gradientKey = "braille";
429
- } else {
430
- gradientKey = "default";
431
- }
432
- const charGradient = CHAR_GRADIENTS[gradientKey];
433
- const char = charGradient?.[Math.min(stack.length - 1, charGradient.length - 1)] ?? "█";
434
- let selectedBar;
435
- let smallestPercent = 100;
436
- for (let j = 0; j < stack.length; j += 1) {
437
- const stackBarIndex = stack[j];
438
- const bar = bars[stackBarIndex];
439
- if (!bar) {
440
- continue;
441
- }
442
- const barState = bar.getBarState();
443
- const barPercent = barState.current / barState.total * 100;
444
- if (barPercent < smallestPercent || barPercent === smallestPercent && (selectedBar === void 0 || stackBarIndex > selectedBar)) {
445
- smallestPercent = barPercent;
446
- selectedBar = stackBarIndex;
447
- }
448
- }
449
- const barIndex = selectedBar ?? stack[0];
450
- const targetBar = bars[barIndex ?? 0];
451
- if (!targetBar) {
452
- return char;
453
- }
454
- const barColor = this.barColors.get(targetBar);
455
- return barColor ? barColor(char) : char;
456
- }
457
- }
458
-
459
- export { MultiBarInstance, MultiProgressBar, ProgressBar, applyStyleToOptions, getBarChar };
@@ -1,48 +0,0 @@
1
- import type { Options as RfsOptions } from "rotating-file-stream";
2
- /**
3
- * Rotating File Stream.
4
- *
5
- * A wrapper for the `rotating-file-stream` module that provides optional immediate
6
- * writing to disk by creating and closing a new stream on each write operation.
7
- * This is useful for ensuring log messages are written immediately rather than buffered.
8
- * @example
9
- * ```typescript
10
- * // Buffered writing (default)
11
- * const bufferedStream = new RotatingFileStream("/var/log/app.log", false, {
12
- * interval: "1d",
13
- * size: "10M"
14
- * });
15
- *
16
- * // Immediate writing
17
- * const immediateStream = new RotatingFileStream("/var/log/app.log", true, {
18
- * interval: "1d"
19
- * });
20
- * ```
21
- */
22
- declare class RotatingFileStream {
23
- #private;
24
- /**
25
- * Creates a new RotatingFileStream instance.
26
- * @param filePath Path to the log file
27
- * @param writeImmediately Whether to write immediately or buffer writes
28
- * @param options Options for the rotating file stream
29
- * @throws {Error} If the 'rotating-file-stream' package is not installed
30
- */
31
- constructor(filePath: string, writeImmediately?: boolean, options?: RfsOptions);
32
- /**
33
- * Writes a message to the rotating file stream.
34
- *
35
- * If writeImmediately was set to true in the constructor, a new stream
36
- * is created for each write operation. Otherwise, uses the buffered stream.
37
- * @param message The message to write to the file
38
- */
39
- write(message: string): void;
40
- /**
41
- * Ends the rotating file stream.
42
- *
43
- * Closes the underlying stream. When `writeImmediately` is not `true`,
44
- * calling `write` after calling this method will throw an error.
45
- */
46
- end(): void;
47
- }
48
- export default RotatingFileStream;
@@ -1,7 +0,0 @@
1
- /**
2
- * Compresses data using gzip compression.
3
- * @param data The data to compress as a string
4
- * @returns A Promise that resolves to the compressed data as Uint8Array
5
- */
6
- declare const compressData: (data: string) => Promise<Uint8Array>;
7
- export default compressData;
@@ -1,30 +0,0 @@
1
- /**
2
- * Error thrown when a log entry exceeds the maximum allowed size.
3
- */
4
- declare class LogSizeError extends Error {
5
- /**
6
- * The log entry data that caused the error
7
- */
8
- readonly logData: Record<string, unknown>;
9
- /**
10
- * The actual size of the log entry in bytes
11
- */
12
- readonly actualSize: number;
13
- /**
14
- * The maximum allowed size in bytes
15
- */
16
- readonly maxSize: number;
17
- /**
18
- * Creates a new LogSizeError instance.
19
- * @param message Descriptive error message explaining the size violation
20
- * @param logData The log entry data that caused the error
21
- * @param actualSize Size of the log entry in bytes
22
- * @param maxSize Maximum allowed size in bytes
23
- * @example
24
- * ```typescript
25
- * throw new LogSizeError("Log too large", logData, 2000000, 1000000);
26
- * ```
27
- */
28
- constructor(message: string, logData: Record<string, unknown>, actualSize: number, maxSize: number);
29
- }
30
- export default LogSizeError;