layerbase 0.1.2 → 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/{src/cli.tsx → dist/cli.js} +36 -35
- package/dist/cli.js.map +1 -0
- package/dist/commands/alias.js +27 -0
- package/dist/commands/alias.js.map +1 -0
- package/dist/commands/connect.js +51 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/connection-string.js +43 -0
- package/dist/commands/connection-string.js.map +1 -0
- package/dist/commands/interactive.js +125 -0
- package/dist/commands/interactive.js.map +1 -0
- package/dist/commands/login.js +61 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.js +25 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/ls.js +60 -0
- package/dist/commands/ls.js.map +1 -0
- package/dist/commands/whoami.js +49 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/lib/alias.js +68 -0
- package/dist/lib/alias.js.map +1 -0
- package/dist/lib/browser-login.js +78 -0
- package/dist/lib/browser-login.js.map +1 -0
- package/dist/lib/cloud-api.js +44 -0
- package/dist/lib/cloud-api.js.map +1 -0
- package/dist/lib/config.js +32 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/engines.js +89 -0
- package/dist/lib/engines.js.map +1 -0
- package/dist/lib/format.js +38 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/launch.js +43 -0
- package/dist/lib/launch.js.map +1 -0
- package/dist/lib/open-browser.js +18 -0
- package/dist/lib/open-browser.js.map +1 -0
- package/dist/lib/run-spindb.js +49 -0
- package/dist/lib/run-spindb.js.map +1 -0
- package/dist/lib/token.js +15 -0
- package/dist/lib/token.js.map +1 -0
- package/dist/ui/app.js +27 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/brand.js +8 -0
- package/dist/ui/brand.js.map +1 -0
- package/dist/ui/connecting.js +7 -0
- package/dist/ui/connecting.js.map +1 -0
- package/dist/ui/menu.js +33 -0
- package/dist/ui/menu.js.map +1 -0
- package/dist/ui/press-enter.js +13 -0
- package/dist/ui/press-enter.js.map +1 -0
- package/dist/ui/unknown.js +12 -0
- package/dist/ui/unknown.js.map +1 -0
- package/package.json +15 -9
- package/bin/layerbase.mjs +0 -5
- package/src/commands/alias.tsx +0 -28
- package/src/commands/connect.tsx +0 -66
- package/src/commands/connection-string.tsx +0 -49
- package/src/commands/interactive.tsx +0 -168
- package/src/commands/login.tsx +0 -103
- package/src/commands/logout.tsx +0 -27
- package/src/commands/ls.tsx +0 -99
- package/src/commands/whoami.tsx +0 -64
- package/src/lib/alias.ts +0 -84
- package/src/lib/browser-login.ts +0 -115
- package/src/lib/cloud-api.ts +0 -96
- package/src/lib/config.ts +0 -45
- package/src/lib/engines.ts +0 -124
- package/src/lib/format.ts +0 -47
- package/src/lib/launch.ts +0 -47
- package/src/lib/open-browser.ts +0 -20
- package/src/lib/run-spindb.ts +0 -51
- package/src/lib/token.ts +0 -19
- package/src/ui/app.tsx +0 -38
- package/src/ui/brand.tsx +0 -15
- package/src/ui/connecting.tsx +0 -13
- package/src/ui/menu.tsx +0 -56
- package/src/ui/press-enter.tsx +0 -11
- package/src/ui/unknown.tsx +0 -17
package/src/lib/run-spindb.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process'
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
|
-
import { join, delimiter } from 'node:path'
|
|
4
|
-
|
|
5
|
-
// Is spindb installed on PATH? If so we run it by bare name (spawn resolves it
|
|
6
|
-
// via PATH); otherwise we run it through the package runner that launched
|
|
7
|
-
// layerbase, so `npx layerbase` users get `npx spindb` with no global install.
|
|
8
|
-
function spindbOnPath(): boolean {
|
|
9
|
-
const exts =
|
|
10
|
-
process.platform === 'win32' ? ['.cmd', '.exe', '.bat', ''] : ['']
|
|
11
|
-
for (const dir of (process.env.PATH ?? '').split(delimiter)) {
|
|
12
|
-
if (!dir) continue
|
|
13
|
-
for (const ext of exts) {
|
|
14
|
-
if (existsSync(join(dir, `spindb${ext}`))) return true
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return false
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function detectPackageRunner(): string {
|
|
21
|
-
const userAgent = process.env.npm_config_user_agent ?? ''
|
|
22
|
-
if (userAgent.startsWith('pnpm')) return 'pnpx'
|
|
23
|
-
if (userAgent.startsWith('bun')) return 'bunx'
|
|
24
|
-
return 'npx'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Hand the terminal to the local spindb CLI, passing through any args. This is
|
|
28
|
-
// the bridge: spindb manages local databases, layerbase adds the cloud account
|
|
29
|
-
// layer around it.
|
|
30
|
-
export async function runSpindb(args: string[] = []): Promise<number> {
|
|
31
|
-
const onPath = spindbOnPath()
|
|
32
|
-
const command = onPath ? 'spindb' : detectPackageRunner()
|
|
33
|
-
const fullArgs = onPath ? args : ['spindb', ...args]
|
|
34
|
-
|
|
35
|
-
return new Promise<number>((resolve) => {
|
|
36
|
-
const child = spawn(command, fullArgs, {
|
|
37
|
-
stdio: 'inherit',
|
|
38
|
-
// Windows needs a shell to resolve `spindb.cmd` / the package runner.
|
|
39
|
-
shell: process.platform === 'win32',
|
|
40
|
-
})
|
|
41
|
-
child.on('error', (error) => {
|
|
42
|
-
process.stderr.write(
|
|
43
|
-
`Failed to run spindb: ${error.message}\n` +
|
|
44
|
-
'Install spindb (https://github.com/robertjbass/spindb) or make sure ' +
|
|
45
|
-
'it is on your PATH.\n',
|
|
46
|
-
)
|
|
47
|
-
resolve(127)
|
|
48
|
-
})
|
|
49
|
-
child.on('exit', (code) => resolve(code ?? 0))
|
|
50
|
-
})
|
|
51
|
-
}
|
package/src/lib/token.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type TokenClaims = {
|
|
2
|
-
email?: string
|
|
3
|
-
// JWT exp claim, in SECONDS since the epoch.
|
|
4
|
-
exp?: number
|
|
5
|
-
sub?: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// Decode (without verifying) the claims from the stored JWT. Used only for
|
|
9
|
-
// friendly local display: the email and the expiry. Returns null on any parse
|
|
10
|
-
// failure.
|
|
11
|
-
export function decodeTokenClaims(token: string): TokenClaims | null {
|
|
12
|
-
const part = token.split('.')[1]
|
|
13
|
-
if (!part) return null
|
|
14
|
-
try {
|
|
15
|
-
return JSON.parse(Buffer.from(part, 'base64url').toString()) as TokenClaims
|
|
16
|
-
} catch {
|
|
17
|
-
return null
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/ui/app.tsx
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Login } from '../commands/login'
|
|
2
|
-
import { Logout } from '../commands/logout'
|
|
3
|
-
import { List } from '../commands/ls'
|
|
4
|
-
import { Whoami } from '../commands/whoami'
|
|
5
|
-
import { Alias } from '../commands/alias'
|
|
6
|
-
import { ConnectionString } from '../commands/connection-string'
|
|
7
|
-
import { Unknown } from './unknown'
|
|
8
|
-
|
|
9
|
-
export type CommandFlags = {
|
|
10
|
-
print?: boolean
|
|
11
|
-
json?: boolean
|
|
12
|
-
apiUrl?: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type AppProps = {
|
|
16
|
-
command: string
|
|
17
|
-
args: string[]
|
|
18
|
-
flags: CommandFlags
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function App({ command, args, flags }: AppProps) {
|
|
22
|
-
switch (command) {
|
|
23
|
-
case 'login':
|
|
24
|
-
return <Login flags={flags} />
|
|
25
|
-
case 'logout':
|
|
26
|
-
return <Logout />
|
|
27
|
-
case 'ls':
|
|
28
|
-
return <List json={flags.json ?? false} />
|
|
29
|
-
case 'whoami':
|
|
30
|
-
return <Whoami json={flags.json ?? false} />
|
|
31
|
-
case 'alias':
|
|
32
|
-
return <Alias />
|
|
33
|
-
case 'connection-string':
|
|
34
|
-
return <ConnectionString dbRef={args[0]} />
|
|
35
|
-
default:
|
|
36
|
-
return <Unknown command={command} />
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/ui/brand.tsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Box, Text } from 'ink'
|
|
2
|
-
|
|
3
|
-
// Soft Layerbase blue. Truecolor terminals get the exact shade; others degrade.
|
|
4
|
-
export const ACCENT = '#7c9cff'
|
|
5
|
-
|
|
6
|
-
export function Header({ subtitle }: { subtitle?: string }) {
|
|
7
|
-
return (
|
|
8
|
-
<Box marginBottom={1}>
|
|
9
|
-
<Text bold color={ACCENT}>
|
|
10
|
-
{'◆'} Layerbase
|
|
11
|
-
</Text>
|
|
12
|
-
{subtitle ? <Text dimColor> {subtitle}</Text> : null}
|
|
13
|
-
</Box>
|
|
14
|
-
)
|
|
15
|
-
}
|
package/src/ui/connecting.tsx
DELETED
package/src/ui/menu.tsx
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { Box, Text, useInput } from 'ink'
|
|
3
|
-
import { ACCENT } from './brand'
|
|
4
|
-
|
|
5
|
-
export type MenuItem = { label: string; value: string; hint?: string }
|
|
6
|
-
|
|
7
|
-
// A minimal arrow-key select list (no dependency), so `layerbase` with no
|
|
8
|
-
// command lands on a menu the way spindb does.
|
|
9
|
-
export function Menu({
|
|
10
|
-
items,
|
|
11
|
-
onSelect,
|
|
12
|
-
}: {
|
|
13
|
-
items: MenuItem[]
|
|
14
|
-
onSelect: (value: string) => void
|
|
15
|
-
}) {
|
|
16
|
-
const [index, setIndex] = useState(0)
|
|
17
|
-
|
|
18
|
-
useInput((input, key) => {
|
|
19
|
-
if (key.upArrow) {
|
|
20
|
-
setIndex((i) => (i === 0 ? items.length - 1 : i - 1))
|
|
21
|
-
} else if (key.downArrow) {
|
|
22
|
-
setIndex((i) => (i === items.length - 1 ? 0 : i + 1))
|
|
23
|
-
} else if (key.return) {
|
|
24
|
-
const item = items[index]
|
|
25
|
-
if (item) onSelect(item.value)
|
|
26
|
-
} else if (input === 'q') {
|
|
27
|
-
onSelect('quit')
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// Pad labels so any hints line up in a column.
|
|
32
|
-
const labelWidth = Math.max(...items.map((i) => i.label.length)) + 3
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<Box flexDirection="column">
|
|
36
|
-
{items.map((item, i) => {
|
|
37
|
-
const active = i === index
|
|
38
|
-
const label = item.hint ? item.label.padEnd(labelWidth) : item.label
|
|
39
|
-
return (
|
|
40
|
-
<Box key={item.value}>
|
|
41
|
-
<Text color={active ? ACCENT : undefined} bold={active}>
|
|
42
|
-
{active ? '❯ ' : ' '}
|
|
43
|
-
{label}
|
|
44
|
-
</Text>
|
|
45
|
-
{item.hint ? <Text dimColor>{item.hint}</Text> : null}
|
|
46
|
-
</Box>
|
|
47
|
-
)
|
|
48
|
-
})}
|
|
49
|
-
<Box marginTop={1}>
|
|
50
|
-
<Text dimColor>
|
|
51
|
-
Up/Down to move {'·'} Enter to select {'·'} q to quit
|
|
52
|
-
</Text>
|
|
53
|
-
</Box>
|
|
54
|
-
</Box>
|
|
55
|
-
)
|
|
56
|
-
}
|
package/src/ui/press-enter.tsx
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Text, useApp, useInput } from 'ink'
|
|
2
|
-
|
|
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) exit()
|
|
9
|
-
})
|
|
10
|
-
return <Text dimColor>Press Enter to return to the menu</Text>
|
|
11
|
-
}
|
package/src/ui/unknown.tsx
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
import { Text, useApp } from 'ink'
|
|
3
|
-
|
|
4
|
-
export function Unknown({ command }: { command: string }) {
|
|
5
|
-
const { exit } = useApp()
|
|
6
|
-
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
process.exitCode = 1
|
|
9
|
-
exit()
|
|
10
|
-
}, [exit])
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
<Text color="red">
|
|
14
|
-
Unknown command: {command}. Run `layerbase help` to see the commands.
|
|
15
|
-
</Text>
|
|
16
|
-
)
|
|
17
|
-
}
|