layerbase 0.1.3 → 0.3.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.
Files changed (81) hide show
  1. package/{src/cli.tsx → dist/cli.js} +37 -36
  2. package/dist/cli.js.map +1 -0
  3. package/dist/commands/alias.js +27 -0
  4. package/dist/commands/alias.js.map +1 -0
  5. package/dist/commands/connect.js +51 -0
  6. package/dist/commands/connect.js.map +1 -0
  7. package/dist/commands/connection-string.js +43 -0
  8. package/dist/commands/connection-string.js.map +1 -0
  9. package/dist/commands/interactive.js +148 -0
  10. package/dist/commands/interactive.js.map +1 -0
  11. package/dist/commands/login.js +61 -0
  12. package/dist/commands/login.js.map +1 -0
  13. package/dist/commands/logout.js +25 -0
  14. package/dist/commands/logout.js.map +1 -0
  15. package/dist/commands/ls.js +60 -0
  16. package/dist/commands/ls.js.map +1 -0
  17. package/dist/commands/whoami.js +49 -0
  18. package/dist/commands/whoami.js.map +1 -0
  19. package/dist/lib/alias.js +68 -0
  20. package/dist/lib/alias.js.map +1 -0
  21. package/dist/lib/browser-login.js +78 -0
  22. package/dist/lib/browser-login.js.map +1 -0
  23. package/dist/lib/cloud-api.js +44 -0
  24. package/dist/lib/cloud-api.js.map +1 -0
  25. package/dist/lib/commands.js +73 -0
  26. package/dist/lib/commands.js.map +1 -0
  27. package/dist/lib/config.js +32 -0
  28. package/dist/lib/config.js.map +1 -0
  29. package/dist/lib/engines.js +89 -0
  30. package/dist/lib/engines.js.map +1 -0
  31. package/dist/lib/format.js +38 -0
  32. package/dist/lib/format.js.map +1 -0
  33. package/dist/lib/launch.js +43 -0
  34. package/dist/lib/launch.js.map +1 -0
  35. package/dist/lib/open-browser.js +18 -0
  36. package/dist/lib/open-browser.js.map +1 -0
  37. package/dist/lib/run-spindb.js +49 -0
  38. package/dist/lib/run-spindb.js.map +1 -0
  39. package/dist/lib/token.js +15 -0
  40. package/dist/lib/token.js.map +1 -0
  41. package/dist/ui/app.js +27 -0
  42. package/dist/ui/app.js.map +1 -0
  43. package/dist/ui/brand.js +8 -0
  44. package/dist/ui/brand.js.map +1 -0
  45. package/dist/ui/connecting.js +7 -0
  46. package/dist/ui/connecting.js.map +1 -0
  47. package/dist/ui/menu.js +33 -0
  48. package/dist/ui/menu.js.map +1 -0
  49. package/dist/ui/press-enter.js +13 -0
  50. package/dist/ui/press-enter.js.map +1 -0
  51. package/dist/ui/prompt.js +59 -0
  52. package/dist/ui/prompt.js.map +1 -0
  53. package/dist/ui/unknown.js +12 -0
  54. package/dist/ui/unknown.js.map +1 -0
  55. package/package.json +15 -10
  56. package/bin/layerbase.mjs +0 -15
  57. package/src/commands/alias.tsx +0 -28
  58. package/src/commands/connect.tsx +0 -66
  59. package/src/commands/connection-string.tsx +0 -49
  60. package/src/commands/interactive.tsx +0 -168
  61. package/src/commands/login.tsx +0 -103
  62. package/src/commands/logout.tsx +0 -27
  63. package/src/commands/ls.tsx +0 -99
  64. package/src/commands/whoami.tsx +0 -64
  65. package/src/lib/alias.ts +0 -84
  66. package/src/lib/browser-login.ts +0 -115
  67. package/src/lib/cloud-api.ts +0 -96
  68. package/src/lib/config.ts +0 -45
  69. package/src/lib/engines.ts +0 -124
  70. package/src/lib/format.ts +0 -47
  71. package/src/lib/launch.ts +0 -47
  72. package/src/lib/open-browser.ts +0 -20
  73. package/src/lib/run-spindb.ts +0 -51
  74. package/src/lib/token.ts +0 -19
  75. package/src/ui/app.tsx +0 -38
  76. package/src/ui/brand.tsx +0 -15
  77. package/src/ui/connecting.tsx +0 -13
  78. package/src/ui/menu.tsx +0 -56
  79. package/src/ui/press-enter.tsx +0 -11
  80. package/src/ui/unknown.tsx +0 -17
  81. package/tsconfig.json +0 -17
