zero-db-tool 0.0.0-stage → 1.0.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.
@@ -0,0 +1,239 @@
1
+ /**
2
+ * SQL 词法闸门:只读/写入语句分类与安全检查。
3
+ *
4
+ * - sql_query 只读:SELECT/PRAGMA/EXPLAIN/SHOW/DESCRIBE/WITH,单语句
5
+ * - sql_exec 只允许 INSERT/UPDATE;DELETE/DROP/DDL/事务等一律拒绝
6
+ * - 所有守卫都是纯函数,便于单测
7
+ */
8
+ export const READ_ONLY_LEADING_TOKENS = new Set([
9
+ "SELECT", "PRAGMA", "EXPLAIN", "SHOW", "DESCRIBE", "WITH",
10
+ ]);
11
+ export const WRITE_LEADING_TOKENS = new Set([
12
+ "INSERT", "UPDATE", "DELETE", "REPLACE", "CREATE", "DROP", "ALTER", "TRUNCATE",
13
+ "VACUUM", "REINDEX", "ATTACH", "DETACH", "BEGIN", "COMMIT", "ROLLBACK",
14
+ "SAVEPOINT", "RELEASE", "ANALYZE", "GRANT", "REVOKE", "MERGE", "CALL",
15
+ "EXECUTE", "SET", "USE", "LOAD", "IMPORT", "COPY", "OPTIMIZE", "RENAME",
16
+ ]);
17
+ export class SqlGuardError extends Error {
18
+ code;
19
+ constructor(code, message, options) {
20
+ super(message, options);
21
+ this.code = code;
22
+ this.name = "SqlGuardError";
23
+ }
24
+ }
25
+ /** Strip SQL comments (-- line, block) outside string literals. */
26
+ export function stripSqlComments(sql) {
27
+ let out = "";
28
+ let i = 0;
29
+ let inSingle = false;
30
+ let inDouble = false;
31
+ while (i < sql.length) {
32
+ const ch = sql[i];
33
+ const next = sql[i + 1];
34
+ if (!inSingle && !inDouble) {
35
+ if (ch === "-" && next === "-") {
36
+ const end = sql.indexOf("\n", i);
37
+ i = end === -1 ? sql.length : end;
38
+ continue;
39
+ }
40
+ if (ch === "/" && next === "*") {
41
+ const end = sql.indexOf("*/", i + 2);
42
+ i = end === -1 ? sql.length : end + 2;
43
+ continue;
44
+ }
45
+ if (ch === "'")
46
+ inSingle = true;
47
+ else if (ch === '"')
48
+ inDouble = true;
49
+ }
50
+ else if (inSingle) {
51
+ if (ch === "'") {
52
+ if (next === "'") {
53
+ out += "''";
54
+ i += 2;
55
+ continue;
56
+ }
57
+ inSingle = false;
58
+ }
59
+ }
60
+ else if (inDouble && ch === '"') {
61
+ inDouble = false;
62
+ }
63
+ out += ch;
64
+ i += 1;
65
+ }
66
+ return out;
67
+ }
68
+ /** Split a script into top-level statements, respecting literals and comments. */
69
+ export function splitStatements(sql) {
70
+ const parts = [];
71
+ let current = "";
72
+ let inSingle = false;
73
+ let inDouble = false;
74
+ let i = 0;
75
+ while (i < sql.length) {
76
+ const ch = sql[i];
77
+ const next = sql[i + 1];
78
+ if (!inSingle && !inDouble) {
79
+ if (ch === "-" && next === "-") {
80
+ const end = sql.indexOf("\n", i);
81
+ const stop = end === -1 ? sql.length : end;
82
+ current += sql.slice(i, stop);
83
+ i = stop;
84
+ continue;
85
+ }
86
+ if (ch === "/" && next === "*") {
87
+ const end = sql.indexOf("*/", i + 2);
88
+ const stop = end === -1 ? sql.length : end + 2;
89
+ current += sql.slice(i, stop);
90
+ i = stop;
91
+ continue;
92
+ }
93
+ if (ch === "'") {
94
+ inSingle = true;
95
+ current += ch;
96
+ i += 1;
97
+ continue;
98
+ }
99
+ if (ch === '"') {
100
+ inDouble = true;
101
+ current += ch;
102
+ i += 1;
103
+ continue;
104
+ }
105
+ if (ch === ";") {
106
+ parts.push(current);
107
+ current = "";
108
+ i += 1;
109
+ continue;
110
+ }
111
+ current += ch;
112
+ i += 1;
113
+ continue;
114
+ }
115
+ if (inSingle) {
116
+ if (ch === "'") {
117
+ if (next === "'") {
118
+ current += "''";
119
+ i += 2;
120
+ continue;
121
+ }
122
+ inSingle = false;
123
+ }
124
+ }
125
+ else if (inDouble && ch === '"') {
126
+ inDouble = false;
127
+ }
128
+ current += ch;
129
+ i += 1;
130
+ }
131
+ parts.push(current);
132
+ return parts.map((part) => part.trim()).filter(Boolean);
133
+ }
134
+ export function leadingToken(statement) {
135
+ const match = /^\s*([A-Za-z_][A-Za-z0-9_]*)/.exec(statement);
136
+ return match?.[1]?.toUpperCase() ?? "";
137
+ }
138
+ export function assertSingleStatement(statements) {
139
+ if (statements.length > 1) {
140
+ throw new SqlGuardError("DB_MULTI_STATEMENT_REJECTED", `sql_query accepts exactly one statement (got ${statements.length}); use sql_exec for INSERT/UPDATE batches`);
141
+ }
142
+ }
143
+ /** Allow only INSERT or UPDATE statements for sql_exec batches. */
144
+ export function assertWriteStatement(statement) {
145
+ const bare = stripSqlComments(statement);
146
+ const token = leadingToken(bare);
147
+ if (token !== "INSERT" && token !== "UPDATE") {
148
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_exec rejected: only INSERT and UPDATE are allowed (got " + (token || "nothing") + ")");
149
+ }
150
+ if (/\b(?:DELETE|DROP|ALTER|TRUNCATE|CREATE|REPLACE|MERGE|GRANT|REVOKE|CALL|EXECUTE|COPY|LOAD|VACUUM|REINDEX|ATTACH|DETACH|BEGIN|COMMIT|ROLLBACK|SAVEPOINT|RELEASE|USE)\b/i.test(bare)) {
151
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_exec rejected: statement contains a forbidden mutation");
152
+ }
153
+ return token;
154
+ }
155
+ /** SQLite table-valued pragmas that only read metadata. */
156
+ const READ_ONLY_PRAGMA_CALLS = new Set([
157
+ "table_info", "table_xinfo", "index_list", "index_info", "index_xinfo",
158
+ "foreign_key_list", "database_list", "collation_list", "function_list",
159
+ "module_list", "pragma_list",
160
+ ]);
161
+ /** Lexical read-only gate for sql_query (statement must already be single). */
162
+ export function assertReadOnlyStatement(statement) {
163
+ const bare = stripSqlComments(statement);
164
+ const token = leadingToken(bare);
165
+ if (!READ_ONLY_LEADING_TOKENS.has(token)) {
166
+ if (WRITE_LEADING_TOKENS.has(token)) {
167
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", `sql_query rejected: leading token ${token} is not read-only`);
168
+ }
169
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", `sql_query rejected: statement must start with SELECT/PRAGMA/EXPLAIN/SHOW/DESCRIBE/WITH (got ${token || "nothing"})`);
170
+ }
171
+ const folded = bare.toUpperCase();
172
+ if (/\bFOR\s+UPDATE\b/.test(folded) || /\bFOR\s+SHARE\b/.test(folded)) {
173
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_query rejected: FOR UPDATE / FOR SHARE locking clauses are not read-only");
174
+ }
175
+ if (/\bSELECT\b[^;]*\bINTO\b/.test(folded)) {
176
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_query rejected: SELECT ... INTO creates a table");
177
+ }
178
+ if (token === "WITH") {
179
+ if (/\)\s*(INSERT|UPDATE|DELETE|MERGE|REPLACE)\b/.test(folded) || /\bAS\s*\(\s*(INSERT|UPDATE|DELETE|MERGE|REPLACE)\b/.test(folded)) {
180
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_query rejected: data-modifying CTE (WITH ... INSERT/UPDATE/DELETE)");
181
+ }
182
+ if (/\b(INSERT|UPDATE|DELETE|MERGE|REPLACE)\b/.test(folded)) {
183
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_query rejected: data-modifying statement inside WITH");
184
+ }
185
+ }
186
+ if (token === "PRAGMA") {
187
+ if (/^PRAGMA\s+[A-Za-z0-9_.]+\s*=/.test(bare.trim().toUpperCase())) {
188
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_query rejected: PRAGMA assignment writes configuration");
189
+ }
190
+ // Call-form is read-only only for SQLite's table-valued pragmas; the rest may set state.
191
+ const callForm = /^PRAGMA\s+([A-Za-z0-9_.]+)\s*\(/i.exec(bare.trim());
192
+ if (callForm && !READ_ONLY_PRAGMA_CALLS.has(callForm[1].toLowerCase())) {
193
+ throw new SqlGuardError("DB_READ_ONLY_VIOLATION", "sql_query rejected: PRAGMA call-form assignment writes configuration");
194
+ }
195
+ }
196
+ }
197
+ /** Identifier guard for interpolated table names (schema/stats). */
198
+ export function assertSafeIdentifier(name) {
199
+ const trimmed = name.trim();
200
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(trimmed)) {
201
+ throw new SqlGuardError("DB_INVALID_CONFIG", `invalid SQL identifier: ${JSON.stringify(trimmed)}`);
202
+ }
203
+ return trimmed;
204
+ }
205
+ /** JSON-safe cell value: bigint -> decimal string, binary -> size placeholder. */
206
+ export function jsonSafeValue(value) {
207
+ if (typeof value === "bigint")
208
+ return value.toString();
209
+ if (value instanceof Uint8Array)
210
+ return "<BLOB " + value.byteLength + "B>";
211
+ if (value instanceof Date)
212
+ return value.toISOString();
213
+ return value;
214
+ }
215
+ export function jsonSafeRows(rows) {
216
+ return rows.map((row) => Object.fromEntries(Object.entries(row).map(([key, value]) => [key, jsonSafeValue(value)])));
217
+ }
218
+ export function formatTable(columns, rows) {
219
+ const cell = (value) => (value === null || value === undefined ? "" : String(value));
220
+ return [columns.join(" | "), columns.map(() => "---").join(" | "), rows.map((row) => columns.map((column) => cell(row[column])).join(" | ")).join("\n")].join("\n");
221
+ }
222
+ export function toCsv(columns, rows) {
223
+ const escape = (value) => {
224
+ const text = value === null || value === undefined ? "" : String(value);
225
+ return /[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
226
+ };
227
+ return [columns.join(","), ...rows.map((row) => columns.map((column) => escape(row[column])).join(","))].join("\n");
228
+ }
229
+ /** True when the driver error means the server session is gone and one reopen may heal it. */
230
+ export function isDbConnectionLoss(error) {
231
+ if (!error || typeof error !== "object")
232
+ return false;
233
+ const err = error;
234
+ const code = typeof err.code === "string" ? err.code.toUpperCase() : "";
235
+ const message = typeof err.message === "string" ? err.message : "";
236
+ if (["ECONNRESET", "EPIPE", "ETIMEDOUT", "PROTOCOL_CONNECTION_LOST", "CONNECTION_LOST", "57P01", "57P03", "08003", "08006"].includes(code))
237
+ return true;
238
+ return /connection lost|connection closed|connection ended|connection terminated|server closed the connection unexpectedly/i.test(message);
239
+ }
package/dist/tools.js ADDED
@@ -0,0 +1,229 @@
1
+ /**
2
+ * 六个模型工具:
3
+ * sql_query 只读单语句
4
+ * sql_exec INSERT 直通;含 UPDATE 时由本工具直接向用户发起批准
5
+ * sql_schema 列出表/视图,或描述一张表的列
6
+ * sql_stats 表数量、逐表行数、SQLite 文件大小
7
+ * sql_health 逐连接探活 + 治理摘要
8
+ * sql_connections 列出/新增/删除/测试连接
9
+ */
10
+ import { DbConnectionError } from "./connections.js";
11
+ import { SQL_MAX_ROWS_DEFAULT, SQL_MAX_ROWS_LIMIT, SQL_QUERY_TIMEOUT_MS, SQL_EXEC_TIMEOUT_MS, } from "./manager.js";
12
+ import { SqlGuardError } from "./sql-guard.js";
13
+ const TOOL_DESCRIPTION = "Governed SQL access over named database connections (sqlite via node:sqlite; PostgreSQL via pg; MySQL via mysql2). " +
14
+ "sql_query is READ-ONLY (SELECT/PRAGMA/EXPLAIN/SHOW/DESCRIBE/WITH; single statement). " +
15
+ "Before writing any SQL, call sql_schema to inspect real table/column names — never guess identifiers. " +
16
+ "sql_exec permits INSERT directly; UPDATE asks the user for approval inside the call. DELETE, DROP, DDL, permissions, transactions and all other mutations remain forbidden. " +
17
+ "sql_stats counts rows per table (can be expensive on large tables). sql_health probes connectivity. " +
18
+ "sql_connections manages configs: adding a connection is low-risk, but run action=\"test\" before first real use.";
19
+ function mapErrorCode(error) {
20
+ if (error instanceof SqlGuardError)
21
+ return error.code;
22
+ if (error instanceof DbConnectionError)
23
+ return error.code;
24
+ const code = error && typeof error === "object" && "code" in error ? String(error.code) : "";
25
+ switch (code) {
26
+ case "DB_CONNECTION_NOT_FOUND":
27
+ case "DB_ENV_MISSING":
28
+ case "DB_ENGINE_UNAVAILABLE":
29
+ case "DB_ENGINE_ERROR":
30
+ case "DB_INVALID_CONFIG":
31
+ return code;
32
+ default:
33
+ return "DB_ENGINE_ERROR";
34
+ }
35
+ }
36
+ async function envelope(operation) {
37
+ try {
38
+ const result = await operation();
39
+ return { text: JSON.stringify({ ok: true, ...result }) };
40
+ }
41
+ catch (error) {
42
+ return {
43
+ text: JSON.stringify({ ok: false, error: { code: mapErrorCode(error), message: error instanceof Error ? error.message : String(error) } }),
44
+ isError: true,
45
+ };
46
+ }
47
+ }
48
+ const output = {
49
+ schema: {
50
+ type: "object",
51
+ properties: {
52
+ text: { type: "string", description: "JSON result text" },
53
+ isError: { type: "boolean", description: "true when the operation was rejected or failed" },
54
+ },
55
+ required: ["text"],
56
+ },
57
+ render: (_args, value) => [{ type: "text", text: value.text }],
58
+ };
59
+ export function registerTools(ctx, service) {
60
+ const tools = ctx.tools;
61
+ if (!tools?.register)
62
+ return;
63
+ tools.register({
64
+ name: "sql_query",
65
+ timeoutMs: SQL_QUERY_TIMEOUT_MS + 10_000,
66
+ description: TOOL_DESCRIPTION,
67
+ parameters: {
68
+ type: "object",
69
+ properties: {
70
+ connection: { type: "string", description: "Named database connection." },
71
+ sql: { type: "string", description: "One read-only SQL statement (SELECT/PRAGMA/EXPLAIN/SHOW/DESCRIBE/WITH)." },
72
+ format: { type: "string", enum: ["json", "table", "csv"], description: "Optional text rendering of the rows; default json." },
73
+ limit: { type: "number", description: `Max rows (default ${SQL_MAX_ROWS_DEFAULT}, cap ${SQL_MAX_ROWS_LIMIT}).` },
74
+ },
75
+ required: ["connection", "sql"],
76
+ },
77
+ output,
78
+ execute: async (args) => envelope(async () => {
79
+ const result = await service.query(args.connection, args.sql, args.format ?? "json", args.limit ?? SQL_MAX_ROWS_DEFAULT);
80
+ return { connection: result.connection, columns: result.columns, rows: result.rows, rowCount: result.rowCount, truncated: result.truncated, ...(result.text !== undefined ? { text: result.text } : {}) };
81
+ }),
82
+ });
83
+ tools.register({
84
+ name: "sql_exec",
85
+ timeoutMs: SQL_EXEC_TIMEOUT_MS + 30_000,
86
+ description: TOOL_DESCRIPTION,
87
+ parameters: {
88
+ type: "object",
89
+ properties: {
90
+ connection: { type: "string", description: "Named database connection." },
91
+ sql: { type: "string", description: "One or more INSERT/UPDATE statements separated by semicolons. A batch containing UPDATE prompts the user for approval before it runs." },
92
+ },
93
+ required: ["connection", "sql"],
94
+ },
95
+ output,
96
+ execute: async (args, exec) => envelope(async () => {
97
+ if (service.needsApproval(args.sql)) {
98
+ await requestWriteApproval(ctx, exec, args.connection, args.sql);
99
+ }
100
+ const result = await service.execute(args.connection, args.sql);
101
+ return { connection: args.connection, statementCount: result.statementCount, affectedRows: result.affectedRows, results: result.results };
102
+ }),
103
+ });
104
+ tools.register({
105
+ name: "sql_schema",
106
+ timeoutMs: SQL_QUERY_TIMEOUT_MS + 10_000,
107
+ description: TOOL_DESCRIPTION,
108
+ parameters: {
109
+ type: "object",
110
+ properties: {
111
+ connection: { type: "string", description: "Named database connection." },
112
+ table: { type: "string", description: "Table name to describe; omit to list all tables and views." },
113
+ },
114
+ required: ["connection"],
115
+ },
116
+ output,
117
+ execute: async (args) => envelope(async () => ({ ...(await service.schema(args.connection, args.table)) })),
118
+ });
119
+ tools.register({
120
+ name: "sql_stats",
121
+ timeoutMs: SQL_EXEC_TIMEOUT_MS + 10_000,
122
+ description: TOOL_DESCRIPTION,
123
+ parameters: {
124
+ type: "object",
125
+ properties: { connection: { type: "string", description: "Named database connection." } },
126
+ required: ["connection"],
127
+ },
128
+ output,
129
+ execute: async (args) => envelope(async () => ({ ...(await service.stats(args.connection)) })),
130
+ });
131
+ tools.register({
132
+ name: "sql_health",
133
+ timeoutMs: SQL_EXEC_TIMEOUT_MS,
134
+ description: TOOL_DESCRIPTION,
135
+ parameters: { type: "object", properties: {} },
136
+ output,
137
+ execute: async () => envelope(async () => ({
138
+ connections: await service.health(),
139
+ readOnlyMode: true,
140
+ writeGate: "ask_user_question",
141
+ maxRowsDefault: SQL_MAX_ROWS_DEFAULT,
142
+ maxRowsLimit: SQL_MAX_ROWS_LIMIT,
143
+ queryTimeoutMs: SQL_QUERY_TIMEOUT_MS,
144
+ execTimeoutMs: SQL_EXEC_TIMEOUT_MS,
145
+ })),
146
+ });
147
+ tools.register({
148
+ name: "sql_connections",
149
+ timeoutMs: SQL_QUERY_TIMEOUT_MS + 10_000,
150
+ description: TOOL_DESCRIPTION,
151
+ parameters: {
152
+ type: "object",
153
+ properties: {
154
+ action: { type: "string", enum: ["list", "add", "remove", "test"], description: "Operation to perform." },
155
+ name: { type: "string", description: "Connection name (add/remove/test)." },
156
+ engine: { type: "string", enum: ["sqlite", "postgres", "mysql"], description: "Database engine (add)." },
157
+ path: { type: "string", description: "sqlite only: ABSOLUTE database file path." },
158
+ mode: { type: "string", enum: ["parameters", "url-env"], description: "postgres/mysql connection method; default parameters." },
159
+ urlEnv: { type: "string", description: "url-env mode: environment variable NAME holding the full DSN." },
160
+ host: { type: "string", description: "postgres/mysql host name or IP." },
161
+ port: { type: "number", description: "Optional port (5432 for PostgreSQL, 3306 for MySQL by default)." },
162
+ database: { type: "string", description: "postgres/mysql database name." },
163
+ username: { type: "string", description: "postgres/mysql user name." },
164
+ passwordEnv: { type: "string", description: "Environment variable NAME holding the password; never ask for a password in chat." },
165
+ ssl: { type: "boolean", description: "Enable TLS/SSL." },
166
+ },
167
+ required: ["action"],
168
+ },
169
+ output,
170
+ execute: async (args) => envelope(async () => {
171
+ if (args.action === "list")
172
+ return { connections: service.list() };
173
+ if (!args.name)
174
+ throw new SqlGuardError("DB_INVALID_CONFIG", "name is required for add/remove/test");
175
+ if (args.action === "test")
176
+ return { name: args.name, result: await service.test(args.name) };
177
+ if (args.action === "remove") {
178
+ const removed = await service.remove(args.name);
179
+ if (!removed)
180
+ throw new DbConnectionError("DB_CONNECTION_NOT_FOUND", `no database connection named "${args.name}"`);
181
+ return { removed: args.name };
182
+ }
183
+ if (!args.engine)
184
+ throw new SqlGuardError("DB_INVALID_CONFIG", "action=add requires name and engine");
185
+ const summary = await service.add({
186
+ name: args.name,
187
+ engine: args.engine,
188
+ ...(args.path ? { path: args.path } : {}),
189
+ ...(args.mode ? { mode: args.mode } : {}),
190
+ ...(args.urlEnv ? { urlEnv: args.urlEnv } : {}),
191
+ ...(args.host ? { host: args.host } : {}),
192
+ ...(args.port !== undefined ? { port: args.port } : {}),
193
+ ...(args.database ? { database: args.database } : {}),
194
+ ...(args.username ? { username: args.username } : {}),
195
+ ...(args.passwordEnv ? { passwordMode: "environment", passwordEnv: args.passwordEnv } : {}),
196
+ ...(args.ssl !== undefined ? { ssl: args.ssl } : {}),
197
+ });
198
+ return { added: { name: summary.name, engine: summary.engine }, note: "connection registered; run action=\"test\" before first real use" };
199
+ }),
200
+ });
201
+ }
202
+ /** Ask the human before an UPDATE batch runs; fail closed when no question UI is available. */
203
+ async function requestWriteApproval(ctx, exec, connection, sql) {
204
+ const questions = ctx.get?.("userQuestions", true);
205
+ if (!questions?.ask) {
206
+ throw new SqlGuardError("DB_CONFIRMATION_REQUIRED", "sql_exec needs the ask_user_question confirmation gate, which is unavailable in this session");
207
+ }
208
+ const agent = exec?.agent;
209
+ if (!agent) {
210
+ throw new SqlGuardError("DB_CONFIRMATION_REQUIRED", "sql_exec needs a live session to ask for confirmation");
211
+ }
212
+ const answer = await questions.ask({
213
+ questions: [{
214
+ id: "approve-sql-write",
215
+ header: "SQL 写入确认",
216
+ question: `连接 ${connection} 上即将执行包含 UPDATE 的语句:\n\n${sql}\n\n批准后立即执行。`,
217
+ options: [
218
+ { label: "批准", description: "执行这批 INSERT/UPDATE 语句。" },
219
+ { label: "拒绝", description: "不执行,语句不会发送到数据库。" },
220
+ ],
221
+ }],
222
+ agent,
223
+ signal: exec?.signal,
224
+ });
225
+ const selected = answer.answers.find((item) => item.id === "approve-sql-write")?.selected ?? [];
226
+ if (!selected.includes("批准")) {
227
+ throw new SqlGuardError("DB_CONFIRMATION_REQUIRED", "the user rejected the UPDATE batch");
228
+ }
229
+ }
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "zero-db-tool",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "DSH 数据库工作台:连接下拉 + 对象树 + 数据/结构/SQL,SQLite/PostgreSQL/MySQL,只读优先,六个 sql_* 工具",
5
+ "type": "module",
6
+ "license": "BSD-3-Clause",
7
+ "engines": {
8
+ "node": ">=22",
9
+ "dsh": ">=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.2 <0.3.0-0"
10
+ },
11
+ "main": "dist/index.js",
12
+ "exports": {
13
+ ".": "./dist/index.js",
14
+ "./client": "./client/client.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "client",
20
+ "cordis.patch.yml",
21
+ "README.md",
22
+ "LICENSE",
23
+ "assets/icon.png"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json && node scripts/build-client.mjs",
27
+ "typecheck": "tsc -p tsconfig.json --noEmit",
28
+ "test": "vitest run",
29
+ "prepack": "npm run build",
30
+ "prepare": "npm run build",
31
+ "build:client": "node scripts/build-client.mjs"
32
+ },
33
+ "dsh": {
34
+ "bundle": {
35
+ "patch": "./cordis.patch.yml"
36
+ },
37
+ "client": {
38
+ "inject": [
39
+ "@deepseek-ai/dsh-client-locale",
40
+ "@deepseek-ai/dsh-client-ui-sidebar-right"
41
+ ],
42
+ "platform": "web"
43
+ }
44
+ },
45
+ "peerDependencies": {
46
+ "@deepseek-ai/cordis": "^4.0.1"
47
+ },
48
+ "dependencies": {
49
+ "mysql2": "^3.24.4",
50
+ "pg": "^8.23.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^24.0.0",
54
+ "typescript": "^5.9.3",
55
+ "vitest": "^4.1.11",
56
+ "esbuild": "^0.28.0",
57
+ "react": "^19.0.0",
58
+ "react-dom": "^19.0.0",
59
+ "@types/react": "^19.0.0",
60
+ "@types/react-dom": "^19.0.0",
61
+ "antd": "^5.27.0",
62
+ "@ant-design/icons": "^5.6.0",
63
+ "jsdom": "^27.0.0"
64
+ }
65
+ }