@visulima/pail 3.1.0 → 3.2.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.
- package/CHANGELOG.md +59 -0
- package/LICENSE.md +3 -407
- package/README.md +298 -0
- package/dist/constants.d.ts +37 -0
- package/dist/index.browser.d.ts +47 -12
- package/dist/index.browser.js +12 -1
- package/dist/index.server.d.ts +65 -40
- package/dist/index.server.js +533 -2
- package/dist/interactive/index.d.ts +2 -28
- package/dist/interactive/index.js +2 -1
- package/dist/interactive/interactive-manager.d.ts +108 -0
- package/dist/interactive/interactive-stream-hook.d.ts +68 -0
- package/dist/object-tree.d.ts +65 -7
- package/dist/object-tree.js +89 -2
- package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
- package/dist/packem_shared/JsonReporter-C0AXk99i.js +58 -0
- package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
- package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
- package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
- package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
- package/dist/packem_shared/index-BomQ3E6J.js +650 -0
- package/dist/packem_shared/index-DqKWykfa.js +1146 -0
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
- package/dist/packem_shared/pail.browser-CPjQrsyy.js +1427 -0
- package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
- package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
- package/dist/pail.browser.d.ts +412 -0
- package/dist/pail.server.d.ts +233 -0
- package/dist/processor/caller/caller-processor.d.ts +40 -7
- package/dist/processor/caller/caller-processor.js +59 -1
- package/dist/processor/caller/get-caller-filename.d.ts +23 -0
- package/dist/processor/message-formatter-processor.d.ts +44 -9
- package/dist/processor/message-formatter-processor.js +67 -1
- package/dist/processor/opentelemetry-processor.d.ts +70 -0
- package/dist/processor/opentelemetry-processor.js +52 -0
- package/dist/processor/redact-processor.d.ts +39 -8
- package/dist/processor/redact-processor.js +30 -1
- package/dist/progress-bar.d.ts +75 -15
- package/dist/progress-bar.js +404 -1
- package/dist/reporter/file/json-file-reporter.d.ts +39 -20
- package/dist/reporter/file/json-file-reporter.js +136 -4
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +48 -0
- package/dist/reporter/http/abstract-http-reporter.d.ts +215 -0
- package/dist/reporter/http/abstract-http-reporter.js +435 -0
- package/dist/reporter/http/http-reporter.d.ts +39 -0
- package/dist/reporter/http/http-reporter.edge-light.d.ts +40 -0
- package/dist/reporter/http/http-reporter.edge-light.js +651 -0
- package/dist/reporter/http/http-reporter.js +13 -0
- package/dist/reporter/http/utils/compression.d.ts +7 -0
- package/dist/reporter/http/utils/log-size-error.d.ts +30 -0
- package/dist/reporter/http/utils/retry.d.ts +27 -0
- package/dist/reporter/json/abstract-json-reporter.d.ts +61 -0
- package/dist/reporter/json/index.browser.d.ts +3 -13
- package/dist/reporter/json/index.browser.js +2 -1
- package/dist/reporter/json/index.d.ts +3 -16
- package/dist/reporter/json/index.js +2 -1
- package/dist/reporter/json/json-reporter.browser.d.ts +40 -0
- package/dist/reporter/json/json-reporter.server.d.ts +50 -0
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +83 -0
- package/dist/reporter/pretty/index.browser.d.ts +2 -13
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +2 -25
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +36 -0
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +70 -0
- package/dist/reporter/raw/raw-reporter.browser.d.ts +5 -0
- package/dist/reporter/raw/raw-reporter.server.d.ts +13 -0
- package/dist/reporter/simple/simple-reporter.server.d.ts +10 -14
- package/dist/reporter/simple/simple-reporter.server.js +186 -8
- package/dist/reporter/utils/default-inspector-config.d.ts +3 -0
- package/dist/reporter/utils/format-label.d.ts +3 -0
- package/dist/spinner.d.ts +170 -104
- package/dist/spinner.js +2150 -1
- package/dist/types.d.ts +241 -0
- package/dist/utils/ansi-escapes.d.ts +4 -0
- package/dist/utils/arrayify.d.ts +2 -0
- package/dist/utils/get-longest-badge.d.ts +4 -0
- package/dist/utils/get-longest-label.d.ts +4 -0
- package/dist/utils/merge-types.d.ts +4 -0
- package/dist/utils/stream/safe-stream-handler.d.ts +21 -0
- package/dist/utils/write-console-log-based-on-level.d.ts +4 -0
- package/dist/utils/write-stream.d.ts +2 -0
- package/package.json +53 -4
- package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
- package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
- package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
- package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
- package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
- package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
- package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
- package/dist/packem_shared/abstract-json-reporter-CPsNkpz8.d.ts +0 -22
- package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-DB2G-qlI.d.ts +0 -28
- package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
- package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
- package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
- package/dist/packem_shared/index-CysYvHXs.js +0 -8
- package/dist/packem_shared/index-D9hWq9ka.js +0 -1
- package/dist/packem_shared/index.d-BR1GjZri.d.ts +0 -53
- package/dist/packem_shared/index.d-oxZvg_y7.d.ts +0 -20
- package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
- package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
- package/dist/packem_shared/pail.browser-CmWcqnn9.d.ts +0 -64
- package/dist/packem_shared/types-DVzG8TWL.d.ts +0 -95
- package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
- package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive Stream Hook.
|
|
3
|
+
*
|
|
4
|
+
* A utility class that hooks into Node.js WriteStreams to capture output
|
|
5
|
+
* for interactive terminal applications. It allows temporarily intercepting
|
|
6
|
+
* stream writes to enable features like progress bars and dynamic updates.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const hook = new InteractiveStreamHook(process.stdout);
|
|
10
|
+
* hook.active(); // Start capturing output
|
|
11
|
+
*
|
|
12
|
+
* // Output will be stored in history instead of being written to stdout
|
|
13
|
+
* console.log("This won't appear immediately");
|
|
14
|
+
*
|
|
15
|
+
* hook.inactive(); // Stop capturing and replay stored output
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare class InteractiveStreamHook {
|
|
19
|
+
#private;
|
|
20
|
+
/** Constant indicating the stream write operation was successful */
|
|
21
|
+
static readonly DRAIN = true;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new InteractiveStreamHook for the given stream.
|
|
24
|
+
* @param stream The Node.js WriteStream to hook into (usually stdout or stderr)
|
|
25
|
+
*/
|
|
26
|
+
constructor(stream: NodeJS.WriteStream);
|
|
27
|
+
/**
|
|
28
|
+
* Activates the stream hook.
|
|
29
|
+
*
|
|
30
|
+
* When active, all writes to the stream are captured in history instead of
|
|
31
|
+
* being written immediately. This allows for interactive features like
|
|
32
|
+
* progress bars that can update dynamically.
|
|
33
|
+
*/
|
|
34
|
+
active(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Erases the specified number of lines from the terminal.
|
|
37
|
+
*
|
|
38
|
+
* Uses ANSI escape sequences to remove lines from the current cursor position
|
|
39
|
+
* upwards, which is useful for clearing previous output in interactive applications.
|
|
40
|
+
* @param count Number of lines to erase (including the current line)
|
|
41
|
+
*/
|
|
42
|
+
erase(count: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Deactivates the stream hook and replays captured output.
|
|
45
|
+
*
|
|
46
|
+
* Restores normal stream operation and outputs all captured history.
|
|
47
|
+
* Optionally adds a newline separator before replaying the history.
|
|
48
|
+
* @param separateHistory Whether to add a newline before replaying history
|
|
49
|
+
*/
|
|
50
|
+
inactive(separateHistory?: boolean): void;
|
|
51
|
+
/**
|
|
52
|
+
* Renews the stream hook state.
|
|
53
|
+
*
|
|
54
|
+
* Restores the original stream write method and shows the cursor.
|
|
55
|
+
* This is typically called when temporarily suspending interactive mode.
|
|
56
|
+
*/
|
|
57
|
+
renew(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Writes a message directly to the underlying stream.
|
|
60
|
+
*
|
|
61
|
+
* Bypasses the hook mechanism and writes directly using the original
|
|
62
|
+
* stream write method. Useful for writing control sequences or
|
|
63
|
+
* messages that should not be captured in history.
|
|
64
|
+
* @param message The message to write to the stream
|
|
65
|
+
*/
|
|
66
|
+
write(message: string): void;
|
|
67
|
+
}
|
|
68
|
+
export default InteractiveStreamHook;
|
package/dist/object-tree.d.ts
CHANGED
|
@@ -1,17 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Function to render a node value for display
|
|
3
|
+
* @param node The node to render
|
|
4
|
+
* @returns A string representation or undefined if should not render
|
|
5
|
+
*/
|
|
6
|
+
export type TreeRenderFunction = (node: unknown) => string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Function to sort keys during tree traversal
|
|
9
|
+
* @param a First key for comparison
|
|
10
|
+
* @param b Second key for comparison
|
|
11
|
+
* @returns Negative if a < b, positive if a > b, 0 if equal
|
|
12
|
+
*/
|
|
13
|
+
export type TreeSortFunction = (a: string, b: string) => number;
|
|
14
|
+
/**
|
|
15
|
+
* Configuration options for object tree rendering
|
|
16
|
+
*/
|
|
17
|
+
export interface ObjectTreeOptions {
|
|
18
|
+
/** Text to display for circular references (default: " (circular ref.)") */
|
|
4
19
|
breakCircularWith?: string | null | undefined;
|
|
20
|
+
/** Whether to return as single string or array of lines (default: true) */
|
|
5
21
|
joined?: boolean;
|
|
22
|
+
/** Connector for neighbor keys (default: "├─ ") */
|
|
6
23
|
keyNeighbour?: string;
|
|
24
|
+
/** Connector for non-neighbor keys (default: "└─ ") */
|
|
7
25
|
keyNoNeighbour?: string;
|
|
26
|
+
/** Function to render node values (default: renders primitives) */
|
|
8
27
|
renderFn?: TreeRenderFunction;
|
|
28
|
+
/** Separator between key and value (default: ": ") */
|
|
9
29
|
separator?: string;
|
|
30
|
+
/** Function to sort object keys (default: natural order) */
|
|
10
31
|
sortFn?: TreeSortFunction | undefined;
|
|
32
|
+
/** Spacer for neighbor branches (default: "│ ") */
|
|
11
33
|
spacerNeighbour?: string;
|
|
34
|
+
/** Spacer for non-neighbor branches (default: " ") */
|
|
12
35
|
spacerNoNeighbour?: string;
|
|
13
36
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Renders an object as an ASCII tree structure.
|
|
39
|
+
* @param tree The object to render as a tree
|
|
40
|
+
* @param options Configuration options for tree rendering
|
|
41
|
+
* @returns Formatted tree as string or array of lines
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const obj = {
|
|
45
|
+
* name: "John",
|
|
46
|
+
* age: 30,
|
|
47
|
+
* address: {
|
|
48
|
+
* street: "Main St",
|
|
49
|
+
* city: "New York"
|
|
50
|
+
* }
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* // Default output as string
|
|
54
|
+
* console.log(renderObjectTree(obj));
|
|
55
|
+
*
|
|
56
|
+
* // Custom rendering
|
|
57
|
+
* console.log(renderObjectTree(obj, {
|
|
58
|
+
* sortFn: (a, b) => a.localeCompare(b),
|
|
59
|
+
* renderFn: (node) => {
|
|
60
|
+
* if (typeof node === 'string') return node.toUpperCase();
|
|
61
|
+
* return ['boolean', 'string', 'number'].includes(typeof node)
|
|
62
|
+
* ? String(node)
|
|
63
|
+
* : undefined;
|
|
64
|
+
* }
|
|
65
|
+
* }));
|
|
66
|
+
*
|
|
67
|
+
* // Get as array of lines
|
|
68
|
+
* const lines = renderObjectTree(obj, { joined: false });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare const renderObjectTree: (tree: Record<string, unknown> | unknown[], options?: ObjectTreeOptions) => string | string[];
|
|
72
|
+
/**
|
|
73
|
+
* Default export for CommonJS compatibility
|
|
74
|
+
*/
|
|
75
|
+
export default renderObjectTree;
|
package/dist/object-tree.js
CHANGED
|
@@ -1,2 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const buildContext = (options) => {
|
|
2
|
+
const context = {
|
|
3
|
+
breakCircularWith: " (circular ref.)",
|
|
4
|
+
joined: true,
|
|
5
|
+
keyNeighbour: "├─ ",
|
|
6
|
+
keyNoNeighbour: "└─ ",
|
|
7
|
+
renderFn: (node) => {
|
|
8
|
+
if (["boolean", "number", "string"].includes(typeof node)) {
|
|
9
|
+
return String(node);
|
|
10
|
+
}
|
|
11
|
+
return void 0;
|
|
12
|
+
},
|
|
13
|
+
separator: ": ",
|
|
14
|
+
sortFn: void 0,
|
|
15
|
+
spacerNeighbour: "│ ",
|
|
16
|
+
spacerNoNeighbour: " ",
|
|
17
|
+
...options
|
|
18
|
+
};
|
|
19
|
+
if (typeof context.joined !== "boolean") {
|
|
20
|
+
throw new TypeError('Option "joined" must be a boolean');
|
|
21
|
+
}
|
|
22
|
+
if (typeof context.spacerNoNeighbour !== "string") {
|
|
23
|
+
throw new TypeError('Option "spacerNoNeighbour" must be a string');
|
|
24
|
+
}
|
|
25
|
+
if (typeof context.spacerNeighbour !== "string") {
|
|
26
|
+
throw new TypeError('Option "spacerNeighbour" must be a string');
|
|
27
|
+
}
|
|
28
|
+
if (typeof context.keyNoNeighbour !== "string") {
|
|
29
|
+
throw new TypeError('Option "keyNoNeighbour" must be a string');
|
|
30
|
+
}
|
|
31
|
+
if (typeof context.keyNeighbour !== "string") {
|
|
32
|
+
throw new TypeError('Option "keyNeighbour" must be a string');
|
|
33
|
+
}
|
|
34
|
+
if (typeof context.separator !== "string") {
|
|
35
|
+
throw new TypeError('Option "separator" must be a string');
|
|
36
|
+
}
|
|
37
|
+
if (typeof context.renderFn !== "function") {
|
|
38
|
+
throw new TypeError('Option "renderFn" must be a function');
|
|
39
|
+
}
|
|
40
|
+
if (context.sortFn !== void 0 && typeof context.sortFn !== "function") {
|
|
41
|
+
throw new TypeError('Option "sortFn" must be a function or undefined');
|
|
42
|
+
}
|
|
43
|
+
if (context.breakCircularWith !== null && typeof context.breakCircularWith !== "string") {
|
|
44
|
+
throw new TypeError('Option "breakCircularWith" must be a string or null');
|
|
45
|
+
}
|
|
46
|
+
return context;
|
|
47
|
+
};
|
|
48
|
+
const renderObjectTree = (tree, options) => {
|
|
49
|
+
const context = buildContext(options);
|
|
50
|
+
const result = [];
|
|
51
|
+
const rootRendered = context.renderFn(tree);
|
|
52
|
+
if (rootRendered !== void 0) {
|
|
53
|
+
result.push(String(rootRendered));
|
|
54
|
+
}
|
|
55
|
+
const sort = (input) => {
|
|
56
|
+
if (context.sortFn === void 0) {
|
|
57
|
+
return input;
|
|
58
|
+
}
|
|
59
|
+
return input.toSorted((a, b) => context?.sortFn?.(b, a) ?? 0);
|
|
60
|
+
};
|
|
61
|
+
const neighbours = [];
|
|
62
|
+
const keys = sort(Object.keys(tree)).map((k) => [k]);
|
|
63
|
+
const lookup = [tree];
|
|
64
|
+
while (keys.length > 0) {
|
|
65
|
+
const key = keys.pop() ?? [];
|
|
66
|
+
const node = lookup[key.length - 1][key[key.length - 1] ?? ""];
|
|
67
|
+
const isCircular = context.breakCircularWith !== null && lookup.slice(0, key.length).includes(node);
|
|
68
|
+
neighbours[key.length - 1] = keys.length > 0 && (keys[keys.length - 1]?.length ?? 0) === key.length;
|
|
69
|
+
const indent = neighbours.slice(0, key.length - 1).map((n) => {
|
|
70
|
+
if (n) {
|
|
71
|
+
return context.spacerNeighbour;
|
|
72
|
+
}
|
|
73
|
+
return context.spacerNoNeighbour;
|
|
74
|
+
}).join("");
|
|
75
|
+
const connector = neighbours[key.length - 1] ? context.keyNeighbour : context.keyNoNeighbour;
|
|
76
|
+
const keyName = key[key.length - 1];
|
|
77
|
+
const nodeRendered = context.renderFn(node);
|
|
78
|
+
const value = nodeRendered === void 0 ? "" : `${context.separator}${nodeRendered}`;
|
|
79
|
+
const circular = isCircular ? context.breakCircularWith : "";
|
|
80
|
+
result.push(`${indent}${connector}${keyName}${value}${circular}`);
|
|
81
|
+
if (node !== null && typeof node === "object" && !Array.isArray(node) && !isCircular) {
|
|
82
|
+
keys.push(...sort(Object.keys(node)).map((k) => [...key, k]));
|
|
83
|
+
lookup[key.length] = node;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return context.joined === true ? result.join("\n") : result;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { renderObjectTree as default, renderObjectTree };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { E as EMPTY_SYMBOL } from './constants-DfDr4MHC.js';
|
|
2
|
+
|
|
3
|
+
function isPlainObject(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ErrorProto = Object.create(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
cause: {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
value: void 0,
|
|
17
|
+
writable: true
|
|
18
|
+
},
|
|
19
|
+
code: {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
value: void 0,
|
|
22
|
+
writable: true
|
|
23
|
+
},
|
|
24
|
+
errors: {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
value: void 0,
|
|
27
|
+
writable: true
|
|
28
|
+
},
|
|
29
|
+
message: {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
value: void 0,
|
|
32
|
+
writable: true
|
|
33
|
+
},
|
|
34
|
+
name: {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
value: void 0,
|
|
37
|
+
writable: true
|
|
38
|
+
},
|
|
39
|
+
stack: {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
value: void 0,
|
|
42
|
+
writable: true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
|
|
47
|
+
const toJSON = (from) => {
|
|
48
|
+
toJsonWasCalled.add(from);
|
|
49
|
+
const json = from.toJSON();
|
|
50
|
+
toJsonWasCalled.delete(from);
|
|
51
|
+
return json;
|
|
52
|
+
};
|
|
53
|
+
const serializeValue = (value, seen, depth, options) => {
|
|
54
|
+
if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
|
|
55
|
+
return "[object Buffer]";
|
|
56
|
+
}
|
|
57
|
+
if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
|
|
58
|
+
return "[object Stream]";
|
|
59
|
+
}
|
|
60
|
+
if (value instanceof Error) {
|
|
61
|
+
if (seen.includes(value)) {
|
|
62
|
+
return "[Circular]";
|
|
63
|
+
}
|
|
64
|
+
depth += 1;
|
|
65
|
+
return _serialize(value, options, seen, depth);
|
|
66
|
+
}
|
|
67
|
+
if (options.useToJSON && typeof value.toJSON === "function") {
|
|
68
|
+
return value.toJSON();
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "object" && value instanceof Date) {
|
|
71
|
+
return value.toISOString();
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === "function") {
|
|
74
|
+
return `[Function: ${value.name || "anonymous"}]`;
|
|
75
|
+
}
|
|
76
|
+
if (isPlainObject(value)) {
|
|
77
|
+
depth += 1;
|
|
78
|
+
if (options.maxDepth && depth >= options.maxDepth) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
const plainObject = {};
|
|
82
|
+
for (const key in value) {
|
|
83
|
+
plainObject[key] = serializeValue(value[key], seen, depth, options);
|
|
84
|
+
}
|
|
85
|
+
return plainObject;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return value;
|
|
89
|
+
} catch {
|
|
90
|
+
return "[Not Available]";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const _serialize = (error, options, seen, depth) => {
|
|
94
|
+
seen.push(error);
|
|
95
|
+
if (options.maxDepth === 0) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
|
|
99
|
+
return toJSON(error);
|
|
100
|
+
}
|
|
101
|
+
const protoError = Object.create(ErrorProto);
|
|
102
|
+
protoError.name = Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name;
|
|
103
|
+
protoError.message = error.message;
|
|
104
|
+
protoError.stack = error.stack;
|
|
105
|
+
if (Array.isArray(error.errors)) {
|
|
106
|
+
const aggregateErrors = [];
|
|
107
|
+
for (const aggregateError of error.errors) {
|
|
108
|
+
if (!(aggregateError instanceof Error)) {
|
|
109
|
+
throw new TypeError("All errors in the 'errors' property must be instances of Error");
|
|
110
|
+
}
|
|
111
|
+
if (seen.includes(aggregateError)) {
|
|
112
|
+
protoError.errors = [];
|
|
113
|
+
return protoError;
|
|
114
|
+
}
|
|
115
|
+
aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
|
|
116
|
+
}
|
|
117
|
+
protoError.errors = aggregateErrors;
|
|
118
|
+
}
|
|
119
|
+
if (error.cause instanceof Error && !seen.includes(error.cause)) {
|
|
120
|
+
protoError.cause = _serialize(error.cause, options, seen, depth);
|
|
121
|
+
}
|
|
122
|
+
for (const key in error) {
|
|
123
|
+
if (protoError[key] === void 0) {
|
|
124
|
+
const value = error[key];
|
|
125
|
+
protoError[key] = serializeValue(value, seen, depth, options);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(options.exclude) && options.exclude.length > 0) {
|
|
129
|
+
for (const key of options.exclude) {
|
|
130
|
+
try {
|
|
131
|
+
delete protoError[key];
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return protoError;
|
|
137
|
+
};
|
|
138
|
+
const serialize = (error, options = {}) => _serialize(
|
|
139
|
+
error,
|
|
140
|
+
{
|
|
141
|
+
exclude: options.exclude ?? [],
|
|
142
|
+
maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
|
|
143
|
+
useToJSON: options.useToJSON ?? false
|
|
144
|
+
},
|
|
145
|
+
[],
|
|
146
|
+
0
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
class AbstractJsonReporter {
|
|
150
|
+
/** Custom stringify function for object serialization */
|
|
151
|
+
stringify;
|
|
152
|
+
/** Error serialization options */
|
|
153
|
+
errorOptions;
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new AbstractJsonReporter instance.
|
|
156
|
+
* @param options Configuration options for JSON formatting and error handling
|
|
157
|
+
*/
|
|
158
|
+
constructor(options = {}) {
|
|
159
|
+
this.errorOptions = options.error ?? {};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets a custom stringify function for object serialization.
|
|
163
|
+
* @param function_ The stringify function to use for serialization
|
|
164
|
+
*/
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
166
|
+
setStringify(function_) {
|
|
167
|
+
this.stringify = function_;
|
|
168
|
+
}
|
|
169
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
170
|
+
log(meta) {
|
|
171
|
+
const { context, error, file, message, type, ...rest } = meta;
|
|
172
|
+
if (rest.label) {
|
|
173
|
+
rest.label = rest.label.trim();
|
|
174
|
+
}
|
|
175
|
+
if (file) {
|
|
176
|
+
rest.file = `${file.name}:${file.line}${file.column ? `:${file.column}` : ""}`;
|
|
177
|
+
}
|
|
178
|
+
if (message === EMPTY_SYMBOL) {
|
|
179
|
+
rest.message = void 0;
|
|
180
|
+
} else {
|
|
181
|
+
rest.message = message;
|
|
182
|
+
}
|
|
183
|
+
if (error) {
|
|
184
|
+
rest.error = serialize(error, this.errorOptions);
|
|
185
|
+
}
|
|
186
|
+
if (context) {
|
|
187
|
+
const newContext = [];
|
|
188
|
+
for (const item of context) {
|
|
189
|
+
if (item === EMPTY_SYMBOL) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (item instanceof Error) {
|
|
193
|
+
newContext.push(serialize(item, this.errorOptions));
|
|
194
|
+
} else {
|
|
195
|
+
newContext.push(item);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
rest.context = newContext;
|
|
199
|
+
}
|
|
200
|
+
this._log(this.stringify(rest), type.level);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { AbstractJsonReporter };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { t as terminalSize, w as wordWrap, W as WrapMode } from './index-DqKWykfa.js';
|
|
2
|
+
|
|
3
|
+
class InteractiveManager {
|
|
4
|
+
#stream;
|
|
5
|
+
#isActive = false;
|
|
6
|
+
#isSuspended = false;
|
|
7
|
+
#lastLength = 0;
|
|
8
|
+
#outside = 0;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new InteractiveManager with the given stream hooks.
|
|
11
|
+
* @param stdout Hook for stdout stream
|
|
12
|
+
* @param stderr Hook for stderr stream
|
|
13
|
+
*/
|
|
14
|
+
constructor(stdout, stderr) {
|
|
15
|
+
this.#stream = {
|
|
16
|
+
stderr,
|
|
17
|
+
stdout
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Last printed rows count.
|
|
22
|
+
*
|
|
23
|
+
* Tracks the number of rows that were last written to the terminal.
|
|
24
|
+
* Used internally for managing cursor positioning and output updates.
|
|
25
|
+
*/
|
|
26
|
+
get lastLength() {
|
|
27
|
+
return this.#lastLength;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Rows count outside editable area.
|
|
31
|
+
*
|
|
32
|
+
* Tracks the number of rows that extend beyond the current terminal height.
|
|
33
|
+
* Used for managing scrolling and ensuring all output remains visible.
|
|
34
|
+
*/
|
|
35
|
+
get outside() {
|
|
36
|
+
return this.#outside;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook activity status.
|
|
40
|
+
*
|
|
41
|
+
* Indicates whether the interactive hooks are currently active.
|
|
42
|
+
* When true, streams are being intercepted for interactive output.
|
|
43
|
+
*/
|
|
44
|
+
get isHooked() {
|
|
45
|
+
return this.#isActive;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Suspend status for active hooks.
|
|
49
|
+
*
|
|
50
|
+
* Indicates whether interactive mode is temporarily suspended.
|
|
51
|
+
* When suspended, external output can be written without interference.
|
|
52
|
+
*/
|
|
53
|
+
get isSuspended() {
|
|
54
|
+
return this.#isSuspended;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Removes lines from the terminal output.
|
|
58
|
+
*
|
|
59
|
+
* Erases the specified number of lines from the bottom of the output,
|
|
60
|
+
* moving the cursor up and clearing the lines. Useful for removing
|
|
61
|
+
* previous interactive output before displaying new content.
|
|
62
|
+
* @param stream The stream to erase lines from ("stdout" or "stderr")
|
|
63
|
+
* @param count Number of lines to remove (defaults to lastLength)
|
|
64
|
+
* @throws {TypeError} If the specified stream is not available
|
|
65
|
+
*/
|
|
66
|
+
erase(stream, count = this.#lastLength) {
|
|
67
|
+
if (this.#stream[stream] === void 0) {
|
|
68
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
69
|
+
}
|
|
70
|
+
this.#stream[stream].erase(count);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Hook stdout and stderr streams.
|
|
74
|
+
* @returns Success status
|
|
75
|
+
*/
|
|
76
|
+
hook() {
|
|
77
|
+
if (!this.#isActive) {
|
|
78
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
79
|
+
this.#clear(true);
|
|
80
|
+
}
|
|
81
|
+
return this.#isActive;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resume suspend hooks.
|
|
85
|
+
* @param stream Stream to resume
|
|
86
|
+
* @param eraseRowCount erase output rows count
|
|
87
|
+
*/
|
|
88
|
+
resume(stream, eraseRowCount) {
|
|
89
|
+
if (this.#isSuspended) {
|
|
90
|
+
this.#isSuspended = false;
|
|
91
|
+
if (eraseRowCount) {
|
|
92
|
+
this.erase(stream, eraseRowCount);
|
|
93
|
+
}
|
|
94
|
+
this.#lastLength = 0;
|
|
95
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Suspend active hooks for external output.
|
|
100
|
+
* @param stream Stream to suspend
|
|
101
|
+
* @param erase erase output
|
|
102
|
+
*/
|
|
103
|
+
suspend(stream, erase = true) {
|
|
104
|
+
if (!this.#isSuspended) {
|
|
105
|
+
this.#isSuspended = true;
|
|
106
|
+
if (erase) {
|
|
107
|
+
this.erase(stream);
|
|
108
|
+
}
|
|
109
|
+
Object.values(this.#stream).forEach((hook) => hook.renew());
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Unhooks both stdout and stderr streams and print their story of logs.
|
|
114
|
+
* @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
|
|
115
|
+
* @returns Success status
|
|
116
|
+
*/
|
|
117
|
+
unhook(separateHistory = true) {
|
|
118
|
+
if (this.#isActive) {
|
|
119
|
+
Object.values(this.#stream).forEach((hook) => hook.inactive(separateHistory));
|
|
120
|
+
this.#clear();
|
|
121
|
+
}
|
|
122
|
+
return !this.#isActive;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Update output.
|
|
126
|
+
* @param stream Stream to write to
|
|
127
|
+
* @param rows Text lines to write to standard output
|
|
128
|
+
* @param from Index of the line starting from which the contents of the terminal are being overwritten
|
|
129
|
+
*/
|
|
130
|
+
update(stream, rows, from = 0) {
|
|
131
|
+
if (rows.length > 0) {
|
|
132
|
+
if (this.#stream[stream] === void 0) {
|
|
133
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
134
|
+
}
|
|
135
|
+
const hook = this.#stream[stream];
|
|
136
|
+
const { columns: width, rows: height } = terminalSize();
|
|
137
|
+
const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));
|
|
138
|
+
const actualLength = this.lastLength - position;
|
|
139
|
+
const outside = Math.max(actualLength - height, this.outside);
|
|
140
|
+
let output = rows.reduce(
|
|
141
|
+
(accumulator, row) => [
|
|
142
|
+
...accumulator,
|
|
143
|
+
wordWrap(row, {
|
|
144
|
+
trim: false,
|
|
145
|
+
width,
|
|
146
|
+
wrapMode: WrapMode.STRICT_WIDTH
|
|
147
|
+
})
|
|
148
|
+
],
|
|
149
|
+
[]
|
|
150
|
+
);
|
|
151
|
+
if (height <= actualLength) {
|
|
152
|
+
hook.erase(height);
|
|
153
|
+
if (position < outside) {
|
|
154
|
+
output = output.slice(outside - position + 1);
|
|
155
|
+
}
|
|
156
|
+
} else if (actualLength) {
|
|
157
|
+
hook.erase(actualLength);
|
|
158
|
+
}
|
|
159
|
+
hook.write(`${output.join("\n")}
|
|
160
|
+
`);
|
|
161
|
+
this.#lastLength = outside ? outside + output.length + 1 : output.length;
|
|
162
|
+
this.#outside = Math.max(this.lastLength - height, this.outside);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
#clear(status = false) {
|
|
166
|
+
this.#isActive = status;
|
|
167
|
+
this.#lastLength = 0;
|
|
168
|
+
this.#outside = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { InteractiveManager as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export { I as default } from './interactive-stream-hook-DG4BtN12.js';
|