package/dist/ui/app.js ADDED
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Login } from '../commands/login.js';
3
+ import { Logout } from '../commands/logout.js';
4
+ import { List } from '../commands/ls.js';
5
+ import { Whoami } from '../commands/whoami.js';
6
+ import { Alias } from '../commands/alias.js';
7
+ import { ConnectionString } from '../commands/connection-string.js';
8
+ import { Unknown } from '../ui/unknown.js';
9
+ export function App({ command, args, flags }) {
10
+ switch (command) {
11
+ case 'login':
12
+ return _jsx(Login, { flags: flags });
13
+ case 'logout':
14
+ return _jsx(Logout, {});
15
+ case 'ls':
16
+ return _jsx(List, { json: flags.json ?? false });
17
+ case 'whoami':
18
+ return _jsx(Whoami, { json: flags.json ?? false });
19
+ case 'alias':
20
+ return _jsx(Alias, {});
21
+ case 'connection-string':
22
+ return _jsx(ConnectionString, { dbRef: args[0] });
23
+ default:
24
+ return _jsx(Unknown, { command: command });
25
+ }
26
+ }
27
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/ui/app.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AActC,MAAM,UAAU,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAY;IACpD,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,OAAO;YACV,OAAO,KAAC,KAAK,IAAC,KAAK,EAAE,KAAK,GAAI,CAAA;QAChC,KAAK,QAAQ;YACX,OAAO,KAAC,MAAM,KAAG,CAAA;QACnB,KAAK,IAAI;YACP,OAAO,KAAC,IAAI,IAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,GAAI,CAAA;QAC5C,KAAK,QAAQ;YACX,OAAO,KAAC,MAAM,IAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,GAAI,CAAA;QAC9C,KAAK,OAAO;YACV,OAAO,KAAC,KAAK,KAAG,CAAA;QAClB,KAAK,mBAAmB;YACtB,OAAO,KAAC,gBAAgB,IAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,GAAI,CAAA;QAC7C;YACE,OAAO,KAAC,OAAO,IAAC,OAAO,EAAE,OAAO,GAAI,CAAA;IACxC,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ // Soft Layerbase blue. Truecolor terminals get the exact shade; others degrade.
4
+ export const ACCENT = '#7c9cff';
5
+ export function Header({ subtitle }) {
6
+ return (_jsxs(Box, { marginBottom: 1, children: [_jsxs(Text, { bold: true, color: ACCENT, children: ['◆', " Layerbase"] }), subtitle ? _jsxs(Text, { dimColor: true, children: [" ", subtitle] }) : null] }));
7
+ }
8
+ //# sourceMappingURL=brand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/ui/brand.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE/B,gFAAgF;AAChF,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAA;AAE/B,MAAM,UAAU,MAAM,CAAC,EAAE,QAAQ,EAAyB;IACxD,OAAO,CACL,MAAC,GAAG,IAAC,YAAY,EAAE,CAAC,aAClB,MAAC,IAAI,IAAC,IAAI,QAAC,KAAK,EAAE,MAAM,aACrB,GAAG,kBACC,EACN,QAAQ,CAAC,CAAC,CAAC,MAAC,IAAI,IAAC,QAAQ,wBAAG,QAAQ,IAAQ,CAAC,CAAC,CAAC,IAAI,IAChD,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ import Spinner from 'ink-spinner';
4
+ export function Connecting({ label }) {
5
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "cyan", children: _jsx(Spinner, { type: "dots" }) }), _jsxs(Text, { children: [" ", label] })] }));
6
+ }
7
+ //# sourceMappingURL=connecting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connecting.js","sourceRoot":"","sources":["../../src/ui/connecting.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,OAAO,MAAM,aAAa,CAAA;AAEjC,MAAM,UAAU,UAAU,CAAC,EAAE,KAAK,EAAqB;IACrD,OAAO,CACL,MAAC,GAAG,eACF,KAAC,IAAI,IAAC,KAAK,EAAC,MAAM,YAChB,KAAC,OAAO,IAAC,IAAI,EAAC,MAAM,GAAG,GAClB,EACP,MAAC,IAAI,oBAAG,KAAK,IAAQ,IACjB,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Box, Text, useInput } from 'ink';
4
+ import { ACCENT } from '../ui/brand.js';
5
+ // A minimal arrow-key select list (no dependency), so `layerbase` with no
6
+ // command lands on a menu the way spindb does.
7
+ export function Menu({ items, onSelect, }) {
8
+ const [index, setIndex] = useState(0);
9
+ useInput((input, key) => {
10
+ if (key.upArrow) {
11
+ setIndex((i) => (i === 0 ? items.length - 1 : i - 1));
12
+ }
13
+ else if (key.downArrow) {
14
+ setIndex((i) => (i === items.length - 1 ? 0 : i + 1));
15
+ }
16
+ else if (key.return) {
17
+ const item = items[index];
18
+ if (item)
19
+ onSelect(item.value);
20
+ }
21
+ else if (input === 'q') {
22
+ onSelect('quit');
23
+ }
24
+ });
25
+ // Pad labels so any hints line up in a column.
26
+ const labelWidth = Math.max(...items.map((i) => i.label.length)) + 3;
27
+ return (_jsxs(Box, { flexDirection: "column", children: [items.map((item, i) => {
28
+ const active = i === index;
29
+ const label = item.hint ? item.label.padEnd(labelWidth) : item.label;
30
+ return (_jsxs(Box, { children: [_jsxs(Text, { color: active ? ACCENT : undefined, bold: active, children: [active ? '❯ ' : ' ', label] }), item.hint ? _jsx(Text, { dimColor: true, children: item.hint }) : null] }, item.value));
31
+ }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Up/Down to move ", '·', " Enter to select ", '·', " q to quit"] }) })] }));
32
+ }
33
+ //# sourceMappingURL=menu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/ui/menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAInC,0EAA0E;AAC1E,+CAA+C;AAC/C,MAAM,UAAU,IAAI,CAAC,EACnB,KAAK,EACL,QAAQ,GAIT;IACC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAErC,QAAQ,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACtB,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAChB,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACvD,CAAC;aAAM,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;YACzB,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,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KAL7C,IAAI,CAAC,KAAK,CAMd,CACP,CAAA;YACH,CAAC,CAAC,EACF,KAAC,GAAG,IAAC,SAAS,EAAE,CAAC,YACf,MAAC,IAAI,IAAC,QAAQ,uCACK,GAAG,uBAAmB,GAAG,kBACrC,GACH,IACF,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Text, useApp, useInput } from 'ink';
3
+ // A tiny gate between a hub action and returning to the menu, so the action's
4
+ // output stays readable until the user is ready to move on.
5
+ export function PressEnter() {
6
+ const { exit } = useApp();
7
+ useInput((_input, key) => {
8
+ if (key.return)
9
+ exit();
10
+ });
11
+ return _jsx(Text, { dimColor: true, children: "Press Enter to return to the menu" });
12
+ }
13
+ //# sourceMappingURL=press-enter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"press-enter.js","sourceRoot":"","sources":["../../src/ui/press-enter.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAE5C,8EAA8E;AAC9E,4DAA4D;AAC5D,MAAM,UAAU,UAAU;IACxB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAA;IACzB,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACvB,IAAI,GAAG,CAAC,MAAM;YAAE,IAAI,EAAE,CAAA;IACxB,CAAC,CAAC,CAAA;IACF,OAAO,KAAC,IAAI,IAAC,QAAQ,wDAAyC,CAAA;AAChE,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Box, Text, useInput } from 'ink';
4
+ import { ACCENT } from '../ui/brand.js';
5
+ // A Claude-Code-style input line: type a /command (with a live palette you can
6
+ // arrow through and Tab-complete), or type free text. Enter submits. The palette
7
+ // shows only while typing a bare slash token (it hides once you add arguments).
8
+ export function Prompt({ commands, onSubmit, }) {
9
+ const [value, setValue] = useState('');
10
+ const [index, setIndex] = useState(0);
11
+ const showPalette = /^\/[a-z-]*$/i.test(value);
12
+ const query = showPalette ? value.slice(1).toLowerCase() : '';
13
+ const matches = showPalette
14
+ ? commands.filter((c) => c.name.startsWith(query))
15
+ : [];
16
+ const active = matches.length ? Math.min(index, matches.length - 1) : 0;
17
+ useInput((input, key) => {
18
+ if (key.return) {
19
+ const chosen = matches[active];
20
+ if (showPalette && chosen)
21
+ onSubmit(`/${chosen.name}`);
22
+ else
23
+ onSubmit(value);
24
+ return;
25
+ }
26
+ if (key.upArrow) {
27
+ if (matches.length)
28
+ setIndex((i) => (i <= 0 ? matches.length - 1 : i - 1));
29
+ return;
30
+ }
31
+ if (key.downArrow) {
32
+ if (matches.length)
33
+ setIndex((i) => (i >= matches.length - 1 ? 0 : i + 1));
34
+ return;
35
+ }
36
+ if (key.tab) {
37
+ const chosen = matches[active];
38
+ if (chosen) {
39
+ setValue(`/${chosen.name}`);
40
+ setIndex(0);
41
+ }
42
+ return;
43
+ }
44
+ if (key.backspace || key.delete) {
45
+ setValue((v) => v.slice(0, -1));
46
+ setIndex(0);
47
+ return;
48
+ }
49
+ if (input && !key.ctrl && !key.meta) {
50
+ setValue((v) => v + input);
51
+ setIndex(0);
52
+ }
53
+ });
54
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: ACCENT, children: '❯ ' }), _jsx(Text, { children: value }), _jsx(Text, { inverse: true, children: " " })] }), showPalette ? (_jsx(Box, { flexDirection: "column", marginTop: 1, children: matches.length === 0 ? (_jsx(Text, { dimColor: true, children: " no matching command" })) : (matches.map((c, i) => {
55
+ const on = i === active;
56
+ return (_jsxs(Box, { children: [_jsxs(Text, { color: on ? ACCENT : undefined, bold: on, children: [on ? '❯ ' : ' ', `/${c.name}`.padEnd(12)] }), _jsx(Text, { dimColor: true, children: c.summary })] }, c.name));
57
+ })) })) : (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Type a /command (or / to browse) ", '·', " Enter to run ", '·', " Ctrl+C to quit"] }) }))] }));
58
+ }
59
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/ui/prompt.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAInC,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,MAAM,UAAU,MAAM,CAAC,EACrB,QAAQ,EACR,QAAQ,GAIT;IACC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;IACtC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAErC,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC7D,MAAM,OAAO,GAAG,WAAW;QACzB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC,CAAC,EAAE,CAAA;IACN,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAEvE,QAAQ,CAAC,CA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CAAC,IAAI,CAMV,CACP,CAAA;gBACH,CAAC,CAAC,CACH,GACG,CACP,CAAC,CAAC,CAAC,CACF,KAAC,GAAG,IAAC,SAAS,EAAE,CAAC,YACf,MAAC,IAAI,IAAC,QAAQ,wDACsB,GAAG,oBAAgB,GAAG,uBAEnD,GACH,CACP,IACG,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect } from 'react';
3
+ import { Text, useApp } from 'ink';
4
+ export function Unknown({ command }) {
5
+ const { exit } = useApp();
6
+ useEffect(() => {
7
+ process.exitCode = 1;
8
+ exit();
9
+ }, [exit]);
10
+ return (_jsxs(Text, { color: "red", children: ["Unknown command: ", command, ". Run `layerbase help` to see the commands."] }));
11
+ }
12
+ //# sourceMappingURL=unknown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../src/ui/unknown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAElC,MAAM,UAAU,OAAO,CAAC,EAAE,OAAO,EAAuB;IACtD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAA;IAEzB,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;QACpB,IAAI,EAAE,CAAA;IACR,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IAEV,OAAO,CACL,MAAC,IAAI,IAAC,KAAK,EAAC,KAAK,kCACG,OAAO,mDACpB,CACR,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,34 +1,37 @@
1
1
  {
2
2
  "name": "layerbase",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "Layerbase cloud CLI: connect to your managed databases without leaking the connection string into shell history.",
5
5
  "type": "module",
6
6
  "bin": {
7
- "layerbase": "bin/layerbase.mjs",
8
- "lbase": "bin/layerbase.mjs"
7
+ "layerbase": "dist/cli.js",
8
+ "lbase": "dist/cli.js"
9
9
  },
10
10
  "files": [
11
- "bin",
12
- "src",
13
- "tsconfig.json"
11
+ "dist"
14
12
  ],
15
13
  "engines": {
16
14
  "node": ">=20"
17
15
  },
18
16
  "scripts": {
19
17
  "dev": "tsx src/cli.tsx",
20
- "start": "node bin/layerbase.mjs",
18
+ "start": "node dist/cli.js",
19
+ "build": "pnpm clean && pnpm build:tsc && pnpm build:alias && pnpm build:shebang",
20
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
21
+ "build:tsc": "tsc -p tsconfig.build.json",
22
+ "build:alias": "tsc-alias -p tsconfig.build.json --resolve-full-paths",
23
+ "build:shebang": "node scripts/shebang.mjs",
21
24
  "format": "prettier --write .",
22
25
  "lint": "eslint .",
23
26
  "check:types": "tsc --noEmit",
24
- "check": "tsc --noEmit && eslint ."
27
+ "check": "tsc --noEmit && eslint .",
28
+ "prepack": "pnpm build"
25
29
  },
26
30
  "dependencies": {
27
31
  "ink": "^7.1.0",
28
32
  "ink-spinner": "^5.0.0",
29
33
  "meow": "^14.1.0",
30
- "react": "^19.2.0",
31
- "tsx": "^4.22.4"
34
+ "react": "^19.2.0"
32
35
  },
33
36
  "devDependencies": {
34
37
  "@eslint/js": "^9.18.0",
@@ -36,6 +39,8 @@
36
39
  "@types/react": "^19.2.0",
37
40
  "eslint": "^9.18.0",
38
41
  "prettier": "^3.4.2",
42
+ "tsc-alias": "^1.8.10",
43
+ "tsx": "^4.22.4",
39
44
  "typescript": "^5.7.2",
40
45
  "typescript-eslint": "^8.18.0"
41
46
  },
package/bin/layerbase.mjs DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- // No build step: tsx transpiles the TypeScript/JSX entry at runtime.
3
- // Point tsx at our shipped tsconfig so it uses the automatic JSX runtime even
4
- // when installed under node_modules (tsx ignores a tsconfig it finds inside
5
- // node_modules during its normal walk-up, which otherwise defaults JSX to the
6
- // classic runtime and crashes with "React is not defined").
7
- import { fileURLToPath, URL } from 'node:url'
8
- import process from 'node:process'
9
- import { tsImport } from 'tsx/esm/api'
10
-
11
- process.env.TSX_TSCONFIG_PATH = fileURLToPath(
12
- new URL('../tsconfig.json', import.meta.url),
13
- )
14
-
15
- await tsImport('../src/cli.tsx', import.meta.url)
@@ -1,28 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import { Text, useApp } from 'ink'
3
- import { setupLb } from '../lib/alias'
4
-
5
- type Result = { ok: boolean; text: string }
6
-
7
- // Sets up the short `lb` command, but only when it is free on this system.
8
- export function Alias() {
9
- const { exit } = useApp()
10
- const [result, setResult] = useState<Result | null>(null)
11
-
12
- useEffect(() => {
13
- const outcome = setupLb()
14
- if (outcome.ok) {
15
- setResult({ ok: true, text: 'The `lb` shortcut is ready. Try `lb`.' })
16
- } else {
17
- process.exitCode = 1
18
- setResult({ ok: false, text: outcome.reason })
19
- }
20
- }, [])
21
-
22
- useEffect(() => {
23
- if (result) exit()
24
- }, [result, exit])
25
-
26
- if (!result) return null
27
- return <Text color={result.ok ? 'green' : 'yellow'}>{result.text}</Text>
28
- }
@@ -1,66 +0,0 @@
1
- import { render } from 'ink'
2
- import { Connecting } from '../ui/connecting'
3
- import { getConnectionInfo } from '../lib/cloud-api'
4
- import { buildLaunchPlan } from '../lib/engines'
5
- import { runClient } from '../lib/launch'
6
- import { printConnectionInfo } from '../lib/format'
7
- import type { CommandFlags } from '../ui/app'
8
-
9
- type ExecOptions = {
10
- command: string
11
- args: string[]
12
- flags: CommandFlags
13
- }
14
-
15
- // Resolve a database and hand the TTY to its native client. Returns the client's
16
- // exit code (or 1 on a resolve/launch error) WITHOUT exiting the process, so it
17
- // is reusable from both the CLI path and the interactive menu. Ink renders only
18
- // a transient spinner during the cloud lookup, then unmounts before the client
19
- // takes over the terminal.
20
- export async function connectToDatabase(options: {
21
- dbRef: string
22
- command: string
23
- print?: boolean
24
- }): Promise<number> {
25
- const { dbRef, command, print } = options
26
-
27
- const spinner = render(<Connecting label={`Resolving ${dbRef}...`} />)
28
- let info
29
- try {
30
- info = await getConnectionInfo(dbRef)
31
- } catch (error) {
32
- spinner.unmount()
33
- process.stderr.write(`${(error as Error).message}\n`)
34
- return 1
35
- }
36
- spinner.unmount()
37
-
38
- if (print) {
39
- printConnectionInfo(info)
40
- return 0
41
- }
42
-
43
- let plan
44
- try {
45
- plan = buildLaunchPlan({ info, command })
46
- } catch (error) {
47
- process.stderr.write(`${(error as Error).message}\n`)
48
- return 1
49
- }
50
-
51
- return runClient(plan)
52
- }
53
-
54
- // CLI entrypoint for connect/psql/redis-cli/mysql: resolve + launch, then exit.
55
- export async function runExec(options: ExecOptions): Promise<void> {
56
- const { command, flags } = options
57
- const dbRef = options.args[0]
58
-
59
- if (!dbRef) {
60
- process.stderr.write(`Usage: layerbase ${command} <db>\n`)
61
- process.exit(1)
62
- }
63
-
64
- const code = await connectToDatabase({ dbRef, command, print: flags.print })
65
- process.exit(code)
66
- }
@@ -1,49 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import { Text, useApp } from 'ink'
3
- import { getConnectionInfo } from '../lib/cloud-api'
4
- import { buildConnectionString } from '../lib/format'
5
-
6
- type State =
7
- | { kind: 'loading' }
8
- | { kind: 'error'; message: string }
9
- | { kind: 'done' }
10
-
11
- // Opt-in escape hatch: prints the full connection string (with password) to
12
- // stdout for piping into an app. The secure path is `layerbase connect`.
13
- export function ConnectionString({ dbRef }: { dbRef: string | undefined }) {
14
- const { exit } = useApp()
15
- const [state, setState] = useState<State>({ kind: 'loading' })
16
-
17
- useEffect(() => {
18
- async function fetchAndPrintConnectionString() {
19
- if (!dbRef) {
20
- setState({
21
- kind: 'error',
22
- message: 'Usage: layerbase connection-string <db>',
23
- })
24
- process.exitCode = 1
25
- return
26
- }
27
- try {
28
- const info = await getConnectionInfo(dbRef)
29
- process.stdout.write(`${buildConnectionString(info)}\n`)
30
- setState({ kind: 'done' })
31
- } catch (error) {
32
- setState({ kind: 'error', message: (error as Error).message })
33
- process.exitCode = 1
34
- }
35
- }
36
- fetchAndPrintConnectionString()
37
- }, [dbRef])
38
-
39
- useEffect(() => {
40
- if (state.kind !== 'loading') {
41
- exit()
42
- }
43
- }, [state, exit])
44
-
45
- if (state.kind === 'error') {
46
- return <Text color="red">{state.message}</Text>
47
- }
48
- return null
49
- }
@@ -1,168 +0,0 @@
1
- import { render, Box, Text } from 'ink'
2
- import { Menu } from '../ui/menu'
3
- import type { MenuItem } from '../ui/menu'
4
- import { Header } from '../ui/brand'
5
- import { Connecting } from '../ui/connecting'
6
- import { PressEnter } from '../ui/press-enter'
7
- import { loadCredentials } from '../lib/config'
8
- import type { StoredCredentials } from '../lib/config'
9
- import { decodeTokenClaims } from '../lib/token'
10
- import { listDatabases } from '../lib/cloud-api'
11
- import type { CloudDatabase } from '../lib/cloud-api'
12
- import { runSpindb } from '../lib/run-spindb'
13
- import { connectToDatabase } from './connect'
14
- import { lbStatus } from '../lib/alias'
15
- import { App } from '../ui/app'
16
- import type { CommandFlags } from '../ui/app'
17
-
18
- const BACK = '__back__'
19
-
20
- function clearScreen(): void {
21
- // Clear the visible screen and home the cursor (scrollback is preserved).
22
- process.stdout.write('')
23
- }
24
-
25
- function accountLine(creds: StoredCredentials | null): {
26
- text: string
27
- loggedIn: boolean
28
- } {
29
- if (!creds) return { text: 'Not signed in', loggedIn: false }
30
- const email = decodeTokenClaims(creds.token)?.email
31
- return { text: email ? `Signed in as ${email}` : 'Signed in', loggedIn: true }
32
- }
33
-
34
- function buildItems(loggedIn: boolean, lbAvailable: boolean): MenuItem[] {
35
- const items: MenuItem[] = []
36
- if (loggedIn) {
37
- items.push({ label: 'List cloud databases', value: 'ls' })
38
- items.push({ label: 'Connect to a database', value: 'connect' })
39
- } else {
40
- items.push({ label: 'Log in', value: 'login', hint: 'browser sign-in' })
41
- }
42
- items.push({ label: 'Run spindb', value: 'spindb', hint: 'local databases' })
43
- if (loggedIn) items.push({ label: 'Log out', value: 'logout' })
44
- if (lbAvailable) {
45
- items.push({ label: 'Enable the lb shortcut', value: 'alias' })
46
- }
47
- items.push({ label: 'Quit', value: 'quit' })
48
- return items
49
- }
50
-
51
- function pick(creds: StoredCredentials | null): Promise<string> {
52
- const loggedIn = Boolean(creds)
53
- const lbAvailable = lbStatus().state === 'available'
54
- const items = buildItems(loggedIn, lbAvailable)
55
- const account = accountLine(creds)
56
-
57
- return new Promise<string>((resolve) => {
58
- const app = render(
59
- <Box flexDirection="column" paddingX={1} paddingY={1}>
60
- <Header subtitle="cloud + local databases" />
61
- <Box marginBottom={1}>
62
- <Text
63
- color={account.loggedIn ? 'green' : undefined}
64
- dimColor={!account.loggedIn}
65
- >
66
- {account.text}
67
- </Text>
68
- </Box>
69
- <Menu
70
- items={items}
71
- onSelect={(value) => {
72
- app.unmount()
73
- resolve(value)
74
- }}
75
- />
76
- </Box>,
77
- )
78
- })
79
- }
80
-
81
- function pickDatabase(databases: CloudDatabase[]): Promise<string | null> {
82
- const items: MenuItem[] = databases.map((db) => ({
83
- label: db.name,
84
- value: db.id,
85
- hint: `${db.engine} · ${db.status}`,
86
- }))
87
- items.push({ label: 'Back', value: BACK })
88
-
89
- return new Promise<string | null>((resolve) => {
90
- const app = render(
91
- <Box flexDirection="column" paddingX={1} paddingY={1}>
92
- <Text bold>Pick a database to connect to</Text>
93
- <Box marginTop={1}>
94
- <Menu
95
- items={items}
96
- onSelect={(value) => {
97
- app.unmount()
98
- resolve(value === BACK ? null : value)
99
- }}
100
- />
101
- </Box>
102
- </Box>,
103
- )
104
- })
105
- }
106
-
107
- // Menu action: list the user's databases, let them pick one, and connect with
108
- // the right client. Returns to the hub when the client exits (or on Back/error).
109
- async function runConnectFlow(): Promise<void> {
110
- const spinner = render(<Connecting label="Loading your databases..." />)
111
- let databases: CloudDatabase[]
112
- try {
113
- databases = await listDatabases()
114
- } catch (error) {
115
- spinner.unmount()
116
- process.stderr.write(`${(error as Error).message}\n`)
117
- return
118
- }
119
- spinner.unmount()
120
-
121
- if (databases.length === 0) {
122
- process.stdout.write(
123
- 'No databases yet. Create one at https://layerbase.com.\n',
124
- )
125
- return
126
- }
127
-
128
- const dbRef = await pickDatabase(databases)
129
- if (!dbRef) return
130
-
131
- await connectToDatabase({ dbRef, command: 'connect' })
132
- }
133
-
134
- async function waitForEnter(): Promise<void> {
135
- const instance = render(<PressEnter />)
136
- await instance.waitUntilExit()
137
- }
138
-
139
- // The no-command experience: a small hub. Each action runs on a clean screen,
140
- // then waits for Enter and returns to the menu, so you can sign in, then list,
141
- // then connect, ... Cloud actions depend on auth; spindb is always offered.
142
- export async function runInteractive(flags: CommandFlags): Promise<void> {
143
- for (;;) {
144
- clearScreen()
145
- const creds = await loadCredentials()
146
- const choice = await pick(creds)
147
-
148
- if (choice === 'quit') {
149
- clearScreen()
150
- process.exitCode = 0
151
- return
152
- }
153
-
154
- clearScreen()
155
- if (choice === 'spindb') {
156
- await runSpindb([])
157
- } else if (choice === 'connect') {
158
- await runConnectFlow()
159
- } else {
160
- // login / logout / ls / alias run through the same Ink dispatcher as
161
- // typed commands; wait for the action to finish.
162
- const instance = render(<App command={choice} args={[]} flags={flags} />)
163
- await instance.waitUntilExit()
164
- }
165
-
166
- await waitForEnter()
167
- }
168
- }