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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE.md +0 -46
  3. package/dist/index.browser.js +1 -1
  4. package/dist/index.server.d.ts +0 -4
  5. package/dist/index.server.js +23 -407
  6. package/dist/middleware/elysia.js +2 -2
  7. package/dist/middleware/express.js +1 -1
  8. package/dist/middleware/fastify.js +2 -2
  9. package/dist/middleware/next/handler.d.ts +1 -1
  10. package/dist/middleware/next/middleware.d.ts +1 -1
  11. package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
  12. package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
  13. package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
  14. package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
  15. package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-BCvyNzXO.js} +1239 -7
  16. package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-BtTr13Ha.js} +1 -3
  17. package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CXAKYCb8.js} +2296 -2296
  18. package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
  19. package/dist/pail.server.d.ts +1 -76
  20. package/dist/processor/caller/caller-processor.js +1 -1
  21. package/dist/processor/environment-processor.js +10 -3
  22. package/dist/reporter/file/json-file-reporter.js +1 -1
  23. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  24. package/dist/reporter/http/http-reporter.edge-light.js +1 -5
  25. package/dist/reporter/json/index.browser.js +2 -2
  26. package/dist/reporter/json/index.js +2 -2
  27. package/dist/reporter/pretty/index.browser.js +1 -1
  28. package/dist/reporter/pretty/index.js +1 -1
  29. package/dist/reporter/pretty/pretty-reporter.server.d.ts +1 -1
  30. package/dist/reporter/raw/raw-reporter.server.d.ts +1 -1
  31. package/dist/reporter/simple/simple-reporter.server.d.ts +1 -1
  32. package/dist/reporter/simple/simple-reporter.server.js +1 -1
  33. package/dist/types.d.ts +1 -1
  34. package/dist/utils/write-console-log-based-on-level.d.ts +1 -1
  35. package/dist/wide-event.d.ts +1 -1
  36. package/dist/wide-event.js +3 -2
  37. package/package.json +6 -17
  38. package/dist/interactive/index.d.ts +0 -2
  39. package/dist/interactive/index.js +0 -2
  40. package/dist/interactive/interactive-manager.d.ts +0 -108
  41. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  42. package/dist/packem_shared/InteractiveManager-CowYA3Hx.js +0 -178
  43. package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
  44. package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
  45. package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
  46. package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
  47. package/dist/progress-bar.d.ts +0 -145
  48. package/dist/progress-bar.js +0 -459
  49. package/dist/spinner.d.ts +0 -220
  50. package/dist/spinner.js +0 -2183
  51. package/dist/utils/ansi-escapes.d.ts +0 -4
@@ -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 };