@adep/runtime 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,3 +17,11 @@ export declare function stripLiterals(sql: string): string;
|
|
|
17
17
|
export declare function assertReadOnlyQuery(sql: string): void;
|
|
18
18
|
/** 断言裸 SQL 安全:DML 写(INSERT / UPDATE / DELETE),DDL 拒绝。不满足抛 DB_UNSAFE_OP。 */
|
|
19
19
|
export declare function assertWriteQuery(sql: string): void;
|
|
20
|
+
/** `cloud.db.execute`(2026-10-14,BUG-4)的语句分类:决定转发到哪条既有守卫链。 */
|
|
21
|
+
export type StatementKind = 'read' | 'write' | 'ddl';
|
|
22
|
+
/**
|
|
23
|
+
* 分类单条语句(不做安全检查——`execute` 实现会先过 `assertSafeStatement` 同款边界)。
|
|
24
|
+
* 未知动词(PRAGMA / VACUUM / EXPLAIN…)归 `ddl`:保守走「允许但只回影响行数」的一档,
|
|
25
|
+
* 与既有「DDL 拒绝」分叉——由 execute 的实现决定是否放行(见 builder/index.ts 注释)。
|
|
26
|
+
*/
|
|
27
|
+
export declare function classifyStatement(sql: string): StatementKind;
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,8 @@ var DB_RPC = {
|
|
|
26
26
|
query: "query",
|
|
27
27
|
/** 写路径(CF-013):`(method=writeQuery, args=[sql, params])` → `{ changes }`。 */
|
|
28
28
|
writeQuery: "writeQuery",
|
|
29
|
+
/** 通用执行(BUG-4,2026-10-14):`(method=execute, args=[sql, params?])` → `{ changes }`。 */
|
|
30
|
+
execute: "execute",
|
|
29
31
|
/** 读取 owned 表变更流(DB-006):`(method=changes, args=[table, query])`。 */
|
|
30
32
|
changes: "changes",
|
|
31
33
|
/** 开启事务:`begin → txId`。 */
|
|
@@ -415,6 +417,14 @@ function assertWriteQuery(sql) {
|
|
|
415
417
|
);
|
|
416
418
|
}
|
|
417
419
|
}
|
|
420
|
+
function classifyStatement(sql) {
|
|
421
|
+
const head = sqlHead(stripLiterals(sql));
|
|
422
|
+
if (head.startsWith("SELECT") || head.startsWith("WITH")) return "read";
|
|
423
|
+
if (head.startsWith("INSERT") || head.startsWith("UPDATE") || head.startsWith("DELETE")) {
|
|
424
|
+
return "write";
|
|
425
|
+
}
|
|
426
|
+
return "ddl";
|
|
427
|
+
}
|
|
418
428
|
|
|
419
429
|
// packages/runtime/src/database/builder/owned.ts
|
|
420
430
|
var OWNED_PK = "id";
|
|
@@ -967,6 +977,21 @@ function createCloudDb(driver, options = {}) {
|
|
|
967
977
|
assertWriteQuery(sql);
|
|
968
978
|
return driver.run(sql, params);
|
|
969
979
|
},
|
|
980
|
+
async execute(sql, params = []) {
|
|
981
|
+
if (sql.trim() === "") {
|
|
982
|
+
throw unsafeOperation("execute \u7684 sql \u4E0D\u80FD\u4E3A\u7A7A");
|
|
983
|
+
}
|
|
984
|
+
if (!Array.isArray(params)) {
|
|
985
|
+
throw unsafeOperation("execute \u7684 params \u5FC5\u987B\u662F\u6570\u7EC4\uFF08\u65E0\u53C2\u53EF\u4E0D\u4F20\uFF09");
|
|
986
|
+
}
|
|
987
|
+
guardWrite();
|
|
988
|
+
const kind = classifyStatement(sql);
|
|
989
|
+
if (kind === "read") {
|
|
990
|
+
await driver.all(sql, params);
|
|
991
|
+
return { changes: 0 };
|
|
992
|
+
}
|
|
993
|
+
return driver.run(sql, params);
|
|
994
|
+
},
|
|
970
995
|
async changes(table, query = {}) {
|
|
971
996
|
return readChanges(driver, table, query);
|
|
972
997
|
}
|
|
@@ -1042,6 +1067,10 @@ function createDbCapability(driver, options = {}) {
|
|
|
1042
1067
|
const [sql, params] = args;
|
|
1043
1068
|
return await db.writeQuery(sql, params);
|
|
1044
1069
|
}
|
|
1070
|
+
case DB_RPC.execute: {
|
|
1071
|
+
const [sql, params] = args;
|
|
1072
|
+
return await db.execute(sql, params ?? []);
|
|
1073
|
+
}
|
|
1045
1074
|
case DB_RPC.changes: {
|
|
1046
1075
|
const [table, query] = args;
|
|
1047
1076
|
return await db.changes(table, query);
|
|
@@ -16,6 +16,8 @@ export declare const DB_RPC: {
|
|
|
16
16
|
readonly query: "query";
|
|
17
17
|
/** 写路径(CF-013):`(method=writeQuery, args=[sql, params])` → `{ changes }`。 */
|
|
18
18
|
readonly writeQuery: "writeQuery";
|
|
19
|
+
/** 通用执行(BUG-4,2026-10-14):`(method=execute, args=[sql, params?])` → `{ changes }`。 */
|
|
20
|
+
readonly execute: "execute";
|
|
19
21
|
/** 读取 owned 表变更流(DB-006):`(method=changes, args=[table, query])`。 */
|
|
20
22
|
readonly changes: "changes";
|
|
21
23
|
/** 开启事务:`begin → txId`。 */
|
|
@@ -21,6 +21,21 @@ export declare const OOM_CODE = "FN_EXEC_OOM";
|
|
|
21
21
|
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
22
22
|
/** 内存上限缺省值(MB)。 */
|
|
23
23
|
export declare const DEFAULT_MEMORY_LIMIT_MB = 128;
|
|
24
|
+
/**
|
|
25
|
+
* 调试执行(`POST /v1/functions/:id/run`)允许的触发方法白名单。
|
|
26
|
+
*
|
|
27
|
+
* ⚠️ **这是唯一真相源**:服务端请求体 schema(`server/domains/functions/logs/routes.ts`)
|
|
28
|
+
* 与 IDE 工具 `function_invoke` 的入参声明(`app/ide/plugins/devtools.ts`)都必须从这里取。
|
|
29
|
+
*
|
|
30
|
+
* 历史缺陷(2026-10-17 集成测试实测):schema 曾写死 `GET | POST`,而工具声明了
|
|
31
|
+
* `PUT / PATCH / DELETE`——Agent 照工具声明发 PATCH 调试,服务端 422 拒绝,且报错是
|
|
32
|
+
* 形如「Property 'method' should be one of: 'string', 'string'」的 schema 文案,模型无法据此纠正,
|
|
33
|
+
* 于是在同一调用上反复失败、把一整轮预算烧光。执行器本身接受任意方法(`ExecutorRequest.method`
|
|
34
|
+
* 是 string),限死的只是上面那两处声明,所以修法是把它们收敛到这一份清单。
|
|
35
|
+
*/
|
|
36
|
+
export declare const FUNCTION_RUN_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
37
|
+
/** 白名单元素类型(供 schema / 工具声明共用,避免两处各写一遍字面量)。 */
|
|
38
|
+
export type FunctionRunMethod = (typeof FUNCTION_RUN_METHODS)[number];
|
|
24
39
|
/** 可作为函数错误状态的合法 HTTP 码区间(FN-011:业务可表达 4xx/5xx 语义)。 */
|
|
25
40
|
export declare function isHttpStatus(status: unknown): status is number;
|
|
26
41
|
/**
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"homepage": "https://adep.top",
|
|
9
9
|
"bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
|
|
10
|
-
"version": "0.3.
|
|
10
|
+
"version": "0.3.4",
|
|
11
11
|
"private": false,
|
|
12
12
|
"type": "module",
|
|
13
13
|
"sideEffects": false,
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@adep/types": "0.3.
|
|
35
|
+
"@adep/types": "0.3.2"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "vitest run",
|