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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE.md +143 -931
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +2 -2
  6. package/dist/index.server.d.ts +722 -65
  7. package/dist/index.server.js +27 -410
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/elysia.js +2 -2
  10. package/dist/middleware/express.d.ts +73 -71
  11. package/dist/middleware/express.js +1 -1
  12. package/dist/middleware/fastify.d.ts +69 -67
  13. package/dist/middleware/fastify.js +2 -2
  14. package/dist/middleware/hono.d.ts +74 -72
  15. package/dist/middleware/next/handler.d.ts +101 -34
  16. package/dist/middleware/sveltekit.d.ts +100 -98
  17. package/dist/object-tree.d.ts +67 -70
  18. package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
  19. package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
  20. package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
  21. package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
  22. package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-CIbrmjUV.js} +2 -4
  23. package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-CNJEO9g7.js} +1250 -15
  24. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  25. package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CkqCt5hg.js} +2300 -2298
  26. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  27. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  28. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  29. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  30. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  31. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  32. package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
  33. package/dist/processor/caller/caller-processor.d.ts +49 -47
  34. package/dist/processor/caller/caller-processor.js +1 -1
  35. package/dist/processor/environment-processor.d.ts +113 -113
  36. package/dist/processor/message-formatter-processor.d.ts +51 -49
  37. package/dist/processor/message-formatter-processor.js +2 -2
  38. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  39. package/dist/processor/redact-processor.d.ts +60 -41
  40. package/dist/processor/sampling-processor.d.ts +102 -101
  41. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  42. package/dist/reporter/file/json-file-reporter.js +1 -1
  43. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  44. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  45. package/dist/reporter/http/http-reporter.d.ts +40 -36
  46. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  47. package/dist/reporter/http/http-reporter.edge-light.js +1 -5
  48. package/dist/reporter/json/index.browser.d.ts +99 -3
  49. package/dist/reporter/json/index.browser.js +2 -2
  50. package/dist/reporter/json/index.d.ts +51 -3
  51. package/dist/reporter/json/index.js +2 -2
  52. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +219 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  57. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  58. package/dist/wide-event.d.ts +5 -300
  59. package/dist/wide-event.js +3 -2
  60. package/package.json +9 -21
  61. package/dist/constants.d.ts +0 -37
  62. package/dist/interactive/index.d.ts +0 -2
  63. package/dist/interactive/index.js +0 -2
  64. package/dist/interactive/interactive-manager.d.ts +0 -108
  65. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  66. package/dist/middleware/next/middleware.d.ts +0 -59
  67. package/dist/middleware/next/storage.d.ts +0 -14
  68. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  69. package/dist/middleware/shared/headers.d.ts +0 -14
  70. package/dist/middleware/shared/routes.d.ts +0 -30
  71. package/dist/middleware/shared/storage.d.ts +0 -29
  72. package/dist/packem_shared/InteractiveManager-CowYA3Hx.js +0 -178
  73. package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
  74. package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
  75. package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
  76. package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
  77. package/dist/pail.browser.d.ts +0 -412
  78. package/dist/pail.server.d.ts +0 -233
  79. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  80. package/dist/progress-bar.d.ts +0 -145
  81. package/dist/progress-bar.js +0 -459
  82. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  83. package/dist/reporter/http/utils/compression.d.ts +0 -7
  84. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  85. package/dist/reporter/http/utils/retry.d.ts +0 -27
  86. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  87. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  88. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  89. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  90. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  91. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  92. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  93. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  94. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  95. package/dist/reporter/utils/format-label.d.ts +0 -3
  96. package/dist/spinner.d.ts +0 -220
  97. package/dist/spinner.js +0 -2183
  98. package/dist/types.d.ts +0 -241
  99. package/dist/utils/ansi-escapes.d.ts +0 -4
  100. package/dist/utils/arrayify.d.ts +0 -2
  101. package/dist/utils/get-longest-badge.d.ts +0 -4
  102. package/dist/utils/get-longest-label.d.ts +0 -4
  103. package/dist/utils/merge-types.d.ts +0 -4
  104. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  105. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  106. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,14 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- import type { WideEvent } from "../../wide-event.d.ts";
