@lark-apaas/miaoda-cli 0.1.1-alpha.06e1628 → 0.1.1-alpha.07b4fd5

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.
@@ -96,15 +96,45 @@ async function execSql(opts) {
96
96
  const body = (await response.json());
97
97
  try {
98
98
  const data = (0, client_1.extractData)(body);
99
- return data.results ?? [];
99
+ const results = data.results ?? [];
100
+ // 新协议(dataloom 端 InnerAdminExecuteSQL 错误统一走 success envelope):
101
+ // results 末尾追加一条 SqlType="ERROR" 的哨兵,data 字段是 {code,message} JSON。
102
+ // 这样网关在错误路径不会吞业务字段,CLI 拿到完整 partial_results + statement_index。
103
+ const last = results.at(-1);
104
+ if (last?.sqlType === "ERROR") {
105
+ const appErr = parseSqlErrorSentinel(last.data);
106
+ appErr.partial_results = results.slice(0, -1);
107
+ const stmtIdx = data.errorStatementIndex;
108
+ if (typeof stmtIdx === "number")
109
+ appErr.statement_index = stmtIdx;
110
+ throw appErr;
111
+ }
112
+ return results;
100
113
  }
101
114
  catch (appErr) {
102
- // HTTP 2xx 但 envelope status_code != 0 的多语句失败路径:同样挂 partial_results
115
+ // 旧协议兼容(dataloom 服务端未部署新协议时):HTTP 2xx 但 envelope status_code != 0
116
+ // 走 mapDbHttpError → AppError,partial_results 已被网关吞,仅保留 code+message。
103
117
  if (appErr instanceof error_1.AppError)
104
118
  attachSqlPartialResults(body, appErr);
105
119
  throw appErr;
106
120
  }
107
121
  }
122
+ /**
123
+ * 解析 InnerAdminExecuteSQL 错误哨兵(results 末尾那条 SqlType="ERROR" 项)的 data 字段。
124
+ * 服务端约定:data 是 `{"code":"k_dl_xxx","message":"..."}` 形态的 JSON 字符串。
125
+ * 解析失败则降级为 INTERNAL_DB_ERROR + 原始字符串,避免哨兵格式异常时整条调用炸掉。
126
+ */
127
+ function parseSqlErrorSentinel(payload) {
128
+ try {
129
+ const parsed = JSON.parse(payload);
130
+ const code = typeof parsed.code === "string" && parsed.code !== "" ? parsed.code : "INTERNAL_DB_ERROR";
131
+ const message = typeof parsed.message === "string" ? parsed.message : payload;
132
+ return new error_1.AppError(code, message);
133
+ }
134
+ catch {
135
+ return new error_1.AppError("INTERNAL_DB_ERROR", payload);
136
+ }
137
+ }
108
138
  // ── db schema → InnerGetSchema ──
109
139
  /**
110
140
  * 查询 schema(admin-inner)。
@@ -118,6 +118,9 @@ const BIZ_ERR_MAP = new Map(Object.entries({
118
118
  "k_dl_000003": { code: "SQL_OPERATION_FORBIDDEN" },
119
119
  // k_dl_1300002:PG 执行错误;实际 SQLSTATE 由 extractSqlstate 单独映射
120
120
  // 未匹配到 SQLSTATE 时走下面兜底 DB_API_<code>
121
+ // k_dl_1300015:SELECT 结果超过 1000 行硬拦;多行 hint 由 output.ts 的
122
+ // SERVER_ERROR_HINTS 按语义 code 兜底,这里只做 code 改名
123
+ "k_dl_1300015": { code: "RESULT_SET_TOO_LARGE" },
121
124
  }));
122
125
  /** PG SQLSTATE → CLI code(当前 dataloom 不一定透传,预留未来使用) */
123
126
  exports.SQLSTATE_MAP = {
@@ -20,8 +20,10 @@ const colors_1 = require("./colors");
20
20
  * 具体 hint(如 did-you-mean、shared.resolveAppId 等),它们优先级更高。
21
21
  */
22
22
  const SERVER_ERROR_HINTS = {
23
- // SELECT 结果集超过 1000 行硬拦:spec 多行引导
24
- "k_dl_1300015": [
23
+ // SELECT 结果集超过 1000 行硬拦:spec 多行引导。
24
+ // key 用 BIZ_ERR_MAP 映射后的语义 code(不是原始服务端 k_dl_xxx),保持
25
+ // 与 help / 文档里宣传的 RESULT_SET_TOO_LARGE 一致。
26
+ "RESULT_SET_TOO_LARGE": [
25
27
  "Add `LIMIT <n>` to your SQL to narrow the result.",
26
28
  "For counts, use `SELECT count(*) FROM ...`; for aggregation, use GROUP BY with filters.",
27
29
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-cli",
3
- "version": "0.1.1-alpha.06e1628",
3
+ "version": "0.1.1-alpha.07b4fd5",
4
4
  "description": "Miaoda 平台命令行工具,面向 Agent 调用",
5
5
  "type": "commonjs",
6
6
  "bin": {