dsh-sql 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +3 -1
- package/README.md +3 -1
- package/cordis.patch.yml +2 -0
- package/lib/config.d.ts +4 -0
- package/lib/config.js +13 -1
- package/lib/tools.js +2 -2
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -38,6 +38,8 @@ dsh plugin --profile web add dsh-sql
|
|
|
38
38
|
user: root
|
|
39
39
|
database: legacy
|
|
40
40
|
maxRows: 1000 # query row cap (1-10000)
|
|
41
|
+
queryTimeoutMs: 60000 # per-query timeout (default 60s, 5s - 10min)
|
|
42
|
+
execTimeoutMs: 120000 # per-write timeout (default 120s, 5s - 10min)
|
|
41
43
|
readOnly: false # true disables sql_exec
|
|
42
44
|
writeApproval: true # approve write operations first (default true)
|
|
43
45
|
```
|
|
@@ -80,7 +82,7 @@ sql_exec { sql: UPDATE orders SET status = 'paid' WHERE id = 42 }
|
|
|
80
82
|
|
|
81
83
|
```bash
|
|
82
84
|
pnpm install
|
|
83
|
-
pnpm test # build +
|
|
85
|
+
pnpm test # build + 35 tests, including a real SQLite integration suite
|
|
84
86
|
```
|
|
85
87
|
|
|
86
88
|
## License
|
package/README.md
CHANGED
|
@@ -38,6 +38,8 @@ dsh plugin --profile web add dsh-sql
|
|
|
38
38
|
user: root
|
|
39
39
|
database: legacy
|
|
40
40
|
maxRows: 1000 # 查询返回行数上限(1-10000)
|
|
41
|
+
queryTimeoutMs: 60000 # 单次查询超时(默认 60 秒,5 秒 - 10 分钟)
|
|
42
|
+
execTimeoutMs: 120000 # 单次写操作超时(默认 120 秒,5 秒 - 10 分钟)
|
|
41
43
|
readOnly: false # true 时禁用 sql_exec
|
|
42
44
|
writeApproval: true # 写操作先弹审批(默认 true)
|
|
43
45
|
```
|
|
@@ -80,7 +82,7 @@ sql_exec { sql: UPDATE orders SET status = 'paid' WHERE id = 42 }
|
|
|
80
82
|
|
|
81
83
|
```bash
|
|
82
84
|
pnpm install
|
|
83
|
-
pnpm test # 构建 +
|
|
85
|
+
pnpm test # 构建 + 35 个测试(含真实 SQLite 集成)
|
|
84
86
|
```
|
|
85
87
|
|
|
86
88
|
## License
|
package/cordis.patch.yml
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# engine: sqlite
|
|
13
13
|
# file: E:\data\app.db
|
|
14
14
|
# maxRows: 1000 # sql_query 返回行数上限(1-10000,默认 1000)
|
|
15
|
+
queryTimeoutMs: 60000 # 单次查询超时(5 秒 - 10 分钟)
|
|
16
|
+
execTimeoutMs: 120000 # 单次写操作超时(5 秒 - 10 分钟)
|
|
15
17
|
# readOnly: false # true 时 sql_exec 被禁用
|
|
16
18
|
# writeApproval: true # 写操作先弹审批(默认 true)
|
|
17
19
|
#
|
package/lib/config.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface SqlConfig {
|
|
|
20
20
|
maxRows?: number;
|
|
21
21
|
readOnly?: boolean;
|
|
22
22
|
writeApproval?: boolean;
|
|
23
|
+
queryTimeoutMs?: number;
|
|
24
|
+
execTimeoutMs?: number;
|
|
23
25
|
}
|
|
24
26
|
/** 解析后的配置。 */
|
|
25
27
|
export interface ResolvedSqlConfig {
|
|
@@ -27,6 +29,8 @@ export interface ResolvedSqlConfig {
|
|
|
27
29
|
maxRows: number;
|
|
28
30
|
readOnly: boolean;
|
|
29
31
|
writeApproval: boolean;
|
|
32
|
+
queryTimeoutMs: number;
|
|
33
|
+
execTimeoutMs: number;
|
|
30
34
|
}
|
|
31
35
|
/** 连接密码环境变量名:DSH_SQL_PASSWORD_<NAME 大写>。 */
|
|
32
36
|
export declare function passwordEnvName(name: string): string;
|
package/lib/config.js
CHANGED
|
@@ -53,9 +53,21 @@ export function resolveConfig(config, env = process.env) {
|
|
|
53
53
|
throw new Error('maxRows 必须是大于 0 的整数。');
|
|
54
54
|
maxRows = Math.min(10000, cfg.maxRows);
|
|
55
55
|
}
|
|
56
|
+
let queryTimeoutMs = 60000;
|
|
57
|
+
if (cfg.queryTimeoutMs !== undefined) {
|
|
58
|
+
if (typeof cfg.queryTimeoutMs !== 'number' || !Number.isFinite(cfg.queryTimeoutMs) || cfg.queryTimeoutMs <= 0)
|
|
59
|
+
throw new Error('queryTimeoutMs 必须是大于 0 的数字(毫秒)。');
|
|
60
|
+
queryTimeoutMs = Math.min(600000, Math.max(5000, Math.round(cfg.queryTimeoutMs)));
|
|
61
|
+
}
|
|
62
|
+
let execTimeoutMs = 120000;
|
|
63
|
+
if (cfg.execTimeoutMs !== undefined) {
|
|
64
|
+
if (typeof cfg.execTimeoutMs !== 'number' || !Number.isFinite(cfg.execTimeoutMs) || cfg.execTimeoutMs <= 0)
|
|
65
|
+
throw new Error('execTimeoutMs 必须是大于 0 的数字(毫秒)。');
|
|
66
|
+
execTimeoutMs = Math.min(600000, Math.max(5000, Math.round(cfg.execTimeoutMs)));
|
|
67
|
+
}
|
|
56
68
|
const readOnly = cfg.readOnly === true;
|
|
57
69
|
const writeApproval = cfg.writeApproval !== false;
|
|
58
|
-
return { connections, maxRows, readOnly, writeApproval };
|
|
70
|
+
return { connections, maxRows, readOnly, writeApproval, queryTimeoutMs, execTimeoutMs };
|
|
59
71
|
}
|
|
60
72
|
/** 校验表名/标识符,防注入到 schema 语句。 */
|
|
61
73
|
export function assertIdentifier(name, label) {
|
package/lib/tools.js
CHANGED
|
@@ -306,7 +306,7 @@ export function buildSqlTools(config) {
|
|
|
306
306
|
maxRows: cfg.maxRows,
|
|
307
307
|
};
|
|
308
308
|
},
|
|
309
|
-
timeoutMs:
|
|
309
|
+
timeoutMs: cfg.queryTimeoutMs,
|
|
310
310
|
};
|
|
311
311
|
const sqlExec = {
|
|
312
312
|
name: 'sql_exec',
|
|
@@ -334,7 +334,7 @@ export function buildSqlTools(config) {
|
|
|
334
334
|
gate(exec, next) {
|
|
335
335
|
return next(); // 审批门由 index.ts 注入(需要宿主 ctx)
|
|
336
336
|
},
|
|
337
|
-
timeoutMs:
|
|
337
|
+
timeoutMs: cfg.execTimeoutMs,
|
|
338
338
|
};
|
|
339
339
|
const sqlSchema = {
|
|
340
340
|
name: 'sql_schema',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sql",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH 工程师级数据库插件:sql_list/query/exec/schema 四工具,SQLite/MySQL/PostgreSQL
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "DSH 工程师级数据库插件:sql_list/query/exec/schema 四工具,SQLite/MySQL/PostgreSQL 三引擎、多连接、只读模式与写操作审批门、词法级只读保护、流式行数钳制与可配置查询/写超时。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|