@myrialabs/clopen 0.3.6 → 0.3.8
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 +4 -4
- package/backend/database/migrations/030_add_files_panel_state_to_user_projects.ts +34 -0
- package/backend/database/migrations/031_create_db_client_tables.ts +74 -0
- package/backend/database/migrations/index.ts +14 -0
- package/backend/database/queries/db-client-connection-queries.ts +237 -0
- package/backend/database/queries/db-client-query-history-queries.ts +113 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/project-queries.ts +23 -0
- package/backend/db-client/connection-manager.ts +257 -0
- package/backend/db-client/drivers/bun-sql-helpers.ts +41 -0
- package/backend/db-client/drivers/mongodb.ts +358 -0
- package/backend/db-client/drivers/mysql.ts +385 -0
- package/backend/db-client/drivers/postgres.ts +446 -0
- package/backend/db-client/drivers/redis.ts +267 -0
- package/backend/db-client/drivers/sql-builders.ts +215 -0
- package/backend/db-client/drivers/sqlite.ts +346 -0
- package/backend/db-client/drivers/types.ts +92 -0
- package/backend/db-client/query-executor.ts +126 -0
- package/backend/db-client/ssh-tunnel.ts +122 -0
- package/backend/engine/install-recipes.ts +216 -137
- package/backend/engine/install-runner.ts +39 -0
- package/backend/git/git-service.ts +12 -0
- package/backend/mcp/servers/browser-automation/index.ts +6 -6
- package/backend/preview/browser/browser-pool.ts +10 -9
- package/backend/preview/browser/scripts/video-stream.ts +9 -3
- package/backend/tunnel/cloudflared/binary.ts +22 -4
- package/backend/tunnel/cloudflared/index.ts +2 -1
- package/backend/tunnel/cloudflared/tunnel.ts +17 -4
- package/backend/tunnel/global-tunnel-manager.ts +29 -51
- package/backend/tunnel/project-tunnel-manager.ts +14 -53
- package/backend/ws/db-client/connections.ts +180 -0
- package/backend/ws/db-client/index.ts +17 -0
- package/backend/ws/db-client/io.ts +458 -0
- package/backend/ws/db-client/query.ts +162 -0
- package/backend/ws/db-client/schema.ts +76 -0
- package/backend/ws/db-client/structure.ts +218 -0
- package/backend/ws/files/index.ts +5 -1
- package/backend/ws/files/read.ts +32 -0
- package/backend/ws/files/state.ts +39 -0
- package/backend/ws/index.ts +6 -2
- package/backend/ws/system-tools/install.ts +2 -1
- package/backend/ws/system-tools/status.ts +5 -4
- package/dist/assets/{index-BU8wB4Fg.js → index-DqAGCTFT.js} +2 -2
- package/dist/assets/{main-cQx6vfxB.js → main-DsED0rLr.js} +244 -192
- package/dist/assets/main-eWY9R8g9.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +4 -2
- package/shared/constants/preview.ts +48 -4
- package/shared/types/database/schema.ts +48 -1
- package/shared/types/db-client/connection.ts +60 -0
- package/shared/types/db-client/index.ts +6 -0
- package/shared/types/db-client/query.ts +77 -0
- package/shared/utils/logger.ts +1 -0
- package/dist/assets/main-B3tMwjjU.css +0 -1
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ A complete development environment designed around AI-assisted workflows, built
|
|
|
57
57
|
- **Cloudflare Tunnel** — One-click public HTTPS URL for your local dev server. Built-in QR code for instant mobile access. Share your work without deploying
|
|
58
58
|
- **MCP Support** — Full Model Context Protocol integration. Connect AI tools, external APIs, and custom capabilities to your AI agents with zero friction
|
|
59
59
|
- **Flexible Authentication** — No Login or With Login mode with admin/member roles, invite links, rate-limited login, and CLI token recovery
|
|
60
|
-
- **System Tools Installer** — Install Git, Claude Code, OpenCode, and
|
|
60
|
+
- **System Tools Installer** — Install Git, Claude Code, OpenCode, Chrome, and Cloudflared (for Public Tunnel) straight from the admin Settings UI, with live install output streamed to the browser via xterm.js
|
|
61
61
|
- **Background Processing** — Chat, terminal, and other processes continue running even when you close the browser — come back later and pick up where you left off
|
|
62
62
|
- **Database Management** — Browse tables, run queries, and inspect your database directly from the workspace *(coming soon)*
|
|
63
63
|
|
|
@@ -88,7 +88,7 @@ Or manually via Bun:
|
|
|
88
88
|
bun add -g @myrialabs/clopen
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
You can also update from the **Settings
|
|
91
|
+
You can also update from the **Settings → Maintenance > Updates** section in the web UI.
|
|
92
92
|
|
|
93
93
|
### Usage
|
|
94
94
|
|
|
@@ -107,9 +107,9 @@ On first launch, a setup wizard guides you through:
|
|
|
107
107
|
3. **AI Engines** — Check Claude Code and OpenCode installation status
|
|
108
108
|
4. **Preferences** — Set theme, font size, and notification preferences
|
|
109
109
|
|
|
110
|
-
You can change the authentication mode anytime in **Settings
|
|
110
|
+
You can change the authentication mode anytime in **Settings → Security > Authentication**.
|
|
111
111
|
|
|
112
|
-
To invite team members (With Login mode), go to **Settings
|
|
112
|
+
To invite team members (With Login mode), go to **Settings → Team > Invite** and generate an invite link (valid for 15 minutes).
|
|
113
113
|
|
|
114
114
|
If you lose your admin token:
|
|
115
115
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Add files_panel_state to user_projects for files panel restore';
|
|
5
|
+
|
|
6
|
+
export const up = (db: DatabaseConnection): void => {
|
|
7
|
+
debug.log('migration', 'Adding files_panel_state to user_projects...');
|
|
8
|
+
db.exec(`ALTER TABLE user_projects ADD COLUMN files_panel_state TEXT`);
|
|
9
|
+
debug.log('migration', 'files_panel_state column added');
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const down = (db: DatabaseConnection): void => {
|
|
13
|
+
debug.log('migration', 'Removing files_panel_state from user_projects...');
|
|
14
|
+
db.exec(`
|
|
15
|
+
CREATE TABLE user_projects_backup AS
|
|
16
|
+
SELECT user_id, project_id, joined_at, current_session_id FROM user_projects
|
|
17
|
+
`);
|
|
18
|
+
db.exec(`DROP TABLE user_projects`);
|
|
19
|
+
db.exec(`
|
|
20
|
+
CREATE TABLE user_projects (
|
|
21
|
+
user_id TEXT NOT NULL,
|
|
22
|
+
project_id TEXT NOT NULL,
|
|
23
|
+
joined_at TEXT NOT NULL,
|
|
24
|
+
current_session_id TEXT,
|
|
25
|
+
PRIMARY KEY (user_id, project_id),
|
|
26
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
|
|
27
|
+
)
|
|
28
|
+
`);
|
|
29
|
+
db.exec(`INSERT INTO user_projects SELECT * FROM user_projects_backup`);
|
|
30
|
+
db.exec(`DROP TABLE user_projects_backup`);
|
|
31
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_user_projects_user_id ON user_projects(user_id)`);
|
|
32
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_user_projects_project_id ON user_projects(project_id)`);
|
|
33
|
+
debug.log('migration', 'files_panel_state column removed');
|
|
34
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Create db_client_connections and db_client_query_history tables';
|
|
5
|
+
|
|
6
|
+
export const up = (db: DatabaseConnection): void => {
|
|
7
|
+
debug.log('migration', 'Creating db_client_connections table...');
|
|
8
|
+
|
|
9
|
+
db.exec(`
|
|
10
|
+
CREATE TABLE IF NOT EXISTS db_client_connections (
|
|
11
|
+
id TEXT PRIMARY KEY,
|
|
12
|
+
name TEXT NOT NULL,
|
|
13
|
+
driver TEXT NOT NULL CHECK (driver IN ('mysql','postgres','sqlite','mongodb','redis')),
|
|
14
|
+
host TEXT,
|
|
15
|
+
port INTEGER,
|
|
16
|
+
username TEXT,
|
|
17
|
+
password TEXT,
|
|
18
|
+
database TEXT,
|
|
19
|
+
ssl_mode TEXT DEFAULT 'disable' CHECK (ssl_mode IN ('disable','require','verify-ca','verify-full')),
|
|
20
|
+
ssl_ca TEXT,
|
|
21
|
+
ssh_enabled INTEGER NOT NULL DEFAULT 0,
|
|
22
|
+
ssh_host TEXT,
|
|
23
|
+
ssh_port INTEGER DEFAULT 22,
|
|
24
|
+
ssh_username TEXT,
|
|
25
|
+
ssh_auth_method TEXT DEFAULT 'password' CHECK (ssh_auth_method IN ('password','key')),
|
|
26
|
+
ssh_password TEXT,
|
|
27
|
+
ssh_private_key TEXT,
|
|
28
|
+
ssh_passphrase TEXT,
|
|
29
|
+
options_json TEXT,
|
|
30
|
+
color TEXT,
|
|
31
|
+
created_at TEXT NOT NULL,
|
|
32
|
+
updated_at TEXT NOT NULL,
|
|
33
|
+
last_used_at TEXT
|
|
34
|
+
)
|
|
35
|
+
`);
|
|
36
|
+
|
|
37
|
+
db.exec(`
|
|
38
|
+
CREATE INDEX IF NOT EXISTS idx_db_client_conn_last_used
|
|
39
|
+
ON db_client_connections(last_used_at DESC)
|
|
40
|
+
`);
|
|
41
|
+
|
|
42
|
+
debug.log('migration', 'Creating db_client_query_history table...');
|
|
43
|
+
|
|
44
|
+
db.exec(`
|
|
45
|
+
CREATE TABLE IF NOT EXISTS db_client_query_history (
|
|
46
|
+
id TEXT PRIMARY KEY,
|
|
47
|
+
connection_id TEXT NOT NULL,
|
|
48
|
+
user_id TEXT,
|
|
49
|
+
query TEXT NOT NULL,
|
|
50
|
+
duration_ms INTEGER,
|
|
51
|
+
row_count INTEGER,
|
|
52
|
+
status TEXT NOT NULL CHECK (status IN ('success','error')),
|
|
53
|
+
error TEXT,
|
|
54
|
+
executed_at TEXT NOT NULL,
|
|
55
|
+
FOREIGN KEY (connection_id) REFERENCES db_client_connections(id) ON DELETE CASCADE
|
|
56
|
+
)
|
|
57
|
+
`);
|
|
58
|
+
|
|
59
|
+
db.exec(`
|
|
60
|
+
CREATE INDEX IF NOT EXISTS idx_db_client_hist_conn_time
|
|
61
|
+
ON db_client_query_history(connection_id, executed_at DESC)
|
|
62
|
+
`);
|
|
63
|
+
|
|
64
|
+
debug.log('migration', 'db-client tables created');
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const down = (db: DatabaseConnection): void => {
|
|
68
|
+
debug.log('migration', 'Dropping db-client tables...');
|
|
69
|
+
db.exec('DROP INDEX IF EXISTS idx_db_client_hist_conn_time');
|
|
70
|
+
db.exec('DROP INDEX IF EXISTS idx_db_client_conn_last_used');
|
|
71
|
+
db.exec('DROP TABLE IF EXISTS db_client_query_history');
|
|
72
|
+
db.exec('DROP TABLE IF EXISTS db_client_connections');
|
|
73
|
+
debug.log('migration', 'db-client tables dropped');
|
|
74
|
+
};
|
|
@@ -28,6 +28,8 @@ import * as migration026 from './026_create_invite_tokens_table';
|
|
|
28
28
|
import * as migration027 from './027_create_opencode_providers_table';
|
|
29
29
|
import * as migration028 from './028_create_opencode_accounts_table';
|
|
30
30
|
import * as migration029 from './029_migrate_messages_to_unified';
|
|
31
|
+
import * as migration030 from './030_add_files_panel_state_to_user_projects';
|
|
32
|
+
import * as migration031 from './031_create_db_client_tables';
|
|
31
33
|
|
|
32
34
|
// Export all migrations in order
|
|
33
35
|
export const migrations = [
|
|
@@ -204,6 +206,18 @@ export const migrations = [
|
|
|
204
206
|
description: migration029.description,
|
|
205
207
|
up: migration029.up,
|
|
206
208
|
down: migration029.down
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: '030',
|
|
212
|
+
description: migration030.description,
|
|
213
|
+
up: migration030.up,
|
|
214
|
+
down: migration030.down
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
id: '031',
|
|
218
|
+
description: migration031.description,
|
|
219
|
+
up: migration031.up,
|
|
220
|
+
down: migration031.down
|
|
207
221
|
}
|
|
208
222
|
];
|
|
209
223
|
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { getDatabase } from '../index';
|
|
2
|
+
import type { DBDbClientConnectionRow } from '$shared/types/database/schema';
|
|
3
|
+
import type {
|
|
4
|
+
DbClientConnection,
|
|
5
|
+
DbClientConnectionInput,
|
|
6
|
+
DbClientSshConfig,
|
|
7
|
+
DbDriver,
|
|
8
|
+
DbSshAuthMethod,
|
|
9
|
+
DbSslMode
|
|
10
|
+
} from '$shared/types/db-client';
|
|
11
|
+
|
|
12
|
+
const DEFAULT_SSH: DbClientSshConfig = {
|
|
13
|
+
enabled: false,
|
|
14
|
+
host: '',
|
|
15
|
+
port: 22,
|
|
16
|
+
username: '',
|
|
17
|
+
authMethod: 'password',
|
|
18
|
+
password: '',
|
|
19
|
+
privateKey: '',
|
|
20
|
+
passphrase: ''
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function rowToConnection(row: DBDbClientConnectionRow): DbClientConnection {
|
|
24
|
+
let options: Record<string, unknown> = {};
|
|
25
|
+
if (row.options_json) {
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(row.options_json);
|
|
28
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
29
|
+
options = parsed as Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
options = {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ssh: DbClientSshConfig = {
|
|
37
|
+
enabled: row.ssh_enabled === 1,
|
|
38
|
+
host: row.ssh_host ?? '',
|
|
39
|
+
port: row.ssh_port ?? 22,
|
|
40
|
+
username: row.ssh_username ?? '',
|
|
41
|
+
authMethod: (row.ssh_auth_method ?? 'password') as DbSshAuthMethod,
|
|
42
|
+
password: row.ssh_password ?? '',
|
|
43
|
+
privateKey: row.ssh_private_key ?? '',
|
|
44
|
+
passphrase: row.ssh_passphrase ?? ''
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
id: row.id,
|
|
49
|
+
name: row.name,
|
|
50
|
+
driver: row.driver as DbDriver,
|
|
51
|
+
host: row.host,
|
|
52
|
+
port: row.port,
|
|
53
|
+
username: row.username,
|
|
54
|
+
password: row.password,
|
|
55
|
+
database: row.database,
|
|
56
|
+
sslMode: (row.ssl_mode ?? 'disable') as DbSslMode,
|
|
57
|
+
sslCa: row.ssl_ca,
|
|
58
|
+
ssh,
|
|
59
|
+
options,
|
|
60
|
+
color: row.color,
|
|
61
|
+
createdAt: row.created_at,
|
|
62
|
+
updatedAt: row.updated_at,
|
|
63
|
+
lastUsedAt: row.last_used_at
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface InsertParams {
|
|
68
|
+
name: string;
|
|
69
|
+
driver: DbDriver;
|
|
70
|
+
host: string | null;
|
|
71
|
+
port: number | null;
|
|
72
|
+
username: string | null;
|
|
73
|
+
password: string | null;
|
|
74
|
+
database: string | null;
|
|
75
|
+
sslMode: DbSslMode;
|
|
76
|
+
sslCa: string | null;
|
|
77
|
+
ssh: DbClientSshConfig;
|
|
78
|
+
options: Record<string, unknown>;
|
|
79
|
+
color: string | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function normalizeInput(input: DbClientConnectionInput): InsertParams {
|
|
83
|
+
const ssh: DbClientSshConfig = {
|
|
84
|
+
...DEFAULT_SSH,
|
|
85
|
+
...(input.ssh ?? {})
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
name: input.name,
|
|
89
|
+
driver: input.driver,
|
|
90
|
+
host: input.host ?? null,
|
|
91
|
+
port: input.port ?? null,
|
|
92
|
+
username: input.username ?? null,
|
|
93
|
+
password: input.password ?? null,
|
|
94
|
+
database: input.database ?? null,
|
|
95
|
+
sslMode: input.sslMode ?? 'disable',
|
|
96
|
+
sslCa: input.sslCa ?? null,
|
|
97
|
+
ssh,
|
|
98
|
+
options: input.options ?? {},
|
|
99
|
+
color: input.color ?? null
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const dbClientConnectionQueries = {
|
|
104
|
+
list(): DbClientConnection[] {
|
|
105
|
+
const db = getDatabase();
|
|
106
|
+
const rows = db.prepare(`
|
|
107
|
+
SELECT * FROM db_client_connections
|
|
108
|
+
ORDER BY (last_used_at IS NULL), last_used_at DESC, created_at DESC
|
|
109
|
+
`).all() as DBDbClientConnectionRow[];
|
|
110
|
+
return rows.map(rowToConnection);
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
get(id: string): DbClientConnection | null {
|
|
114
|
+
const db = getDatabase();
|
|
115
|
+
const row = db.prepare(`
|
|
116
|
+
SELECT * FROM db_client_connections WHERE id = ?
|
|
117
|
+
`).get(id) as DBDbClientConnectionRow | null;
|
|
118
|
+
return row ? rowToConnection(row) : null;
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
create(input: DbClientConnectionInput): DbClientConnection {
|
|
122
|
+
const db = getDatabase();
|
|
123
|
+
const id = crypto.randomUUID();
|
|
124
|
+
const now = new Date().toISOString();
|
|
125
|
+
const params = normalizeInput(input);
|
|
126
|
+
|
|
127
|
+
db.prepare(`
|
|
128
|
+
INSERT INTO db_client_connections (
|
|
129
|
+
id, name, driver,
|
|
130
|
+
host, port, username, password, database,
|
|
131
|
+
ssl_mode, ssl_ca,
|
|
132
|
+
ssh_enabled, ssh_host, ssh_port, ssh_username, ssh_auth_method,
|
|
133
|
+
ssh_password, ssh_private_key, ssh_passphrase,
|
|
134
|
+
options_json, color,
|
|
135
|
+
created_at, updated_at, last_used_at
|
|
136
|
+
) VALUES (
|
|
137
|
+
?, ?, ?,
|
|
138
|
+
?, ?, ?, ?, ?,
|
|
139
|
+
?, ?,
|
|
140
|
+
?, ?, ?, ?, ?,
|
|
141
|
+
?, ?, ?,
|
|
142
|
+
?, ?,
|
|
143
|
+
?, ?, ?
|
|
144
|
+
)
|
|
145
|
+
`).run(
|
|
146
|
+
id, params.name, params.driver,
|
|
147
|
+
params.host, params.port, params.username, params.password, params.database,
|
|
148
|
+
params.sslMode, params.sslCa,
|
|
149
|
+
params.ssh.enabled ? 1 : 0,
|
|
150
|
+
params.ssh.host || null,
|
|
151
|
+
params.ssh.port,
|
|
152
|
+
params.ssh.username || null,
|
|
153
|
+
params.ssh.authMethod,
|
|
154
|
+
params.ssh.password || null,
|
|
155
|
+
params.ssh.privateKey || null,
|
|
156
|
+
params.ssh.passphrase || null,
|
|
157
|
+
JSON.stringify(params.options),
|
|
158
|
+
params.color,
|
|
159
|
+
now, now, null
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const row = db.prepare('SELECT * FROM db_client_connections WHERE id = ?').get(id) as DBDbClientConnectionRow;
|
|
163
|
+
return rowToConnection(row);
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
update(id: string, patch: Partial<DbClientConnectionInput>): DbClientConnection {
|
|
167
|
+
const db = getDatabase();
|
|
168
|
+
const existing = db.prepare('SELECT * FROM db_client_connections WHERE id = ?').get(id) as DBDbClientConnectionRow | null;
|
|
169
|
+
if (!existing) {
|
|
170
|
+
throw new Error('db-client connection not found');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const sets: string[] = [];
|
|
174
|
+
const values: unknown[] = [];
|
|
175
|
+
const push = (col: string, val: unknown): void => {
|
|
176
|
+
sets.push(`${col} = ?`);
|
|
177
|
+
values.push(val);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
if (patch.name !== undefined) push('name', patch.name);
|
|
181
|
+
if (patch.driver !== undefined) push('driver', patch.driver);
|
|
182
|
+
if (patch.host !== undefined) push('host', patch.host || null);
|
|
183
|
+
if (patch.port !== undefined) push('port', patch.port ?? null);
|
|
184
|
+
if (patch.username !== undefined) push('username', patch.username || null);
|
|
185
|
+
if (patch.password !== undefined) push('password', patch.password || null);
|
|
186
|
+
if (patch.database !== undefined) push('database', patch.database || null);
|
|
187
|
+
if (patch.sslMode !== undefined) push('ssl_mode', patch.sslMode);
|
|
188
|
+
if (patch.sslCa !== undefined) push('ssl_ca', patch.sslCa || null);
|
|
189
|
+
if (patch.color !== undefined) push('color', patch.color || null);
|
|
190
|
+
if (patch.options !== undefined) push('options_json', JSON.stringify(patch.options ?? {}));
|
|
191
|
+
|
|
192
|
+
if (patch.ssh !== undefined) {
|
|
193
|
+
const merged: DbClientSshConfig = {
|
|
194
|
+
enabled: existing.ssh_enabled === 1,
|
|
195
|
+
host: existing.ssh_host ?? '',
|
|
196
|
+
port: existing.ssh_port ?? 22,
|
|
197
|
+
username: existing.ssh_username ?? '',
|
|
198
|
+
authMethod: (existing.ssh_auth_method ?? 'password') as DbSshAuthMethod,
|
|
199
|
+
password: existing.ssh_password ?? '',
|
|
200
|
+
privateKey: existing.ssh_private_key ?? '',
|
|
201
|
+
passphrase: existing.ssh_passphrase ?? '',
|
|
202
|
+
...patch.ssh
|
|
203
|
+
};
|
|
204
|
+
push('ssh_enabled', merged.enabled ? 1 : 0);
|
|
205
|
+
push('ssh_host', merged.host || null);
|
|
206
|
+
push('ssh_port', merged.port);
|
|
207
|
+
push('ssh_username', merged.username || null);
|
|
208
|
+
push('ssh_auth_method', merged.authMethod);
|
|
209
|
+
push('ssh_password', merged.password || null);
|
|
210
|
+
push('ssh_private_key', merged.privateKey || null);
|
|
211
|
+
push('ssh_passphrase', merged.passphrase || null);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
push('updated_at', new Date().toISOString());
|
|
215
|
+
|
|
216
|
+
if (sets.length === 0) {
|
|
217
|
+
return rowToConnection(existing);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
values.push(id);
|
|
221
|
+
db.prepare(`UPDATE db_client_connections SET ${sets.join(', ')} WHERE id = ?`).run(...values);
|
|
222
|
+
|
|
223
|
+
const row = db.prepare('SELECT * FROM db_client_connections WHERE id = ?').get(id) as DBDbClientConnectionRow;
|
|
224
|
+
return rowToConnection(row);
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
delete(id: string): void {
|
|
228
|
+
const db = getDatabase();
|
|
229
|
+
db.prepare('DELETE FROM db_client_connections WHERE id = ?').run(id);
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
markUsed(id: string): void {
|
|
233
|
+
const db = getDatabase();
|
|
234
|
+
const now = new Date().toISOString();
|
|
235
|
+
db.prepare('UPDATE db_client_connections SET last_used_at = ? WHERE id = ?').run(now, id);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { getDatabase } from '../index';
|
|
2
|
+
import type { DBDbClientQueryHistoryRow } from '$shared/types/database/schema';
|
|
3
|
+
import type { DbClientQueryHistoryEntry } from '$shared/types/db-client';
|
|
4
|
+
|
|
5
|
+
function rowToEntry(row: DBDbClientQueryHistoryRow): DbClientQueryHistoryEntry {
|
|
6
|
+
return {
|
|
7
|
+
id: row.id,
|
|
8
|
+
connectionId: row.connection_id,
|
|
9
|
+
userId: row.user_id,
|
|
10
|
+
query: row.query,
|
|
11
|
+
durationMs: row.duration_ms,
|
|
12
|
+
rowCount: row.row_count,
|
|
13
|
+
status: row.status,
|
|
14
|
+
error: row.error,
|
|
15
|
+
executedAt: row.executed_at
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface InsertHistoryInput {
|
|
20
|
+
connectionId: string;
|
|
21
|
+
userId: string | null;
|
|
22
|
+
query: string;
|
|
23
|
+
durationMs: number | null;
|
|
24
|
+
rowCount: number | null;
|
|
25
|
+
status: 'success' | 'error';
|
|
26
|
+
error: string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const dbClientQueryHistoryQueries = {
|
|
30
|
+
insert(input: InsertHistoryInput): DbClientQueryHistoryEntry {
|
|
31
|
+
const db = getDatabase();
|
|
32
|
+
const id = crypto.randomUUID();
|
|
33
|
+
const now = new Date().toISOString();
|
|
34
|
+
|
|
35
|
+
db.prepare(`
|
|
36
|
+
INSERT INTO db_client_query_history (
|
|
37
|
+
id, connection_id, user_id, query,
|
|
38
|
+
duration_ms, row_count, status, error, executed_at
|
|
39
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
40
|
+
`).run(
|
|
41
|
+
id, input.connectionId, input.userId, input.query,
|
|
42
|
+
input.durationMs, input.rowCount, input.status, input.error, now
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const row = db.prepare(
|
|
46
|
+
'SELECT * FROM db_client_query_history WHERE id = ?'
|
|
47
|
+
).get(id) as DBDbClientQueryHistoryRow;
|
|
48
|
+
return rowToEntry(row);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
list(opts: {
|
|
52
|
+
connectionId: string;
|
|
53
|
+
limit?: number;
|
|
54
|
+
offset?: number;
|
|
55
|
+
search?: string;
|
|
56
|
+
}): { items: DbClientQueryHistoryEntry[]; total: number } {
|
|
57
|
+
const db = getDatabase();
|
|
58
|
+
const limit = opts.limit ?? 50;
|
|
59
|
+
const offset = opts.offset ?? 0;
|
|
60
|
+
const search = opts.search?.trim();
|
|
61
|
+
|
|
62
|
+
let where = 'connection_id = ?';
|
|
63
|
+
const params: unknown[] = [opts.connectionId];
|
|
64
|
+
if (search) {
|
|
65
|
+
where += ' AND query LIKE ?';
|
|
66
|
+
params.push(`%${search}%`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const totalRow = db.prepare(
|
|
70
|
+
`SELECT COUNT(*) as count FROM db_client_query_history WHERE ${where}`
|
|
71
|
+
).get(...params) as { count: number };
|
|
72
|
+
|
|
73
|
+
const rows = db.prepare(
|
|
74
|
+
`SELECT * FROM db_client_query_history
|
|
75
|
+
WHERE ${where}
|
|
76
|
+
ORDER BY executed_at DESC
|
|
77
|
+
LIMIT ? OFFSET ?`
|
|
78
|
+
).all(...params, limit, offset) as DBDbClientQueryHistoryRow[];
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
items: rows.map(rowToEntry),
|
|
82
|
+
total: totalRow.count
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
deleteByConnection(connectionId: string): number {
|
|
87
|
+
const db = getDatabase();
|
|
88
|
+
const result = db.prepare(
|
|
89
|
+
'DELETE FROM db_client_query_history WHERE connection_id = ?'
|
|
90
|
+
).run(connectionId) as { changes: number };
|
|
91
|
+
return result.changes;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
deleteOne(id: string): void {
|
|
95
|
+
const db = getDatabase();
|
|
96
|
+
db.prepare('DELETE FROM db_client_query_history WHERE id = ?').run(id);
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
prune(connectionId: string, keep: number): number {
|
|
100
|
+
const db = getDatabase();
|
|
101
|
+
const result = db.prepare(`
|
|
102
|
+
DELETE FROM db_client_query_history
|
|
103
|
+
WHERE connection_id = ?
|
|
104
|
+
AND id NOT IN (
|
|
105
|
+
SELECT id FROM db_client_query_history
|
|
106
|
+
WHERE connection_id = ?
|
|
107
|
+
ORDER BY executed_at DESC
|
|
108
|
+
LIMIT ?
|
|
109
|
+
)
|
|
110
|
+
`).run(connectionId, connectionId, keep) as { changes: number };
|
|
111
|
+
return result.changes;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
@@ -7,4 +7,6 @@ export { dbUtils } from './utils-queries';
|
|
|
7
7
|
export { snapshotQueries } from './snapshot-queries';
|
|
8
8
|
export { checkpointQueries } from './checkpoint-queries';
|
|
9
9
|
export { engineQueries } from './engine-queries';
|
|
10
|
-
export { authQueries } from './auth-queries';
|
|
10
|
+
export { authQueries } from './auth-queries';
|
|
11
|
+
export { dbClientConnectionQueries } from './db-client-connection-queries';
|
|
12
|
+
export { dbClientQueryHistoryQueries } from './db-client-query-history-queries';
|
|
@@ -110,5 +110,28 @@ export const projectQueries = {
|
|
|
110
110
|
SET current_session_id = ?
|
|
111
111
|
WHERE user_id = ? AND project_id = ?
|
|
112
112
|
`).run(sessionId, userId, projectId);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
getFilesPanelState(userId: string, projectId: string): string | null {
|
|
116
|
+
const db = getDatabase();
|
|
117
|
+
const result = db.prepare(`
|
|
118
|
+
SELECT files_panel_state FROM user_projects
|
|
119
|
+
WHERE user_id = ? AND project_id = ?
|
|
120
|
+
`).get(userId, projectId) as { files_panel_state: string | null } | null;
|
|
121
|
+
return result?.files_panel_state || null;
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
setFilesPanelState(userId: string, projectId: string, state: string | null): void {
|
|
125
|
+
const db = getDatabase();
|
|
126
|
+
const now = new Date().toISOString();
|
|
127
|
+
db.prepare(`
|
|
128
|
+
INSERT OR IGNORE INTO user_projects (user_id, project_id, joined_at)
|
|
129
|
+
VALUES (?, ?, ?)
|
|
130
|
+
`).run(userId, projectId, now);
|
|
131
|
+
db.prepare(`
|
|
132
|
+
UPDATE user_projects
|
|
133
|
+
SET files_panel_state = ?
|
|
134
|
+
WHERE user_id = ? AND project_id = ?
|
|
135
|
+
`).run(state, userId, projectId);
|
|
113
136
|
}
|
|
114
137
|
};
|