@visulima/pail 4.0.0-alpha.9 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/CHANGELOG.md +519 -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 +43 -58
  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,404 +0,0 @@
1
- const CHAR_GRADIENTS = {
2
- default: ["█", "▓", "▒", "░"],
3
- rect: ["▬", "▮", "▯", "▭"]
4
- };
5
- const BAR_REGEX = /\[([^[\]]*)\]/u;
6
- const getBarChar = (char, style, complete = true) => {
7
- if (char) {
8
- return char;
9
- }
10
- switch (style) {
11
- case "ascii": {
12
- return complete ? "#" : "-";
13
- }
14
- case "filled": {
15
- return complete ? "█" : " ";
16
- }
17
- case "rect": {
18
- return complete ? "▬" : "▭";
19
- }
20
- case "shades_classic": {
21
- return complete ? "█" : "░";
22
- }
23
- case "shades_grey": {
24
- return complete ? "▓" : "░";
25
- }
26
- case "solid": {
27
- return complete ? "█" : " ";
28
- }
29
- default: {
30
- return complete ? "█" : "░";
31
- }
32
- }
33
- };
34
- const applyStyleToOptions = (options) => {
35
- if (!options.style) {
36
- return options;
37
- }
38
- const { style } = options;
39
- const result = { ...options };
40
- if (result.barCompleteChar === void 0) {
41
- result.barCompleteChar = getBarChar(void 0, style, true);
42
- }
43
- if (result.barIncompleteChar === void 0) {
44
- result.barIncompleteChar = getBarChar(void 0, style, false);
45
- }
46
- if (result.barGlue === void 0) {
47
- result.barGlue = "";
48
- }
49
- return result;
50
- };
51
- class ProgressBar {
52
- options;
53
- current;
54
- startTime;
55
- interactiveManager;
56
- isActive = false;
57
- payload;
58
- /**
59
- * Creates a new progress bar instance.
60
- * @param options Configuration options for the progress bar
61
- * @param interactiveManager Optional interactive manager for rendering
62
- * @param payload Optional initial payload data for format placeholders
63
- */
64
- constructor(options, interactiveManager, payload) {
65
- const isCompleteArray = Array.isArray(options.barCompleteChar);
66
- const isIncompleteArray = Array.isArray(options.barIncompleteChar);
67
- const isGradientMode = isCompleteArray || isIncompleteArray;
68
- const completeChar = isCompleteArray ? options.barCompleteChar : getBarChar(options.barCompleteChar, "shades_classic");
69
- const incompleteChar = isIncompleteArray ? options.barIncompleteChar : getBarChar(options.barIncompleteChar, "shades_classic", false);
70
- this.options = {
71
- barCompleteChar: completeChar,
72
- barIncompleteChar: incompleteChar,
73
- current: 0,
74
- fps: 10,
75
- width: 40,
76
- ...options
77
- };
78
- if (isGradientMode) {
79
- if (!Array.isArray(this.options.barCompleteChar)) {
80
- this.options.barCompleteChar = [this.options.barCompleteChar];
81
- }
82
- if (!Array.isArray(this.options.barIncompleteChar)) {
83
- this.options.barIncompleteChar = [this.options.barIncompleteChar];
84
- }
85
- }
86
- this.current = this.options.current ?? 0;
87
- this.startTime = Date.now();
88
- this.interactiveManager = interactiveManager;
89
- this.payload = payload;
90
- }
91
- /**
92
- * Updates the progress bar to a new value.
93
- * @param current The current progress value
94
- * @param payload Optional payload data to merge with existing data
95
- */
96
- update(current, payload) {
97
- this.current = Math.min(current, this.options.total);
98
- if (payload) {
99
- this.payload = { ...this.payload, ...payload };
100
- }
101
- if (this.interactiveManager && this.isActive) {
102
- const progressBar = this.render();
103
- this.interactiveManager.update("stdout", [progressBar]);
104
- }
105
- }
106
- /**
107
- * Increments the progress bar by a specified step.
108
- * @param step Amount to increment (default: 1)
109
- * @param payload Optional payload data to merge with existing data
110
- */
111
- increment(step = 1, payload) {
112
- this.update(this.current + step, payload);
113
- }
114
- /**
115
- * Renders the progress bar as a formatted string.
116
- * @returns Formatted progress bar string with all placeholders replaced
117
- */
118
- // eslint-disable-next-line sonarjs/cognitive-complexity
119
- render() {
120
- const total = this.options.total > 0 ? this.options.total : 1;
121
- const width = Math.max(0, this.options.width ?? 40);
122
- const percentage = Math.max(0, Math.min(100, Math.round(this.current / total * 100)));
123
- const filled = Math.max(0, Math.min(width, Math.round(this.current / total * width)));
124
- const empty = width - filled;
125
- let bar;
126
- if (Array.isArray(this.options.barCompleteChar) || Array.isArray(this.options.barIncompleteChar)) {
127
- const completeChars = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar : void 0;
128
- const incompleteChars = Array.isArray(this.options.barIncompleteChar) ? this.options.barIncompleteChar : void 0;
129
- const completeChar = completeChars?.[completeChars.length - 1] ?? (typeof this.options.barCompleteChar === "string" ? this.options.barCompleteChar : "█");
130
- const incompleteChar = incompleteChars?.[0] ?? (typeof this.options.barIncompleteChar === "string" ? this.options.barIncompleteChar : "░");
131
- const completeLength = completeChars?.length ?? 1;
132
- const progressRatio = this.current / total;
133
- const totalSteps = width * completeLength;
134
- const currentStep = Math.round(progressRatio * totalSteps);
135
- const fractional = currentStep % completeLength;
136
- let barContent = "";
137
- for (let i = 0; i < width; i += 1) {
138
- if (i < filled) {
139
- const isGradientBoundary = i === filled - 1 && fractional > 0 && completeChars;
140
- barContent += isGradientBoundary ? completeChars[Math.max(0, fractional - 1)] : completeChar;
141
- } else {
142
- barContent += incompleteChar;
143
- }
144
- }
145
- bar = barContent;
146
- } else {
147
- const completeChar = typeof this.options.barCompleteChar === "string" ? this.options.barCompleteChar : "█";
148
- const incompleteChar = typeof this.options.barIncompleteChar === "string" ? this.options.barIncompleteChar : "░";
149
- bar = completeChar.repeat(filled) + incompleteChar.repeat(empty);
150
- }
151
- let format = this.options.format ?? "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}";
152
- if (this.payload) {
153
- for (const [k, v] of Object.entries(this.payload)) {
154
- format = format.replaceAll(`{${k}}`, String(v));
155
- }
156
- }
157
- const eta = this.calculateETA();
158
- return format.replaceAll("{bar}", bar).replaceAll("{percentage}", String(percentage)).replaceAll("{value}", String(this.current)).replaceAll("{total}", String(this.options.total)).replaceAll("{eta}", String(eta));
159
- }
160
- /**
161
- * Starts the progress bar.
162
- * @param total Optional total value to set
163
- * @param startValue Optional starting value
164
- * @param payload Optional initial payload data
165
- */
166
- start(total, startValue, payload) {
167
- if (total !== void 0) {
168
- this.options.total = total;
169
- }
170
- if (startValue !== void 0) {
171
- this.current = startValue;
172
- }
173
- this.startTime = Date.now();
174
- this.isActive = true;
175
- if (this.interactiveManager) {
176
- this.interactiveManager.hook();
177
- this.update(this.current, payload);
178
- }
179
- }
180
- /**
181
- * Stops the progress bar and cleanup.
182
- */
183
- stop() {
184
- this.isActive = false;
185
- if (this.interactiveManager) {
186
- this.interactiveManager.unhook(false);
187
- }
188
- }
189
- calculateETA() {
190
- if (this.current === 0) {
191
- return 0;
192
- }
193
- const elapsed = (Date.now() - this.startTime) / 1e3;
194
- if (elapsed < 0.1) {
195
- return 0;
196
- }
197
- const rate = this.current / elapsed;
198
- const remaining = this.options.total - this.current;
199
- return Math.round(remaining / rate);
200
- }
201
- }
202
- class MultiBarInstance extends ProgressBar {
203
- multiBar;
204
- constructor(multiBar, options, payload) {
205
- super(options, void 0, payload);
206
- this.multiBar = multiBar;
207
- }
208
- update(current, payload) {
209
- super.update(current, payload);
210
- this.multiBar.renderAll();
211
- }
212
- getBarState() {
213
- const completeChar = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar[this.options.barCompleteChar.length - 1] : getBarChar(this.options.barCompleteChar, this.options.style ?? "shades_classic", true);
214
- return {
215
- char: completeChar ?? "█",
216
- current: this.current,
217
- total: this.options.total
218
- };
219
- }
220
- }
221
- class MultiProgressBar {
222
- bars = /* @__PURE__ */ new Map();
223
- options;
224
- interactiveManager;
225
- isActive = false;
226
- nextBarId = 0;
227
- composite = false;
228
- barColors = /* @__PURE__ */ new Map();
229
- /**
230
- * Creates a new multi progress bar manager.
231
- * @param options Configuration options for the progress bars
232
- * @param interactiveManager Optional interactive manager for rendering
233
- */
234
- constructor(options = {}, interactiveManager) {
235
- this.options = {
236
- barCompleteChar: getBarChar(void 0, "shades_classic"),
237
- barIncompleteChar: getBarChar(void 0, "shades_classic", false),
238
- composite: false,
239
- format: "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}",
240
- fps: 10,
241
- ...options
242
- };
243
- this.composite = this.options.composite ?? false;
244
- this.interactiveManager = interactiveManager;
245
- }
246
- /**
247
- * Creates a new progress bar within this multi-bar manager.
248
- * @param total Total value for the progress bar
249
- * @param current Starting current value (default: 0)
250
- * @param payload Optional initial payload data for format placeholders
251
- * @returns The created progress bar instance
252
- */
253
- create(total, current = 0, payload) {
254
- const barId = `bar_${this.nextBarId++}`;
255
- const bar = new MultiBarInstance(
256
- this,
257
- {
258
- barCompleteChar: this.options.barCompleteChar,
259
- barIncompleteChar: this.options.barIncompleteChar,
260
- current,
261
- format: this.options.format,
262
- fps: this.options.fps,
263
- total,
264
- width: 40
265
- },
266
- payload
267
- );
268
- this.bars.set(barId, bar);
269
- if (!this.isActive && this.interactiveManager) {
270
- this.interactiveManager.hook();
271
- this.isActive = true;
272
- this.renderAll();
273
- }
274
- return bar;
275
- }
276
- /**
277
- * Removes a progress bar from the manager.
278
- * @param bar The progress bar instance to remove
279
- * @returns True if the bar was removed, false if not found
280
- */
281
- remove(bar) {
282
- for (const [id, existingBar] of this.bars.entries()) {
283
- if (existingBar === bar) {
284
- this.bars.delete(id);
285
- if (this.bars.size === 0) {
286
- if (this.interactiveManager) {
287
- this.interactiveManager.unhook(false);
288
- }
289
- this.isActive = false;
290
- } else {
291
- this.renderAll();
292
- }
293
- return true;
294
- }
295
- }
296
- return false;
297
- }
298
- /**
299
- * Renders all progress bars.
300
- */
301
- renderAll() {
302
- if (!this.interactiveManager || !this.isActive) {
303
- return;
304
- }
305
- const lines = [];
306
- if (this.composite) {
307
- const barsArray = [...this.bars.values()];
308
- if (barsArray.length > 0) {
309
- const compositeOutput = this.renderComposite(barsArray);
310
- lines.push(compositeOutput);
311
- }
312
- } else {
313
- for (const bar of this.bars.values()) {
314
- lines.push(bar.render());
315
- }
316
- }
317
- this.interactiveManager.update("stdout", lines);
318
- }
319
- /**
320
- * Sets or removes a color function for a specific bar.
321
- * @param bar The progress bar instance to color (must be from this MultiProgressBar)
322
- * @param color Color function or undefined to remove color
323
- */
324
- setBarColor(bar, color) {
325
- for (const instance of this.bars.values()) {
326
- if (instance === bar) {
327
- if (color) {
328
- this.barColors.set(instance, color);
329
- } else {
330
- this.barColors.delete(instance);
331
- }
332
- break;
333
- }
334
- }
335
- }
336
- /**
337
- * Stops all progress bars and cleanup.
338
- */
339
- // eslint-disable-next-line sonarjs/no-identical-functions
340
- stop() {
341
- this.isActive = false;
342
- if (this.interactiveManager) {
343
- this.interactiveManager.unhook(false);
344
- }
345
- }
346
- renderComposite(bars) {
347
- if (bars.length === 0) {
348
- return "";
349
- }
350
- const firstBar = bars[0];
351
- if (!firstBar) {
352
- return "";
353
- }
354
- const output = firstBar.render();
355
- const barMatch = output.match(BAR_REGEX);
356
- if (!barMatch || !barMatch[1]) {
357
- return output;
358
- }
359
- const width = barMatch[1].length;
360
- const grid = Array.from({ length: width }, () => []);
361
- bars.forEach((bar, index) => {
362
- const state = bar.getBarState();
363
- const filled = Math.round(state.current / state.total * width);
364
- for (let i = 0; i < width; i += 1) {
365
- if (i < filled) {
366
- grid[i]?.push(index);
367
- }
368
- }
369
- });
370
- const composite = Array.from({ length: width }, (_, i) => this.getCompositeChar(bars, grid[i])).join("");
371
- return output.replace(BAR_REGEX, `[${composite}]`);
372
- }
373
- getCompositeChar(bars, stack) {
374
- if (!stack || stack.length === 0) {
375
- const defaultBar = bars[0];
376
- return defaultBar?.getBarState().char ?? "█";
377
- }
378
- const charGradient = CHAR_GRADIENTS[this.options.style === "rect" ? "rect" : "default"];
379
- const char = charGradient?.[Math.min(stack.length - 1, charGradient.length - 1)] ?? "█";
380
- let selectedBar;
381
- let smallestPercent = 100;
382
- for (const stackBarIndex of stack) {
383
- const bar = bars[stackBarIndex];
384
- if (!bar) {
385
- continue;
386
- }
387
- const barState = bar.getBarState();
388
- const barPercent = barState.current / barState.total * 100;
389
- if (barPercent < smallestPercent || barPercent === smallestPercent && (selectedBar === void 0 || stackBarIndex > selectedBar)) {
390
- smallestPercent = barPercent;
391
- selectedBar = stackBarIndex;
392
- }
393
- }
394
- const barIndex = selectedBar ?? stack[0];
395
- const targetBar = bars[barIndex ?? 0];
396
- if (!targetBar) {
397
- return char;
398
- }
399
- const barColor = this.barColors.get(targetBar);
400
- return barColor ? barColor(char) : char;
401
- }
402
- }
403
-
404
- 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;
@@ -1,27 +0,0 @@
1
- /**
2
- * Sends an HTTP request with retry logic and rate limiting support.
3
- * @param url The URL to send the request to
4
- * @param method The HTTP method to use
5
- * @param headers Request headers
6
- * @param body The request body (string or Uint8Array)
7
- * @param maxRetries Maximum number of retry attempts
8
- * @param retryDelay Base delay between retries in milliseconds
9
- * @param respectRateLimit Whether to respect rate limiting (429 responses)
10
- * @param onDebugRequestResponse Optional callback for debugging requests/responses
11
- * @param onError Optional callback for error handling
12
- */
13
- declare const sendWithRetry: (url: string, method: string, headers: Record<string, string>, body: string | Uint8Array, maxRetries: number, retryDelay: number, respectRateLimit: boolean, onDebugRequestResponse?: (requestResponse: {
14
- req: {
15
- body: string | Uint8Array;
16
- headers: Record<string, string>;
17
- method: string;
18
- url: string;
19
- };
20
- res: {
21
- body: string;
22
- headers: Record<string, string>;
23
- status: number;
24
- statusText: string;
25
- };
26
- }) => void, onError?: (error: Error) => void) => Promise<void>;
27
- export default sendWithRetry;
@@ -1,61 +0,0 @@
1
- import type { stringify } from "safe-stable-stringify";
2
- import type { LiteralUnion } from "type-fest";
3
- import type { ExtendedRfc5424LogLevels, ReadonlyMeta, StringifyAwareReporter } from "../../types.d.ts";
4
- /**
5
- * Options for configuring JSON reporters.
6
- */
7
- export type AbstractJsonReporterOptions = {
8
- /** Error serialization options */
9
- error: Partial<{
10
- /** Properties to exclude from error serialization */
11
- exclude?: string[];
12
- /** Maximum depth for error object serialization */
13
- maxDepth?: number;
14
- /** Whether to use toJSON methods during serialization */
15
- useToJSON?: boolean;
16
- }>;
17
- };
18
- /**
19
- * Abstract JSON Reporter.
20
- *
21
- * Base class for JSON-based reporters that provides common functionality
22
- * for serializing log metadata to JSON format. Handles error serialization,
23
- * context processing, and provides a template method for actual output.
24
- * @template L - The log level type
25
- * @example
26
- * ```typescript
27
- * class CustomJsonReporter extends AbstractJsonReporter {
28
- * protected _log(message: string): void {
29
- * console.log(message);
30
- * }
31
- * }
32
- * ```
33
- */
34
- export declare abstract class AbstractJsonReporter<L extends string = string> implements StringifyAwareReporter<L> {
35
- /** Custom stringify function for object serialization */
36
- protected stringify: typeof stringify | undefined;
37
- /** Error serialization options */
38
- protected errorOptions: AbstractJsonReporterOptions["error"];
39
- /**
40
- * Creates a new AbstractJsonReporter instance.
41
- * @param options Configuration options for JSON formatting and error handling
42
- */
43
- constructor(options?: Partial<AbstractJsonReporterOptions>);
44
- /**
45
- * Sets a custom stringify function for object serialization.
46
- * @param function_ The stringify function to use for serialization
47
- */
48
- setStringify(function_: any): void;
49
- log(meta: ReadonlyMeta<L>): void;
50
- /**
51
- * Template method for outputting the JSON log message.
52
- *
53
- * Subclasses must implement this method to define how the JSON message
54
- * is actually written (to console, file, network, etc.).
55
- * @param message The JSON-formatted log message
56
- * @param logLevel The log level of the message
57
- * @protected
58
- * @abstract
59
- */
60
- protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
61
- }
@@ -1,40 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { ExtendedRfc5424LogLevels } from "../../types.d.ts";
3
- import type { AbstractJsonReporterOptions } from "./abstract-json-reporter.d.ts";
4
- import { AbstractJsonReporter } from "./abstract-json-reporter.d.ts";
5
- /**
6
- * Browser JSON Reporter.
7
- *
8
- * A JSON reporter for browser environments that outputs structured log data
9
- * to the browser console. Uses appropriate console methods based on log level.
10
- * @template L - The log level type
11
- * @example
12
- * ```typescript
13
- * import { createPail } from "@visulima/pail";
14
- *
15
- * const logger = createPail({
16
- * reporters: [new JsonReporter()]
17
- * });
18
- *
19
- * logger.info("Application started", { version: "1.0.0" });
20
- * // Outputs: {"level":"info","message":"Application started","context":[{"version":"1.0.0"}],...}
21
- * ```
22
- */
23
- declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> {
24
- /**
25
- * Creates a new Browser JSON Reporter instance.
26
- * @param options Configuration options for JSON formatting
27
- */
28
- constructor(options?: Partial<AbstractJsonReporterOptions>);
29
- /**
30
- * Outputs the JSON message to the browser console.
31
- *
32
- * Uses the appropriate console method based on the log level
33
- * (console.log, console.error, console.warn, etc.).
34
- * @param message The JSON-formatted log message
35
- * @param logLevel The log level determining which console method to use
36
- * @protected
37
- */
38
- protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
39
- }
40
- export default JsonReporter;
@@ -1,50 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { ExtendedRfc5424LogLevels, StreamAwareReporter } from "../../types.d.ts";
3
- import type { AbstractJsonReporterOptions } from "./abstract-json-reporter.d.ts";
4
- import { AbstractJsonReporter } from "./abstract-json-reporter.d.ts";
5
- /**
6
- * Server JSON Reporter.
7
- *
8
- * A JSON reporter for Node.js server environments that outputs structured log data
9
- * to stdout/stderr streams. Routes error-level logs to stderr and others to stdout.
10
- * @template L - The log level type
11
- * @example
12
- * ```typescript
13
- * import { createPail } from "@visulima/pail";
14
- *
15
- * const logger = createPail({
16
- * reporters: [new JsonReporter()]
17
- * });
18
- *
19
- * logger.info("Server started", { port: 3000 });
20
- * logger.error("Database connection failed", error);
21
- * ```
22
- */
23
- declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> implements StreamAwareReporter<L> {
24
- #private;
25
- /**
26
- * Creates a new Server JSON Reporter instance.
27
- * @param options Configuration options for JSON formatting
28
- */
29
- constructor(options?: Partial<AbstractJsonReporterOptions>);
30
- /**
31
- * Sets the stdout stream for the reporter.
32
- * @param stdout_ The writable stream to use for stdout output
33
- */
34
- setStdout(stdout_: NodeJS.WriteStream): void;
35
- /**
36
- * Sets the stderr stream for the reporter.
37
- * @param stderr_ The writable stream to use for stderr output
38
- */
39
- setStderr(stderr_: NodeJS.WriteStream): void;
40
- /**
41
- * Outputs the JSON message to the appropriate stream.
42
- *
43
- * Routes error and warning level messages to stderr, others to stdout.
44
- * @param message The JSON-formatted log message
45
- * @param logLevel The log level determining which stream to use
46
- * @protected
47
- */
48
- protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
49
- }
50
- export default JsonReporter;