@visulima/pail 3.2.2 → 4.0.0-alpha.10
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.
- package/CHANGELOG.md +188 -0
- package/LICENSE.md +434 -6
- package/README.md +355 -24
- package/dist/error.d.ts +104 -0
- package/dist/error.js +76 -0
- package/dist/index.browser.d.ts +3 -1
- package/dist/index.browser.js +1490 -3
- package/dist/index.server.d.ts +3 -1
- package/dist/index.server.js +2668 -14
- package/dist/interactive/index.js +2 -2
- package/dist/middleware/elysia.d.ts +71 -0
- package/dist/middleware/elysia.js +70 -0
- package/dist/middleware/express.d.ts +86 -0
- package/dist/middleware/express.js +29 -0
- package/dist/middleware/fastify.d.ts +81 -0
- package/dist/middleware/fastify.js +46 -0
- package/dist/middleware/hono.d.ts +85 -0
- package/dist/middleware/hono.js +33 -0
- package/dist/middleware/next/handler.d.ts +36 -0
- package/dist/middleware/next/handler.js +53 -0
- package/dist/middleware/next/middleware.d.ts +59 -0
- package/dist/middleware/next/storage.d.ts +14 -0
- package/dist/middleware/shared/create-middleware-logger.d.ts +82 -0
- package/dist/middleware/shared/headers.d.ts +14 -0
- package/dist/middleware/shared/routes.d.ts +30 -0
- package/dist/middleware/shared/storage.d.ts +29 -0
- package/dist/middleware/sveltekit.d.ts +123 -0
- package/dist/middleware/sveltekit.js +43 -0
- package/dist/object-tree.d.ts +2 -2
- package/dist/object-tree.js +7 -7
- package/dist/packem_shared/{AbstractJsonReporter-intFdT_A.js → AbstractJsonReporter-CjtVgHbU.js} +112 -28
- package/dist/packem_shared/AbstractJsonReporter-DlugSJpY.js +288 -0
- package/dist/packem_shared/{InteractiveManager-CZ85hGNW.js → InteractiveManager-CowYA3Hx.js} +17 -11
- package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-BypRlYTX.js} +3 -11
- package/dist/packem_shared/{JsonReporter-C0AXk99i.js → JsonReporter-BgPvIyC2.js} +2 -2
- package/dist/packem_shared/{JsonReporter-DcM2LBX9.js → JsonReporter-Dbw82ewj.js} +2 -2
- package/dist/packem_shared/{PrettyReporter-CuLLKr6-.js → PrettyReporter-C2dCzIaf.js} +54 -8
- package/dist/packem_shared/{format-label-Btft2KGP.js → PrettyReporter-gMqa7j_m.js} +372 -78
- package/dist/packem_shared/Spinner-Cokext9b.js +2183 -0
- package/dist/packem_shared/abstract-pretty-reporter-szQO-IgK.js +2635 -0
- package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
- package/dist/packem_shared/{constants-DfDr4MHC.js → constants-omsTHUWB.js} +1 -1
- package/dist/packem_shared/createPailError-B_sgL0nF.js +76 -0
- package/dist/packem_shared/getBarChar-D7JfmdTr.js +459 -0
- package/dist/packem_shared/headers-BxHWM6KI.js +127 -0
- package/dist/packem_shared/{index-DqKWykfa.js → index-BEfVUy9P.js} +174 -64
- package/dist/packem_shared/{index-BomQ3E6J.js → index-Bx3-C0j9.js} +29 -21
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +24 -0
- package/dist/packem_shared/storage-D0vqz8OX.js +36 -0
- package/dist/packem_shared/{InteractiveStreamHook-DiSubbJ1.js → useLogger-D0rU3lcX.js} +13 -1
- package/dist/packem_shared/{write-console-log-based-on-level-DBmRYXpj.js → write-console-log-based-on-level-ree2lDPw.js} +5 -4
- package/dist/packem_shared/{write-stream-BG8fhcs3.js → write-stream-BuFtjATz.js} +1 -1
- package/dist/pail.browser.d.ts +1 -1
- package/dist/processor/environment-processor.d.ts +124 -0
- package/dist/processor/environment-processor.js +82 -0
- package/dist/processor/message-formatter-processor.d.ts +2 -2
- package/dist/processor/message-formatter-processor.js +654 -6
- package/dist/processor/opentelemetry-processor.js +4 -4
- package/dist/processor/redact-processor.d.ts +1 -1
- package/dist/processor/redact-processor.js +2 -1
- package/dist/processor/sampling-processor.d.ts +111 -0
- package/dist/processor/sampling-processor.js +59 -0
- package/dist/progress-bar.d.ts +10 -1
- package/dist/progress-bar.js +75 -20
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.js +23 -26
- package/dist/reporter/http/http-reporter.edge-light.js +134 -53
- package/dist/reporter/json/abstract-json-reporter.d.ts +1 -1
- package/dist/reporter/json/index.browser.js +2 -2
- package/dist/reporter/json/index.js +2 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.js +8 -12
- package/dist/spinner.js +37 -4
- package/dist/types.d.ts +4 -4
- package/dist/wide-event.d.ts +300 -0
- package/dist/wide-event.js +283 -0
- package/package.json +73 -8
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +0 -222
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +0 -50
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
- package/dist/packem_shared/pail.browser-CPjQrsyy.js +0 -1427
|
@@ -4,7 +4,7 @@ import type { Meta, Processor } from "../types.d.ts";
|
|
|
4
4
|
* Redact Processor.
|
|
5
5
|
*
|
|
6
6
|
* A processor that redacts sensitive information from log messages and metadata.
|
|
7
|
-
* Uses the {@link https://
|
|
7
|
+
* Uses the {@link https://visulima.com/packages/redact/|@visulima/redact} library to identify and mask sensitive data like
|
|
8
8
|
* passwords, API keys, credit card numbers, and other PII.
|
|
9
9
|
* @template L - The log level type
|
|
10
10
|
* @example
|
|
@@ -9,7 +9,8 @@ class RedactProcessor {
|
|
|
9
9
|
* @param options Additional redaction options
|
|
10
10
|
*/
|
|
11
11
|
constructor(rules, options) {
|
|
12
|
-
|
|
12
|
+
const effectiveRules = rules ?? standardRules;
|
|
13
|
+
this.#redact = (input) => redact(input, effectiveRules, options);
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Processes log metadata to redact sensitive information.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Meta, Processor } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Head sampling configuration.
|
|
4
|
+
*
|
|
5
|
+
* Controls random sampling rates per log level. Each key is a log level name
|
|
6
|
+
* and the value is the percentage (0-100) of logs at that level to keep.
|
|
7
|
+
* Levels not listed default to 100 (keep all).
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const headSampling: HeadSamplingConfig = {
|
|
11
|
+
* debug: 0, // Drop all debug logs
|
|
12
|
+
* informational: 10, // Keep 10% of info logs
|
|
13
|
+
* warning: 50, // Keep 50% of warning logs
|
|
14
|
+
* error: 100, // Keep all error logs
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
type HeadSamplingConfig = Partial<Record<string, number>>;
|
|
19
|
+
/**
|
|
20
|
+
* Tail sampling condition function.
|
|
21
|
+
*
|
|
22
|
+
* A function that receives the log metadata and returns true if the log
|
|
23
|
+
* should be force-kept regardless of head sampling. This allows keeping
|
|
24
|
+
* important logs based on their content (e.g., errors, slow operations).
|
|
25
|
+
* @template L - The log level type
|
|
26
|
+
*/
|
|
27
|
+
type TailSamplingCondition<L extends string = string> = (meta: Readonly<Meta<L>>) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Sampling processor configuration options.
|
|
30
|
+
*/
|
|
31
|
+
interface SamplingProcessorOptions<L extends string = string> {
|
|
32
|
+
/**
|
|
33
|
+
* Head sampling rates per log level.
|
|
34
|
+
*
|
|
35
|
+
* A map of log level to sampling percentage (0-100).
|
|
36
|
+
* Levels not specified default to 100 (keep all).
|
|
37
|
+
* Set to 0 to drop all logs at that level.
|
|
38
|
+
*/
|
|
39
|
+
head?: HeadSamplingConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Tail sampling conditions.
|
|
42
|
+
*
|
|
43
|
+
* An array of condition functions that can force-keep a log entry
|
|
44
|
+
* even if it was dropped by head sampling. If any condition returns true,
|
|
45
|
+
* the log is kept.
|
|
46
|
+
*/
|
|
47
|
+
tail?: TailSamplingCondition<L>[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sampling Processor.
|
|
51
|
+
*
|
|
52
|
+
* Inspired by evlog's production sampling strategy, this processor implements
|
|
53
|
+
* both head sampling (random per-level) and tail sampling (force-keep based
|
|
54
|
+
* on conditions) to control log volume in production environments.
|
|
55
|
+
*
|
|
56
|
+
* **Head sampling** randomly drops a percentage of logs per level. This is
|
|
57
|
+
* evaluated first and provides broad volume control.
|
|
58
|
+
*
|
|
59
|
+
* **Tail sampling** can override head sampling to force-keep important logs
|
|
60
|
+
* based on their content. For example, you might drop 90% of info logs but
|
|
61
|
+
* force-keep any that contain error information or relate to slow operations.
|
|
62
|
+
*
|
|
63
|
+
* When a log is dropped by sampling, the processor sets a `__dropped: true`
|
|
64
|
+
* boolean flag on the meta object. Reporters should check for this flag and
|
|
65
|
+
* skip entries where `__dropped` is `true`.
|
|
66
|
+
* @template L - The log level type
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { createPail } from "@visulima/pail";
|
|
70
|
+
* import SamplingProcessor from "@visulima/pail/processor/sampling";
|
|
71
|
+
*
|
|
72
|
+
* const logger = createPail({
|
|
73
|
+
* processors: [
|
|
74
|
+
* new SamplingProcessor({
|
|
75
|
+
* head: {
|
|
76
|
+
* debug: 0, // Drop all debug logs
|
|
77
|
+
* informational: 10, // Keep 10% of info logs
|
|
78
|
+
* warning: 50, // Keep 50% of warnings
|
|
79
|
+
* error: 100, // Keep all errors
|
|
80
|
+
* },
|
|
81
|
+
* tail: [
|
|
82
|
+
* // Force-keep logs with errors regardless of head sampling
|
|
83
|
+
* (meta) => meta.error !== undefined,
|
|
84
|
+
* // Force-keep logs from critical scopes
|
|
85
|
+
* (meta) => meta.scope?.includes("payment") ?? false,
|
|
86
|
+
* ],
|
|
87
|
+
* }),
|
|
88
|
+
* ],
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare class SamplingProcessor<L extends string = string> implements Processor<L> {
|
|
93
|
+
#private;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new SamplingProcessor instance.
|
|
96
|
+
* @param options Sampling configuration options
|
|
97
|
+
*/
|
|
98
|
+
constructor(options?: SamplingProcessorOptions<L>);
|
|
99
|
+
/**
|
|
100
|
+
* Processes log metadata to apply sampling rules.
|
|
101
|
+
*
|
|
102
|
+
* First evaluates head sampling (random per-level), then checks tail
|
|
103
|
+
* sampling conditions. If a log is dropped, the meta is marked with
|
|
104
|
+
* `__dropped: true` so reporters can skip it.
|
|
105
|
+
* @param meta The log metadata to process
|
|
106
|
+
* @returns The processed metadata, potentially marked as dropped
|
|
107
|
+
*/
|
|
108
|
+
process(meta: Meta<L>): Meta<L>;
|
|
109
|
+
}
|
|
110
|
+
export default SamplingProcessor;
|
|
111
|
+
export type { HeadSamplingConfig, SamplingProcessorOptions, TailSamplingCondition };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class SamplingProcessor {
|
|
2
|
+
#headRates;
|
|
3
|
+
#tailConditions;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new SamplingProcessor instance.
|
|
6
|
+
* @param options Sampling configuration options
|
|
7
|
+
*/
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.#headRates = options.head ?? {};
|
|
10
|
+
this.#tailConditions = options.tail ?? [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Processes log metadata to apply sampling rules.
|
|
14
|
+
*
|
|
15
|
+
* First evaluates head sampling (random per-level), then checks tail
|
|
16
|
+
* sampling conditions. If a log is dropped, the meta is marked with
|
|
17
|
+
* `__dropped: true` so reporters can skip it.
|
|
18
|
+
* @param meta The log metadata to process
|
|
19
|
+
* @returns The processed metadata, potentially marked as dropped
|
|
20
|
+
*/
|
|
21
|
+
process(meta) {
|
|
22
|
+
const level = meta.type.level;
|
|
23
|
+
if (this.#shouldDrop(level) && !this.#shouldForceKeep(meta)) {
|
|
24
|
+
return { ...meta, dropped: true };
|
|
25
|
+
}
|
|
26
|
+
return meta;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Evaluates head sampling for the given log level.
|
|
30
|
+
* @returns true if the log should be dropped
|
|
31
|
+
*/
|
|
32
|
+
#shouldDrop(level) {
|
|
33
|
+
const rate = this.#headRates[level];
|
|
34
|
+
if (rate === void 0) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (rate <= 0) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (rate >= 100) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return Math.random() * 100 >= rate;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Evaluates tail sampling conditions.
|
|
47
|
+
* @returns true if any condition forces keeping the log
|
|
48
|
+
*/
|
|
49
|
+
#shouldForceKeep(meta) {
|
|
50
|
+
for (let i = 0; i < this.#tailConditions.length; i += 1) {
|
|
51
|
+
if (this.#tailConditions[i](meta)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { SamplingProcessor as default };
|
package/dist/progress-bar.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type InteractiveManager from "./interactive/interactive-manager.d.ts";
|
|
2
|
-
export type ProgressBarStyle = "shades_classic" | "shades_grey" | "rect" | "filled" | "solid" | "ascii" | "custom";
|
|
2
|
+
export type ProgressBarStyle = "shades_classic" | "shades_grey" | "rect" | "filled" | "solid" | "ascii" | "braille" | "custom";
|
|
3
3
|
export interface ProgressBarOptions {
|
|
4
4
|
barCompleteChar?: string | string[];
|
|
5
5
|
barGlue?: string;
|
|
@@ -7,6 +7,9 @@ export interface ProgressBarOptions {
|
|
|
7
7
|
current?: number;
|
|
8
8
|
format?: string;
|
|
9
9
|
fps?: number;
|
|
10
|
+
peak?: number;
|
|
11
|
+
peakChar?: string;
|
|
12
|
+
roundedCaps?: boolean;
|
|
10
13
|
style?: ProgressBarStyle;
|
|
11
14
|
total: number;
|
|
12
15
|
width?: number;
|
|
@@ -55,6 +58,11 @@ export declare class ProgressBar {
|
|
|
55
58
|
* @param payload Optional payload data to merge with existing data
|
|
56
59
|
*/
|
|
57
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;
|
|
58
66
|
/**
|
|
59
67
|
* Increments the progress bar by a specified step.
|
|
60
68
|
* @param step Amount to increment (default: 1)
|
|
@@ -77,6 +85,7 @@ export declare class ProgressBar {
|
|
|
77
85
|
* Stops the progress bar and cleanup.
|
|
78
86
|
*/
|
|
79
87
|
stop(): void;
|
|
88
|
+
private calculatePeakPosition;
|
|
80
89
|
private calculateETA;
|
|
81
90
|
}
|
|
82
91
|
export declare class MultiBarInstance extends ProgressBar {
|
package/dist/progress-bar.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
const CHAR_GRADIENTS = {
|
|
2
|
+
braille: ["⣿", "⡷", "⢾", "⠤"],
|
|
2
3
|
default: ["█", "▓", "▒", "░"],
|
|
3
4
|
rect: ["▬", "▮", "▯", "▭"]
|
|
4
5
|
};
|
|
6
|
+
const BRAILLE_FULL = "⣿";
|
|
7
|
+
const BRAILLE_CAP_LEFT = "⢾";
|
|
8
|
+
const BRAILLE_CAP_RIGHT = "⡷";
|
|
9
|
+
const BRAILLE_EMPTY = "⠤";
|
|
5
10
|
const BAR_REGEX = /\[([^[\]]*)\]/u;
|
|
6
11
|
const getBarChar = (char, style, complete = true) => {
|
|
7
12
|
if (char) {
|
|
@@ -11,6 +16,9 @@ const getBarChar = (char, style, complete = true) => {
|
|
|
11
16
|
case "ascii": {
|
|
12
17
|
return complete ? "#" : "-";
|
|
13
18
|
}
|
|
19
|
+
case "braille": {
|
|
20
|
+
return complete ? BRAILLE_FULL : BRAILLE_EMPTY;
|
|
21
|
+
}
|
|
14
22
|
case "filled": {
|
|
15
23
|
return complete ? "█" : " ";
|
|
16
24
|
}
|
|
@@ -37,15 +45,9 @@ const applyStyleToOptions = (options) => {
|
|
|
37
45
|
}
|
|
38
46
|
const { style } = options;
|
|
39
47
|
const result = { ...options };
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
}
|
|
48
|
+
result.barCompleteChar ??= getBarChar(void 0, style, true);
|
|
49
|
+
result.barIncompleteChar ??= getBarChar(void 0, style, false);
|
|
50
|
+
result.barGlue ??= "";
|
|
49
51
|
return result;
|
|
50
52
|
};
|
|
51
53
|
class ProgressBar {
|
|
@@ -65,8 +67,9 @@ class ProgressBar {
|
|
|
65
67
|
const isCompleteArray = Array.isArray(options.barCompleteChar);
|
|
66
68
|
const isIncompleteArray = Array.isArray(options.barIncompleteChar);
|
|
67
69
|
const isGradientMode = isCompleteArray || isIncompleteArray;
|
|
68
|
-
const
|
|
69
|
-
const
|
|
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);
|
|
70
73
|
this.options = {
|
|
71
74
|
barCompleteChar: completeChar,
|
|
72
75
|
barIncompleteChar: incompleteChar,
|
|
@@ -103,6 +106,13 @@ class ProgressBar {
|
|
|
103
106
|
this.interactiveManager.update("stdout", [progressBar]);
|
|
104
107
|
}
|
|
105
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
|
+
}
|
|
106
116
|
/**
|
|
107
117
|
* Increments the progress bar by a specified step.
|
|
108
118
|
* @param step Amount to increment (default: 1)
|
|
@@ -123,6 +133,7 @@ class ProgressBar {
|
|
|
123
133
|
const filled = Math.max(0, Math.min(width, Math.round(this.current / total * width)));
|
|
124
134
|
const empty = width - filled;
|
|
125
135
|
let bar;
|
|
136
|
+
const useCaps = this.options.roundedCaps === true || this.options.roundedCaps === void 0 && this.options.style === "braille";
|
|
126
137
|
if (Array.isArray(this.options.barCompleteChar) || Array.isArray(this.options.barIncompleteChar)) {
|
|
127
138
|
const completeChars = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar : void 0;
|
|
128
139
|
const incompleteChars = Array.isArray(this.options.barIncompleteChar) ? this.options.barIncompleteChar : void 0;
|
|
@@ -137,7 +148,7 @@ class ProgressBar {
|
|
|
137
148
|
for (let i = 0; i < width; i += 1) {
|
|
138
149
|
if (i < filled) {
|
|
139
150
|
const isGradientBoundary = i === filled - 1 && fractional > 0 && completeChars;
|
|
140
|
-
barContent += isGradientBoundary ? completeChars[Math.max(0, fractional - 1)] : completeChar;
|
|
151
|
+
barContent += isGradientBoundary ? completeChars[Math.max(0, fractional - 1)] ?? completeChar : completeChar;
|
|
141
152
|
} else {
|
|
142
153
|
barContent += incompleteChar;
|
|
143
154
|
}
|
|
@@ -146,11 +157,35 @@ class ProgressBar {
|
|
|
146
157
|
} else {
|
|
147
158
|
const completeChar = typeof this.options.barCompleteChar === "string" ? this.options.barCompleteChar : "█";
|
|
148
159
|
const incompleteChar = typeof this.options.barIncompleteChar === "string" ? this.options.barIncompleteChar : "░";
|
|
149
|
-
|
|
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("");
|
|
150
183
|
}
|
|
151
184
|
let format = this.options.format ?? "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}";
|
|
152
185
|
if (this.payload) {
|
|
153
|
-
|
|
186
|
+
const entries = Object.entries(this.payload);
|
|
187
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
188
|
+
const [k, v] = entries[i];
|
|
154
189
|
format = format.replaceAll(`{${k}}`, String(v));
|
|
155
190
|
}
|
|
156
191
|
}
|
|
@@ -186,6 +221,17 @@ class ProgressBar {
|
|
|
186
221
|
this.interactiveManager.unhook(false);
|
|
187
222
|
}
|
|
188
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
|
+
}
|
|
189
235
|
calculateETA() {
|
|
190
236
|
if (this.current === 0) {
|
|
191
237
|
return 0;
|
|
@@ -210,7 +256,7 @@ class MultiBarInstance extends ProgressBar {
|
|
|
210
256
|
this.multiBar.renderAll();
|
|
211
257
|
}
|
|
212
258
|
getBarState() {
|
|
213
|
-
const completeChar = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar
|
|
259
|
+
const completeChar = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar.at(-1) : getBarChar(this.options.barCompleteChar, this.options.style ?? "shades_classic", true);
|
|
214
260
|
return {
|
|
215
261
|
char: completeChar ?? "█",
|
|
216
262
|
current: this.current,
|
|
@@ -251,7 +297,7 @@ class MultiProgressBar {
|
|
|
251
297
|
* @returns The created progress bar instance
|
|
252
298
|
*/
|
|
253
299
|
create(total, current = 0, payload) {
|
|
254
|
-
const barId = `bar_${this.nextBarId++}`;
|
|
300
|
+
const barId = `bar_${String(this.nextBarId++)}`;
|
|
255
301
|
const bar = new MultiBarInstance(
|
|
256
302
|
this,
|
|
257
303
|
{
|
|
@@ -352,8 +398,8 @@ class MultiProgressBar {
|
|
|
352
398
|
return "";
|
|
353
399
|
}
|
|
354
400
|
const output = firstBar.render();
|
|
355
|
-
const barMatch =
|
|
356
|
-
if (!barMatch
|
|
401
|
+
const barMatch = BAR_REGEX.exec(output);
|
|
402
|
+
if (!barMatch?.[1]) {
|
|
357
403
|
return output;
|
|
358
404
|
}
|
|
359
405
|
const width = barMatch[1].length;
|
|
@@ -375,11 +421,20 @@ class MultiProgressBar {
|
|
|
375
421
|
const defaultBar = bars[0];
|
|
376
422
|
return defaultBar?.getBarState().char ?? "█";
|
|
377
423
|
}
|
|
378
|
-
|
|
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];
|
|
379
433
|
const char = charGradient?.[Math.min(stack.length - 1, charGradient.length - 1)] ?? "█";
|
|
380
434
|
let selectedBar;
|
|
381
435
|
let smallestPercent = 100;
|
|
382
|
-
for (
|
|
436
|
+
for (let j = 0; j < stack.length; j += 1) {
|
|
437
|
+
const stackBarIndex = stack[j];
|
|
383
438
|
const bar = bars[stackBarIndex];
|
|
384
439
|
if (!bar) {
|
|
385
440
|
continue;
|
|
@@ -20,7 +20,7 @@ const __cjs_getBuiltinModule = (module) => {
|
|
|
20
20
|
const {
|
|
21
21
|
Buffer
|
|
22
22
|
} = __cjs_getBuiltinModule("node:buffer");
|
|
23
|
-
import { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-
|
|
23
|
+
import { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-CjtVgHbU.js';
|
|
24
24
|
const {
|
|
25
25
|
gzipSync
|
|
26
26
|
} = __cjs_getBuiltinModule("node:zlib");
|
|
@@ -33,24 +33,25 @@ const compressData = async (data) => {
|
|
|
33
33
|
const reader = stream.readable.getReader();
|
|
34
34
|
const encoder = new TextEncoder();
|
|
35
35
|
const chunks = [];
|
|
36
|
-
writer.write(encoder.encode(data));
|
|
37
|
-
writer.close();
|
|
36
|
+
await writer.write(encoder.encode(data));
|
|
37
|
+
await writer.close();
|
|
38
38
|
let done = false;
|
|
39
39
|
while (!done) {
|
|
40
|
-
const
|
|
41
|
-
done =
|
|
42
|
-
if (
|
|
43
|
-
chunks.push(
|
|
40
|
+
const result = await reader.read();
|
|
41
|
+
done = result.done;
|
|
42
|
+
if (result.value) {
|
|
43
|
+
chunks.push(result.value);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
const totalLength = chunks.reduce((accumulator, chunk) => accumulator + chunk.length, 0);
|
|
47
|
-
const
|
|
47
|
+
const resultBuffer = new Uint8Array(totalLength);
|
|
48
48
|
let offset = 0;
|
|
49
|
-
for (
|
|
50
|
-
|
|
49
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
50
|
+
const chunk = chunks[i];
|
|
51
|
+
resultBuffer.set(chunk, offset);
|
|
51
52
|
offset += chunk.length;
|
|
52
53
|
}
|
|
53
|
-
return
|
|
54
|
+
return resultBuffer;
|
|
54
55
|
}
|
|
55
56
|
return gzipSync(data);
|
|
56
57
|
};
|
|
@@ -125,7 +126,7 @@ const processResponse = async (response, url, method, headers, body, onDebugRequ
|
|
|
125
126
|
return false;
|
|
126
127
|
}
|
|
127
128
|
if (response.status < 500 && response.status !== 429) {
|
|
128
|
-
const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
129
|
+
const error = new Error(`HTTP ${String(response.status)}: ${response.statusText}`);
|
|
129
130
|
if (onError) {
|
|
130
131
|
onError(error);
|
|
131
132
|
}
|
|
@@ -185,7 +186,7 @@ const sendWithRetry = async (url, method, headers, body, maxRetries, retryDelay,
|
|
|
185
186
|
continue;
|
|
186
187
|
}
|
|
187
188
|
if (!response.ok) {
|
|
188
|
-
const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
189
|
+
const error = new Error(`HTTP ${String(response.status)}: ${response.statusText}`);
|
|
189
190
|
if (onError) {
|
|
190
191
|
onError(error);
|
|
191
192
|
}
|
|
@@ -298,7 +299,7 @@ class AbstractHttpReporter extends AbstractJsonReporter {
|
|
|
298
299
|
const logEntrySize = this.edgeCompat || typeof TextEncoder === "undefined" ? Buffer.byteLength(payload, "utf8") : new TextEncoder().encode(payload).length;
|
|
299
300
|
if (logEntrySize > this.maxLogSize) {
|
|
300
301
|
const error = new LogSizeError(
|
|
301
|
-
`Log entry exceeds maximum size of ${this.maxLogSize} bytes. Size: ${logEntrySize} bytes`,
|
|
302
|
+
`Log entry exceeds maximum size of ${String(this.maxLogSize)} bytes. Size: ${String(logEntrySize)} bytes`,
|
|
302
303
|
{ data: payloadTemplate.data, logLevel: logLevelString, message: messageString },
|
|
303
304
|
logEntrySize,
|
|
304
305
|
this.maxLogSize
|
|
@@ -330,17 +331,15 @@ class AbstractHttpReporter extends AbstractJsonReporter {
|
|
|
330
331
|
const payloadSizeWithEntry = this.currentBatchSize + logEntrySize + this.batchSendDelimiter.length;
|
|
331
332
|
const payloadSizeThreshold = this.maxPayloadSize * 0.9;
|
|
332
333
|
if (payloadSizeWithEntry > payloadSizeThreshold && this.batchQueue.length > 0) {
|
|
333
|
-
this.processBatch();
|
|
334
|
+
void this.processBatch();
|
|
334
335
|
}
|
|
335
336
|
this.batchQueue.push(payload);
|
|
336
337
|
this.currentBatchSize += logEntrySize + this.batchSendDelimiter.length;
|
|
337
|
-
|
|
338
|
-
this.
|
|
339
|
-
|
|
340
|
-
}, this.batchSendTimeout);
|
|
341
|
-
}
|
|
338
|
+
this.batchTimeout ??= setTimeout(() => {
|
|
339
|
+
void this.processBatch();
|
|
340
|
+
}, this.batchSendTimeout);
|
|
342
341
|
if (this.batchQueue.length >= this.batchSize) {
|
|
343
|
-
this.processBatch();
|
|
342
|
+
void this.processBatch();
|
|
344
343
|
}
|
|
345
344
|
}
|
|
346
345
|
/**
|
|
@@ -371,7 +370,7 @@ class AbstractHttpReporter extends AbstractJsonReporter {
|
|
|
371
370
|
} finally {
|
|
372
371
|
this.isProcessingBatch = false;
|
|
373
372
|
if (this.batchQueue.length > 0) {
|
|
374
|
-
this.processBatch();
|
|
373
|
+
void this.processBatch();
|
|
375
374
|
}
|
|
376
375
|
}
|
|
377
376
|
}
|
|
@@ -404,9 +403,7 @@ class AbstractHttpReporter extends AbstractJsonReporter {
|
|
|
404
403
|
*/
|
|
405
404
|
async sendPayload(payload, contentType) {
|
|
406
405
|
const headers = typeof this.headers === "function" ? this.headers() : { ...this.headers };
|
|
407
|
-
|
|
408
|
-
headers["content-type"] = contentType ?? this.contentType;
|
|
409
|
-
}
|
|
406
|
+
headers["content-type"] ??= contentType ?? this.contentType;
|
|
410
407
|
let finalPayload = payload;
|
|
411
408
|
if (this.compression && !this.edgeCompat) {
|
|
412
409
|
try {
|
|
@@ -414,7 +411,7 @@ class AbstractHttpReporter extends AbstractJsonReporter {
|
|
|
414
411
|
headers["content-encoding"] = "gzip";
|
|
415
412
|
} catch (error) {
|
|
416
413
|
if (this.onError) {
|
|
417
|
-
this.onError(new Error(`Compression failed: ${error}`));
|
|
414
|
+
this.onError(new Error(`Compression failed: ${String(error)}`));
|
|
418
415
|
}
|
|
419
416
|
}
|
|
420
417
|
}
|