@myrialabs/clopen 0.3.7 → 0.3.9
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/backend/auth/permissions.ts +41 -2
- package/backend/chat/stream-manager.ts +71 -0
- 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/032_seed_copilot_provider.ts +19 -0
- package/backend/database/migrations/033_seed_codex_provider.ts +19 -0
- package/backend/database/migrations/034_seed_qwen_provider.ts +119 -0
- package/backend/database/migrations/035_add_owner_to_db_client_connections.ts +34 -0
- package/backend/database/migrations/index.ts +43 -1
- package/backend/database/queries/db-client-connection-queries.ts +343 -0
- package/backend/database/queries/db-client-query-history-queries.ts +113 -0
- package/backend/database/queries/engine-queries.ts +12 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/project-queries.ts +28 -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/README.md +1702 -0
- package/backend/engine/adapters/claude/models.ts +141 -0
- package/backend/engine/adapters/claude/stream.ts +1 -1
- package/backend/engine/adapters/codex/credential.ts +179 -0
- package/backend/engine/adapters/codex/error-handler.ts +65 -0
- package/backend/engine/adapters/codex/index.ts +1 -0
- package/backend/engine/adapters/codex/message-converter.ts +646 -0
- package/backend/engine/adapters/codex/models.ts +105 -0
- package/backend/engine/adapters/codex/patch-rollout.ts +169 -0
- package/backend/engine/adapters/codex/session-fork.ts +149 -0
- package/backend/engine/adapters/codex/stream.ts +310 -0
- package/backend/engine/adapters/codex/usage-rollout.ts +145 -0
- package/backend/engine/adapters/copilot/error-handler.ts +94 -0
- package/backend/engine/adapters/copilot/index.ts +1 -0
- package/backend/engine/adapters/copilot/message-converter.ts +973 -0
- package/backend/engine/adapters/copilot/models.ts +92 -0
- package/backend/engine/adapters/copilot/session-fork.ts +111 -0
- package/backend/engine/adapters/copilot/stream.ts +573 -0
- package/backend/engine/adapters/opencode/config.ts +56 -104
- package/backend/engine/adapters/opencode/error-handler.ts +71 -0
- package/backend/engine/adapters/opencode/models.ts +79 -0
- package/backend/engine/adapters/opencode/presets.ts +91 -0
- package/backend/engine/adapters/opencode/stream.ts +5 -115
- package/backend/engine/adapters/qwen/credential.ts +78 -0
- package/backend/engine/adapters/qwen/environment.ts +84 -0
- package/backend/engine/adapters/qwen/error-handler.ts +71 -0
- package/backend/engine/adapters/qwen/index.ts +1 -0
- package/backend/engine/adapters/qwen/message-converter.ts +1055 -0
- package/backend/engine/adapters/qwen/models.ts +81 -0
- package/backend/engine/adapters/qwen/presets.ts +51 -0
- package/backend/engine/adapters/qwen/session-fork.ts +97 -0
- package/backend/engine/adapters/qwen/stream.ts +380 -0
- package/backend/engine/index.ts +35 -0
- package/backend/engine/install-recipes.ts +80 -1
- package/backend/engine/install-runner.ts +4 -0
- package/backend/git/git-service.ts +12 -0
- package/backend/mcp/README.md +84 -14
- package/backend/mcp/config.ts +218 -17
- package/backend/mcp/index.ts +2 -0
- package/backend/mcp/project-context.ts +55 -0
- package/backend/mcp/servers/browser-automation/actions.ts +6 -1
- package/backend/mcp/servers/helper.ts +13 -0
- package/backend/middleware/error-handler.ts +16 -2
- package/backend/preview/browser/browser-preview-service.ts +4 -4
- package/backend/preview/browser/scripts/video-stream.ts +9 -3
- package/backend/ws/README.md +128 -3
- package/backend/ws/access.ts +56 -0
- package/backend/ws/chat/stream.ts +36 -12
- package/backend/ws/db-client/access.ts +19 -0
- package/backend/ws/db-client/connections.ts +194 -0
- package/backend/ws/db-client/index.ts +17 -0
- package/backend/ws/db-client/io.ts +456 -0
- package/backend/ws/db-client/query.ts +214 -0
- package/backend/ws/db-client/schema.ts +81 -0
- package/backend/ws/db-client/structure.ts +230 -0
- package/backend/ws/engine/access.ts +39 -0
- package/backend/ws/engine/claude/accounts.ts +15 -10
- package/backend/ws/engine/codex/accounts.ts +516 -0
- package/backend/ws/engine/codex/index.ts +14 -0
- package/backend/ws/engine/codex/status.ts +87 -0
- package/backend/ws/engine/copilot/accounts.ts +122 -0
- package/backend/ws/engine/copilot/index.ts +13 -0
- package/backend/ws/engine/copilot/status.ts +54 -0
- package/backend/ws/engine/index.ts +7 -1
- package/backend/ws/engine/opencode/providers.ts +1 -1
- package/backend/ws/engine/qwen/accounts.ts +137 -0
- package/backend/ws/engine/qwen/index.ts +15 -0
- package/backend/ws/engine/qwen/presets.ts +40 -0
- package/backend/ws/engine/qwen/status.ts +54 -0
- package/backend/ws/files/index.ts +5 -1
- package/backend/ws/files/read.ts +34 -0
- package/backend/ws/files/state.ts +42 -0
- package/backend/ws/files/watch.ts +7 -1
- package/backend/ws/git/branch.ts +13 -19
- package/backend/ws/git/commit-message.ts +3 -4
- package/backend/ws/git/commit.ts +5 -7
- package/backend/ws/git/conflict.ts +7 -10
- package/backend/ws/git/diff.ts +7 -10
- package/backend/ws/git/log.ts +3 -4
- package/backend/ws/git/remote.ts +30 -43
- package/backend/ws/git/staging.ts +13 -19
- package/backend/ws/git/status.ts +7 -11
- package/backend/ws/index.ts +5 -1
- package/backend/ws/messages/crud.ts +7 -13
- package/backend/ws/preview/access.ts +45 -0
- package/backend/ws/preview/browser/cleanup.ts +3 -11
- package/backend/ws/preview/browser/console.ts +5 -40
- package/backend/ws/preview/browser/interact.ts +2 -6
- package/backend/ws/preview/browser/native-ui.ts +5 -18
- package/backend/ws/preview/browser/stats.ts +2 -12
- package/backend/ws/preview/browser/tab-info.ts +4 -20
- package/backend/ws/preview/browser/tab.ts +4 -27
- package/backend/ws/preview/browser/webcodecs.ts +6 -47
- package/backend/ws/projects/crud.ts +4 -10
- package/backend/ws/projects/status.ts +2 -0
- package/backend/ws/sessions/crud.ts +22 -33
- package/backend/ws/settings/crud.ts +13 -13
- package/backend/ws/snapshot/restore.ts +5 -2
- package/backend/ws/snapshot/timeline.ts +3 -1
- package/backend/ws/system-tools/access.ts +28 -0
- package/backend/ws/system-tools/install.ts +13 -4
- package/backend/ws/system-tools/status.ts +5 -2
- package/backend/ws/terminal/access.ts +56 -0
- package/backend/ws/terminal/persistence.ts +12 -6
- package/backend/ws/terminal/session.ts +35 -14
- package/backend/ws/terminal/stream.ts +4 -1
- package/dist/assets/{index-C86jwBxR.js → index-D8V2wj9B.js} +2 -2
- package/dist/assets/{main-DhLx8wD1.js → main-C9nYVmnw.js} +222 -195
- package/dist/assets/main-hspyFOoK.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +7 -1
- package/shared/constants/engines.ts +45 -140
- package/shared/types/database/schema.ts +49 -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/types/unified/common.ts +1 -1
- package/shared/types/unified/engine.ts +29 -1
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +1 -1
- package/shared/types/unified/tool.ts +17 -2
- package/shared/utils/logger.ts +1 -0
- package/shared/utils/ws-server.ts +14 -0
- package/dist/assets/main-jTnmAoXS.css +0 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* db-client — connection CRUD + health WS handlers.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { t } from 'elysia';
|
|
6
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
7
|
+
import { initializeDatabase } from '../../database';
|
|
8
|
+
import { dbClientConnectionQueries } from '../../database/queries';
|
|
9
|
+
import { connectionManager } from '../../db-client/connection-manager';
|
|
10
|
+
import type {
|
|
11
|
+
DbClientConnectionInput,
|
|
12
|
+
DbDriver,
|
|
13
|
+
DbSshAuthMethod,
|
|
14
|
+
DbSslMode
|
|
15
|
+
} from '$shared/types/db-client';
|
|
16
|
+
import { debug } from '$shared/utils/logger';
|
|
17
|
+
import { getDbClientPrincipal, requireDbClientConnectionAccess } from './access';
|
|
18
|
+
|
|
19
|
+
const driverSchema = t.Union([
|
|
20
|
+
t.Literal('mysql'),
|
|
21
|
+
t.Literal('postgres'),
|
|
22
|
+
t.Literal('sqlite'),
|
|
23
|
+
t.Literal('mongodb'),
|
|
24
|
+
t.Literal('redis')
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const sslModeSchema = t.Union([
|
|
28
|
+
t.Literal('disable'),
|
|
29
|
+
t.Literal('require'),
|
|
30
|
+
t.Literal('verify-ca'),
|
|
31
|
+
t.Literal('verify-full')
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const sshAuthSchema = t.Union([t.Literal('password'), t.Literal('key')]);
|
|
35
|
+
|
|
36
|
+
const sshInputSchema = t.Object({
|
|
37
|
+
enabled: t.Optional(t.Boolean()),
|
|
38
|
+
host: t.Optional(t.String()),
|
|
39
|
+
port: t.Optional(t.Number()),
|
|
40
|
+
username: t.Optional(t.String()),
|
|
41
|
+
authMethod: t.Optional(sshAuthSchema),
|
|
42
|
+
password: t.Optional(t.String()),
|
|
43
|
+
privateKey: t.Optional(t.String()),
|
|
44
|
+
passphrase: t.Optional(t.String())
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const connectionInputSchema = t.Object({
|
|
48
|
+
name: t.String({ minLength: 1 }),
|
|
49
|
+
driver: driverSchema,
|
|
50
|
+
host: t.Optional(t.String()),
|
|
51
|
+
port: t.Optional(t.Number()),
|
|
52
|
+
username: t.Optional(t.String()),
|
|
53
|
+
password: t.Optional(t.String()),
|
|
54
|
+
database: t.Optional(t.String()),
|
|
55
|
+
sslMode: t.Optional(sslModeSchema),
|
|
56
|
+
sslCa: t.Optional(t.String()),
|
|
57
|
+
ssh: t.Optional(sshInputSchema),
|
|
58
|
+
options: t.Optional(t.Record(t.String(), t.Any())),
|
|
59
|
+
color: t.Optional(t.String())
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const connectionPatchSchema = t.Object({
|
|
63
|
+
name: t.Optional(t.String({ minLength: 1 })),
|
|
64
|
+
driver: t.Optional(driverSchema),
|
|
65
|
+
host: t.Optional(t.String()),
|
|
66
|
+
port: t.Optional(t.Number()),
|
|
67
|
+
username: t.Optional(t.String()),
|
|
68
|
+
password: t.Optional(t.String()),
|
|
69
|
+
database: t.Optional(t.String()),
|
|
70
|
+
sslMode: t.Optional(sslModeSchema),
|
|
71
|
+
sslCa: t.Optional(t.String()),
|
|
72
|
+
ssh: t.Optional(sshInputSchema),
|
|
73
|
+
options: t.Optional(t.Record(t.String(), t.Any())),
|
|
74
|
+
color: t.Optional(t.String())
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const healthSchema = t.Object({
|
|
78
|
+
ok: t.Boolean(),
|
|
79
|
+
latencyMs: t.Nullable(t.Number()),
|
|
80
|
+
serverVersion: t.Nullable(t.String()),
|
|
81
|
+
sshOk: t.Nullable(t.Boolean()),
|
|
82
|
+
error: t.Nullable(t.String())
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const connectionTestSchema = t.Union([
|
|
86
|
+
t.Object({ id: t.String({ minLength: 1 }) }),
|
|
87
|
+
connectionInputSchema
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
function isInput(v: unknown): v is DbClientConnectionInput {
|
|
91
|
+
return typeof v === 'object' && v !== null && 'driver' in (v as Record<string, unknown>);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function normalizeSshPatch(input: DbClientConnectionInput['ssh']): DbClientConnectionInput['ssh'] {
|
|
95
|
+
if (!input) return undefined;
|
|
96
|
+
return {
|
|
97
|
+
...input,
|
|
98
|
+
authMethod: (input.authMethod ?? 'password') as DbSshAuthMethod
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function ensureInputDefaults(input: DbClientConnectionInput): DbClientConnectionInput {
|
|
103
|
+
return {
|
|
104
|
+
...input,
|
|
105
|
+
driver: input.driver as DbDriver,
|
|
106
|
+
sslMode: (input.sslMode ?? 'disable') as DbSslMode,
|
|
107
|
+
ssh: normalizeSshPatch(input.ssh)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const connectionsHandler = createRouter()
|
|
112
|
+
.http('db-client:list', {
|
|
113
|
+
data: t.Object({}),
|
|
114
|
+
response: t.Array(t.Any())
|
|
115
|
+
}, async ({ conn }) => {
|
|
116
|
+
await initializeDatabase();
|
|
117
|
+
const { userId, isAdmin } = getDbClientPrincipal(conn);
|
|
118
|
+
return dbClientConnectionQueries.listForUser(userId, isAdmin);
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
.http('db-client:get', {
|
|
122
|
+
data: t.Object({ id: t.String({ minLength: 1 }) }),
|
|
123
|
+
response: t.Any()
|
|
124
|
+
}, async ({ data, conn }) => {
|
|
125
|
+
const { userId, isAdmin } = getDbClientPrincipal(conn);
|
|
126
|
+
const connection = dbClientConnectionQueries.getForUser(data.id, userId, isAdmin);
|
|
127
|
+
if (!connection) throw new Error('db-client connection not found');
|
|
128
|
+
return connection;
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
.http('db-client:create', {
|
|
132
|
+
data: connectionInputSchema,
|
|
133
|
+
response: t.Any()
|
|
134
|
+
}, async ({ data, conn }) => {
|
|
135
|
+
await initializeDatabase();
|
|
136
|
+
const { userId } = getDbClientPrincipal(conn);
|
|
137
|
+
const created = dbClientConnectionQueries.createForUser(
|
|
138
|
+
ensureInputDefaults(data as DbClientConnectionInput),
|
|
139
|
+
userId
|
|
140
|
+
);
|
|
141
|
+
debug.log('db-client', `created connection ${created.id} (${created.driver})`);
|
|
142
|
+
return created;
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
.http('db-client:update', {
|
|
146
|
+
data: t.Object({
|
|
147
|
+
id: t.String({ minLength: 1 }),
|
|
148
|
+
patch: connectionPatchSchema
|
|
149
|
+
}),
|
|
150
|
+
response: t.Any()
|
|
151
|
+
}, async ({ data, conn }) => {
|
|
152
|
+
const { userId, isAdmin } = getDbClientPrincipal(conn);
|
|
153
|
+
requireDbClientConnectionAccess(conn, data.id);
|
|
154
|
+
const patch = data.patch as Partial<DbClientConnectionInput>;
|
|
155
|
+
const normalized: Partial<DbClientConnectionInput> = {
|
|
156
|
+
...patch,
|
|
157
|
+
ssh: patch.ssh ? normalizeSshPatch(patch.ssh) : undefined
|
|
158
|
+
};
|
|
159
|
+
// Drop the live adapter so the next access re-opens with new settings.
|
|
160
|
+
await connectionManager.release(data.id);
|
|
161
|
+
return dbClientConnectionQueries.updateForUser(data.id, normalized, userId, isAdmin);
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
.http('db-client:delete', {
|
|
165
|
+
data: t.Object({ id: t.String({ minLength: 1 }) }),
|
|
166
|
+
response: t.Object({ ok: t.Boolean() })
|
|
167
|
+
}, async ({ data, conn }) => {
|
|
168
|
+
const { userId, isAdmin } = getDbClientPrincipal(conn);
|
|
169
|
+
requireDbClientConnectionAccess(conn, data.id);
|
|
170
|
+
await connectionManager.release(data.id);
|
|
171
|
+
dbClientConnectionQueries.deleteForUser(data.id, userId, isAdmin);
|
|
172
|
+
return { ok: true };
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
.http('db-client:test', {
|
|
176
|
+
data: connectionTestSchema,
|
|
177
|
+
response: healthSchema
|
|
178
|
+
}, async ({ data, conn }) => {
|
|
179
|
+
await initializeDatabase();
|
|
180
|
+
if (isInput(data)) {
|
|
181
|
+
return connectionManager.test(ensureInputDefaults(data as DbClientConnectionInput));
|
|
182
|
+
}
|
|
183
|
+
const id = (data as { id: string }).id;
|
|
184
|
+
requireDbClientConnectionAccess(conn, id);
|
|
185
|
+
return connectionManager.test({ id });
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
.http('db-client:health', {
|
|
189
|
+
data: t.Object({ id: t.String({ minLength: 1 }) }),
|
|
190
|
+
response: healthSchema
|
|
191
|
+
}, async ({ data, conn }) => {
|
|
192
|
+
requireDbClientConnectionAccess(conn, data.id);
|
|
193
|
+
return connectionManager.test({ id: data.id });
|
|
194
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* db-client WebSocket router.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
6
|
+
import { connectionsHandler } from './connections';
|
|
7
|
+
import { schemaHandler } from './schema';
|
|
8
|
+
import { queryHandler } from './query';
|
|
9
|
+
import { structureHandler } from './structure';
|
|
10
|
+
import { ioHandler } from './io';
|
|
11
|
+
|
|
12
|
+
export const dbClientRouter = createRouter()
|
|
13
|
+
.merge(connectionsHandler)
|
|
14
|
+
.merge(schemaHandler)
|
|
15
|
+
.merge(queryHandler)
|
|
16
|
+
.merge(structureHandler)
|
|
17
|
+
.merge(ioHandler);
|
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* db-client — import/export WS handlers.
|
|
3
|
+
*
|
|
4
|
+
* Export builds a single combined file in the requested format,
|
|
5
|
+
* sending it back as a string for the client to download.
|
|
6
|
+
*
|
|
7
|
+
* Import parses a single uploaded file in the requested format and
|
|
8
|
+
* applies it to the connection (DDL/INSERT for SQL drivers, insertMany
|
|
9
|
+
* for mongodb, SET/HSET/etc for redis).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { t } from 'elysia';
|
|
13
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
14
|
+
import { connectionManager } from '../../db-client/connection-manager';
|
|
15
|
+
import type { DbClientObjectDetails, DbClientQueryResult } from '$shared/types/db-client';
|
|
16
|
+
import { requireDbClientConnectionAccess } from './access';
|
|
17
|
+
|
|
18
|
+
type SqlDriver = 'mysql' | 'postgres' | 'sqlite';
|
|
19
|
+
|
|
20
|
+
function quoteIdent(driver: SqlDriver, name: string): string {
|
|
21
|
+
if (driver === 'mysql') return '`' + name.replace(/`/g, '``') + '`';
|
|
22
|
+
return '"' + name.replace(/"/g, '""') + '"';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function qualified(driver: SqlDriver, parts: Array<string | undefined>): string {
|
|
26
|
+
return parts.filter((p): p is string => Boolean(p)).map((p) => quoteIdent(driver, p)).join('.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sqlLiteral(v: unknown): string {
|
|
30
|
+
if (v === null || v === undefined) return 'NULL';
|
|
31
|
+
if (typeof v === 'number' || typeof v === 'bigint') return String(v);
|
|
32
|
+
if (typeof v === 'boolean') return v ? '1' : '0';
|
|
33
|
+
if (v instanceof Date) return `'${v.toISOString()}'`;
|
|
34
|
+
if (typeof v === 'object') return `'${JSON.stringify(v).replace(/'/g, "''")}'`;
|
|
35
|
+
return `'${String(v).replace(/'/g, "''")}'`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function csvCell(v: unknown): string {
|
|
39
|
+
if (v === null || v === undefined) return '';
|
|
40
|
+
const s = typeof v === 'object' ? JSON.stringify(v) : String(v);
|
|
41
|
+
if (/[",\n\r]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
|
|
42
|
+
return s;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseCsv(text: string): { headers: string[]; rows: string[][] } {
|
|
46
|
+
const rows: string[][] = [];
|
|
47
|
+
let field = '';
|
|
48
|
+
let row: string[] = [];
|
|
49
|
+
let inQuotes = false;
|
|
50
|
+
for (let i = 0; i < text.length; i++) {
|
|
51
|
+
const ch = text[i];
|
|
52
|
+
if (inQuotes) {
|
|
53
|
+
if (ch === '"' && text[i + 1] === '"') { field += '"'; i++; }
|
|
54
|
+
else if (ch === '"') inQuotes = false;
|
|
55
|
+
else field += ch;
|
|
56
|
+
} else {
|
|
57
|
+
if (ch === '"') inQuotes = true;
|
|
58
|
+
else if (ch === ',') { row.push(field); field = ''; }
|
|
59
|
+
else if (ch === '\n') { row.push(field); rows.push(row); row = []; field = ''; }
|
|
60
|
+
else if (ch === '\r') { /* skip */ }
|
|
61
|
+
else field += ch;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (field.length > 0 || row.length > 0) { row.push(field); rows.push(row); }
|
|
65
|
+
const headers = rows.shift() ?? [];
|
|
66
|
+
return { headers, rows };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function splitSqlStatements(sql: string): string[] {
|
|
70
|
+
const out: string[] = [];
|
|
71
|
+
let buf = '';
|
|
72
|
+
let inSingle = false;
|
|
73
|
+
let inDouble = false;
|
|
74
|
+
let inBacktick = false;
|
|
75
|
+
let inLineComment = false;
|
|
76
|
+
let inBlockComment = false;
|
|
77
|
+
for (let i = 0; i < sql.length; i++) {
|
|
78
|
+
const ch = sql[i];
|
|
79
|
+
const next = sql[i + 1];
|
|
80
|
+
if (inLineComment) {
|
|
81
|
+
if (ch === '\n') inLineComment = false;
|
|
82
|
+
buf += ch;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (inBlockComment) {
|
|
86
|
+
if (ch === '*' && next === '/') { inBlockComment = false; buf += '*/'; i++; continue; }
|
|
87
|
+
buf += ch;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!inSingle && !inDouble && !inBacktick) {
|
|
91
|
+
if (ch === '-' && next === '-') { inLineComment = true; buf += '--'; i++; continue; }
|
|
92
|
+
if (ch === '/' && next === '*') { inBlockComment = true; buf += '/*'; i++; continue; }
|
|
93
|
+
}
|
|
94
|
+
if (!inDouble && !inBacktick && ch === "'" && sql[i - 1] !== '\\') inSingle = !inSingle;
|
|
95
|
+
else if (!inSingle && !inBacktick && ch === '"' && sql[i - 1] !== '\\') inDouble = !inDouble;
|
|
96
|
+
else if (!inSingle && !inDouble && ch === '`') inBacktick = !inBacktick;
|
|
97
|
+
if (ch === ';' && !inSingle && !inDouble && !inBacktick) {
|
|
98
|
+
const trimmed = buf.trim();
|
|
99
|
+
if (trimmed.length > 0) out.push(trimmed);
|
|
100
|
+
buf = '';
|
|
101
|
+
} else {
|
|
102
|
+
buf += ch;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const tail = buf.trim();
|
|
106
|
+
if (tail.length > 0) out.push(tail);
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function readAllRows(connectionId: string, driver: SqlDriver, table: string, database?: string, schema?: string): Promise<DbClientQueryResult> {
|
|
111
|
+
const adapter = await connectionManager.get(connectionId);
|
|
112
|
+
if (!adapter.executeRead) throw new Error('executeRead not supported');
|
|
113
|
+
const fqt = qualified(driver, [database, schema, table]);
|
|
114
|
+
return adapter.executeRead(`SELECT * FROM ${fqt}`, [], { database, limit: 1_000_000 });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function getColumns(connectionId: string, driver: 'mysql' | 'postgres' | 'sqlite' | 'mongodb', table: string, database?: string, schema?: string): Promise<DbClientObjectDetails> {
|
|
118
|
+
const adapter = await connectionManager.get(connectionId);
|
|
119
|
+
if (!adapter.getObjectDetails) throw new Error('getObjectDetails not supported');
|
|
120
|
+
return adapter.getObjectDetails(table, driver === 'mongodb' ? 'collection' : 'table', database, schema);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function buildCreateTableSql(driver: SqlDriver, details: DbClientObjectDetails, tableName: string, database?: string, schema?: string): string {
|
|
124
|
+
const cols = details.columns ?? [];
|
|
125
|
+
const fqt = qualified(driver, [database, schema, tableName]);
|
|
126
|
+
const lines: string[] = [];
|
|
127
|
+
for (const c of cols) {
|
|
128
|
+
const parts = [quoteIdent(driver, c.name), c.type];
|
|
129
|
+
if (!c.nullable) parts.push('NOT NULL');
|
|
130
|
+
if (c.default !== null && c.default !== undefined && c.default !== '') parts.push(`DEFAULT ${c.default}`);
|
|
131
|
+
if (c.isPrimary) parts.push('PRIMARY KEY');
|
|
132
|
+
if (c.isUnique && !c.isPrimary) parts.push('UNIQUE');
|
|
133
|
+
lines.push(' ' + parts.join(' '));
|
|
134
|
+
}
|
|
135
|
+
return `CREATE TABLE ${fqt} (\n${lines.join(',\n')}\n);`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const ioHandler = createRouter()
|
|
139
|
+
.http('db-client:data:export', {
|
|
140
|
+
data: t.Object({
|
|
141
|
+
connectionId: t.String({ minLength: 1 }),
|
|
142
|
+
database: t.Optional(t.String()),
|
|
143
|
+
schema: t.Optional(t.String()),
|
|
144
|
+
tables: t.Array(t.String({ minLength: 1 })),
|
|
145
|
+
format: t.Union([
|
|
146
|
+
t.Literal('sql'), t.Literal('csv'), t.Literal('json'),
|
|
147
|
+
t.Literal('jsonl'), t.Literal('redis')
|
|
148
|
+
]),
|
|
149
|
+
withData: t.Optional(t.Boolean()),
|
|
150
|
+
schemaOnly: t.Optional(t.Boolean())
|
|
151
|
+
}),
|
|
152
|
+
response: t.Object({
|
|
153
|
+
filename: t.String(),
|
|
154
|
+
content: t.String(),
|
|
155
|
+
mimeType: t.String()
|
|
156
|
+
})
|
|
157
|
+
}, async ({ data, conn }) => {
|
|
158
|
+
const connection = requireDbClientConnectionAccess(conn, data.connectionId);
|
|
159
|
+
const driver = connection.driver;
|
|
160
|
+
const withData = data.schemaOnly ? false : (data.withData ?? true);
|
|
161
|
+
|
|
162
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
163
|
+
const baseName = data.tables.length === 1 ? data.tables[0] : `export-${data.tables.length}-tables`;
|
|
164
|
+
|
|
165
|
+
if (driver === 'mysql' || driver === 'postgres' || driver === 'sqlite') {
|
|
166
|
+
const sqlDriver = driver as SqlDriver;
|
|
167
|
+
if (data.format === 'sql') {
|
|
168
|
+
const parts: string[] = [];
|
|
169
|
+
for (const t of data.tables) {
|
|
170
|
+
const details = await getColumns(data.connectionId, sqlDriver, t, data.database, data.schema);
|
|
171
|
+
parts.push(`-- Table: ${t}`);
|
|
172
|
+
parts.push(buildCreateTableSql(sqlDriver, details, t, data.database, data.schema));
|
|
173
|
+
if (withData) {
|
|
174
|
+
const result = await readAllRows(data.connectionId, sqlDriver, t, data.database, data.schema);
|
|
175
|
+
const cols = result.columns.map((c) => c.name);
|
|
176
|
+
const fqt = qualified(sqlDriver, [data.database, data.schema, t]);
|
|
177
|
+
const colSql = cols.map((c) => quoteIdent(sqlDriver, c)).join(', ');
|
|
178
|
+
for (const row of result.rows) {
|
|
179
|
+
const vals = cols.map((c) => sqlLiteral(row[c])).join(', ');
|
|
180
|
+
parts.push(`INSERT INTO ${fqt} (${colSql}) VALUES (${vals});`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
parts.push('');
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
filename: `${baseName}-${stamp}.sql`,
|
|
187
|
+
content: parts.join('\n'),
|
|
188
|
+
mimeType: 'application/sql'
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (data.format === 'csv') {
|
|
192
|
+
if (data.tables.length !== 1) throw new Error('CSV export supports a single table only');
|
|
193
|
+
const t = data.tables[0];
|
|
194
|
+
const result = await readAllRows(data.connectionId, sqlDriver, t, data.database, data.schema);
|
|
195
|
+
const cols = result.columns.map((c) => c.name);
|
|
196
|
+
const lines: string[] = [cols.map(csvCell).join(',')];
|
|
197
|
+
for (const row of result.rows) {
|
|
198
|
+
lines.push(cols.map((c) => csvCell(row[c])).join(','));
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
filename: `${baseName}-${stamp}.csv`,
|
|
202
|
+
content: lines.join('\n'),
|
|
203
|
+
mimeType: 'text/csv'
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (data.format === 'json') {
|
|
207
|
+
const out: Record<string, unknown[]> = {};
|
|
208
|
+
for (const t of data.tables) {
|
|
209
|
+
if (!withData) { out[t] = []; continue; }
|
|
210
|
+
const result = await readAllRows(data.connectionId, sqlDriver, t, data.database, data.schema);
|
|
211
|
+
out[t] = result.rows;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
filename: `${baseName}-${stamp}.json`,
|
|
215
|
+
content: JSON.stringify(out, null, 2),
|
|
216
|
+
mimeType: 'application/json'
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
throw new Error(`Format ${data.format} not supported for ${driver}`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (driver === 'mongodb') {
|
|
223
|
+
const adapter = await connectionManager.get(data.connectionId);
|
|
224
|
+
if (data.format === 'json' || data.format === 'jsonl') {
|
|
225
|
+
const out: Record<string, unknown[]> = {};
|
|
226
|
+
for (const coll of data.tables) {
|
|
227
|
+
if (!withData) { out[coll] = []; continue; }
|
|
228
|
+
const q = JSON.stringify({
|
|
229
|
+
collection: coll,
|
|
230
|
+
op: 'find',
|
|
231
|
+
args: [{}, { limit: 1_000_000 }]
|
|
232
|
+
});
|
|
233
|
+
if (!adapter.executeRead) throw new Error('executeRead not supported');
|
|
234
|
+
const result = await adapter.executeRead(q, [], { database: data.database });
|
|
235
|
+
out[coll] = result.rows;
|
|
236
|
+
}
|
|
237
|
+
if (data.format === 'jsonl') {
|
|
238
|
+
if (data.tables.length !== 1) throw new Error('JSONL export supports a single collection only');
|
|
239
|
+
const docs = out[data.tables[0]] ?? [];
|
|
240
|
+
return {
|
|
241
|
+
filename: `${baseName}-${stamp}.jsonl`,
|
|
242
|
+
content: docs.map((d) => JSON.stringify(d)).join('\n'),
|
|
243
|
+
mimeType: 'application/x-ndjson'
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
filename: `${baseName}-${stamp}.json`,
|
|
248
|
+
content: JSON.stringify(out, null, 2),
|
|
249
|
+
mimeType: 'application/json'
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
throw new Error(`Format ${data.format} not supported for mongodb`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (driver === 'redis') {
|
|
256
|
+
const adapter = await connectionManager.get(data.connectionId);
|
|
257
|
+
if (!adapter.executeRead || !adapter.executeWrite) throw new Error('redis exec not supported');
|
|
258
|
+
interface KeyEntry { key: string; type: string; ttl: number | null; value: unknown }
|
|
259
|
+
const entries: KeyEntry[] = [];
|
|
260
|
+
for (const key of data.tables) {
|
|
261
|
+
const typeRes = await adapter.executeRead(JSON.stringify(['TYPE', key]), [], {});
|
|
262
|
+
const ttlRes = await adapter.executeRead(JSON.stringify(['TTL', key]), [], {});
|
|
263
|
+
const type = (typeRes.rows[0] as { result?: string } | undefined)?.result ?? 'string';
|
|
264
|
+
const ttl = ((ttlRes.rows[0] as { result?: number } | undefined)?.result ?? -1) > 0
|
|
265
|
+
? (ttlRes.rows[0] as { result?: number }).result ?? null
|
|
266
|
+
: null;
|
|
267
|
+
let cmd: unknown[];
|
|
268
|
+
switch (type) {
|
|
269
|
+
case 'list': cmd = ['LRANGE', key, '0', '-1']; break;
|
|
270
|
+
case 'hash': cmd = ['HGETALL', key]; break;
|
|
271
|
+
case 'set': cmd = ['SMEMBERS', key]; break;
|
|
272
|
+
case 'zset': cmd = ['ZRANGE', key, '0', '-1', 'WITHSCORES']; break;
|
|
273
|
+
default: cmd = ['GET', key];
|
|
274
|
+
}
|
|
275
|
+
const valRes = await adapter.executeRead(JSON.stringify(cmd), [], {});
|
|
276
|
+
const value = (valRes.rows[0] as { result?: unknown } | undefined)?.result ?? null;
|
|
277
|
+
entries.push({ key, type, ttl, value });
|
|
278
|
+
}
|
|
279
|
+
if (data.format === 'json') {
|
|
280
|
+
const out: Record<string, { type: string; ttl: number | null; value: unknown }> = {};
|
|
281
|
+
for (const e of entries) out[e.key] = { type: e.type, ttl: e.ttl, value: e.value };
|
|
282
|
+
return {
|
|
283
|
+
filename: `${baseName}-${stamp}.json`,
|
|
284
|
+
content: JSON.stringify(out, null, 2),
|
|
285
|
+
mimeType: 'application/json'
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (data.format === 'redis') {
|
|
289
|
+
const lines: string[] = [];
|
|
290
|
+
for (const e of entries) {
|
|
291
|
+
switch (e.type) {
|
|
292
|
+
case 'string': lines.push(`SET ${e.key} ${JSON.stringify(String(e.value ?? ''))}`); break;
|
|
293
|
+
case 'list': {
|
|
294
|
+
const arr = Array.isArray(e.value) ? e.value : [];
|
|
295
|
+
if (arr.length > 0) lines.push(`RPUSH ${e.key} ${arr.map((v) => JSON.stringify(String(v))).join(' ')}`);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case 'hash': {
|
|
299
|
+
const obj = (typeof e.value === 'object' && e.value !== null) ? e.value as Record<string, unknown> : {};
|
|
300
|
+
const pairs = Object.entries(obj).flatMap(([k, v]) => [k, String(v)]);
|
|
301
|
+
if (pairs.length > 0) lines.push(`HSET ${e.key} ${pairs.map((p) => JSON.stringify(p)).join(' ')}`);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
case 'set': {
|
|
305
|
+
const arr = Array.isArray(e.value) ? e.value : [];
|
|
306
|
+
if (arr.length > 0) lines.push(`SADD ${e.key} ${arr.map((v) => JSON.stringify(String(v))).join(' ')}`);
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
default: break;
|
|
310
|
+
}
|
|
311
|
+
if (e.ttl && e.ttl > 0) lines.push(`EXPIRE ${e.key} ${e.ttl}`);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
filename: `${baseName}-${stamp}.redis`,
|
|
315
|
+
content: lines.join('\n'),
|
|
316
|
+
mimeType: 'text/plain'
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
throw new Error(`Format ${data.format} not supported for redis`);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
throw new Error(`Driver ${driver} not supported`);
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
.http('db-client:data:import', {
|
|
326
|
+
data: t.Object({
|
|
327
|
+
connectionId: t.String({ minLength: 1 }),
|
|
328
|
+
database: t.Optional(t.String()),
|
|
329
|
+
schema: t.Optional(t.String()),
|
|
330
|
+
format: t.Union([
|
|
331
|
+
t.Literal('sql'), t.Literal('csv'), t.Literal('json'),
|
|
332
|
+
t.Literal('jsonl'), t.Literal('redis')
|
|
333
|
+
]),
|
|
334
|
+
content: t.String(),
|
|
335
|
+
targetTable: t.Optional(t.String())
|
|
336
|
+
}),
|
|
337
|
+
response: t.Object({
|
|
338
|
+
ok: t.Boolean(),
|
|
339
|
+
count: t.Number(),
|
|
340
|
+
message: t.String()
|
|
341
|
+
})
|
|
342
|
+
}, async ({ data, conn }) => {
|
|
343
|
+
const connection = requireDbClientConnectionAccess(conn, data.connectionId);
|
|
344
|
+
const driver = connection.driver;
|
|
345
|
+
const adapter = await connectionManager.get(data.connectionId);
|
|
346
|
+
|
|
347
|
+
if (driver === 'mysql' || driver === 'postgres' || driver === 'sqlite') {
|
|
348
|
+
if (data.format === 'sql') {
|
|
349
|
+
const stmts = splitSqlStatements(data.content);
|
|
350
|
+
let count = 0;
|
|
351
|
+
for (const s of stmts) {
|
|
352
|
+
if (!adapter.executeWrite) throw new Error('executeWrite not supported');
|
|
353
|
+
await adapter.executeWrite(s, [], { database: data.database });
|
|
354
|
+
count++;
|
|
355
|
+
}
|
|
356
|
+
return { ok: true, count, message: `Executed ${count} statement(s)` };
|
|
357
|
+
}
|
|
358
|
+
if (data.format === 'json') {
|
|
359
|
+
const parsed = JSON.parse(data.content) as Record<string, Record<string, unknown>[]>;
|
|
360
|
+
let total = 0;
|
|
361
|
+
for (const [table, rows] of Object.entries(parsed)) {
|
|
362
|
+
if (!Array.isArray(rows) || rows.length === 0) continue;
|
|
363
|
+
if (!adapter.insertRow) throw new Error('insertRow not supported');
|
|
364
|
+
for (const row of rows) {
|
|
365
|
+
await adapter.insertRow(table, row, { database: data.database, schema: data.schema });
|
|
366
|
+
total++;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return { ok: true, count: total, message: `Inserted ${total} row(s)` };
|
|
370
|
+
}
|
|
371
|
+
if (data.format === 'csv') {
|
|
372
|
+
if (!data.targetTable) throw new Error('CSV import requires targetTable');
|
|
373
|
+
const { headers, rows } = parseCsv(data.content);
|
|
374
|
+
if (!adapter.insertRow) throw new Error('insertRow not supported');
|
|
375
|
+
let count = 0;
|
|
376
|
+
for (const row of rows) {
|
|
377
|
+
if (row.every((v) => v === '')) continue;
|
|
378
|
+
const obj: Record<string, unknown> = {};
|
|
379
|
+
for (let i = 0; i < headers.length; i++) obj[headers[i]] = row[i] ?? '';
|
|
380
|
+
await adapter.insertRow(data.targetTable, obj, { database: data.database, schema: data.schema });
|
|
381
|
+
count++;
|
|
382
|
+
}
|
|
383
|
+
return { ok: true, count, message: `Inserted ${count} row(s) into ${data.targetTable}` };
|
|
384
|
+
}
|
|
385
|
+
throw new Error(`Format ${data.format} not supported for ${driver}`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (driver === 'mongodb') {
|
|
389
|
+
if (data.format === 'json') {
|
|
390
|
+
const parsed = JSON.parse(data.content) as Record<string, unknown[]>;
|
|
391
|
+
let total = 0;
|
|
392
|
+
if (!adapter.insertRow) throw new Error('insertRow not supported');
|
|
393
|
+
for (const [coll, docs] of Object.entries(parsed)) {
|
|
394
|
+
if (!Array.isArray(docs)) continue;
|
|
395
|
+
for (const doc of docs) {
|
|
396
|
+
await adapter.insertRow(coll, doc as Record<string, unknown>, { database: data.database });
|
|
397
|
+
total++;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return { ok: true, count: total, message: `Inserted ${total} document(s)` };
|
|
401
|
+
}
|
|
402
|
+
if (data.format === 'jsonl') {
|
|
403
|
+
if (!data.targetTable) throw new Error('JSONL import requires targetTable');
|
|
404
|
+
const lines = data.content.split('\n').map((l) => l.trim()).filter((l) => l.length > 0);
|
|
405
|
+
if (!adapter.insertRow) throw new Error('insertRow not supported');
|
|
406
|
+
let count = 0;
|
|
407
|
+
for (const line of lines) {
|
|
408
|
+
const doc = JSON.parse(line) as Record<string, unknown>;
|
|
409
|
+
await adapter.insertRow(data.targetTable, doc, { database: data.database });
|
|
410
|
+
count++;
|
|
411
|
+
}
|
|
412
|
+
return { ok: true, count, message: `Inserted ${count} document(s) into ${data.targetTable}` };
|
|
413
|
+
}
|
|
414
|
+
throw new Error(`Format ${data.format} not supported for mongodb`);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (driver === 'redis') {
|
|
418
|
+
if (!adapter.executeWrite) throw new Error('executeWrite not supported');
|
|
419
|
+
if (data.format === 'redis') {
|
|
420
|
+
const lines = data.content.split('\n').map((l) => l.trim()).filter((l) => l.length > 0);
|
|
421
|
+
let count = 0;
|
|
422
|
+
for (const line of lines) {
|
|
423
|
+
await adapter.executeWrite(line, [], {});
|
|
424
|
+
count++;
|
|
425
|
+
}
|
|
426
|
+
return { ok: true, count, message: `Executed ${count} command(s)` };
|
|
427
|
+
}
|
|
428
|
+
if (data.format === 'json') {
|
|
429
|
+
const parsed = JSON.parse(data.content) as Record<string, { type?: string; ttl?: number | null; value: unknown }>;
|
|
430
|
+
let count = 0;
|
|
431
|
+
for (const [key, entry] of Object.entries(parsed)) {
|
|
432
|
+
const type = entry.type ?? 'string';
|
|
433
|
+
let cmd: unknown[] = [];
|
|
434
|
+
switch (type) {
|
|
435
|
+
case 'list': cmd = ['RPUSH', key, ...((entry.value as unknown[]) ?? []).map(String)]; break;
|
|
436
|
+
case 'hash': {
|
|
437
|
+
const obj = (typeof entry.value === 'object' && entry.value !== null) ? entry.value as Record<string, unknown> : {};
|
|
438
|
+
cmd = ['HSET', key, ...Object.entries(obj).flatMap(([k, v]) => [k, String(v)])];
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
case 'set': cmd = ['SADD', key, ...((entry.value as unknown[]) ?? []).map(String)]; break;
|
|
442
|
+
default: cmd = ['SET', key, String(entry.value ?? '')];
|
|
443
|
+
}
|
|
444
|
+
await adapter.executeWrite(JSON.stringify(cmd), [], {});
|
|
445
|
+
if (entry.ttl && entry.ttl > 0) {
|
|
446
|
+
await adapter.executeWrite(JSON.stringify(['EXPIRE', key, String(entry.ttl)]), [], {});
|
|
447
|
+
}
|
|
448
|
+
count++;
|
|
449
|
+
}
|
|
450
|
+
return { ok: true, count, message: `Imported ${count} key(s)` };
|
|
451
|
+
}
|
|
452
|
+
throw new Error(`Format ${data.format} not supported for redis`);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
throw new Error(`Driver ${driver} not supported`);
|
|
456
|
+
});
|