@rsktash/beads-ui 0.1.2 → 0.1.4
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/README.md +110 -0
- package/dist/assets/{index-BSNzF5KT.js → index-CeliZ293.js} +19 -19
- package/dist/index.html +1 -1
- package/package.json +3 -2
- package/server/cli/usage.js +18 -0
- package/server/dolt-pool.js +69 -13
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Beads UI</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-CeliZ293.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-Ux6DCth7.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body style="background: #FDFBF7; color: #1A1A1A;">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsktash/beads-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/rsktash/beads-ui.git"
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"dev": "concurrently \"vite --config client/vite.config.ts\" \"node server/index.js\"",
|
|
20
20
|
"build": "vite build --config client/vite.config.ts",
|
|
21
|
-
"start": "node server/index.js"
|
|
21
|
+
"start": "node server/index.js",
|
|
22
|
+
"bd-ui": "PORT=3333 bd-ui"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"debug": "^4.3.7",
|
package/server/cli/usage.js
CHANGED
|
@@ -19,6 +19,24 @@ export function printUsage(out_stream) {
|
|
|
19
19
|
' --open Open the browser after start/restart',
|
|
20
20
|
' --host <addr> Bind to a specific host (default: 127.0.0.1)',
|
|
21
21
|
' --port <num> Bind to a specific port (default: 3000)',
|
|
22
|
+
'',
|
|
23
|
+
'Environment variables:',
|
|
24
|
+
' PORT Server port (default: 3333)',
|
|
25
|
+
' HOST Bind address (default: 127.0.0.1)',
|
|
26
|
+
' BEADS_DOLT_PASSWORD Password for remote Dolt server',
|
|
27
|
+
' VITE_FILE_ATTACHMENT_BASE_URL Base URL for attach:// URIs in markdown',
|
|
28
|
+
'',
|
|
29
|
+
'Dolt modes:',
|
|
30
|
+
' Embedded (default): spawns a local dolt sql-server from .beads/embeddeddolt/',
|
|
31
|
+
' Remote server: set dolt_mode: "server" in .beads/metadata.json with',
|
|
32
|
+
' dolt_server_host, dolt_server_port, dolt_server_user, dolt_database.',
|
|
33
|
+
' Password is read from BEADS_DOLT_PASSWORD env var.',
|
|
34
|
+
'',
|
|
35
|
+
'Attachments:',
|
|
36
|
+
' Markdown content can use attach://<path> URIs for portable file references.',
|
|
37
|
+
' Set VITE_FILE_ATTACHMENT_BASE_URL to resolve them at render time.',
|
|
38
|
+
' Example: attach://bead-42/shot.png becomes',
|
|
39
|
+
' ${VITE_FILE_ATTACHMENT_BASE_URL}/bead-42/shot.png',
|
|
22
40
|
''
|
|
23
41
|
];
|
|
24
42
|
for (const line of lines) {
|
package/server/dolt-pool.js
CHANGED
|
@@ -19,13 +19,22 @@ let serverProcess = null;
|
|
|
19
19
|
/** @type {string | null} */
|
|
20
20
|
let currentDataDir = null;
|
|
21
21
|
|
|
22
|
+
/** @type {'embedded' | 'server' | null} */
|
|
23
|
+
let currentMode = null;
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* @typedef {{ mode: 'embedded', dataDir: string, database: string }} EmbeddedDoltInfo
|
|
27
|
+
* @typedef {{ mode: 'server', host: string, port: number, user: string, password: string, database: string }} ServerDoltInfo
|
|
28
|
+
* @typedef {EmbeddedDoltInfo | ServerDoltInfo} DoltInfo
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolve Dolt connection info from the workspace root.
|
|
33
|
+
* Walks up from cwd to find .beads/metadata.json, then returns either
|
|
34
|
+
* embedded or server connection info depending on dolt_mode.
|
|
26
35
|
*
|
|
27
36
|
* @param {string} cwd
|
|
28
|
-
* @returns {
|
|
37
|
+
* @returns {DoltInfo | null}
|
|
29
38
|
*/
|
|
30
39
|
export function resolveDoltDir(cwd) {
|
|
31
40
|
const metadataPath = findNearestBeadsMetadata(cwd);
|
|
@@ -42,6 +51,18 @@ export function resolveDoltDir(cwd) {
|
|
|
42
51
|
if (metadata.backend !== 'dolt' && metadata.database !== 'dolt') return null;
|
|
43
52
|
|
|
44
53
|
const database = metadata.dolt_database || 'default';
|
|
54
|
+
|
|
55
|
+
if (metadata.dolt_mode === 'server') {
|
|
56
|
+
return {
|
|
57
|
+
mode: 'server',
|
|
58
|
+
host: metadata.dolt_server_host || '127.0.0.1',
|
|
59
|
+
port: metadata.dolt_server_port || 3306,
|
|
60
|
+
user: metadata.dolt_server_user || 'root',
|
|
61
|
+
password: process.env.BEADS_DOLT_PASSWORD || '',
|
|
62
|
+
database
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
45
66
|
const dataDir = path.join(beadsDir, 'embeddeddolt', database);
|
|
46
67
|
|
|
47
68
|
try {
|
|
@@ -50,7 +71,7 @@ export function resolveDoltDir(cwd) {
|
|
|
50
71
|
return null;
|
|
51
72
|
}
|
|
52
73
|
|
|
53
|
-
return { dataDir, database };
|
|
74
|
+
return { mode: 'embedded', dataDir, database };
|
|
54
75
|
}
|
|
55
76
|
|
|
56
77
|
/**
|
|
@@ -67,6 +88,34 @@ export async function startDoltServer(cwd) {
|
|
|
67
88
|
return null;
|
|
68
89
|
}
|
|
69
90
|
|
|
91
|
+
// Server mode — connect directly, no child process
|
|
92
|
+
if (resolved.mode === 'server') {
|
|
93
|
+
const { host, port, user, password, database } = resolved;
|
|
94
|
+
|
|
95
|
+
// Already connected to this server
|
|
96
|
+
if (pool && currentMode === 'server') {
|
|
97
|
+
return pool;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
await stopDoltServer();
|
|
101
|
+
|
|
102
|
+
log('connecting to remote dolt server at %s:%d (database=%s)', host, port, database);
|
|
103
|
+
currentMode = 'server';
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
pool = await createPool({ host, port, user, password, database });
|
|
107
|
+
log('connected to remote dolt server at %s:%d', host, port);
|
|
108
|
+
ensureIndexes(pool).catch((err) => log('ensureIndexes error: %o', err));
|
|
109
|
+
return pool;
|
|
110
|
+
} catch (err) {
|
|
111
|
+
log('failed to connect to remote dolt server: %o', err);
|
|
112
|
+
pool = null;
|
|
113
|
+
currentMode = null;
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Embedded mode — spawn local dolt sql-server
|
|
70
119
|
const { dataDir, database } = resolved;
|
|
71
120
|
|
|
72
121
|
// Already running for this data dir
|
|
@@ -83,6 +132,7 @@ export async function startDoltServer(cwd) {
|
|
|
83
132
|
try { fs.unlinkSync(DOLT_SOCK); } catch { /* ignore */ }
|
|
84
133
|
|
|
85
134
|
currentDataDir = dataDir;
|
|
135
|
+
currentMode = 'embedded';
|
|
86
136
|
|
|
87
137
|
return new Promise((resolve) => {
|
|
88
138
|
const child = spawn('dolt', [
|
|
@@ -119,6 +169,7 @@ export async function startDoltServer(cwd) {
|
|
|
119
169
|
pool = null;
|
|
120
170
|
serverProcess = null;
|
|
121
171
|
currentDataDir = null;
|
|
172
|
+
currentMode = null;
|
|
122
173
|
if (!resolved_already) {
|
|
123
174
|
resolved_already = true;
|
|
124
175
|
resolve(null);
|
|
@@ -144,7 +195,7 @@ export async function startDoltServer(cwd) {
|
|
|
144
195
|
return;
|
|
145
196
|
}
|
|
146
197
|
try {
|
|
147
|
-
const p = await createPool(database);
|
|
198
|
+
const p = await createPool({ host: '127.0.0.1', port: DOLT_PORT, user: 'root', database });
|
|
148
199
|
clearInterval(pollInterval);
|
|
149
200
|
if (!resolved_already) {
|
|
150
201
|
resolved_already = true;
|
|
@@ -169,15 +220,16 @@ export async function startDoltServer(cwd) {
|
|
|
169
220
|
/**
|
|
170
221
|
* Create a mysql2 connection pool.
|
|
171
222
|
*
|
|
172
|
-
* @param {string}
|
|
223
|
+
* @param {{ host: string, port: number, user: string, password?: string, database: string }} opts
|
|
173
224
|
* @returns {Promise<import('mysql2/promise').Pool>}
|
|
174
225
|
*/
|
|
175
|
-
async function createPool(
|
|
226
|
+
async function createPool(opts) {
|
|
176
227
|
const p = mysql.createPool({
|
|
177
|
-
host:
|
|
178
|
-
port:
|
|
179
|
-
user:
|
|
180
|
-
|
|
228
|
+
host: opts.host,
|
|
229
|
+
port: opts.port,
|
|
230
|
+
user: opts.user,
|
|
231
|
+
password: opts.password || undefined,
|
|
232
|
+
database: opts.database,
|
|
181
233
|
waitForConnections: true,
|
|
182
234
|
connectionLimit: 10,
|
|
183
235
|
queueLimit: 50,
|
|
@@ -236,6 +288,7 @@ export async function stopDoltServer() {
|
|
|
236
288
|
serverProcess = null;
|
|
237
289
|
}
|
|
238
290
|
currentDataDir = null;
|
|
291
|
+
currentMode = null;
|
|
239
292
|
}
|
|
240
293
|
|
|
241
294
|
/**
|
|
@@ -250,7 +303,10 @@ export async function rebindDoltServer(cwd) {
|
|
|
250
303
|
await stopDoltServer();
|
|
251
304
|
return null;
|
|
252
305
|
}
|
|
253
|
-
if (resolved.
|
|
306
|
+
if (resolved.mode === 'server' && pool && currentMode === 'server') {
|
|
307
|
+
return pool;
|
|
308
|
+
}
|
|
309
|
+
if (resolved.mode === 'embedded' && resolved.dataDir === currentDataDir && pool && serverProcess && !serverProcess.killed) {
|
|
254
310
|
return pool;
|
|
255
311
|
}
|
|
256
312
|
return startDoltServer(cwd);
|