@loglayer/transport-pretty-terminal 1.0.0

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.
@@ -0,0 +1,288 @@
1
+ import { LoggerlessTransportConfig, LoggerlessTransport, LogLayerTransportParams } from '@loglayer/transport';
2
+ import { ChalkInstance } from 'chalk';
3
+ import * as chalk from 'chalk';
4
+ export { chalk };
5
+
6
+ /**
7
+ * Represents a single log entry in the storage system.
8
+ * Each entry contains metadata and the actual log content.
9
+ */
10
+ interface LogEntry {
11
+ /** Unique identifier for the log entry */
12
+ id: string;
13
+ /** Unix timestamp in milliseconds when the log was created */
14
+ timestamp: number;
15
+ /** Log level (trace, debug, info, warn, error, fatal) */
16
+ level: string;
17
+ /** Main log message content */
18
+ message: string;
19
+ /** Optional structured data associated with the log, stored as JSON string */
20
+ data: string | null;
21
+ }
22
+ /**
23
+ * Configuration for log level colors.
24
+ * Each log level can have its own chalk styling.
25
+ */
26
+ interface ColorConfig {
27
+ /** Style for trace level logs - lowest severity */
28
+ trace?: ChalkInstance;
29
+ /** Style for debug level logs */
30
+ debug?: ChalkInstance;
31
+ /** Style for info level logs - normal operation */
32
+ info?: ChalkInstance;
33
+ /** Style for warning level logs */
34
+ warn?: ChalkInstance;
35
+ /** Style for error level logs */
36
+ error?: ChalkInstance;
37
+ /** Style for fatal level logs - highest severity */
38
+ fatal?: ChalkInstance;
39
+ }
40
+ /**
41
+ * Base configuration for log view styling.
42
+ * Defines colors and styles for different log elements.
43
+ */
44
+ interface ViewConfig {
45
+ /** Color configuration for different log levels */
46
+ colors?: ColorConfig;
47
+ /** Style for log entry IDs */
48
+ logIdColor?: ChalkInstance;
49
+ /** Style for data values in structured data */
50
+ dataValueColor?: ChalkInstance;
51
+ /** Style for data keys in structured data */
52
+ dataKeyColor?: ChalkInstance;
53
+ /** Style for selection indicators in interactive mode */
54
+ selectorColor?: ChalkInstance;
55
+ }
56
+ /**
57
+ * Extended view configuration for detailed/interactive mode.
58
+ * Includes additional styling options for the detailed view UI.
59
+ */
60
+ interface DetailedViewConfig extends ViewConfig {
61
+ /** Style for section headers in detailed view */
62
+ headerColor?: ChalkInstance;
63
+ /** Style for field labels in detailed view */
64
+ labelColor?: ChalkInstance;
65
+ /** Style for visual separators between sections */
66
+ separatorColor?: ChalkInstance;
67
+ /** Configuration for JSON data formatting colors */
68
+ jsonColors?: {
69
+ /** Style for object property names */
70
+ keysColor?: ChalkInstance;
71
+ /** Style for array bullets */
72
+ dashColor?: ChalkInstance;
73
+ /** Default style for numbers */
74
+ numberColor?: ChalkInstance;
75
+ /** Style for single-line strings */
76
+ stringColor?: ChalkInstance;
77
+ /** Style for multi-line strings */
78
+ multilineStringColor?: ChalkInstance;
79
+ /** Style for positive numbers */
80
+ positiveNumberColor?: ChalkInstance;
81
+ /** Style for negative numbers */
82
+ negativeNumberColor?: ChalkInstance;
83
+ /** Style for boolean values */
84
+ booleanColor?: ChalkInstance;
85
+ /** Style for null and undefined values */
86
+ nullUndefinedColor?: ChalkInstance;
87
+ /** Style for date objects */
88
+ dateColor?: ChalkInstance;
89
+ };
90
+ }
91
+ /**
92
+ * Theme configuration for the pretty terminal transport.
93
+ * Defines styling for both simple and detailed view modes.
94
+ */
95
+ interface PrettyTerminalTheme {
96
+ /** Styling configuration for real-time log output mode */
97
+ simpleView: ViewConfig;
98
+ /** Styling configuration for interactive/detailed view mode */
99
+ detailedView: DetailedViewConfig;
100
+ }
101
+ /**
102
+ * Main configuration interface for PrettyTerminalTransport.
103
+ * Extends the base transport configuration with pretty terminal specific options.
104
+ */
105
+ interface PrettyTerminalConfig extends LoggerlessTransportConfig {
106
+ /** Maximum depth for inline data display before collapsing */
107
+ maxInlineDepth?: number;
108
+ /** Maximum length for inline data display before truncating */
109
+ maxInlineLength?: number;
110
+ /** Custom theme configuration for log display */
111
+ theme?: PrettyTerminalTheme;
112
+ /** Path to SQLite file for persistent storage. If not provided, uses in-memory database */
113
+ logFile?: string;
114
+ /** Whether the transport is enabled. If false, all operations will no-op. Defaults to true */
115
+ enabled?: boolean;
116
+ }
117
+
118
+ /**
119
+ * A transport for LogLayer that provides a pretty terminal output with interactive features.
120
+ * This transport implements an interactive terminal UI for viewing and filtering logs.
121
+ *
122
+ * Features:
123
+ * - Real-time log display with color-coded levels
124
+ * - Interactive selection mode for browsing logs
125
+ * - Detailed view for inspecting individual log entries
126
+ * - Search/filter functionality
127
+ * - JSON data pretty printing
128
+ * - Configurable themes and colors
129
+ *
130
+ * The transport uses a singleton pattern to ensure only one instance exists,
131
+ * as it manages terminal input and output which cannot be shared.
132
+ */
133
+
134
+ /**
135
+ * Main transport class that handles pretty terminal output and interactive features.
136
+ * This class coordinates between different components:
137
+ * - LogStorage: Handles persistence of logs in SQLite
138
+ * - LogRenderer: Manages all rendering and formatting
139
+ * - UIManager: Handles user interaction and view state
140
+ *
141
+ * The transport supports two main view modes:
142
+ * 1. Simple View: Real-time log output with basic formatting
143
+ * 2. Interactive View: Full-screen mode with navigation and filtering
144
+ *
145
+ * Usage:
146
+ * ```typescript
147
+ * const transport = PrettyTerminalTransport.getInstance({
148
+ * maxInlineDepth: 4,
149
+ * maxInlineLength: 120,
150
+ * theme: customTheme
151
+ * });
152
+ * ```
153
+ */
154
+ declare class PrettyTerminalTransport extends LoggerlessTransport {
155
+ /** Singleton instance of the transport */
156
+ private static instance;
157
+ /** Handles all rendering and formatting of logs */
158
+ private renderer;
159
+ /** Manages log persistence in SQLite database */
160
+ private storage;
161
+ /** Manages user interaction and view state */
162
+ private uiManager;
163
+ /** Configuration options */
164
+ private config;
165
+ /**
166
+ * Creates a new PrettyTerminalTransport instance.
167
+ * This is a singleton class - only one instance can exist at a time.
168
+ * Use getInstance() instead of constructor directly.
169
+ *
170
+ * @param config - Configuration options for the transport
171
+ * @throws Error if attempting to create multiple instances
172
+ */
173
+ constructor(config?: PrettyTerminalConfig);
174
+ /**
175
+ * Gets or creates the singleton instance of PrettyTerminalTransport.
176
+ * This is the recommended way to obtain a transport instance.
177
+ *
178
+ * @param config - Configuration options for the transport
179
+ * @returns The singleton instance of PrettyTerminalTransport
180
+ */
181
+ static getInstance(config?: PrettyTerminalConfig): PrettyTerminalTransport;
182
+ /**
183
+ * Generates a random ID for each log entry.
184
+ * Uses base36 encoding for compact, readable IDs.
185
+ *
186
+ * @returns A 6-character string ID
187
+ * @example
188
+ * "a1b2c3" // Example generated ID
189
+ */
190
+ private generateId;
191
+ /**
192
+ * Main transport method that receives logs from LogLayer.
193
+ * This method is called for each log event and handles:
194
+ * - Generating a unique ID for the log
195
+ * - Converting the log data to a storable format
196
+ * - Storing the log in the database
197
+ * - Rendering the log if not in selection mode
198
+ *
199
+ * @param logLevel - The severity level of the log
200
+ * @param messages - Array of message strings to be joined
201
+ * @param data - Additional structured data to be logged
202
+ * @param hasData - Whether the log includes additional data
203
+ * @returns The original messages array
204
+ */
205
+ shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams): any[];
206
+ }
207
+
208
+ /**
209
+ * Moonlight - A dark theme with cool blue tones
210
+ * Inspired by moonlit nights and modern IDEs
211
+ *
212
+ * Color Palette:
213
+ * - Primary: Cool blues and soft greens
214
+ * - Accents: Warm yellows and soft reds
215
+ * - Background: Assumes dark terminal (black or very dark grey)
216
+ *
217
+ * Best used with:
218
+ * - Dark terminal themes
219
+ * - Night-time coding sessions
220
+ * - Environments where eye strain is a concern
221
+ */
222
+ declare const moonlight: PrettyTerminalTheme;
223
+ /**
224
+ * Sunlight - A light theme with warm tones
225
+ * Inspired by daylight reading and paper documentation
226
+ *
227
+ * Color Palette:
228
+ * - Primary: Deep, rich colors that contrast well with white
229
+ * - Accents: Earth tones and deep jewel tones
230
+ * - Background: Assumes light terminal (white or very light grey)
231
+ *
232
+ * Best used with:
233
+ * - Light terminal themes
234
+ * - Daytime coding sessions
235
+ * - High-glare environments
236
+ * - Printed documentation
237
+ */
238
+ declare const sunlight: PrettyTerminalTheme;
239
+ /**
240
+ * Neon - A dark theme with vibrant cyberpunk colors
241
+ * Inspired by neon-lit cityscapes and retro-futuristic aesthetics
242
+ *
243
+ * Color Palette:
244
+ * - Primary: Electric blues and hot pinks
245
+ * - Accents: Bright purples and cyber greens
246
+ * - Background: Assumes dark terminal (black or very dark grey)
247
+ *
248
+ * Best used with:
249
+ * - Dark terminal themes
250
+ * - High-contrast preferences
251
+ * - Modern, tech-focused applications
252
+ */
253
+ declare const neon: PrettyTerminalTheme;
254
+ /**
255
+ * Nature - A light theme with organic, earthy colors
256
+ * Inspired by forest landscapes and natural elements
257
+ *
258
+ * Color Palette:
259
+ * - Primary: Deep forest greens and rich browns
260
+ * - Accents: Autumn reds and golden yellows
261
+ * - Background: Assumes light terminal (white or very light grey)
262
+ *
263
+ * Best used with:
264
+ * - Light terminal themes
265
+ * - Nature-inspired interfaces
266
+ * - Applications focusing on readability
267
+ */
268
+ declare const nature: PrettyTerminalTheme;
269
+ /**
270
+ * Pastel - A soft, calming theme with gentle colors
271
+ * Inspired by watercolor paintings and cotton candy skies
272
+ *
273
+ * Color Palette:
274
+ * - Primary: Soft pinks and lavenders
275
+ * - Accents: Mint greens and baby blues
276
+ * - Background: Assumes dark terminal (black or very dark grey)
277
+ *
278
+ * Best used with:
279
+ * - Dark terminal themes
280
+ * - Long coding sessions where eye comfort is priority
281
+ * - Environments where a gentler aesthetic is preferred
282
+ * - Applications focusing on reduced visual stress
283
+ */
284
+ declare const pastel: PrettyTerminalTheme;
285
+
286
+ declare function getPrettyTerminal(config?: PrettyTerminalConfig): PrettyTerminalTransport;
287
+
288
+ export { type ColorConfig, type DetailedViewConfig, type LogEntry, type PrettyTerminalConfig, type PrettyTerminalTheme, PrettyTerminalTransport, type ViewConfig, getPrettyTerminal, moonlight, nature, neon, pastel, sunlight };