@reifydb/shell 0.2.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.
- package/dist/index.css +22 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +393 -0
- package/dist/index.js +1137 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/dist/index.css
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* src/terminal/styles.css */
|
|
2
|
+
.xterm {
|
|
3
|
+
padding: 0;
|
|
4
|
+
}
|
|
5
|
+
.xterm-viewport {
|
|
6
|
+
scrollbar-width: thin;
|
|
7
|
+
scrollbar-color: #45475a #1e1e2e;
|
|
8
|
+
}
|
|
9
|
+
.xterm-viewport::-webkit-scrollbar {
|
|
10
|
+
width: 8px;
|
|
11
|
+
}
|
|
12
|
+
.xterm-viewport::-webkit-scrollbar-track {
|
|
13
|
+
background: #1e1e2e;
|
|
14
|
+
}
|
|
15
|
+
.xterm-viewport::-webkit-scrollbar-thumb {
|
|
16
|
+
background: #45475a;
|
|
17
|
+
border-radius: 4px;
|
|
18
|
+
}
|
|
19
|
+
.xterm-viewport::-webkit-scrollbar-thumb:hover {
|
|
20
|
+
background: #585b70;
|
|
21
|
+
}
|
|
22
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/terminal/styles.css"],"sourcesContent":["/* SPDX-License-Identifier: AGPL-3.0-or-later */\n/* Copyright (c) 2025 ReifyDB */\n\n/* xterm.js container styling */\n.xterm {\n padding: 0;\n}\n\n.xterm-viewport {\n /* Hide scrollbar but keep scrolling functional */\n scrollbar-width: thin;\n scrollbar-color: #45475a #1e1e2e;\n}\n\n.xterm-viewport::-webkit-scrollbar {\n width: 8px;\n}\n\n.xterm-viewport::-webkit-scrollbar-track {\n background: #1e1e2e;\n}\n\n.xterm-viewport::-webkit-scrollbar-thumb {\n background: #45475a;\n border-radius: 4px;\n}\n\n.xterm-viewport::-webkit-scrollbar-thumb:hover {\n background: #585b70;\n}\n"],"mappings":";AAIA,CAAC;AACC,WAAS;AACX;AAEA,CAAC;AAEC,mBAAiB;AACjB,mBAAiB,QAAQ;AAC3B;AAEA,CANC,cAMc;AACb,SAAO;AACT;AAEA,CAVC,cAUc;AACb,cAAY;AACd;AAEA,CAdC,cAcc;AACb,cAAY;AACZ,iBAAe;AACjB;AAEA,CAnBC,cAmBc,yBAAyB;AACtC,cAAY;AACd;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal color theme configuration
|
|
3
|
+
*/
|
|
4
|
+
interface TerminalTheme {
|
|
5
|
+
background: string;
|
|
6
|
+
foreground: string;
|
|
7
|
+
cursor: string;
|
|
8
|
+
cursorAccent: string;
|
|
9
|
+
selectionBackground: string;
|
|
10
|
+
black: string;
|
|
11
|
+
red: string;
|
|
12
|
+
green: string;
|
|
13
|
+
yellow: string;
|
|
14
|
+
blue: string;
|
|
15
|
+
magenta: string;
|
|
16
|
+
cyan: string;
|
|
17
|
+
white: string;
|
|
18
|
+
brightBlack: string;
|
|
19
|
+
brightRed: string;
|
|
20
|
+
brightGreen: string;
|
|
21
|
+
brightYellow: string;
|
|
22
|
+
brightBlue: string;
|
|
23
|
+
brightMagenta: string;
|
|
24
|
+
brightCyan: string;
|
|
25
|
+
brightWhite: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Catppuccin Mocha theme - default theme
|
|
29
|
+
*/
|
|
30
|
+
declare const defaultTheme: TerminalTheme;
|
|
31
|
+
/**
|
|
32
|
+
* ANSI escape codes for terminal colors and formatting
|
|
33
|
+
*/
|
|
34
|
+
declare const COLORS: {
|
|
35
|
+
readonly reset: "\u001B[0m";
|
|
36
|
+
readonly bold: "\u001B[1m";
|
|
37
|
+
readonly dim: "\u001B[2m";
|
|
38
|
+
readonly italic: "\u001B[3m";
|
|
39
|
+
readonly underline: "\u001B[4m";
|
|
40
|
+
readonly black: "\u001B[30m";
|
|
41
|
+
readonly red: "\u001B[31m";
|
|
42
|
+
readonly green: "\u001B[32m";
|
|
43
|
+
readonly yellow: "\u001B[33m";
|
|
44
|
+
readonly blue: "\u001B[34m";
|
|
45
|
+
readonly magenta: "\u001B[35m";
|
|
46
|
+
readonly cyan: "\u001B[36m";
|
|
47
|
+
readonly white: "\u001B[37m";
|
|
48
|
+
readonly brightBlack: "\u001B[90m";
|
|
49
|
+
readonly brightRed: "\u001B[91m";
|
|
50
|
+
readonly brightGreen: "\u001B[92m";
|
|
51
|
+
readonly brightYellow: "\u001B[93m";
|
|
52
|
+
readonly brightBlue: "\u001B[94m";
|
|
53
|
+
readonly brightMagenta: "\u001B[95m";
|
|
54
|
+
readonly brightCyan: "\u001B[96m";
|
|
55
|
+
readonly brightWhite: "\u001B[97m";
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type KeyHandler = (key: string, domEvent: KeyboardEvent) => void;
|
|
59
|
+
declare class TerminalAdapter {
|
|
60
|
+
private terminal;
|
|
61
|
+
private fitAddon;
|
|
62
|
+
private keyHandler;
|
|
63
|
+
private resizeObserver;
|
|
64
|
+
constructor(container: HTMLElement, theme?: TerminalTheme);
|
|
65
|
+
onKey(handler: KeyHandler): void;
|
|
66
|
+
write(text: string): void;
|
|
67
|
+
writeln(text: string): void;
|
|
68
|
+
clear(): void;
|
|
69
|
+
get cols(): number;
|
|
70
|
+
get rows(): number;
|
|
71
|
+
focus(): void;
|
|
72
|
+
dispose(): void;
|
|
73
|
+
static readonly COLORS: {
|
|
74
|
+
readonly reset: "\u001B[0m";
|
|
75
|
+
readonly bold: "\u001B[1m";
|
|
76
|
+
readonly dim: "\u001B[2m";
|
|
77
|
+
readonly italic: "\u001B[3m";
|
|
78
|
+
readonly underline: "\u001B[4m";
|
|
79
|
+
readonly black: "\u001B[30m";
|
|
80
|
+
readonly red: "\u001B[31m";
|
|
81
|
+
readonly green: "\u001B[32m";
|
|
82
|
+
readonly yellow: "\u001B[33m";
|
|
83
|
+
readonly blue: "\u001B[34m";
|
|
84
|
+
readonly magenta: "\u001B[35m";
|
|
85
|
+
readonly cyan: "\u001B[36m";
|
|
86
|
+
readonly white: "\u001B[37m";
|
|
87
|
+
readonly brightBlack: "\u001B[90m";
|
|
88
|
+
readonly brightRed: "\u001B[91m";
|
|
89
|
+
readonly brightGreen: "\u001B[92m";
|
|
90
|
+
readonly brightYellow: "\u001B[93m";
|
|
91
|
+
readonly brightBlue: "\u001B[94m";
|
|
92
|
+
readonly brightMagenta: "\u001B[95m";
|
|
93
|
+
readonly brightCyan: "\u001B[96m";
|
|
94
|
+
readonly brightWhite: "\u001B[97m";
|
|
95
|
+
};
|
|
96
|
+
static cursorUp(n?: number): string;
|
|
97
|
+
static cursorDown(n?: number): string;
|
|
98
|
+
static cursorForward(n?: number): string;
|
|
99
|
+
static cursorBack(n?: number): string;
|
|
100
|
+
static cursorPosition(row: number, col: number): string;
|
|
101
|
+
static clearLine(): string;
|
|
102
|
+
static clearToEndOfLine(): string;
|
|
103
|
+
static clearScreen(): string;
|
|
104
|
+
static saveCursor(): string;
|
|
105
|
+
static restoreCursor(): string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Result from executing a statement
|
|
110
|
+
*/
|
|
111
|
+
interface ExecutionResult {
|
|
112
|
+
success: boolean;
|
|
113
|
+
data?: Record<string, unknown>[];
|
|
114
|
+
error?: string;
|
|
115
|
+
executionTime: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Interface for executing database statements.
|
|
119
|
+
* Implement this interface to connect the shell to any database backend.
|
|
120
|
+
*/
|
|
121
|
+
interface Executor {
|
|
122
|
+
/**
|
|
123
|
+
* Execute a statement and return the result
|
|
124
|
+
*/
|
|
125
|
+
execute(statement: string): Promise<ExecutionResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Get list of tables (optional, used by .tables command)
|
|
128
|
+
*/
|
|
129
|
+
getTables?(): Promise<string[]>;
|
|
130
|
+
/**
|
|
131
|
+
* Get schema for a table (optional, used by .schema command)
|
|
132
|
+
*/
|
|
133
|
+
getSchema?(tableName: string): Promise<string | null>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Display mode for query results
|
|
137
|
+
*/
|
|
138
|
+
type DisplayMode = 'truncate' | 'full';
|
|
139
|
+
/**
|
|
140
|
+
* Interface for history storage.
|
|
141
|
+
* Implement this to customize where history is persisted.
|
|
142
|
+
*/
|
|
143
|
+
interface HistoryStorage {
|
|
144
|
+
load(): string[];
|
|
145
|
+
save(entries: string[]): void;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Configuration options for the Shell
|
|
149
|
+
*/
|
|
150
|
+
interface ShellOptions {
|
|
151
|
+
/**
|
|
152
|
+
* The executor to use for running statements
|
|
153
|
+
*/
|
|
154
|
+
executor: Executor;
|
|
155
|
+
/**
|
|
156
|
+
* Welcome message shown when shell starts.
|
|
157
|
+
* Can be a string, array of strings, or function returning strings.
|
|
158
|
+
* If not provided, a default welcome banner is shown.
|
|
159
|
+
*/
|
|
160
|
+
welcomeMessage?: string | string[] | (() => string[]);
|
|
161
|
+
/**
|
|
162
|
+
* Primary prompt string (default: "reifydb> ")
|
|
163
|
+
* Can include ANSI color codes.
|
|
164
|
+
*/
|
|
165
|
+
prompt?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Prompt length without ANSI codes (for cursor positioning)
|
|
168
|
+
* Required if prompt contains ANSI codes.
|
|
169
|
+
*/
|
|
170
|
+
promptLength?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Continuation prompt for multi-line input (default: " ... ")
|
|
173
|
+
* Can include ANSI color codes.
|
|
174
|
+
*/
|
|
175
|
+
continuationPrompt?: string;
|
|
176
|
+
/**
|
|
177
|
+
* Continuation prompt length without ANSI codes
|
|
178
|
+
* Required if continuationPrompt contains ANSI codes.
|
|
179
|
+
*/
|
|
180
|
+
continuationPromptLength?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Terminal theme colors
|
|
183
|
+
*/
|
|
184
|
+
theme?: TerminalTheme;
|
|
185
|
+
/**
|
|
186
|
+
* Key for localStorage history (default: "reifydb-shell-history")
|
|
187
|
+
*/
|
|
188
|
+
historyKey?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Custom history storage implementation.
|
|
191
|
+
* If provided, historyKey is ignored.
|
|
192
|
+
*/
|
|
193
|
+
historyStorage?: HistoryStorage;
|
|
194
|
+
/**
|
|
195
|
+
* Initial display mode (default: "truncate")
|
|
196
|
+
*/
|
|
197
|
+
displayMode?: DisplayMode;
|
|
198
|
+
/**
|
|
199
|
+
* Callback when user exits the shell
|
|
200
|
+
*/
|
|
201
|
+
onExit?: () => void;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Internal context passed to dot command handlers
|
|
205
|
+
*/
|
|
206
|
+
interface DotCommandContext {
|
|
207
|
+
terminal: TerminalAdapter;
|
|
208
|
+
executor: Executor;
|
|
209
|
+
history: {
|
|
210
|
+
getAll(): string[];
|
|
211
|
+
clear(): void;
|
|
212
|
+
};
|
|
213
|
+
displayMode: DisplayMode;
|
|
214
|
+
setDisplayMode: (mode: DisplayMode) => void;
|
|
215
|
+
clearScreen: () => void;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Result from handling a dot command
|
|
219
|
+
*/
|
|
220
|
+
interface DotCommandResult {
|
|
221
|
+
handled: boolean;
|
|
222
|
+
exit?: boolean;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
declare class Shell {
|
|
226
|
+
private terminal;
|
|
227
|
+
private lineEditor;
|
|
228
|
+
private history;
|
|
229
|
+
private multiline;
|
|
230
|
+
private executor;
|
|
231
|
+
private formatter;
|
|
232
|
+
private displayMode;
|
|
233
|
+
private isExited;
|
|
234
|
+
private primaryPrompt;
|
|
235
|
+
private primaryPromptLen;
|
|
236
|
+
private continuationPrompt;
|
|
237
|
+
private continuationPromptLen;
|
|
238
|
+
private welcomeMessage;
|
|
239
|
+
private onExit;
|
|
240
|
+
constructor(container: HTMLElement, options: ShellOptions);
|
|
241
|
+
start(): void;
|
|
242
|
+
dispose(): void;
|
|
243
|
+
private showWelcomeBanner;
|
|
244
|
+
private showPrompt;
|
|
245
|
+
private getCurrentPromptLen;
|
|
246
|
+
private setupKeyHandler;
|
|
247
|
+
private handleKey;
|
|
248
|
+
private redrawLine;
|
|
249
|
+
private navigateHistory;
|
|
250
|
+
private handleEnter;
|
|
251
|
+
private clearScreen;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class LineEditor {
|
|
255
|
+
private buffer;
|
|
256
|
+
private cursorPos;
|
|
257
|
+
private terminal;
|
|
258
|
+
constructor(terminal: TerminalAdapter);
|
|
259
|
+
get value(): string;
|
|
260
|
+
get cursor(): number;
|
|
261
|
+
clear(): void;
|
|
262
|
+
setValue(value: string): void;
|
|
263
|
+
insert(char: string): void;
|
|
264
|
+
backspace(): boolean;
|
|
265
|
+
delete(): boolean;
|
|
266
|
+
moveLeft(): boolean;
|
|
267
|
+
moveRight(): boolean;
|
|
268
|
+
moveToStart(): void;
|
|
269
|
+
moveToEnd(): void;
|
|
270
|
+
moveWordLeft(): void;
|
|
271
|
+
moveWordRight(): void;
|
|
272
|
+
clearLine(): void;
|
|
273
|
+
deleteToEnd(): void;
|
|
274
|
+
deleteToStart(): void;
|
|
275
|
+
deleteWord(): void;
|
|
276
|
+
render(prompt: string): void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Default localStorage-based history storage
|
|
281
|
+
*/
|
|
282
|
+
declare class LocalStorageHistoryStorage implements HistoryStorage {
|
|
283
|
+
private key;
|
|
284
|
+
constructor(key?: string);
|
|
285
|
+
load(): string[];
|
|
286
|
+
save(entries: string[]): void;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* In-memory history storage (no persistence)
|
|
290
|
+
*/
|
|
291
|
+
declare class MemoryHistoryStorage implements HistoryStorage {
|
|
292
|
+
private entries;
|
|
293
|
+
load(): string[];
|
|
294
|
+
save(entries: string[]): void;
|
|
295
|
+
}
|
|
296
|
+
declare class CommandHistory {
|
|
297
|
+
private entries;
|
|
298
|
+
private position;
|
|
299
|
+
private savedInput;
|
|
300
|
+
private storage;
|
|
301
|
+
constructor(storage?: HistoryStorage, historyKey?: string);
|
|
302
|
+
add(command: string): void;
|
|
303
|
+
previous(currentInput: string): string | null;
|
|
304
|
+
next(): string | null;
|
|
305
|
+
reset(): void;
|
|
306
|
+
getAll(): string[];
|
|
307
|
+
clear(): void;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
declare class MultilineBuffer {
|
|
311
|
+
private lines;
|
|
312
|
+
get isEmpty(): boolean;
|
|
313
|
+
get content(): string;
|
|
314
|
+
addLine(line: string): void;
|
|
315
|
+
clear(): void;
|
|
316
|
+
isComplete(): boolean;
|
|
317
|
+
static isStatementComplete(input: string): boolean;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
declare class OutputFormatter {
|
|
321
|
+
private terminal;
|
|
322
|
+
private displayMode;
|
|
323
|
+
constructor(terminal: TerminalAdapter, displayMode?: DisplayMode);
|
|
324
|
+
setDisplayMode(mode: DisplayMode): void;
|
|
325
|
+
formatResult(result: ExecutionResult): void;
|
|
326
|
+
private formatTable;
|
|
327
|
+
private formatError;
|
|
328
|
+
private formatExecutionTime;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
interface TableColumn {
|
|
332
|
+
name: string;
|
|
333
|
+
width: number;
|
|
334
|
+
}
|
|
335
|
+
interface TableOptions {
|
|
336
|
+
maxWidth?: number;
|
|
337
|
+
truncate?: boolean;
|
|
338
|
+
}
|
|
339
|
+
declare class TableRenderer {
|
|
340
|
+
private data;
|
|
341
|
+
private columns;
|
|
342
|
+
private maxWidth;
|
|
343
|
+
private truncate;
|
|
344
|
+
constructor(data: Record<string, unknown>[], options?: TableOptions);
|
|
345
|
+
private calculateColumns;
|
|
346
|
+
private formatValue;
|
|
347
|
+
private truncateString;
|
|
348
|
+
render(): string[];
|
|
349
|
+
private fitColumns;
|
|
350
|
+
private padCenter;
|
|
351
|
+
private padRight;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Interface for WebAssembly database instances.
|
|
356
|
+
* This matches the WasmDB interface from reifydb-wasm.
|
|
357
|
+
*/
|
|
358
|
+
interface WasmDB {
|
|
359
|
+
admin(rql: string): Promise<unknown> | unknown;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Executor adapter for WebAssembly-based ReifyDB instances.
|
|
363
|
+
*/
|
|
364
|
+
declare class WasmExecutor implements Executor {
|
|
365
|
+
private db;
|
|
366
|
+
constructor(db: WasmDB);
|
|
367
|
+
execute(statement: string): Promise<ExecutionResult>;
|
|
368
|
+
getTables(): Promise<string[]>;
|
|
369
|
+
getSchema(tableName: string): Promise<string | null>;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Interface for WebSocket client.
|
|
374
|
+
* This matches the WsClient interface from @reifydb/client.
|
|
375
|
+
*/
|
|
376
|
+
interface WsClient {
|
|
377
|
+
admin<const S extends readonly unknown[]>(statements: string | string[], params: unknown, schemas: S): Promise<unknown[][]>;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Executor adapter for WebSocket-based ReifyDB connections.
|
|
381
|
+
*/
|
|
382
|
+
declare class WsExecutor implements Executor {
|
|
383
|
+
private client;
|
|
384
|
+
constructor(client: WsClient);
|
|
385
|
+
execute(statement: string): Promise<ExecutionResult>;
|
|
386
|
+
getTables(): Promise<string[]>;
|
|
387
|
+
getSchema(tableName: string): Promise<string | null>;
|
|
388
|
+
private extractValue;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
declare function handleDotCommand(input: string, context: DotCommandContext): Promise<DotCommandResult>;
|
|
392
|
+
|
|
393
|
+
export { COLORS, CommandHistory, type DisplayMode, type DotCommandContext, type DotCommandResult, type ExecutionResult, type Executor, type HistoryStorage, type KeyHandler, LineEditor, LocalStorageHistoryStorage, MemoryHistoryStorage, MultilineBuffer, OutputFormatter, Shell, type ShellOptions, type TableColumn, type TableOptions, TableRenderer, TerminalAdapter, type TerminalTheme, type WasmDB, WasmExecutor, type WsClient, WsExecutor, defaultTheme, handleDotCommand };
|