@lark-apaas/miaoda-cli 0.1.3-alpha.228c3e0 → 0.1.3-alpha.2a09432
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/dist/api/app/api.js +3 -3
- package/dist/api/app/schemas.js +43 -43
- package/dist/api/db/api.js +94 -94
- package/dist/api/db/client.js +41 -41
- package/dist/api/db/parsers.js +20 -20
- package/dist/api/db/sql-keywords.js +87 -87
- package/dist/api/deploy/api.js +5 -5
- package/dist/api/deploy/schemas.js +32 -32
- package/dist/api/file/api.js +64 -64
- package/dist/api/file/client.js +62 -22
- package/dist/api/file/detect.js +3 -3
- package/dist/api/file/parsers.js +5 -5
- package/dist/api/observability/api.js +6 -6
- package/dist/api/observability/schemas.js +14 -14
- package/dist/api/plugin/api.js +31 -31
- package/dist/cli/commands/app/index.js +12 -12
- package/dist/cli/commands/db/index.js +145 -145
- package/dist/cli/commands/deploy/index.js +28 -28
- package/dist/cli/commands/file/index.js +81 -61
- package/dist/cli/commands/observability/index.js +69 -69
- package/dist/cli/commands/plugin/index.js +27 -27
- package/dist/cli/commands/shared.js +10 -10
- package/dist/cli/handlers/app/update.js +2 -2
- package/dist/cli/handlers/db/_operator.js +35 -0
- package/dist/cli/handlers/db/audit.js +43 -34
- package/dist/cli/handlers/db/changelog.js +11 -9
- package/dist/cli/handlers/db/data.js +28 -28
- package/dist/cli/handlers/db/migration.js +23 -23
- package/dist/cli/handlers/db/quota.js +3 -3
- package/dist/cli/handlers/db/recovery.js +40 -40
- package/dist/cli/handlers/db/schema.js +33 -33
- package/dist/cli/handlers/db/sql.js +69 -69
- package/dist/cli/handlers/deploy/deploy.js +4 -4
- package/dist/cli/handlers/deploy/error-log.js +1 -1
- package/dist/cli/handlers/deploy/get.js +3 -3
- package/dist/cli/handlers/deploy/polling.js +11 -11
- package/dist/cli/handlers/file/cp.js +30 -30
- package/dist/cli/handlers/file/ls.js +5 -5
- package/dist/cli/handlers/file/quota.js +2 -2
- package/dist/cli/handlers/file/rm.js +24 -24
- package/dist/cli/handlers/file/sign.js +3 -3
- package/dist/cli/handlers/file/stat.js +9 -9
- package/dist/cli/handlers/observability/analytics.js +47 -47
- package/dist/cli/handlers/observability/helpers.js +2 -2
- package/dist/cli/handlers/observability/log.js +9 -9
- package/dist/cli/handlers/observability/metric.js +26 -26
- package/dist/cli/handlers/observability/trace.js +5 -5
- package/dist/cli/handlers/plugin/plugin-local.js +53 -53
- package/dist/cli/handlers/plugin/plugin.js +15 -15
- package/dist/cli/help.js +16 -16
- package/dist/main.js +12 -12
- package/dist/utils/args.js +1 -1
- package/dist/utils/colors.js +2 -2
- package/dist/utils/config.js +2 -2
- package/dist/utils/devops-error.js +9 -9
- package/dist/utils/error.js +2 -2
- package/dist/utils/git.js +4 -4
- package/dist/utils/http.js +19 -19
- package/dist/utils/output.js +47 -47
- package/dist/utils/poll.js +2 -2
- package/dist/utils/render.js +27 -27
- package/dist/utils/time.js +26 -26
- package/package.json +1 -1
package/dist/api/app/api.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.getAppInfo = getAppInfo;
|
|
|
4
4
|
exports.updateAppMeta = updateAppMeta;
|
|
5
5
|
const http_1 = require("../../utils/http");
|
|
6
6
|
const devops_error_1 = require("../../utils/devops-error");
|
|
7
|
-
const DEFAULT_ERR_CODE =
|
|
7
|
+
const DEFAULT_ERR_CODE = 'INTERNAL_DEVOPS_ERROR';
|
|
8
8
|
function envelopeOpts(errPrefix) {
|
|
9
9
|
return {
|
|
10
10
|
errPrefix,
|
|
@@ -15,11 +15,11 @@ function envelopeOpts(errPrefix) {
|
|
|
15
15
|
/** GET /v1/devops/app/:appID — 获取应用详情 */
|
|
16
16
|
async function getAppInfo(appID) {
|
|
17
17
|
const url = `/v1/devops/app/${encodeURIComponent(appID)}`;
|
|
18
|
-
return (0, http_1.getInnerApi)(url, envelopeOpts(
|
|
18
|
+
return (0, http_1.getInnerApi)(url, envelopeOpts('Failed to get app info'));
|
|
19
19
|
}
|
|
20
20
|
/** POST /v1/devops/app/:appID/meta — 更新应用元数据 */
|
|
21
21
|
async function updateAppMeta(req) {
|
|
22
22
|
const url = `/v1/devops/app/${encodeURIComponent(req.appID)}/meta`;
|
|
23
23
|
// 路径已带 appID,body 里也保留以匹配 BAM IDL 的 sensitive:"no" 透传约定
|
|
24
|
-
return (0, http_1.postInnerApi)(url, req, envelopeOpts(
|
|
24
|
+
return (0, http_1.postInnerApi)(url, req, envelopeOpts('Failed to update app'));
|
|
25
25
|
}
|
package/dist/api/app/schemas.js
CHANGED
|
@@ -5,47 +5,47 @@ const output_1 = require("../../utils/output");
|
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
// Partial<Record<...>>:未来 BAM 加新枚举值时这里没声明也不报错,运行期 lookup 自然得 undefined
|
|
7
7
|
const STATUS_TEXT = {
|
|
8
|
-
[types_1.AppStatus.UNSPECIFIED]:
|
|
9
|
-
[types_1.AppStatus.PREPARING]:
|
|
10
|
-
[types_1.AppStatus.UNRELEASED]:
|
|
11
|
-
[types_1.AppStatus.RELEASED]:
|
|
12
|
-
[types_1.AppStatus.DELETED]:
|
|
13
|
-
[types_1.AppStatus.UPGRADING]:
|
|
8
|
+
[types_1.AppStatus.UNSPECIFIED]: 'unknown',
|
|
9
|
+
[types_1.AppStatus.PREPARING]: 'preparing',
|
|
10
|
+
[types_1.AppStatus.UNRELEASED]: 'unreleased',
|
|
11
|
+
[types_1.AppStatus.RELEASED]: 'released',
|
|
12
|
+
[types_1.AppStatus.DELETED]: 'deleted',
|
|
13
|
+
[types_1.AppStatus.UPGRADING]: 'upgrading',
|
|
14
14
|
};
|
|
15
15
|
const MODE_TEXT = {
|
|
16
|
-
[types_1.AppMode.UNSPECIFIED]:
|
|
17
|
-
[types_1.AppMode.STANDARD]:
|
|
18
|
-
[types_1.AppMode.EXPERT]:
|
|
16
|
+
[types_1.AppMode.UNSPECIFIED]: 'unknown',
|
|
17
|
+
[types_1.AppMode.STANDARD]: 'standard',
|
|
18
|
+
[types_1.AppMode.EXPERT]: 'expert',
|
|
19
19
|
};
|
|
20
20
|
const TYPE_TEXT = {
|
|
21
|
-
[types_1.AppType.UNSPECIFIED]:
|
|
22
|
-
[types_1.AppType.STANDARD]:
|
|
23
|
-
[types_1.AppType.PROTOTYPE]:
|
|
24
|
-
[types_1.AppType.APPLICATION]:
|
|
25
|
-
[types_1.AppType.DESIGN]:
|
|
26
|
-
[types_1.AppType.OPENCLAW]:
|
|
27
|
-
[types_1.AppType.CLAW_SUB]:
|
|
21
|
+
[types_1.AppType.UNSPECIFIED]: 'unknown',
|
|
22
|
+
[types_1.AppType.STANDARD]: 'standard',
|
|
23
|
+
[types_1.AppType.PROTOTYPE]: 'prototype',
|
|
24
|
+
[types_1.AppType.APPLICATION]: 'application',
|
|
25
|
+
[types_1.AppType.DESIGN]: 'design',
|
|
26
|
+
[types_1.AppType.OPENCLAW]: 'openclaw',
|
|
27
|
+
[types_1.AppType.CLAW_SUB]: 'claw_sub',
|
|
28
28
|
};
|
|
29
29
|
const BIZ_TYPE_TEXT = {
|
|
30
|
-
[types_1.BizType.UNSPECIFIED]:
|
|
31
|
-
[types_1.BizType.MIAODA]:
|
|
32
|
-
[types_1.BizType.FORCE]:
|
|
30
|
+
[types_1.BizType.UNSPECIFIED]: 'unknown',
|
|
31
|
+
[types_1.BizType.MIAODA]: 'miaoda',
|
|
32
|
+
[types_1.BizType.FORCE]: 'force',
|
|
33
33
|
};
|
|
34
34
|
const ARCH_TYPE_TEXT = {
|
|
35
|
-
[types_1.ArchType.UNSPECIFIED]:
|
|
36
|
-
[types_1.ArchType.FULL_STACK]:
|
|
37
|
-
[types_1.ArchType.NOT_FULL_STACK]:
|
|
35
|
+
[types_1.ArchType.UNSPECIFIED]: 'unknown',
|
|
36
|
+
[types_1.ArchType.FULL_STACK]: 'full_stack',
|
|
37
|
+
[types_1.ArchType.NOT_FULL_STACK]: 'not_full_stack',
|
|
38
38
|
};
|
|
39
39
|
const SOURCE_TEXT = {
|
|
40
|
-
[types_1.Source.UNSPECIFIED]:
|
|
41
|
-
[types_1.Source.CHAT]:
|
|
42
|
-
[types_1.Source.TEMPLATE]:
|
|
43
|
-
[types_1.Source.IMPORT_ZIP]:
|
|
44
|
-
[types_1.Source.IMPORT_BASE]:
|
|
40
|
+
[types_1.Source.UNSPECIFIED]: 'unknown',
|
|
41
|
+
[types_1.Source.CHAT]: 'chat',
|
|
42
|
+
[types_1.Source.TEMPLATE]: 'template',
|
|
43
|
+
[types_1.Source.IMPORT_ZIP]: 'import_zip',
|
|
44
|
+
[types_1.Source.IMPORT_BASE]: 'import_base',
|
|
45
45
|
};
|
|
46
46
|
function lookup(table) {
|
|
47
47
|
return (v) => {
|
|
48
|
-
if (typeof v !==
|
|
48
|
+
if (typeof v !== 'number')
|
|
49
49
|
return undefined;
|
|
50
50
|
return table[v];
|
|
51
51
|
};
|
|
@@ -59,21 +59,21 @@ function lookup(table) {
|
|
|
59
59
|
*/
|
|
60
60
|
exports.appMetaSchema = {
|
|
61
61
|
columns: [
|
|
62
|
-
{ key:
|
|
63
|
-
{ key:
|
|
64
|
-
{ key:
|
|
65
|
-
{ key:
|
|
66
|
-
{ key:
|
|
67
|
-
{ key:
|
|
68
|
-
{ key:
|
|
69
|
-
{ key:
|
|
70
|
-
{ key:
|
|
71
|
-
{ key:
|
|
72
|
-
{ key:
|
|
73
|
-
{ key:
|
|
74
|
-
{ key:
|
|
75
|
-
{ key:
|
|
76
|
-
{ key:
|
|
62
|
+
{ key: 'appID', label: 'app-id' },
|
|
63
|
+
{ key: 'name' },
|
|
64
|
+
{ key: 'description' },
|
|
65
|
+
{ key: 'status_text', label: 'status', derive: (row) => lookup(STATUS_TEXT)(row.status) },
|
|
66
|
+
{ key: 'appType_text', label: 'type', derive: (row) => lookup(TYPE_TEXT)(row.appType) },
|
|
67
|
+
{ key: 'appMode_text', label: 'mode', derive: (row) => lookup(MODE_TEXT)(row.appMode) },
|
|
68
|
+
{ key: 'bizType_text', label: 'biz-type', derive: (row) => lookup(BIZ_TYPE_TEXT)(row.bizType) },
|
|
69
|
+
{ key: 'archType_text', label: 'arch', derive: (row) => lookup(ARCH_TYPE_TEXT)(row.archType) },
|
|
70
|
+
{ key: 'source_text', label: 'source', derive: (row) => lookup(SOURCE_TEXT)(row.source) },
|
|
71
|
+
{ key: 'ownedBy', label: 'owner' },
|
|
72
|
+
{ key: 'createdBy', label: 'creator' },
|
|
73
|
+
{ key: 'dataBranchID', label: 'branch' },
|
|
74
|
+
{ key: 'parentAppID', label: 'parent-app' },
|
|
75
|
+
{ key: 'createdAt', label: 'created-at', format: output_1.fmt.ms() },
|
|
76
|
+
{ key: 'updatedAt', label: 'updated-at', format: output_1.fmt.ms() },
|
|
77
77
|
],
|
|
78
78
|
strict: true,
|
|
79
79
|
};
|
package/dist/api/db/api.js
CHANGED
|
@@ -18,7 +18,7 @@ const http_1 = require("../../utils/http");
|
|
|
18
18
|
const error_1 = require("../../utils/error");
|
|
19
19
|
const http_client_1 = require("@lark-apaas/http-client");
|
|
20
20
|
const client_1 = require("./client");
|
|
21
|
-
const DEFAULT_TIMEOUT_HINT =
|
|
21
|
+
const DEFAULT_TIMEOUT_HINT = 'The server may still be processing your request. Retry the command if needed.';
|
|
22
22
|
async function mapDbHttpError(err, url, ctx, opts) {
|
|
23
23
|
if (err instanceof error_1.AppError)
|
|
24
24
|
throw err;
|
|
@@ -27,19 +27,19 @@ async function mapDbHttpError(err, url, ctx, opts) {
|
|
|
27
27
|
// 单独抛专用 AppError(带领域可定制的 message + hint),不再包成通用 "Failed to X"。
|
|
28
28
|
if (err instanceof Error) {
|
|
29
29
|
const lower = err.message.toLowerCase();
|
|
30
|
-
if (lower.includes(
|
|
31
|
-
lower.includes(
|
|
32
|
-
err.name ===
|
|
33
|
-
err.name ===
|
|
34
|
-
const code = opts?.timeout?.code ??
|
|
35
|
-
const message = opts?.timeout?.message ??
|
|
30
|
+
if (lower.includes('aborted') ||
|
|
31
|
+
lower.includes('timeout') ||
|
|
32
|
+
err.name === 'AbortError' ||
|
|
33
|
+
err.name === 'TimeoutError') {
|
|
34
|
+
const code = opts?.timeout?.code ?? 'REQUEST_TIMEOUT';
|
|
35
|
+
const message = opts?.timeout?.message ?? 'Request timed out after 30s';
|
|
36
36
|
const hint = opts?.timeout?.hint ?? DEFAULT_TIMEOUT_HINT;
|
|
37
37
|
throw new error_1.AppError(code, message, { next_actions: [hint] });
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
if (err instanceof http_client_1.HttpError) {
|
|
41
41
|
const status = err.response?.status ?? 0;
|
|
42
|
-
const statusText = err.response?.statusText ??
|
|
42
|
+
const statusText = err.response?.statusText ?? '';
|
|
43
43
|
try {
|
|
44
44
|
const body = (await err.response?.json());
|
|
45
45
|
if (body) {
|
|
@@ -91,26 +91,26 @@ function attachSqlPartialResults(body, appErr) {
|
|
|
91
91
|
*/
|
|
92
92
|
async function execSql(opts) {
|
|
93
93
|
const client = (0, http_1.getHttpClient)();
|
|
94
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
94
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/sql', {
|
|
95
95
|
dbBranch: opts.dbBranch,
|
|
96
96
|
});
|
|
97
97
|
const start = Date.now();
|
|
98
98
|
let response;
|
|
99
99
|
try {
|
|
100
100
|
response = await client.post(url, { sql: opts.sql });
|
|
101
|
-
(0, client_1.traceHttp)(
|
|
101
|
+
(0, client_1.traceHttp)('POST', url, start, response);
|
|
102
102
|
}
|
|
103
103
|
catch (err) {
|
|
104
|
-
(0, client_1.traceHttp)(
|
|
105
|
-
await mapDbHttpError(err, url,
|
|
104
|
+
(0, client_1.traceHttp)('POST', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
105
|
+
await mapDbHttpError(err, url, 'Failed to execute SQL', {
|
|
106
106
|
onErrorBody: attachSqlPartialResults,
|
|
107
107
|
// SQL 路径单独的超时文案:PG 的 statement_timeout 会回滚整条事务,所以这里
|
|
108
108
|
// 明示「事务已回滚、没有改动落地」,并把 hint 引导到「简化 SQL / 加 LIMIT / 拆条」。
|
|
109
109
|
timeout: {
|
|
110
|
-
code:
|
|
111
|
-
message:
|
|
112
|
-
hint:
|
|
113
|
-
|
|
110
|
+
code: 'SQL_EXECUTION_TIMEOUT',
|
|
111
|
+
message: 'SQL execution timed out after 30s',
|
|
112
|
+
hint: 'The transaction was rolled back; no changes were applied. ' +
|
|
113
|
+
'Simplify the SQL, add filters or LIMIT for queries, or split it into smaller statements.',
|
|
114
114
|
},
|
|
115
115
|
});
|
|
116
116
|
throw err; // 不可达
|
|
@@ -123,11 +123,11 @@ async function execSql(opts) {
|
|
|
123
123
|
// results 末尾追加一条 SqlType="ERROR" 的哨兵,data 字段是 {code,message} JSON。
|
|
124
124
|
// 这样网关在错误路径不会吞业务字段,CLI 拿到完整 partial_results + statement_index。
|
|
125
125
|
const last = results.at(-1);
|
|
126
|
-
if (last?.sqlType ===
|
|
126
|
+
if (last?.sqlType === 'ERROR') {
|
|
127
127
|
const appErr = parseSqlErrorSentinel(last.data);
|
|
128
128
|
appErr.partial_results = results.slice(0, -1);
|
|
129
129
|
const stmtIdx = data.errorStatementIndex;
|
|
130
|
-
if (typeof stmtIdx ===
|
|
130
|
+
if (typeof stmtIdx === 'number')
|
|
131
131
|
appErr.statement_index = stmtIdx;
|
|
132
132
|
throw appErr;
|
|
133
133
|
}
|
|
@@ -159,12 +159,12 @@ async function execSql(opts) {
|
|
|
159
159
|
function parseSqlErrorSentinel(payload) {
|
|
160
160
|
try {
|
|
161
161
|
const parsed = JSON.parse(payload);
|
|
162
|
-
const code = typeof parsed.code ===
|
|
163
|
-
const message = typeof parsed.message ===
|
|
162
|
+
const code = typeof parsed.code === 'string' && parsed.code !== '' ? parsed.code : 'INTERNAL_DB_ERROR';
|
|
163
|
+
const message = typeof parsed.message === 'string' ? parsed.message : payload;
|
|
164
164
|
return (0, client_1.mapDataloomBizError)(code, message);
|
|
165
165
|
}
|
|
166
166
|
catch {
|
|
167
|
-
return new error_1.AppError(
|
|
167
|
+
return new error_1.AppError('INTERNAL_DB_ERROR', payload);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
// ── db schema → InnerGetSchema ──
|
|
@@ -176,21 +176,21 @@ function parseSqlErrorSentinel(payload) {
|
|
|
176
176
|
*/
|
|
177
177
|
async function getSchema(opts) {
|
|
178
178
|
const client = (0, http_1.getHttpClient)();
|
|
179
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
180
|
-
format: opts.format ??
|
|
179
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/schema', {
|
|
180
|
+
format: opts.format ?? 'schema',
|
|
181
181
|
tableNames: opts.tableNames,
|
|
182
|
-
includeStats: opts.includeStats ?
|
|
182
|
+
includeStats: opts.includeStats ? 'true' : undefined,
|
|
183
183
|
dbBranch: opts.dbBranch,
|
|
184
184
|
});
|
|
185
185
|
const start = Date.now();
|
|
186
186
|
let response;
|
|
187
187
|
try {
|
|
188
188
|
response = await client.get(url);
|
|
189
|
-
(0, client_1.traceHttp)(
|
|
189
|
+
(0, client_1.traceHttp)('GET', url, start, response);
|
|
190
190
|
}
|
|
191
191
|
catch (err) {
|
|
192
|
-
(0, client_1.traceHttp)(
|
|
193
|
-
await mapDbHttpError(err, url,
|
|
192
|
+
(0, client_1.traceHttp)('GET', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
193
|
+
await mapDbHttpError(err, url, 'Failed to get schema');
|
|
194
194
|
throw err; // 不可达
|
|
195
195
|
}
|
|
196
196
|
const body = (await response.json());
|
|
@@ -210,24 +210,24 @@ async function getSchema(opts) {
|
|
|
210
210
|
*/
|
|
211
211
|
async function importData(opts) {
|
|
212
212
|
const client = (0, http_1.getHttpClient)();
|
|
213
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
213
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/data/import');
|
|
214
214
|
const reqBody = {
|
|
215
215
|
tableName: opts.tableName,
|
|
216
216
|
format: opts.format,
|
|
217
|
-
records: opts.body.toString(
|
|
217
|
+
records: opts.body.toString('utf8'),
|
|
218
218
|
};
|
|
219
|
-
if (opts.dbBranch !== undefined && opts.dbBranch !==
|
|
219
|
+
if (opts.dbBranch !== undefined && opts.dbBranch !== '') {
|
|
220
220
|
reqBody.dbBranch = opts.dbBranch;
|
|
221
221
|
}
|
|
222
222
|
const start = Date.now();
|
|
223
223
|
let response;
|
|
224
224
|
try {
|
|
225
225
|
response = await client.post(url, reqBody);
|
|
226
|
-
(0, client_1.traceHttp)(
|
|
226
|
+
(0, client_1.traceHttp)('POST', url, start, response);
|
|
227
227
|
}
|
|
228
228
|
catch (err) {
|
|
229
|
-
(0, client_1.traceHttp)(
|
|
230
|
-
await mapDbHttpError(err, url,
|
|
229
|
+
(0, client_1.traceHttp)('POST', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
230
|
+
await mapDbHttpError(err, url, 'Failed to import data');
|
|
231
231
|
throw err; // 不可达
|
|
232
232
|
}
|
|
233
233
|
// 后端 InnerAdminImportData 响应里 data 直接返 {tableName, recordCount, durationMs}
|
|
@@ -251,7 +251,7 @@ async function importData(opts) {
|
|
|
251
251
|
*/
|
|
252
252
|
async function exportData(opts) {
|
|
253
253
|
const client = (0, http_1.getHttpClient)();
|
|
254
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
254
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/data/export', {
|
|
255
255
|
tableName: opts.tableName,
|
|
256
256
|
format: opts.format,
|
|
257
257
|
limit: String(opts.limit ?? 5000),
|
|
@@ -261,35 +261,35 @@ async function exportData(opts) {
|
|
|
261
261
|
const start = Date.now();
|
|
262
262
|
let response;
|
|
263
263
|
try {
|
|
264
|
-
response = await client.request({ method:
|
|
265
|
-
(0, client_1.traceHttp)(
|
|
264
|
+
response = await client.request({ method: 'POST', url });
|
|
265
|
+
(0, client_1.traceHttp)('POST', url, start, response);
|
|
266
266
|
}
|
|
267
267
|
catch (err) {
|
|
268
|
-
(0, client_1.traceHttp)(
|
|
269
|
-
await mapDbHttpError(err, url,
|
|
268
|
+
(0, client_1.traceHttp)('POST', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
269
|
+
await mapDbHttpError(err, url, 'Failed to export data');
|
|
270
270
|
throw err; // 不可达
|
|
271
271
|
}
|
|
272
272
|
// 成功路径:响应 body 通常是原始 CSV/SQL/JSON 字节,但部分错误场景下网关会返
|
|
273
273
|
// HTTP 200 + JSON envelope(status_code != "0"),需要在这里嗅探兜底。
|
|
274
274
|
const defaultContentType = {
|
|
275
|
-
csv:
|
|
276
|
-
sql:
|
|
277
|
-
json:
|
|
275
|
+
csv: 'text/csv',
|
|
276
|
+
sql: 'text/plain',
|
|
277
|
+
json: 'application/json',
|
|
278
278
|
};
|
|
279
|
-
const contentType = response.headers.get(
|
|
279
|
+
const contentType = response.headers.get('Content-Type') ?? defaultContentType[opts.format];
|
|
280
280
|
const ab = await response.arrayBuffer();
|
|
281
281
|
const buf = Buffer.from(new Uint8Array(ab));
|
|
282
282
|
if (buf.length === 0) {
|
|
283
|
-
throw new error_1.AppError(
|
|
283
|
+
throw new error_1.AppError('INTERNAL_DB_ERROR', 'Empty export response body');
|
|
284
284
|
}
|
|
285
285
|
// Envelope sniff:HTTP 200 + Content-Type 为 application/json + body 解析得到
|
|
286
286
|
// InnerEnvelope 且 status_code 非 "0" 时,按业务错误抛出。
|
|
287
287
|
// CSV / SQL 都是非 JSON 输出,application/json 响应必是错误信封;JSON 格式
|
|
288
288
|
// 成功响应自身就是 application/json,跳过 sniff 避免误判。
|
|
289
|
-
if (opts.format !==
|
|
289
|
+
if (opts.format !== 'json' && /application\/json/i.test(contentType)) {
|
|
290
290
|
try {
|
|
291
|
-
const parsed = JSON.parse(buf.toString(
|
|
292
|
-
if (parsed.status_code != null && parsed.status_code !==
|
|
291
|
+
const parsed = JSON.parse(buf.toString('utf8'));
|
|
292
|
+
if (parsed.status_code != null && parsed.status_code !== '0') {
|
|
293
293
|
// 复用 extractData 的错误映射逻辑(throw AppError)
|
|
294
294
|
(0, client_1.extractData)(parsed);
|
|
295
295
|
}
|
|
@@ -302,7 +302,7 @@ async function exportData(opts) {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
// 后端通过响应头回传记录数(避免污染 body);header 缺失或解析失败 → undefined
|
|
305
|
-
const recordCountHeader = response.headers.get(
|
|
305
|
+
const recordCountHeader = response.headers.get('X-Miaoda-Record-Count');
|
|
306
306
|
const parsedCount = recordCountHeader != null ? Number(recordCountHeader) : NaN;
|
|
307
307
|
const recordCount = Number.isFinite(parsedCount) && parsedCount >= 0 ? parsedCount : undefined;
|
|
308
308
|
return {
|
|
@@ -321,7 +321,7 @@ async function exportData(opts) {
|
|
|
321
321
|
*/
|
|
322
322
|
async function listDDLChangelog(opts) {
|
|
323
323
|
const client = (0, http_1.getHttpClient)();
|
|
324
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
324
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/changelog', {
|
|
325
325
|
table: opts.table,
|
|
326
326
|
since: opts.since,
|
|
327
327
|
until: opts.until,
|
|
@@ -333,18 +333,18 @@ async function listDDLChangelog(opts) {
|
|
|
333
333
|
let response;
|
|
334
334
|
try {
|
|
335
335
|
response = await client.get(url);
|
|
336
|
-
(0, client_1.traceHttp)(
|
|
336
|
+
(0, client_1.traceHttp)('GET', url, start, response);
|
|
337
337
|
}
|
|
338
338
|
catch (err) {
|
|
339
|
-
(0, client_1.traceHttp)(
|
|
340
|
-
await mapDbHttpError(err, url,
|
|
339
|
+
(0, client_1.traceHttp)('GET', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
340
|
+
await mapDbHttpError(err, url, 'Failed to list DDL changelog');
|
|
341
341
|
throw err; // 不可达
|
|
342
342
|
}
|
|
343
343
|
const body = (await response.json());
|
|
344
344
|
const data = (0, client_1.extractData)(body);
|
|
345
345
|
return {
|
|
346
346
|
items: data.items ?? [],
|
|
347
|
-
nextCursor: data.nextCursor && data.nextCursor !==
|
|
347
|
+
nextCursor: data.nextCursor && data.nextCursor !== '' ? data.nextCursor : null,
|
|
348
348
|
hasMore: Boolean(data.hasMore),
|
|
349
349
|
};
|
|
350
350
|
}
|
|
@@ -355,7 +355,7 @@ async function listDDLChangelog(opts) {
|
|
|
355
355
|
*/
|
|
356
356
|
async function getAuditStatus(opts) {
|
|
357
357
|
const client = (0, http_1.getHttpClient)();
|
|
358
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
358
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/audit/status', {
|
|
359
359
|
table: opts.table,
|
|
360
360
|
dbBranch: opts.dbBranch,
|
|
361
361
|
});
|
|
@@ -363,11 +363,11 @@ async function getAuditStatus(opts) {
|
|
|
363
363
|
let response;
|
|
364
364
|
try {
|
|
365
365
|
response = await client.get(url);
|
|
366
|
-
(0, client_1.traceHttp)(
|
|
366
|
+
(0, client_1.traceHttp)('GET', url, start, response);
|
|
367
367
|
}
|
|
368
368
|
catch (err) {
|
|
369
|
-
(0, client_1.traceHttp)(
|
|
370
|
-
await mapDbHttpError(err, url,
|
|
369
|
+
(0, client_1.traceHttp)('GET', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
370
|
+
await mapDbHttpError(err, url, 'Failed to get audit status');
|
|
371
371
|
throw err; // 不可达
|
|
372
372
|
}
|
|
373
373
|
const respBody = (await response.json());
|
|
@@ -380,30 +380,30 @@ async function getAuditStatus(opts) {
|
|
|
380
380
|
*/
|
|
381
381
|
async function setAuditConfig(opts) {
|
|
382
382
|
const client = (0, http_1.getHttpClient)();
|
|
383
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
383
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/audit/config');
|
|
384
384
|
const body = {
|
|
385
385
|
table: opts.table,
|
|
386
386
|
enabled: opts.enabled,
|
|
387
387
|
};
|
|
388
|
-
if (opts.retention !== undefined && opts.retention !==
|
|
388
|
+
if (opts.retention !== undefined && opts.retention !== '')
|
|
389
389
|
body.retention = opts.retention;
|
|
390
|
-
if (opts.dbBranch !== undefined && opts.dbBranch !==
|
|
390
|
+
if (opts.dbBranch !== undefined && opts.dbBranch !== '')
|
|
391
391
|
body.dbBranch = opts.dbBranch;
|
|
392
392
|
const start = Date.now();
|
|
393
393
|
let response;
|
|
394
394
|
try {
|
|
395
395
|
response = await client.post(url, body);
|
|
396
|
-
(0, client_1.traceHttp)(
|
|
396
|
+
(0, client_1.traceHttp)('POST', url, start, response);
|
|
397
397
|
}
|
|
398
398
|
catch (err) {
|
|
399
|
-
(0, client_1.traceHttp)(
|
|
400
|
-
await mapDbHttpError(err, url,
|
|
399
|
+
(0, client_1.traceHttp)('POST', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
400
|
+
await mapDbHttpError(err, url, 'Failed to set audit config');
|
|
401
401
|
throw err; // 不可达
|
|
402
402
|
}
|
|
403
403
|
const respBody = (await response.json());
|
|
404
404
|
const data = (0, client_1.extractData)(respBody);
|
|
405
405
|
if (!data.status) {
|
|
406
|
-
throw new error_1.AppError(
|
|
406
|
+
throw new error_1.AppError('INTERNAL_DB_ERROR', 'audit config response missing status field');
|
|
407
407
|
}
|
|
408
408
|
return data.status;
|
|
409
409
|
}
|
|
@@ -421,11 +421,11 @@ async function setAuditConfig(opts) {
|
|
|
421
421
|
*/
|
|
422
422
|
async function listAuditLog(opts) {
|
|
423
423
|
if (opts.tables.length === 0) {
|
|
424
|
-
throw new error_1.AppError(
|
|
424
|
+
throw new error_1.AppError('ARGS_INVALID', 'at least one table is required');
|
|
425
425
|
}
|
|
426
426
|
const client = (0, http_1.getHttpClient)();
|
|
427
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
428
|
-
tables: opts.tables.join(
|
|
427
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/audit/log', {
|
|
428
|
+
tables: opts.tables.join(','),
|
|
429
429
|
since: opts.since,
|
|
430
430
|
until: opts.until,
|
|
431
431
|
limit: opts.limit !== undefined ? String(opts.limit) : undefined,
|
|
@@ -436,18 +436,18 @@ async function listAuditLog(opts) {
|
|
|
436
436
|
let response;
|
|
437
437
|
try {
|
|
438
438
|
response = await client.get(url);
|
|
439
|
-
(0, client_1.traceHttp)(
|
|
439
|
+
(0, client_1.traceHttp)('GET', url, start, response);
|
|
440
440
|
}
|
|
441
441
|
catch (err) {
|
|
442
|
-
(0, client_1.traceHttp)(
|
|
443
|
-
await mapDbHttpError(err, url,
|
|
442
|
+
(0, client_1.traceHttp)('GET', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
443
|
+
await mapDbHttpError(err, url, 'Failed to list audit log');
|
|
444
444
|
throw err; // 不可达
|
|
445
445
|
}
|
|
446
446
|
const body = (await response.json());
|
|
447
447
|
const data = (0, client_1.extractData)(body);
|
|
448
448
|
return {
|
|
449
449
|
items: data.items ?? [],
|
|
450
|
-
nextCursor: data.nextCursor && data.nextCursor !==
|
|
450
|
+
nextCursor: data.nextCursor && data.nextCursor !== '' ? data.nextCursor : null,
|
|
451
451
|
hasMore: Boolean(data.hasMore),
|
|
452
452
|
skipped: data.skipped ?? [],
|
|
453
453
|
};
|
|
@@ -459,7 +459,7 @@ async function listAuditLog(opts) {
|
|
|
459
459
|
*/
|
|
460
460
|
async function migrationInit(opts) {
|
|
461
461
|
const client = (0, http_1.getHttpClient)();
|
|
462
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
462
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/enableMultiEnv');
|
|
463
463
|
const body = {};
|
|
464
464
|
if (opts.syncData !== undefined)
|
|
465
465
|
body.syncData = opts.syncData;
|
|
@@ -467,11 +467,11 @@ async function migrationInit(opts) {
|
|
|
467
467
|
let response;
|
|
468
468
|
try {
|
|
469
469
|
response = await client.post(url, body);
|
|
470
|
-
(0, client_1.traceHttp)(
|
|
470
|
+
(0, client_1.traceHttp)('POST', url, start, response);
|
|
471
471
|
}
|
|
472
472
|
catch (err) {
|
|
473
|
-
(0, client_1.traceHttp)(
|
|
474
|
-
await mapDbHttpError(err, url,
|
|
473
|
+
(0, client_1.traceHttp)('POST', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
474
|
+
await mapDbHttpError(err, url, 'Failed to init migration');
|
|
475
475
|
throw err; // 不可达
|
|
476
476
|
}
|
|
477
477
|
const respBody = (await response.json());
|
|
@@ -483,16 +483,16 @@ async function migrationInit(opts) {
|
|
|
483
483
|
*/
|
|
484
484
|
async function migrate(opts) {
|
|
485
485
|
const client = (0, http_1.getHttpClient)();
|
|
486
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
486
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/migration');
|
|
487
487
|
const start = Date.now();
|
|
488
488
|
let response;
|
|
489
489
|
try {
|
|
490
490
|
response = await client.post(url, { dryRun: opts.dryRun });
|
|
491
|
-
(0, client_1.traceHttp)(
|
|
491
|
+
(0, client_1.traceHttp)('POST', url, start, response);
|
|
492
492
|
}
|
|
493
493
|
catch (err) {
|
|
494
|
-
(0, client_1.traceHttp)(
|
|
495
|
-
await mapDbHttpError(err, url,
|
|
494
|
+
(0, client_1.traceHttp)('POST', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
495
|
+
await mapDbHttpError(err, url, 'Failed to migrate');
|
|
496
496
|
throw err; // 不可达
|
|
497
497
|
}
|
|
498
498
|
const respBody = (await response.json());
|
|
@@ -505,7 +505,7 @@ async function migrate(opts) {
|
|
|
505
505
|
*/
|
|
506
506
|
async function getMigrationStatus(opts) {
|
|
507
507
|
const client = (0, http_1.getHttpClient)();
|
|
508
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
508
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/migration/status', {
|
|
509
509
|
taskId: opts.taskId,
|
|
510
510
|
dbBranch: opts.dbBranch,
|
|
511
511
|
});
|
|
@@ -513,11 +513,11 @@ async function getMigrationStatus(opts) {
|
|
|
513
513
|
let response;
|
|
514
514
|
try {
|
|
515
515
|
response = await client.get(url);
|
|
516
|
-
(0, client_1.traceHttp)(
|
|
516
|
+
(0, client_1.traceHttp)('GET', url, start, response);
|
|
517
517
|
}
|
|
518
518
|
catch (err) {
|
|
519
|
-
(0, client_1.traceHttp)(
|
|
520
|
-
await mapDbHttpError(err, url,
|
|
519
|
+
(0, client_1.traceHttp)('GET', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
520
|
+
await mapDbHttpError(err, url, 'Failed to get migration status');
|
|
521
521
|
throw err; // 不可达
|
|
522
522
|
}
|
|
523
523
|
const body = (await response.json());
|
|
@@ -530,7 +530,7 @@ async function getMigrationStatus(opts) {
|
|
|
530
530
|
*/
|
|
531
531
|
async function recover(opts) {
|
|
532
532
|
const client = (0, http_1.getHttpClient)();
|
|
533
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
533
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/recovery');
|
|
534
534
|
const start = Date.now();
|
|
535
535
|
let response;
|
|
536
536
|
try {
|
|
@@ -538,11 +538,11 @@ async function recover(opts) {
|
|
|
538
538
|
target: opts.target,
|
|
539
539
|
dryRun: opts.dryRun,
|
|
540
540
|
});
|
|
541
|
-
(0, client_1.traceHttp)(
|
|
541
|
+
(0, client_1.traceHttp)('POST', url, start, response);
|
|
542
542
|
}
|
|
543
543
|
catch (err) {
|
|
544
|
-
(0, client_1.traceHttp)(
|
|
545
|
-
await mapDbHttpError(err, url,
|
|
544
|
+
(0, client_1.traceHttp)('POST', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
545
|
+
await mapDbHttpError(err, url, 'Failed to recover');
|
|
546
546
|
throw err; // 不可达
|
|
547
547
|
}
|
|
548
548
|
const respBody = (await response.json());
|
|
@@ -554,7 +554,7 @@ async function recover(opts) {
|
|
|
554
554
|
*/
|
|
555
555
|
async function getRecoveryPreview(opts) {
|
|
556
556
|
const client = (0, http_1.getHttpClient)();
|
|
557
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
557
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/recovery/preview', {
|
|
558
558
|
previewRequestId: opts.previewRequestId,
|
|
559
559
|
dbBranch: opts.dbBranch,
|
|
560
560
|
});
|
|
@@ -562,11 +562,11 @@ async function getRecoveryPreview(opts) {
|
|
|
562
562
|
let response;
|
|
563
563
|
try {
|
|
564
564
|
response = await client.get(url);
|
|
565
|
-
(0, client_1.traceHttp)(
|
|
565
|
+
(0, client_1.traceHttp)('GET', url, start, response);
|
|
566
566
|
}
|
|
567
567
|
catch (err) {
|
|
568
|
-
(0, client_1.traceHttp)(
|
|
569
|
-
await mapDbHttpError(err, url,
|
|
568
|
+
(0, client_1.traceHttp)('GET', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
569
|
+
await mapDbHttpError(err, url, 'Failed to get recovery preview');
|
|
570
570
|
throw err; // 不可达
|
|
571
571
|
}
|
|
572
572
|
const body = (await response.json());
|
|
@@ -578,16 +578,16 @@ async function getRecoveryPreview(opts) {
|
|
|
578
578
|
*/
|
|
579
579
|
async function getDbQuota(opts) {
|
|
580
580
|
const client = (0, http_1.getHttpClient)();
|
|
581
|
-
const url = (0, client_1.buildInnerUrl)(opts.appId,
|
|
581
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, '/db/quota', { dbBranch: opts.dbBranch });
|
|
582
582
|
const start = Date.now();
|
|
583
583
|
let response;
|
|
584
584
|
try {
|
|
585
585
|
response = await client.get(url);
|
|
586
|
-
(0, client_1.traceHttp)(
|
|
586
|
+
(0, client_1.traceHttp)('GET', url, start, response);
|
|
587
587
|
}
|
|
588
588
|
catch (err) {
|
|
589
|
-
(0, client_1.traceHttp)(
|
|
590
|
-
await mapDbHttpError(err, url,
|
|
589
|
+
(0, client_1.traceHttp)('GET', url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
590
|
+
await mapDbHttpError(err, url, 'Failed to get db quota');
|
|
591
591
|
throw err; // 不可达
|
|
592
592
|
}
|
|
593
593
|
const respBody = (await response.json());
|