@loglayer/transport-pretty-terminal 5.0.2 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +66 -1
- package/dist/index.cjs +7 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -6
- package/dist/index.d.mts +38 -6
- package/dist/index.mjs +7 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -7
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,34 @@ import * as chalk from "chalk";
|
|
|
3
3
|
import { ChalkInstance } from "chalk";
|
|
4
4
|
|
|
5
5
|
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Minimal interface for a prepared SQLite statement.
|
|
8
|
+
* Compatible with better-sqlite3, bun:sqlite, and other synchronous SQLite bindings.
|
|
9
|
+
*/
|
|
10
|
+
interface SqliteStatement {
|
|
11
|
+
run(...params: unknown[]): unknown;
|
|
12
|
+
all(...params: unknown[]): unknown[];
|
|
13
|
+
get(...params: unknown[]): unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Minimal interface for a SQLite database instance.
|
|
17
|
+
* Compatible with better-sqlite3, bun:sqlite, and other synchronous SQLite bindings.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Using bun:sqlite
|
|
21
|
+
* import { Database } from "bun:sqlite";
|
|
22
|
+
* getPrettyTerminal({ database: new Database(":memory:") });
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Using better-sqlite3
|
|
26
|
+
* import Database from "better-sqlite3";
|
|
27
|
+
* getPrettyTerminal({ database: new Database(":memory:") });
|
|
28
|
+
*/
|
|
29
|
+
interface SqliteDatabaseInstance {
|
|
30
|
+
exec(sql: string): void;
|
|
31
|
+
prepare(sql: string): SqliteStatement;
|
|
32
|
+
close(): void;
|
|
33
|
+
}
|
|
6
34
|
/**
|
|
7
35
|
* Represents a single log entry in the storage system.
|
|
8
36
|
* Each entry contains metadata and the actual log content.
|
|
@@ -99,8 +127,12 @@ interface PrettyTerminalConfig extends LoggerlessTransportConfig {
|
|
|
99
127
|
maxInlineLength?: number;
|
|
100
128
|
/** Custom theme configuration for log display */
|
|
101
129
|
theme?: PrettyTerminalTheme;
|
|
102
|
-
/**
|
|
103
|
-
|
|
130
|
+
/**
|
|
131
|
+
* SQLite database instance to use for log storage.
|
|
132
|
+
* The instance must implement `exec`, `prepare`, and `close`.
|
|
133
|
+
* Compatible with better-sqlite3, bun:sqlite, and other synchronous SQLite bindings.
|
|
134
|
+
*/
|
|
135
|
+
database: SqliteDatabaseInstance;
|
|
104
136
|
/** Whether the transport is enabled. If false, all operations will no-op. Defaults to true */
|
|
105
137
|
enabled?: boolean;
|
|
106
138
|
/** Whether to disable interactive mode (keyboard input and navigation). Useful when multiple applications need to print to the same terminal. Defaults to false */
|
|
@@ -147,7 +179,7 @@ declare class PrettyTerminalTransport extends LoggerlessTransport {
|
|
|
147
179
|
* @param config - Configuration options for the transport
|
|
148
180
|
* @throws Error if attempting to create multiple instances
|
|
149
181
|
*/
|
|
150
|
-
constructor(config
|
|
182
|
+
constructor(config: PrettyTerminalConfig);
|
|
151
183
|
/**
|
|
152
184
|
* Gets or creates the singleton instance of PrettyTerminalTransport.
|
|
153
185
|
* This is the recommended way to obtain a transport instance.
|
|
@@ -155,7 +187,7 @@ declare class PrettyTerminalTransport extends LoggerlessTransport {
|
|
|
155
187
|
* @param config - Configuration options for the transport
|
|
156
188
|
* @returns The singleton instance of PrettyTerminalTransport
|
|
157
189
|
*/
|
|
158
|
-
static getInstance(config
|
|
190
|
+
static getInstance(config: PrettyTerminalConfig): PrettyTerminalTransport;
|
|
159
191
|
/**
|
|
160
192
|
* Generates a random ID for each log entry.
|
|
161
193
|
* Uses base36 encoding for compact, readable IDs.
|
|
@@ -267,7 +299,7 @@ declare const nature: PrettyTerminalTheme;
|
|
|
267
299
|
declare const pastel: PrettyTerminalTheme;
|
|
268
300
|
//#endregion
|
|
269
301
|
//#region src/index.d.ts
|
|
270
|
-
declare function getPrettyTerminal(config
|
|
302
|
+
declare function getPrettyTerminal(config: PrettyTerminalConfig): PrettyTerminalTransport;
|
|
271
303
|
//#endregion
|
|
272
|
-
export { ColorConfig, DetailedViewConfig, LogEntry, PrettyTerminalConfig, PrettyTerminalTheme, PrettyTerminalTransport, ViewConfig, chalk, getPrettyTerminal, moonlight, nature, neon, pastel, sunlight };
|
|
304
|
+
export { ColorConfig, DetailedViewConfig, LogEntry, PrettyTerminalConfig, PrettyTerminalTheme, PrettyTerminalTransport, SqliteDatabaseInstance, SqliteStatement, ViewConfig, chalk, getPrettyTerminal, moonlight, nature, neon, pastel, sunlight };
|
|
273
305
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,34 @@ import * as chalk from "chalk";
|
|
|
3
3
|
import { ChalkInstance } from "chalk";
|
|
4
4
|
|
|
5
5
|
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Minimal interface for a prepared SQLite statement.
|
|
8
|
+
* Compatible with better-sqlite3, bun:sqlite, and other synchronous SQLite bindings.
|
|
9
|
+
*/
|
|
10
|
+
interface SqliteStatement {
|
|
11
|
+
run(...params: unknown[]): unknown;
|
|
12
|
+
all(...params: unknown[]): unknown[];
|
|
13
|
+
get(...params: unknown[]): unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Minimal interface for a SQLite database instance.
|
|
17
|
+
* Compatible with better-sqlite3, bun:sqlite, and other synchronous SQLite bindings.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Using bun:sqlite
|
|
21
|
+
* import { Database } from "bun:sqlite";
|
|
22
|
+
* getPrettyTerminal({ database: new Database(":memory:") });
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Using better-sqlite3
|
|
26
|
+
* import Database from "better-sqlite3";
|
|
27
|
+
* getPrettyTerminal({ database: new Database(":memory:") });
|
|
28
|
+
*/
|
|
29
|
+
interface SqliteDatabaseInstance {
|
|
30
|
+
exec(sql: string): void;
|
|
31
|
+
prepare(sql: string): SqliteStatement;
|
|
32
|
+
close(): void;
|
|
33
|
+
}
|
|
6
34
|
/**
|
|
7
35
|
* Represents a single log entry in the storage system.
|
|
8
36
|
* Each entry contains metadata and the actual log content.
|
|
@@ -99,8 +127,12 @@ interface PrettyTerminalConfig extends LoggerlessTransportConfig {
|
|
|
99
127
|
maxInlineLength?: number;
|
|
100
128
|
/** Custom theme configuration for log display */
|
|
101
129
|
theme?: PrettyTerminalTheme;
|
|
102
|
-
/**
|
|
103
|
-
|
|
130
|
+
/**
|
|
131
|
+
* SQLite database instance to use for log storage.
|
|
132
|
+
* The instance must implement `exec`, `prepare`, and `close`.
|
|
133
|
+
* Compatible with better-sqlite3, bun:sqlite, and other synchronous SQLite bindings.
|
|
134
|
+
*/
|
|
135
|
+
database: SqliteDatabaseInstance;
|
|
104
136
|
/** Whether the transport is enabled. If false, all operations will no-op. Defaults to true */
|
|
105
137
|
enabled?: boolean;
|
|
106
138
|
/** Whether to disable interactive mode (keyboard input and navigation). Useful when multiple applications need to print to the same terminal. Defaults to false */
|
|
@@ -147,7 +179,7 @@ declare class PrettyTerminalTransport extends LoggerlessTransport {
|
|
|
147
179
|
* @param config - Configuration options for the transport
|
|
148
180
|
* @throws Error if attempting to create multiple instances
|
|
149
181
|
*/
|
|
150
|
-
constructor(config
|
|
182
|
+
constructor(config: PrettyTerminalConfig);
|
|
151
183
|
/**
|
|
152
184
|
* Gets or creates the singleton instance of PrettyTerminalTransport.
|
|
153
185
|
* This is the recommended way to obtain a transport instance.
|
|
@@ -155,7 +187,7 @@ declare class PrettyTerminalTransport extends LoggerlessTransport {
|
|
|
155
187
|
* @param config - Configuration options for the transport
|
|
156
188
|
* @returns The singleton instance of PrettyTerminalTransport
|
|
157
189
|
*/
|
|
158
|
-
static getInstance(config
|
|
190
|
+
static getInstance(config: PrettyTerminalConfig): PrettyTerminalTransport;
|
|
159
191
|
/**
|
|
160
192
|
* Generates a random ID for each log entry.
|
|
161
193
|
* Uses base36 encoding for compact, readable IDs.
|
|
@@ -267,7 +299,7 @@ declare const nature: PrettyTerminalTheme;
|
|
|
267
299
|
declare const pastel: PrettyTerminalTheme;
|
|
268
300
|
//#endregion
|
|
269
301
|
//#region src/index.d.ts
|
|
270
|
-
declare function getPrettyTerminal(config
|
|
302
|
+
declare function getPrettyTerminal(config: PrettyTerminalConfig): PrettyTerminalTransport;
|
|
271
303
|
//#endregion
|
|
272
|
-
export { ColorConfig, DetailedViewConfig, LogEntry, PrettyTerminalConfig, PrettyTerminalTheme, PrettyTerminalTransport, ViewConfig, chalk, getPrettyTerminal, moonlight, nature, neon, pastel, sunlight };
|
|
304
|
+
export { ColorConfig, DetailedViewConfig, LogEntry, PrettyTerminalConfig, PrettyTerminalTheme, PrettyTerminalTransport, SqliteDatabaseInstance, SqliteStatement, ViewConfig, chalk, getPrettyTerminal, moonlight, nature, neon, pastel, sunlight };
|
|
273
305
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,6 @@ import * as chalk from "chalk";
|
|
|
3
3
|
import chalk$1 from "chalk";
|
|
4
4
|
import wrap from "wrap-ansi";
|
|
5
5
|
import truncate from "cli-truncate";
|
|
6
|
-
import { resolve } from "node:path";
|
|
7
|
-
import Database from "better-sqlite3";
|
|
8
6
|
import keypress from "keypress";
|
|
9
7
|
|
|
10
8
|
//#region src/vendor/utils.js
|
|
@@ -660,12 +658,7 @@ var LogRenderer = class {
|
|
|
660
658
|
//#endregion
|
|
661
659
|
//#region src/LogStorage.ts
|
|
662
660
|
/**
|
|
663
|
-
* LogStorage handles the persistence of log entries using SQLite.
|
|
664
|
-
* Uses an in-memory database for fast access and temporary storage.
|
|
665
|
-
*/
|
|
666
|
-
/**
|
|
667
661
|
* Handles storage and retrieval of log entries using SQLite.
|
|
668
|
-
* Uses an in-memory database for optimal performance and automatic cleanup.
|
|
669
662
|
*
|
|
670
663
|
* The database schema includes:
|
|
671
664
|
* - id: Unique identifier for each log
|
|
@@ -675,18 +668,9 @@ var LogRenderer = class {
|
|
|
675
668
|
* - data: Optional structured data as JSON string
|
|
676
669
|
*/
|
|
677
670
|
var LogStorage = class {
|
|
678
|
-
/** SQLite database instance */
|
|
679
671
|
db;
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
* Initializes a SQLite database and creates the logs table.
|
|
683
|
-
*
|
|
684
|
-
* @param logFile - Optional path to SQLite file for persistent storage.
|
|
685
|
-
* If not provided, uses in-memory database.
|
|
686
|
-
* Relative paths are resolved from the current working directory.
|
|
687
|
-
*/
|
|
688
|
-
constructor(logFile) {
|
|
689
|
-
this.db = new Database(logFile ? logFile.startsWith("/") ? logFile : resolve(process.cwd(), logFile) : ":memory:");
|
|
672
|
+
constructor(database) {
|
|
673
|
+
this.db = database;
|
|
690
674
|
this.initializeDatabase();
|
|
691
675
|
}
|
|
692
676
|
/**
|
|
@@ -1545,7 +1529,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends LoggerlessTr
|
|
|
1545
1529
|
* @param config - Configuration options for the transport
|
|
1546
1530
|
* @throws Error if attempting to create multiple instances
|
|
1547
1531
|
*/
|
|
1548
|
-
constructor(config
|
|
1532
|
+
constructor(config) {
|
|
1549
1533
|
if (PrettyTerminalTransport.instance) throw new Error("PrettyTerminalTransport is a singleton. Use getPrettyTerminal() instead.");
|
|
1550
1534
|
super(config);
|
|
1551
1535
|
this.config = config;
|
|
@@ -1553,7 +1537,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends LoggerlessTr
|
|
|
1553
1537
|
const maxInlineDepth = config.maxInlineDepth || 4;
|
|
1554
1538
|
const maxInlineLength = config.maxInlineLength || 120;
|
|
1555
1539
|
const theme = config.theme || moonlight;
|
|
1556
|
-
const
|
|
1540
|
+
const database = config.database;
|
|
1557
1541
|
const simpleViewConfig = {
|
|
1558
1542
|
colors: {
|
|
1559
1543
|
trace: chalk$1.gray,
|
|
@@ -1600,7 +1584,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends LoggerlessTr
|
|
|
1600
1584
|
...theme.detailedView?.jsonColors
|
|
1601
1585
|
}
|
|
1602
1586
|
};
|
|
1603
|
-
this.storage = new LogStorage(
|
|
1587
|
+
this.storage = new LogStorage(database);
|
|
1604
1588
|
this.renderer = new LogRenderer(simpleViewConfig, detailedViewConfig, maxInlineDepth, maxInlineLength);
|
|
1605
1589
|
this.uiManager = new UIManager(this.renderer, this.storage, config.disableInteractiveMode);
|
|
1606
1590
|
PrettyTerminalTransport.instance = this;
|
|
@@ -1612,7 +1596,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends LoggerlessTr
|
|
|
1612
1596
|
* @param config - Configuration options for the transport
|
|
1613
1597
|
* @returns The singleton instance of PrettyTerminalTransport
|
|
1614
1598
|
*/
|
|
1615
|
-
static getInstance(config
|
|
1599
|
+
static getInstance(config) {
|
|
1616
1600
|
if (!PrettyTerminalTransport.instance) PrettyTerminalTransport.instance = new PrettyTerminalTransport(config);
|
|
1617
1601
|
return PrettyTerminalTransport.instance;
|
|
1618
1602
|
}
|
|
@@ -1657,7 +1641,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends LoggerlessTr
|
|
|
1657
1641
|
|
|
1658
1642
|
//#endregion
|
|
1659
1643
|
//#region src/index.ts
|
|
1660
|
-
function getPrettyTerminal(config
|
|
1644
|
+
function getPrettyTerminal(config) {
|
|
1661
1645
|
return PrettyTerminalTransport.getInstance(config);
|
|
1662
1646
|
}
|
|
1663
1647
|
|