3
- /**
4
- * AsyncLocalStorage instance used to propagate the WideEvent logger
5
- * through Next.js server actions, route handlers, and server components.
6
- */
7
- export declare const pailStorage: AsyncLocalStorage<WideEvent>;
8
- /**
9
- * Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
10
- * Must be called within a `withPail()` wrapped handler or server action.
11
- * @returns The request-scoped WideEvent logger
12
- * @throws Error if called outside of a withPail context
13
- */
14
- export declare const useLogger: () => WideEvent;
@@ -1,82 +0,0 @@
1
- import type { PailBrowserImpl } from "../../pail.d.ts";
2
- import type { DefaultLogTypes, LoggerFunction } from "../../types.d.ts";
3
- import type { WideEventFinishOptions } from "../../wide-event.d.ts";
4
- import { WideEvent } from "../../wide-event.d.ts";
5
- import type { RouteConfig } from "./routes.d.ts";
6
- /**
7
- * A pail instance with dynamically generated log methods.
8
- */
9
- type PailLike<T extends string = string> = PailBrowserImpl<T> & Record<DefaultLogTypes | T, LoggerFunction>;
10
- /**
11
- * Base options shared by all framework middleware adapters.
12
- * @template T - Custom logger type names from the pail instance
13
- */
14
- export interface PailMiddlewareOptions<T extends string = string> {
15
- /**
16
- * Glob patterns for paths to exclude from logging.
17
- * Exclusions take precedence over inclusions.
18
- * @example ["/health", "/api/_internal/**"]
19
- */
20
- exclude?: string[];
21
- /**
22
- * Glob patterns for paths to include in logging.
23
- * If not set, all non-excluded paths are logged.
24
- * @example ["/api/**"]
25
- */
26
- include?: string[];
27
- /**
28
- * The pail logger instance to use for wide event emission.
29
- */
30
- pail: PailLike<T>;
31
- /**
32
- * Route-specific configuration. Maps glob patterns to config.
33
- * First matching route wins.
34
- * @example { "/api/auth/**": { service: "auth-service" } }
35
- */
36
- routes?: Record<string, RouteConfig>;
37
- /**
38
- * Default service name for all wide events.
39
- * Can be overridden per-route via `routes`.
40
- */
41
- service?: string;
42
- }
43
- /**
44
- * Result of creating a middleware logger for a request.
45
- */
46
- export interface MiddlewareLoggerResult {
47
- /**
48
- * Finalize and emit the wide event. Sets status/error before emitting.
49
- * Safe to call multiple times — only the first call emits.
50
- */
51
- finish: (options?: WideEventFinishOptions) => void;
52
- /**
53
- * The request-scoped WideEvent logger.
54
- * Use `set()`, `info()`, `warn()`, `error()`, `debug()` to accumulate context.
55
- */
56
- logger: WideEvent;
57
- /**
58
- * Whether this request was skipped (excluded from logging).
59
- * When true, `logger` and `finish` should not be used.
60
- */
61
- skipped: boolean;
62
- }
63
- /**
64
- * Core factory function used by all framework middleware adapters.
65
- *
66
- * Creates a WideEvent for the given request, checks route inclusion/exclusion,
67
- * resolves the service name, and returns a logger + finish callback.
68
- * @param options Middleware options including pail instance and route config
69
- * @param request Request metadata for the current HTTP request
70
- * @param request.headers Safe headers extracted from the request
71
- * @param request.method The HTTP method (GET, POST, etc.)
72
- * @param request.path The URL path of the request
73
- * @param request.requestId A unique identifier for this request
74
- * @returns A result object with logger, finish callback, and skipped flag
75
- */
76
- export declare const createMiddlewareLogger: <T extends string = string>(options: PailMiddlewareOptions<T>, request: {
77
- headers?: Record<string, string>;
78
- method: string;
79
- path: string;
80
- requestId: string;
81
- }) => MiddlewareLoggerResult;
82
- export {};
@@ -1,14 +0,0 @@
1
- /**
2
- * Extract safe headers from a Web API Headers object, filtering out
3
- * sensitive headers like Authorization, Cookie, and API keys.
4
- * @param headers Web API Headers object
5
- * @returns Plain object of safe header key-value pairs
6
- */
7
- export declare const extractSafeHeaders: (headers: Headers) => Record<string, string>;
8
- /**
9
- * Extract safe headers from a Node.js IncomingHttpHeaders object,
10
- * filtering out sensitive headers.
11
- * @param headers Node.js IncomingHttpHeaders-like object
12
- * @returns Plain object of safe header key-value pairs
13
- */
14
- export declare const extractSafeNodeHeaders: (headers: Record<string, string | string[] | undefined>) => Record<string, string>;
@@ -1,30 +0,0 @@
1
- /**
2
- * Check if a path matches a glob pattern.
3
- */
4
- export declare const matchesPattern: (path: string, pattern: string) => boolean;
5
- /**
6
- * Route configuration for a specific path pattern.
7
- */
8
- export interface RouteConfig {
9
- /** Override the service name for requests matching this route. */
10
- service?: string;
11
- }
12
- /**
13
- * Determine whether a request path should be logged based on include/exclude patterns.
14
- *
15
- * - Exclusions take precedence over inclusions.
16
- * - If no include patterns are provided, all non-excluded paths are logged.
17
- * @param path The request path
18
- * @param include Glob patterns of paths to include
19
- * @param exclude Glob patterns of paths to exclude
20
- * @returns Whether the path should be logged
21
- */
22
- export declare const shouldLog: (path: string, include?: string[], exclude?: string[]) => boolean;
23
- /**
24
- * Get the service name override for a given path based on route configuration.
25
- * Returns the first matching route's service name, or undefined if no match.
26
- * @param path The request path
27
- * @param routes Route configuration map (pattern → config)
28
- * @returns The service name override, or undefined
29
- */
30
- export declare const getServiceForPath: (path: string, routes?: Record<string, RouteConfig>) => string | undefined;
@@ -1,29 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- import type { WideEvent } from "../../wide-event.d.ts";
3
- /**
4
- * Create an isolated AsyncLocalStorage instance and a `useLogger` accessor
5
- * for retrieving the request-scoped WideEvent from anywhere in the call stack.
6
- *
7
- * Each framework adapter should call this once at module level to get its own
8
- * isolated storage instance.
9
- * @param contextHint A description of the expected context, used in the
10
- * error message when `useLogger` is called outside of a request scope.
11
- * @returns An object with `storage` and `useLogger`
12
- * @example
13
- * ```typescript
14
- * const { storage, useLogger } = createLoggerStorage(
15
- * "Express middleware context. Make sure evlog middleware is registered."
16
- * );
17
- *
18
- * // In middleware:
19
- * storage.run(wideEvent, () => next());
20
- *
21
- * // In handler:
22
- * const log = useLogger();
23
- * log.set({ user: { id: 1 } });
24
- * ```
25
- */
26
- export declare const createLoggerStorage: (contextHint: string) => {
27
- storage: AsyncLocalStorage<WideEvent>;
28
- useLogger: () => WideEvent;
29
- };
@@ -1,178 +0,0 @@
1
- import { t as terminalSize, w as wordWrap, W as WrapMode } from './index-BEfVUy9P.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
- this.#stream[stream].erase(count);
68
- }
69
- /**
70
- * Hook stdout and stderr streams.
71
- * @returns Success status
72
- */
73
- hook() {
74
- if (!this.#isActive) {
75
- const hooks = Object.values(this.#stream);
76
- for (let i = 0; i < hooks.length; i += 1) {
77
- hooks[i].active();
78
- }
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
- const hooks = Object.values(this.#stream);
96
- for (let i = 0; i < hooks.length; i += 1) {
97
- hooks[i].active();
98
- }
99
- }
100
- }
101
- /**
102
- * Suspend active hooks for external output.
103
- * @param stream Stream to suspend
104
- * @param erase erase output
105
- */
106
- suspend(stream, erase = true) {
107
- if (!this.#isSuspended) {
108
- this.#isSuspended = true;
109
- if (erase) {
110
- this.erase(stream);
111
- }
112
- const hooks = Object.values(this.#stream);
113
- for (let i = 0; i < hooks.length; i += 1) {
114
- hooks[i].renew();
115
- }
116
- }
117
- }
118
- /**
119
- * Unhooks both stdout and stderr streams and print their story of logs.
120
- * @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
121
- * @returns Success status
122
- */
123
- unhook(separateHistory = true) {
124
- if (this.#isActive) {
125
- const hooks = Object.values(this.#stream);
126
- for (let i = 0; i < hooks.length; i += 1) {
127
- hooks[i].inactive(separateHistory);
128
- }
129
- this.#clear();
130
- }
131
- return !this.#isActive;
132
- }
133
- /**
134
- * Update output.
135
- * @param stream Stream to write to
136
- * @param rows Text lines to write to standard output
137
- * @param from Index of the line starting from which the contents of the terminal are being overwritten
138
- */
139
- update(stream, rows, from = 0) {
140
- if (rows.length > 0) {
141
- const hook = this.#stream[stream];
142
- const { columns: width, rows: height } = terminalSize();
143
- const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));
144
- const actualLength = this.lastLength - position;
145
- const outside = Math.max(actualLength - height, this.outside);
146
- let output = rows.reduce(
147
- (accumulator, row) => [
148
- ...accumulator,
149
- wordWrap(row, {
150
- trim: false,
151
- width,
152
- wrapMode: WrapMode.STRICT_WIDTH
153
- })
154
- ],
155
- []
156
- );
157
- if (height <= actualLength) {
158
- hook.erase(height);
159
- if (position < outside) {
160
- output = output.slice(outside - position + 1);
161
- }
162
- } else if (actualLength) {
163
- hook.erase(actualLength);
164
- }
165
- hook.write(`${output.join("\n")}
166
- `);
167
- this.#lastLength = outside ? outside + output.length + 1 : output.length;
168
- this.#outside = Math.max(this.lastLength - height, this.outside);
169
- }
170
- }
171
- #clear(status = false) {
172
- this.#isActive = status;
173
- this.#lastLength = 0;
174
- this.#outside = 0;
175
- }
176
- }
177
-
178
- export { InteractiveManager as default };
@@ -1,133 +0,0 @@
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
- const {
21
- StringDecoder
22
- } = __cjs_getBuiltinModule("node:string_decoder");
23
-
24
- const ESC = "\x1B[";
25
- const eraseLine = `${ESC}2K`;
26
- const cursorLeft = `${ESC}G`;
27
- const cursorUp = (count = 1) => `${ESC}${String(count)}A`;
28
- const cursorHide = `${ESC}?25l`;
29
- const cursorShow = `${ESC}?25h`;
30
- const eraseLines = (count) => {
31
- let clear = "";
32
- for (let index = 0; index < count; index++) {
33
- clear += eraseLine + (index < count - 1 ? cursorUp() : "");
34
- }
35
- if (count) {
36
- clear += cursorLeft;
37
- }
38
- return clear;
39
- };
40
-
41
- class InteractiveStreamHook {
42
- /** Constant indicating the stream write operation was successful */
43
- static DRAIN = true;
44
- #decoder = new StringDecoder();
45
- #history = [];
46
- #method;
47
- #stream;
48
- /**
49
- * Creates a new InteractiveStreamHook for the given stream.
50
- * @param stream The Node.js WriteStream to hook into (usually stdout or stderr)
51
- */
52
- constructor(stream) {
53
- this.#method = stream.write.bind(stream);
54
- this.#stream = stream;
55
- }
56
- /**
57
- * Activates the stream hook.
58
- *
59
- * When active, all writes to the stream are captured in history instead of
60
- * being written immediately. This allows for interactive features like
61
- * progress bars that can update dynamically.
62
- */
63
- active() {
64
- this.write(cursorHide);
65
- this.#stream.write = (data, ...arguments_) => {
66
- const callback = arguments_.at(-1);
67
- this.#history.push(
68
- // prettier-ignore
69
- this.#decoder.write(
70
- typeof data === "string" ? Buffer.from(data, typeof arguments_[0] === "string" ? arguments_[0] : void 0) : Buffer.from(data)
71
- )
72
- );
73
- if (typeof callback === "function") {
74
- callback();
75
- }
76
- return InteractiveStreamHook.DRAIN;
77
- };
78
- }
79
- /**
80
- * Erases the specified number of lines from the terminal.
81
- *
82
- * Uses ANSI escape sequences to remove lines from the current cursor position
83
- * upwards, which is useful for clearing previous output in interactive applications.
84
- * @param count Number of lines to erase (including the current line)
85
- */
86
- erase(count) {
87
- if (count > 0) {
88
- this.write(eraseLines(count + 1));
89
- }
90
- }
91
- /**
92
- * Deactivates the stream hook and replays captured output.
93
- *
94
- * Restores normal stream operation and outputs all captured history.
95
- * Optionally adds a newline separator before replaying the history.
96
- * @param separateHistory Whether to add a newline before replaying history
97
- */
98
- inactive(separateHistory = false) {
99
- if (this.#history.length > 0) {
100
- if (separateHistory) {
101
- this.write("\n");
102
- }
103
- this.#history.forEach((element) => {
104
- this.write(element);
105
- });
106
- this.#history = [];
107
- }
108
- this.renew();
109
- }
110
- /**
111
- * Renews the stream hook state.
112
- *
113
- * Restores the original stream write method and shows the cursor.
114
- * This is typically called when temporarily suspending interactive mode.
115
- */
116
- renew() {
117
- this.#stream.write = this.#method;
118
- this.write(cursorShow);
119
- }
120
- /**
121
- * Writes a message directly to the underlying stream.
122
- *
123
- * Bypasses the hook mechanism and writes directly using the original
124
- * stream write method. Useful for writing control sequences or
125
- * messages that should not be captured in history.
126
- * @param message The message to write to the stream
127
- */
128
- write(message) {
129
- this.#method.apply(this.#stream, [message]);
130
- }
131
- }
132
-
133
- export { InteractiveStreamHook as default };