@adep/runtime 0.3.3 → 0.3.5
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;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 支持子集:
|
|
5
5
|
* `export default`
|
|
6
|
-
* `export const | let | var | function | class`
|
|
6
|
+
* `export const | let | var | function | class` (含顶层逗号分隔的多声明符)
|
|
7
7
|
* `export { a, b as c }` 裸再导出(引用本模块已有绑定)
|
|
8
8
|
* `export { a, b as c } from './x'` 再导出(FN-035)
|
|
9
9
|
* `export * from './x'` / `export * as ns from './x'` 星号再导出(FN-035)
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
* ⇒ 整个函数 500。FN-035 之前裸再导出正是这样漏的(详见与它配套的
|
|
22
22
|
* `syntaxErrorWithLocation`:连报位都会指到别的文件上,极难定位)。
|
|
23
23
|
*
|
|
24
|
+
* ⚠️ **静默漏登记比 SyntaxError 更贵**:少导出一个名字不会炸,消费侧只拿到 `undefined`,
|
|
25
|
+
* 无栈可查。故多声明符(`export const a = 1, b = 2`)必须逐个数出来;形态判不准就明确报错
|
|
26
|
+
* (解构导出 `export const { a } = x` 同此,见 `scanDeclaration` 与 `declaratorName`)。
|
|
27
|
+
*
|
|
24
28
|
* 行数守恒:每次替换都保持**已有内容的行号不变**——`transpile` 用 strip 模式擦类型,
|
|
25
29
|
* 前提就是行号可信(错误行号、调试面板行号都靠它),吃掉几行就用等量换行补回。
|
|
26
30
|
* 唯一的例外是**末尾追加**的汇总赋值(在最后一行之后),它不移任何已有行。
|
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";
|
|
@@ -669,10 +679,21 @@ function compileSelect(state, dialect) {
|
|
|
669
679
|
if (state.orderBys.length > 0) {
|
|
670
680
|
sql += ` ORDER BY ${state.orderBys.map((order) => `${dialect.quote(order.column)} ${order.direction.toUpperCase()}`).join(", ")}`;
|
|
671
681
|
}
|
|
672
|
-
if (state.limit !== void 0)
|
|
673
|
-
|
|
682
|
+
if (state.limit !== void 0) {
|
|
683
|
+
assertInlineableInt(state.limit, "limit");
|
|
684
|
+
sql += ` LIMIT ${state.limit}`;
|
|
685
|
+
}
|
|
686
|
+
if (state.offset !== void 0) {
|
|
687
|
+
assertInlineableInt(state.offset, "offset");
|
|
688
|
+
sql += ` OFFSET ${state.offset}`;
|
|
689
|
+
}
|
|
674
690
|
return { sql, params };
|
|
675
691
|
}
|
|
692
|
+
function assertInlineableInt(value, name) {
|
|
693
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
694
|
+
throw unsafeOperation(`${name} \u5FC5\u987B\u662F\u975E\u8D1F\u6574\u6570`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
676
697
|
function compileCount(state, dialect) {
|
|
677
698
|
const params = [];
|
|
678
699
|
let sql = `SELECT count(*) AS n FROM ${dialect.quote(state.table)}`;
|
|
@@ -967,6 +988,21 @@ function createCloudDb(driver, options = {}) {
|
|
|
967
988
|
assertWriteQuery(sql);
|
|
968
989
|
return driver.run(sql, params);
|
|
969
990
|
},
|
|
991
|
+
async execute(sql, params = []) {
|
|
992
|
+
if (sql.trim() === "") {
|
|
993
|
+
throw unsafeOperation("execute \u7684 sql \u4E0D\u80FD\u4E3A\u7A7A");
|
|
994
|
+
}
|
|
995
|
+
if (!Array.isArray(params)) {
|
|
996
|
+
throw unsafeOperation("execute \u7684 params \u5FC5\u987B\u662F\u6570\u7EC4\uFF08\u65E0\u53C2\u53EF\u4E0D\u4F20\uFF09");
|
|
997
|
+
}
|
|
998
|
+
guardWrite();
|
|
999
|
+
const kind = classifyStatement(sql);
|
|
1000
|
+
if (kind === "read") {
|
|
1001
|
+
await driver.all(sql, params);
|
|
1002
|
+
return { changes: 0 };
|
|
1003
|
+
}
|
|
1004
|
+
return driver.run(sql, params);
|
|
1005
|
+
},
|
|
970
1006
|
async changes(table, query = {}) {
|
|
971
1007
|
return readChanges(driver, table, query);
|
|
972
1008
|
}
|
|
@@ -1042,6 +1078,10 @@ function createDbCapability(driver, options = {}) {
|
|
|
1042
1078
|
const [sql, params] = args;
|
|
1043
1079
|
return await db.writeQuery(sql, params);
|
|
1044
1080
|
}
|
|
1081
|
+
case DB_RPC.execute: {
|
|
1082
|
+
const [sql, params] = args;
|
|
1083
|
+
return await db.execute(sql, params ?? []);
|
|
1084
|
+
}
|
|
1045
1085
|
case DB_RPC.changes: {
|
|
1046
1086
|
const [table, query] = args;
|
|
1047
1087
|
return await db.changes(table, query);
|
|
@@ -2130,11 +2170,21 @@ function parseWhereClauses(whereRaw, cursor) {
|
|
|
2130
2170
|
const t = part.trim();
|
|
2131
2171
|
if (t.length === 0) continue;
|
|
2132
2172
|
if (/\bIS\s+NULL\b/i.test(t)) {
|
|
2133
|
-
clauses.push({
|
|
2173
|
+
clauses.push({
|
|
2174
|
+
column: unqualifyColumn(ident(t.split(/\s+IS\s+NULL\b/i)[0] ?? "")),
|
|
2175
|
+
operator: "IS NULL",
|
|
2176
|
+
value: null,
|
|
2177
|
+
list: false
|
|
2178
|
+
});
|
|
2134
2179
|
continue;
|
|
2135
2180
|
}
|
|
2136
2181
|
if (/\bIS\s+NOT\s+NULL\b/i.test(t)) {
|
|
2137
|
-
clauses.push({
|
|
2182
|
+
clauses.push({
|
|
2183
|
+
column: unqualifyColumn(ident(t.split(/\s+IS\s+NOT\s+NULL\b/i)[0] ?? "")),
|
|
2184
|
+
operator: "IS NOT NULL",
|
|
2185
|
+
value: null,
|
|
2186
|
+
list: false
|
|
2187
|
+
});
|
|
2138
2188
|
continue;
|
|
2139
2189
|
}
|
|
2140
2190
|
const opMatch = /^\s*((?:"[^"]+")|([A-Za-z_][A-Za-z0-9_.]*))\s*(=|!=|>=|<=|>|<|like|in|not\s+in)\s*(.+)$/i.exec(
|
|
@@ -2311,7 +2361,10 @@ function parseConflictClause(clause, cursor, fallbackCols) {
|
|
|
2311
2361
|
clause.trim()
|
|
2312
2362
|
);
|
|
2313
2363
|
if (m === null) {
|
|
2314
|
-
throw new SimDbError(
|
|
2364
|
+
throw new SimDbError(
|
|
2365
|
+
"DB_UNSAFE_OP",
|
|
2366
|
+
`\u65E0\u6CD5\u89E3\u6790 ON CONFLICT \u5B50\u53E5\uFF1A${clause.trim().slice(0, 60)}\u2026`
|
|
2367
|
+
);
|
|
2315
2368
|
}
|
|
2316
2369
|
const colsRaw = m[1];
|
|
2317
2370
|
const cols = colsRaw === void 0 ? fallbackCols : colsRaw.split(",").map(ident);
|
|
@@ -2515,16 +2568,16 @@ var SimSqlEngine = class {
|
|
|
2515
2568
|
row[col] = values[i] ?? null;
|
|
2516
2569
|
});
|
|
2517
2570
|
if (conflictSpec !== null) {
|
|
2518
|
-
const existing = table.rows.find(
|
|
2519
|
-
(r) => conflictSpec.cols.every((c) => r[c] === row[c])
|
|
2520
|
-
);
|
|
2571
|
+
const existing = table.rows.find((r) => conflictSpec.cols.every((c) => r[c] === row[c]));
|
|
2521
2572
|
if (existing !== void 0) {
|
|
2522
2573
|
const oldRow = { ...existing };
|
|
2523
2574
|
for (const set of conflictSpec.sets) {
|
|
2524
2575
|
existing[set.col] = resolveSetValue(set.value, oldRow, row);
|
|
2525
2576
|
}
|
|
2526
2577
|
inserted += 1;
|
|
2527
|
-
|
|
2578
|
+
this.persist().catch((error) => {
|
|
2579
|
+
console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
|
|
2580
|
+
});
|
|
2528
2581
|
continue;
|
|
2529
2582
|
}
|
|
2530
2583
|
}
|
|
@@ -2532,7 +2585,9 @@ var SimSqlEngine = class {
|
|
|
2532
2585
|
table.rows.push(row);
|
|
2533
2586
|
inserted += 1;
|
|
2534
2587
|
}
|
|
2535
|
-
|
|
2588
|
+
this.persist().catch((error) => {
|
|
2589
|
+
console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
|
|
2590
|
+
});
|
|
2536
2591
|
return { changes: inserted };
|
|
2537
2592
|
}
|
|
2538
2593
|
execUpdate(sql, params) {
|
|
@@ -2562,7 +2617,9 @@ var SimSqlEngine = class {
|
|
|
2562
2617
|
}
|
|
2563
2618
|
changes += 1;
|
|
2564
2619
|
}
|
|
2565
|
-
|
|
2620
|
+
this.persist().catch((error) => {
|
|
2621
|
+
console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
|
|
2622
|
+
});
|
|
2566
2623
|
return { changes };
|
|
2567
2624
|
}
|
|
2568
2625
|
execDelete(sql, params) {
|
|
@@ -2580,7 +2637,9 @@ var SimSqlEngine = class {
|
|
|
2580
2637
|
else changes += 1;
|
|
2581
2638
|
}
|
|
2582
2639
|
table.rows = keep;
|
|
2583
|
-
|
|
2640
|
+
this.persist().catch((error) => {
|
|
2641
|
+
console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
|
|
2642
|
+
});
|
|
2584
2643
|
return { changes };
|
|
2585
2644
|
}
|
|
2586
2645
|
select(sql, params) {
|
|
@@ -2602,7 +2661,9 @@ var SimSqlEngine = class {
|
|
|
2602
2661
|
rows = table.rows.map((row) => {
|
|
2603
2662
|
const merged = { ...row };
|
|
2604
2663
|
for (const j of joins) {
|
|
2605
|
-
const joined = this.tables[j.table]?.rows.find(
|
|
2664
|
+
const joined = this.tables[j.table]?.rows.find(
|
|
2665
|
+
(jr) => jr[j.leftCol] === merged[j.rightCol]
|
|
2666
|
+
);
|
|
2606
2667
|
if (joined !== void 0) {
|
|
2607
2668
|
for (const [k, v] of Object.entries(joined)) merged[`${j.alias}.${k}`] = v;
|
|
2608
2669
|
}
|
|
@@ -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.5",
|
|
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",
|