@reifydb/shell 0.9.0 → 0.9.2
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 +6 -6
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +103 -47
- package/dist/index.js +282 -135
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -27,6 +27,29 @@ var defaultTheme = {
|
|
|
27
27
|
brightCyan: "#94e2d5",
|
|
28
28
|
brightWhite: "#a6adc8"
|
|
29
29
|
};
|
|
30
|
+
var reifydbDarkTheme = {
|
|
31
|
+
background: "#18181b",
|
|
32
|
+
foreground: "#e4e4e7",
|
|
33
|
+
cursor: "#7e85f2",
|
|
34
|
+
cursorAccent: "#18181b",
|
|
35
|
+
selectionBackground: "rgba(126, 133, 242, 0.30)",
|
|
36
|
+
black: "#27272a",
|
|
37
|
+
red: "#f87171",
|
|
38
|
+
green: "#4ade80",
|
|
39
|
+
yellow: "#fbbf24",
|
|
40
|
+
blue: "#7e85f2",
|
|
41
|
+
magenta: "#a78bfa",
|
|
42
|
+
cyan: "#7e85f2",
|
|
43
|
+
white: "#e4e4e7",
|
|
44
|
+
brightBlack: "#71717a",
|
|
45
|
+
brightRed: "#fca5a5",
|
|
46
|
+
brightGreen: "#86efac",
|
|
47
|
+
brightYellow: "#fcd34d",
|
|
48
|
+
brightBlue: "#a5b4fc",
|
|
49
|
+
brightMagenta: "#c4b5fd",
|
|
50
|
+
brightCyan: "#a5b4fc",
|
|
51
|
+
brightWhite: "#fafafa"
|
|
52
|
+
};
|
|
30
53
|
var COLORS = {
|
|
31
54
|
reset: "\x1B[0m",
|
|
32
55
|
bold: "\x1B[1m",
|
|
@@ -290,9 +313,10 @@ var LineEditor = class {
|
|
|
290
313
|
this.cursorPos = newPos;
|
|
291
314
|
}
|
|
292
315
|
// Called by shell to render the line with prompt
|
|
293
|
-
|
|
316
|
+
// `display` carries zero-width ANSI codes only, so cursor math stays on the raw buffer
|
|
317
|
+
render(prompt, display) {
|
|
294
318
|
this.terminal.write(
|
|
295
|
-
"\r" + TerminalAdapter.clearToEndOfLine() + prompt + this.buffer
|
|
319
|
+
"\r" + TerminalAdapter.clearToEndOfLine() + prompt + (display ?? this.buffer)
|
|
296
320
|
);
|
|
297
321
|
const cursorOffset = this.buffer.length - this.cursorPos;
|
|
298
322
|
if (cursorOffset > 0) {
|
|
@@ -343,8 +367,8 @@ var CommandHistory = class {
|
|
|
343
367
|
position = -1;
|
|
344
368
|
savedInput = "";
|
|
345
369
|
storage;
|
|
346
|
-
constructor(storage,
|
|
347
|
-
this.storage = storage ?? new LocalStorageHistoryStorage(
|
|
370
|
+
constructor(storage, historyKey) {
|
|
371
|
+
this.storage = storage ?? new LocalStorageHistoryStorage(historyKey);
|
|
348
372
|
this.entries = this.storage.load();
|
|
349
373
|
}
|
|
350
374
|
add(command) {
|
|
@@ -563,125 +587,177 @@ async function showShape(args, context) {
|
|
|
563
587
|
terminal.writeln(`${C.red}Usage: .shape <table_name>${C.reset}`);
|
|
564
588
|
return;
|
|
565
589
|
}
|
|
566
|
-
const
|
|
567
|
-
const shape = await context.executor.getShape(
|
|
590
|
+
const tableName = args[0];
|
|
591
|
+
const shape = await context.executor.getShape(tableName);
|
|
568
592
|
if (shape) {
|
|
569
593
|
terminal.writeln("");
|
|
570
594
|
terminal.writeln(shape);
|
|
571
595
|
terminal.writeln("");
|
|
572
596
|
} else {
|
|
573
|
-
terminal.writeln(`${C.red}Table not found: ${
|
|
597
|
+
terminal.writeln(`${C.red}Table not found: ${tableName}${C.reset}`);
|
|
574
598
|
}
|
|
575
599
|
}
|
|
576
600
|
|
|
577
601
|
// src/output/table.ts
|
|
602
|
+
import {
|
|
603
|
+
NONE_PRESENTATION,
|
|
604
|
+
cellText,
|
|
605
|
+
inferColumns,
|
|
606
|
+
padToWidth,
|
|
607
|
+
planTable,
|
|
608
|
+
valueRole
|
|
609
|
+
} from "@reifydb/core";
|
|
610
|
+
|
|
611
|
+
// src/ansi.ts
|
|
612
|
+
var RESET = "\x1B[0m";
|
|
613
|
+
function sgr(style) {
|
|
614
|
+
const parameters = [];
|
|
615
|
+
if (style.bold) parameters.push("1");
|
|
616
|
+
if (style.dim) parameters.push("2");
|
|
617
|
+
if (style.italic) parameters.push("3");
|
|
618
|
+
if (style.color) {
|
|
619
|
+
const hex = style.color.replace("#", "");
|
|
620
|
+
const value = parseInt(hex, 16);
|
|
621
|
+
parameters.push(`38;2;${value >> 16 & 255};${value >> 8 & 255};${value & 255}`);
|
|
622
|
+
}
|
|
623
|
+
return parameters.length === 0 ? "" : `\x1B[${parameters.join(";")}m`;
|
|
624
|
+
}
|
|
625
|
+
function paint(text, prefix) {
|
|
626
|
+
return prefix === "" ? text : prefix + text + RESET;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/output/table.ts
|
|
630
|
+
var BORDERS = {
|
|
631
|
+
unicode: {
|
|
632
|
+
vertical: "\u2502",
|
|
633
|
+
horizontal: "\u2500",
|
|
634
|
+
top: ["\u250C", "\u252C", "\u2510"],
|
|
635
|
+
middle: ["\u251C", "\u253C", "\u2524"],
|
|
636
|
+
bottom: ["\u2514", "\u2534", "\u2518"],
|
|
637
|
+
padding: 1,
|
|
638
|
+
columnOverhead: 3,
|
|
639
|
+
tableOverhead: 1
|
|
640
|
+
},
|
|
641
|
+
ascii: {
|
|
642
|
+
vertical: "|",
|
|
643
|
+
horizontal: "-",
|
|
644
|
+
top: ["+", "+", "+"],
|
|
645
|
+
middle: ["+", "+", "+"],
|
|
646
|
+
bottom: ["+", "+", "+"],
|
|
647
|
+
padding: 1,
|
|
648
|
+
columnOverhead: 3,
|
|
649
|
+
tableOverhead: 1
|
|
650
|
+
},
|
|
651
|
+
none: {
|
|
652
|
+
vertical: "",
|
|
653
|
+
horizontal: "\u2500",
|
|
654
|
+
top: ["", "", ""],
|
|
655
|
+
middle: ["", "", ""],
|
|
656
|
+
bottom: ["", "", ""],
|
|
657
|
+
padding: 1,
|
|
658
|
+
columnOverhead: 2,
|
|
659
|
+
tableOverhead: 0
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
var reifydbDarkTableTheme = {
|
|
663
|
+
border: { color: "#3f3f46" },
|
|
664
|
+
header: { color: "#818cf8", bold: true },
|
|
665
|
+
values: {
|
|
666
|
+
none: {
|
|
667
|
+
color: NONE_PRESENTATION.muted ? "#52525b" : void 0,
|
|
668
|
+
italic: NONE_PRESENTATION.italic
|
|
669
|
+
},
|
|
670
|
+
boolean: { color: "#fbbf24" },
|
|
671
|
+
number: { color: "#a5b4fc" },
|
|
672
|
+
temporal: { color: "#5eead4" },
|
|
673
|
+
uuid: { color: "#c4b5fd" },
|
|
674
|
+
string: { color: "#e4e4e7" },
|
|
675
|
+
blob: { color: "#a1a1aa" }
|
|
676
|
+
}
|
|
677
|
+
};
|
|
578
678
|
var TableRenderer = class {
|
|
579
679
|
data;
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
680
|
+
glyphs;
|
|
681
|
+
plan;
|
|
682
|
+
borderPrefix;
|
|
683
|
+
headerPrefix;
|
|
684
|
+
valuePrefixes;
|
|
583
685
|
constructor(data, options = {}) {
|
|
584
686
|
this.data = data;
|
|
585
|
-
this.
|
|
586
|
-
|
|
587
|
-
this.
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
for (const row of this.data) {
|
|
593
|
-
for (const [key, value] of Object.entries(row)) {
|
|
594
|
-
const valueStr = this.formatValue(value);
|
|
595
|
-
const currentMax = columns.get(key) ?? key.length;
|
|
596
|
-
columns.set(key, Math.max(currentMax, valueStr.length));
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
return Array.from(columns.entries()).map(([name, width]) => ({
|
|
600
|
-
name,
|
|
601
|
-
width: Math.max(width, name.length)
|
|
602
|
-
}));
|
|
603
|
-
}
|
|
604
|
-
formatValue(value) {
|
|
605
|
-
if (value === null || value === void 0) {
|
|
606
|
-
return "undefined";
|
|
607
|
-
}
|
|
608
|
-
if (value && typeof value === "object" && "type" in value && typeof value.toString === "function") {
|
|
609
|
-
return value.toString();
|
|
610
|
-
}
|
|
611
|
-
if (typeof value === "object") {
|
|
612
|
-
return JSON.stringify(value);
|
|
687
|
+
this.glyphs = BORDERS[options.border ?? "unicode"];
|
|
688
|
+
const theme = options.theme ?? reifydbDarkTableTheme;
|
|
689
|
+
this.borderPrefix = theme.border ? sgr(theme.border) : "";
|
|
690
|
+
this.headerPrefix = theme.header ? sgr(theme.header) : "";
|
|
691
|
+
this.valuePrefixes = /* @__PURE__ */ new Map();
|
|
692
|
+
for (const [role, style] of Object.entries(theme.values ?? {})) {
|
|
693
|
+
if (style) this.valuePrefixes.set(role, sgr(style));
|
|
613
694
|
}
|
|
614
|
-
|
|
695
|
+
const columns = options.columns ?? inferColumns(data);
|
|
696
|
+
this.plan = planTable(data, columns, {
|
|
697
|
+
width: options.truncate ? options.maxWidth : void 0,
|
|
698
|
+
columnOverhead: this.glyphs.columnOverhead,
|
|
699
|
+
tableOverhead: this.glyphs.tableOverhead
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
get columns() {
|
|
703
|
+
return this.plan.columns.map((entry) => ({ name: entry.column.name, width: entry.width }));
|
|
615
704
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (maxLen <= 3) return str.slice(0, maxLen);
|
|
619
|
-
return str.slice(0, maxLen - 3) + "...";
|
|
705
|
+
get dropped() {
|
|
706
|
+
return this.plan.dropped.map((column) => column.name);
|
|
620
707
|
}
|
|
621
708
|
render() {
|
|
622
|
-
if (this.data.length === 0 || this.columns.length === 0) {
|
|
709
|
+
if (this.data.length === 0 || this.plan.columns.length === 0) {
|
|
623
710
|
return ["(no results)"];
|
|
624
711
|
}
|
|
712
|
+
const bordered = this.glyphs.vertical !== "";
|
|
625
713
|
const lines = [];
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
const result = this.fitColumns(this.maxWidth);
|
|
630
|
-
columnsToShow = result.columns;
|
|
631
|
-
widths = result.widths;
|
|
632
|
-
}
|
|
633
|
-
const separator = "+" + widths.map((w) => "-".repeat(w + 2)).join("+") + "+";
|
|
634
|
-
lines.push(separator);
|
|
635
|
-
const headerCells = columnsToShow.map(
|
|
636
|
-
(col, i) => this.padCenter(col.name, widths[i])
|
|
637
|
-
);
|
|
638
|
-
lines.push("| " + headerCells.join(" | ") + " |");
|
|
639
|
-
lines.push(separator);
|
|
714
|
+
if (bordered) lines.push(this.rule(this.glyphs.top));
|
|
715
|
+
lines.push(this.headerRow());
|
|
716
|
+
lines.push(this.rule(this.glyphs.middle));
|
|
640
717
|
for (const row of this.data) {
|
|
641
|
-
|
|
642
|
-
const value = this.formatValue(row[col.name]);
|
|
643
|
-
const truncated = this.truncate ? this.truncateString(value, widths[i]) : value;
|
|
644
|
-
return this.padRight(truncated, widths[i]);
|
|
645
|
-
});
|
|
646
|
-
lines.push("| " + cells.join(" | ") + " |");
|
|
718
|
+
lines.push(this.dataRow(row));
|
|
647
719
|
}
|
|
648
|
-
lines.push(
|
|
720
|
+
if (bordered) lines.push(this.rule(this.glyphs.bottom));
|
|
649
721
|
return lines;
|
|
650
722
|
}
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
for (const col of this.columns) {
|
|
656
|
-
const colWidth = Math.min(col.width, 40);
|
|
657
|
-
const totalColWidth = colWidth + 3;
|
|
658
|
-
if (currentWidth + totalColWidth <= maxWidth) {
|
|
659
|
-
columns.push(col);
|
|
660
|
-
widths.push(colWidth);
|
|
661
|
-
currentWidth += totalColWidth;
|
|
662
|
-
} else {
|
|
663
|
-
break;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
if (columns.length === 0 && this.columns.length > 0) {
|
|
667
|
-
const firstCol = this.columns[0];
|
|
668
|
-
const availableWidth = maxWidth - 4;
|
|
669
|
-
columns.push(firstCol);
|
|
670
|
-
widths.push(Math.max(availableWidth, 10));
|
|
723
|
+
rule(corners) {
|
|
724
|
+
const pad = this.glyphs.padding * 2;
|
|
725
|
+
if (this.glyphs.vertical === "") {
|
|
726
|
+
return paint(this.glyphs.horizontal.repeat(this.width()), this.borderPrefix);
|
|
671
727
|
}
|
|
672
|
-
|
|
728
|
+
const segments = this.plan.columns.map(
|
|
729
|
+
(entry) => this.glyphs.horizontal.repeat(entry.width + pad)
|
|
730
|
+
);
|
|
731
|
+
const [left, joint, right] = corners;
|
|
732
|
+
return paint(left + segments.join(joint) + right, this.borderPrefix);
|
|
673
733
|
}
|
|
674
|
-
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const right = padding - left;
|
|
679
|
-
return " ".repeat(left) + str + " ".repeat(right);
|
|
734
|
+
width() {
|
|
735
|
+
const gaps = this.glyphs.columnOverhead * (this.plan.columns.length - 1);
|
|
736
|
+
const body = this.plan.columns.reduce((total, entry) => total + entry.width, 0);
|
|
737
|
+
return this.glyphs.padding + body + gaps;
|
|
680
738
|
}
|
|
681
|
-
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
739
|
+
headerRow() {
|
|
740
|
+
const cells = this.plan.columns.map(
|
|
741
|
+
(entry) => paint(padToWidth(entry.column.name, entry.width, entry.column.align), this.headerPrefix)
|
|
742
|
+
);
|
|
743
|
+
return this.joinCells(cells);
|
|
744
|
+
}
|
|
745
|
+
dataRow(row) {
|
|
746
|
+
const cells = this.plan.columns.map((entry) => {
|
|
747
|
+
const value = row[entry.column.name];
|
|
748
|
+
const text = padToWidth(cellText(value, entry.width), entry.width, entry.column.align);
|
|
749
|
+
return paint(text, this.valuePrefixes.get(valueRole(value)) ?? "");
|
|
750
|
+
});
|
|
751
|
+
return this.joinCells(cells);
|
|
752
|
+
}
|
|
753
|
+
joinCells(cells) {
|
|
754
|
+
const pad = " ".repeat(this.glyphs.padding);
|
|
755
|
+
if (this.glyphs.vertical === "") {
|
|
756
|
+
const gap = " ".repeat(this.glyphs.columnOverhead);
|
|
757
|
+
return pad + cells.join(gap);
|
|
758
|
+
}
|
|
759
|
+
const bar = paint(this.glyphs.vertical, this.borderPrefix);
|
|
760
|
+
return bar + pad + cells.join(pad + bar + pad) + pad + bar;
|
|
685
761
|
}
|
|
686
762
|
};
|
|
687
763
|
|
|
@@ -690,49 +766,62 @@ var C2 = TerminalAdapter.COLORS;
|
|
|
690
766
|
var OutputFormatter = class {
|
|
691
767
|
terminal;
|
|
692
768
|
displayMode;
|
|
693
|
-
|
|
769
|
+
border;
|
|
770
|
+
theme;
|
|
771
|
+
constructor(terminal, displayMode = "full", options = {}) {
|
|
694
772
|
this.terminal = terminal;
|
|
695
773
|
this.displayMode = displayMode;
|
|
774
|
+
this.border = options.border;
|
|
775
|
+
this.theme = options.theme;
|
|
696
776
|
}
|
|
697
777
|
setDisplayMode(mode) {
|
|
698
778
|
this.displayMode = mode;
|
|
699
779
|
}
|
|
700
780
|
formatResult(result) {
|
|
701
781
|
if (!result.success) {
|
|
702
|
-
this.formatError(result.error ?? "Unknown error", result.
|
|
782
|
+
this.formatError(result.error ?? "Unknown error", result.executionTime);
|
|
703
783
|
return;
|
|
704
784
|
}
|
|
705
785
|
if (!result.data || result.data.length === 0) {
|
|
706
786
|
this.terminal.writeln("");
|
|
707
787
|
this.terminal.writeln(`${C2.dim}Query executed successfully. No rows returned.${C2.reset}`);
|
|
708
|
-
this.formatExecutionTime(result.
|
|
788
|
+
this.formatExecutionTime(result.executionTime);
|
|
709
789
|
return;
|
|
710
790
|
}
|
|
711
|
-
this.formatTable(result
|
|
791
|
+
this.formatTable(result, result.executionTime);
|
|
712
792
|
}
|
|
713
|
-
formatTable(
|
|
793
|
+
formatTable(result, executionTime) {
|
|
794
|
+
const data = result.data ?? [];
|
|
714
795
|
const renderer = new TableRenderer(data, {
|
|
715
796
|
maxWidth: this.displayMode === "truncate" ? this.terminal.cols - 2 : void 0,
|
|
716
|
-
truncate: this.displayMode === "truncate"
|
|
797
|
+
truncate: this.displayMode === "truncate",
|
|
798
|
+
border: this.border,
|
|
799
|
+
theme: this.theme,
|
|
800
|
+
columns: result.columns
|
|
717
801
|
});
|
|
718
|
-
const lines = renderer.render();
|
|
719
802
|
this.terminal.writeln("");
|
|
720
|
-
for (const line of
|
|
803
|
+
for (const line of renderer.render()) {
|
|
721
804
|
this.terminal.writeln(line);
|
|
722
805
|
}
|
|
723
|
-
const
|
|
806
|
+
const dropped = renderer.dropped;
|
|
807
|
+
if (dropped.length > 0) {
|
|
808
|
+
this.terminal.writeln(
|
|
809
|
+
`${C2.dim}${dropped.length} more column${dropped.length !== 1 ? "s" : ""}: ${dropped.join(", ")}${C2.reset}`
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
const rowCount = data.length;
|
|
724
813
|
this.terminal.writeln("");
|
|
725
814
|
this.terminal.write(
|
|
726
|
-
`${C2.green}${
|
|
815
|
+
`${C2.green}${rowCount} row${rowCount !== 1 ? "s" : ""}${C2.reset}`
|
|
727
816
|
);
|
|
728
|
-
this.formatExecutionTime(
|
|
817
|
+
this.formatExecutionTime(executionTime);
|
|
729
818
|
}
|
|
730
|
-
formatError(error,
|
|
819
|
+
formatError(error, executionTime) {
|
|
731
820
|
this.terminal.writeln("");
|
|
732
821
|
for (const line of error.split("\n")) {
|
|
733
822
|
this.terminal.writeln(line);
|
|
734
823
|
}
|
|
735
|
-
this.formatExecutionTime(
|
|
824
|
+
this.formatExecutionTime(executionTime);
|
|
736
825
|
}
|
|
737
826
|
formatExecutionTime(ms) {
|
|
738
827
|
this.terminal.writeln(` ${C2.dim}(${ms}ms)${C2.reset}`);
|
|
@@ -760,12 +849,16 @@ var Shell = class {
|
|
|
760
849
|
continuationPrompt;
|
|
761
850
|
continuationPromptLen;
|
|
762
851
|
welcomeMessage;
|
|
852
|
+
initialInput;
|
|
853
|
+
highlight;
|
|
763
854
|
onExit;
|
|
764
855
|
onFullscreenChange;
|
|
765
856
|
constructor(container, options) {
|
|
766
857
|
this.executor = options.executor;
|
|
767
858
|
this.displayMode = options.displayMode ?? "full";
|
|
768
859
|
this.welcomeMessage = options.welcomeMessage;
|
|
860
|
+
this.initialInput = options.initialInput;
|
|
861
|
+
this.highlight = options.highlight;
|
|
769
862
|
this.onExit = options.onExit;
|
|
770
863
|
this.onFullscreenChange = options.onFullscreenChange;
|
|
771
864
|
this.primaryPrompt = options.prompt ?? DEFAULT_PRIMARY_PROMPT;
|
|
@@ -774,14 +867,21 @@ var Shell = class {
|
|
|
774
867
|
this.continuationPromptLen = options.continuationPromptLength ?? DEFAULT_CONTINUATION_PROMPT_LEN;
|
|
775
868
|
this.terminal = new TerminalAdapter(container, options.theme);
|
|
776
869
|
this.lineEditor = new LineEditor(this.terminal);
|
|
777
|
-
this.history = new CommandHistory(options.historyStorage, options.
|
|
870
|
+
this.history = new CommandHistory(options.historyStorage, options.historyKey);
|
|
778
871
|
this.multiline = new MultilineBuffer();
|
|
779
|
-
this.formatter = new OutputFormatter(this.terminal, this.displayMode
|
|
872
|
+
this.formatter = new OutputFormatter(this.terminal, this.displayMode, {
|
|
873
|
+
border: options.tableBorder,
|
|
874
|
+
theme: options.tableTheme
|
|
875
|
+
});
|
|
780
876
|
this.setupKeyHandler();
|
|
781
877
|
}
|
|
782
878
|
start() {
|
|
783
879
|
this.showWelcomeBanner();
|
|
784
880
|
this.showPrompt();
|
|
881
|
+
if (this.initialInput) {
|
|
882
|
+
this.lineEditor.setValue(this.initialInput);
|
|
883
|
+
this.redrawLine();
|
|
884
|
+
}
|
|
785
885
|
this.terminal.focus();
|
|
786
886
|
}
|
|
787
887
|
dispose() {
|
|
@@ -929,7 +1029,8 @@ var Shell = class {
|
|
|
929
1029
|
}
|
|
930
1030
|
redrawLine() {
|
|
931
1031
|
const prompt = this.multiline.isEmpty ? this.primaryPrompt : this.continuationPrompt;
|
|
932
|
-
this.
|
|
1032
|
+
const context = this.multiline.isEmpty ? void 0 : this.multiline.content + " ";
|
|
1033
|
+
this.lineEditor.render(prompt, this.highlight?.(this.lineEditor.value, context));
|
|
933
1034
|
}
|
|
934
1035
|
navigateHistory(direction) {
|
|
935
1036
|
let entry;
|
|
@@ -986,12 +1087,47 @@ var Shell = class {
|
|
|
986
1087
|
}
|
|
987
1088
|
clearScreen() {
|
|
988
1089
|
this.terminal.write(TerminalAdapter.clearScreen());
|
|
989
|
-
this.
|
|
990
|
-
this.terminal.write(this.lineEditor.value);
|
|
1090
|
+
this.redrawLine();
|
|
991
1091
|
}
|
|
992
1092
|
};
|
|
993
1093
|
|
|
1094
|
+
// src/input/highlight.ts
|
|
1095
|
+
import { tokenizeRql } from "@reifydb/core";
|
|
1096
|
+
var reifydbDarkPalette = {
|
|
1097
|
+
keyword: { color: "#818cf8", bold: true },
|
|
1098
|
+
string: { color: "#a5b4fc" },
|
|
1099
|
+
number: { color: "#a5b4fc", bold: true },
|
|
1100
|
+
comment: { color: "#71717a", italic: true },
|
|
1101
|
+
operator: { color: "#a1a1aa" },
|
|
1102
|
+
identifier: { color: "#e4e4e7" },
|
|
1103
|
+
key: { color: "#818cf8", bold: true },
|
|
1104
|
+
namespace: { color: "#5eead4" },
|
|
1105
|
+
entity: { color: "#99f6e4" },
|
|
1106
|
+
function: { color: "#fbbf24" }
|
|
1107
|
+
};
|
|
1108
|
+
function rqlHighlighter(palette = reifydbDarkPalette) {
|
|
1109
|
+
const prefixes = /* @__PURE__ */ new Map();
|
|
1110
|
+
for (const [kind, style] of Object.entries(palette)) {
|
|
1111
|
+
if (style) prefixes.set(kind, sgr(style));
|
|
1112
|
+
}
|
|
1113
|
+
return (line, context) => {
|
|
1114
|
+
const offset = context?.length ?? 0;
|
|
1115
|
+
const end = offset + line.length;
|
|
1116
|
+
let painted = "";
|
|
1117
|
+
for (const token of tokenizeRql((context ?? "") + line)) {
|
|
1118
|
+
const start = Math.max(token.start, offset);
|
|
1119
|
+
const stop = Math.min(token.end, end);
|
|
1120
|
+
if (start >= stop) continue;
|
|
1121
|
+
const text = line.slice(start - offset, stop - offset);
|
|
1122
|
+
const prefix = prefixes.get(token.kind);
|
|
1123
|
+
painted += prefix ? prefix + text + RESET : text;
|
|
1124
|
+
}
|
|
1125
|
+
return painted;
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
|
|
994
1129
|
// src/executors/wasm-executor.ts
|
|
1130
|
+
import { inferColumns as inferColumns2 } from "@reifydb/core";
|
|
995
1131
|
var WasmExecutor = class {
|
|
996
1132
|
db;
|
|
997
1133
|
constructor(db) {
|
|
@@ -1004,24 +1140,26 @@ var WasmExecutor = class {
|
|
|
1004
1140
|
return {
|
|
1005
1141
|
success: true,
|
|
1006
1142
|
data: [],
|
|
1007
|
-
|
|
1143
|
+
executionTime: 0
|
|
1008
1144
|
};
|
|
1009
1145
|
}
|
|
1010
|
-
const
|
|
1146
|
+
const startTime = performance.now();
|
|
1011
1147
|
try {
|
|
1012
1148
|
const results = await this.db.admin(query);
|
|
1013
1149
|
const endTime = performance.now();
|
|
1150
|
+
const data = Array.isArray(results) ? results : [];
|
|
1014
1151
|
return {
|
|
1015
1152
|
success: true,
|
|
1016
|
-
data
|
|
1017
|
-
|
|
1153
|
+
data,
|
|
1154
|
+
columns: inferColumns2(data),
|
|
1155
|
+
executionTime: Math.round(endTime - startTime)
|
|
1018
1156
|
};
|
|
1019
1157
|
} catch (error) {
|
|
1020
1158
|
const endTime = performance.now();
|
|
1021
1159
|
return {
|
|
1022
1160
|
success: false,
|
|
1023
1161
|
error: error instanceof Error ? error.message : String(error),
|
|
1024
|
-
|
|
1162
|
+
executionTime: Math.round(endTime - startTime)
|
|
1025
1163
|
};
|
|
1026
1164
|
}
|
|
1027
1165
|
}
|
|
@@ -1040,16 +1178,16 @@ var WasmExecutor = class {
|
|
|
1040
1178
|
return [];
|
|
1041
1179
|
}
|
|
1042
1180
|
}
|
|
1043
|
-
async getShape(
|
|
1181
|
+
async getShape(tableName) {
|
|
1044
1182
|
try {
|
|
1045
1183
|
const result = await this.db.admin(
|
|
1046
|
-
`FROM system::columns FILTER table = "${
|
|
1184
|
+
`FROM system::columns FILTER table = "${tableName}" MAP { name, type }`
|
|
1047
1185
|
);
|
|
1048
1186
|
if (Array.isArray(result) && result.length > 0) {
|
|
1049
1187
|
const columns = result.map(
|
|
1050
1188
|
(row) => ` ${row.name}: ${row.type}`
|
|
1051
1189
|
).join(",\n");
|
|
1052
|
-
return `${
|
|
1190
|
+
return `${tableName} {
|
|
1053
1191
|
${columns}
|
|
1054
1192
|
}`;
|
|
1055
1193
|
}
|
|
@@ -1061,6 +1199,7 @@ ${columns}
|
|
|
1061
1199
|
};
|
|
1062
1200
|
|
|
1063
1201
|
// src/executors/ws-executor.ts
|
|
1202
|
+
import { inferColumns as inferColumns3 } from "@reifydb/core";
|
|
1064
1203
|
var WsExecutor = class {
|
|
1065
1204
|
client;
|
|
1066
1205
|
constructor(client) {
|
|
@@ -1073,10 +1212,10 @@ var WsExecutor = class {
|
|
|
1073
1212
|
return {
|
|
1074
1213
|
success: true,
|
|
1075
1214
|
data: [],
|
|
1076
|
-
|
|
1215
|
+
executionTime: 0
|
|
1077
1216
|
};
|
|
1078
1217
|
}
|
|
1079
|
-
const
|
|
1218
|
+
const startTime = performance.now();
|
|
1080
1219
|
try {
|
|
1081
1220
|
const frames = await this.client.admin(query, null, []);
|
|
1082
1221
|
const endTime = performance.now();
|
|
@@ -1094,23 +1233,24 @@ var WsExecutor = class {
|
|
|
1094
1233
|
return {
|
|
1095
1234
|
success: true,
|
|
1096
1235
|
data,
|
|
1097
|
-
|
|
1236
|
+
columns: inferColumns3(data),
|
|
1237
|
+
executionTime: Math.round(endTime - startTime)
|
|
1098
1238
|
};
|
|
1099
1239
|
} catch (error) {
|
|
1100
1240
|
const endTime = performance.now();
|
|
1101
|
-
let
|
|
1241
|
+
let errorMessage;
|
|
1102
1242
|
if (error && typeof error === "object" && "diagnostic" in error) {
|
|
1103
1243
|
const diagnostic = error.diagnostic;
|
|
1104
|
-
|
|
1244
|
+
errorMessage = diagnostic.message;
|
|
1105
1245
|
} else if (error instanceof Error) {
|
|
1106
|
-
|
|
1246
|
+
errorMessage = error.message;
|
|
1107
1247
|
} else {
|
|
1108
|
-
|
|
1248
|
+
errorMessage = String(error);
|
|
1109
1249
|
}
|
|
1110
1250
|
return {
|
|
1111
1251
|
success: false,
|
|
1112
|
-
error:
|
|
1113
|
-
|
|
1252
|
+
error: errorMessage,
|
|
1253
|
+
executionTime: Math.round(endTime - startTime)
|
|
1114
1254
|
};
|
|
1115
1255
|
}
|
|
1116
1256
|
}
|
|
@@ -1132,10 +1272,10 @@ var WsExecutor = class {
|
|
|
1132
1272
|
return [];
|
|
1133
1273
|
}
|
|
1134
1274
|
}
|
|
1135
|
-
async getShape(
|
|
1275
|
+
async getShape(tableName) {
|
|
1136
1276
|
try {
|
|
1137
1277
|
const frames = await this.client.admin(
|
|
1138
|
-
`FROM system::columns FILTER table = "${
|
|
1278
|
+
`FROM system::columns FILTER table = "${tableName}" MAP { name, type }`,
|
|
1139
1279
|
null,
|
|
1140
1280
|
[]
|
|
1141
1281
|
);
|
|
@@ -1145,7 +1285,7 @@ var WsExecutor = class {
|
|
|
1145
1285
|
const r = row;
|
|
1146
1286
|
return ` ${this.extractValue(r.name)}: ${this.extractValue(r.type)}`;
|
|
1147
1287
|
}).join(",\n");
|
|
1148
|
-
return `${
|
|
1288
|
+
return `${tableName} {
|
|
1149
1289
|
${columns}
|
|
1150
1290
|
}`;
|
|
1151
1291
|
}
|
|
@@ -1169,12 +1309,19 @@ export {
|
|
|
1169
1309
|
MemoryHistoryStorage,
|
|
1170
1310
|
MultilineBuffer,
|
|
1171
1311
|
OutputFormatter,
|
|
1312
|
+
RESET,
|
|
1172
1313
|
Shell,
|
|
1173
1314
|
TableRenderer,
|
|
1174
1315
|
TerminalAdapter,
|
|
1175
1316
|
WasmExecutor,
|
|
1176
1317
|
WsExecutor,
|
|
1177
1318
|
defaultTheme,
|
|
1178
|
-
handleDotCommand
|
|
1319
|
+
handleDotCommand,
|
|
1320
|
+
paint,
|
|
1321
|
+
reifydbDarkPalette,
|
|
1322
|
+
reifydbDarkTableTheme,
|
|
1323
|
+
reifydbDarkTheme,
|
|
1324
|
+
rqlHighlighter,
|
|
1325
|
+
sgr
|
|
1179
1326
|
};
|
|
1180
1327
|
//# sourceMappingURL=index.js.map
|