@lark-apaas/miaoda-cli 0.1.2-alpha.746290f → 0.1.2-alpha.9eeb185
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/db/api.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.getSchema = getSchema;
|
|
|
5
5
|
exports.importData = importData;
|
|
6
6
|
exports.exportData = exportData;
|
|
7
7
|
exports.listDDLChangelog = listDDLChangelog;
|
|
8
|
+
exports.getAuditStatus = getAuditStatus;
|
|
8
9
|
exports.setAuditConfig = setAuditConfig;
|
|
9
10
|
exports.migrationInit = migrationInit;
|
|
10
11
|
exports.migrate = migrate;
|
|
@@ -332,13 +333,35 @@ async function listDDLChangelog(opts) {
|
|
|
332
333
|
hasMore: Boolean(data.hasMore),
|
|
333
334
|
};
|
|
334
335
|
}
|
|
335
|
-
// ── db audit → InnerAdminSetAuditConfig ──
|
|
336
|
+
// ── db audit → InnerAdminGetAuditStatus / InnerAdminSetAuditConfig ──
|
|
337
|
+
/**
|
|
338
|
+
* 后端:GET /v1/dataloom/app/{appId}/db/audit/status?table=&dbBranch=
|
|
339
|
+
* 查表审计开关状态。table 非空 → 单表过滤;空 → 返当前 workspace 全部已配置表。
|
|
340
|
+
*/
|
|
341
|
+
async function getAuditStatus(opts) {
|
|
342
|
+
const client = (0, http_1.getHttpClient)();
|
|
343
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/audit/status", {
|
|
344
|
+
table: opts.table,
|
|
345
|
+
dbBranch: opts.dbBranch,
|
|
346
|
+
});
|
|
347
|
+
const start = Date.now();
|
|
348
|
+
let response;
|
|
349
|
+
try {
|
|
350
|
+
response = await client.get(url);
|
|
351
|
+
(0, client_1.traceHttp)("GET", url, start, response);
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
(0, client_1.traceHttp)("GET", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
355
|
+
await mapDbHttpError(err, url, "Failed to get audit status");
|
|
356
|
+
throw err; // 不可达
|
|
357
|
+
}
|
|
358
|
+
const respBody = (await response.json());
|
|
359
|
+
const data = (0, client_1.extractData)(respBody);
|
|
360
|
+
return data.items ?? [];
|
|
361
|
+
}
|
|
336
362
|
/**
|
|
337
363
|
* 后端:POST /v1/dataloom/app/{appId}/db/audit/config
|
|
338
364
|
* 写:enabled=true 开启 / false 关闭。retention 仅 enabled=true 生效。
|
|
339
|
-
*
|
|
340
|
-
* 读路径(status / log)不在此模块——CLI handler 走 execSql 直接 SELECT
|
|
341
|
-
* `_dl_audit_config` / `_dl_audit_log` 元数据表。
|
|
342
365
|
*/
|
|
343
366
|
async function setAuditConfig(opts) {
|
|
344
367
|
const client = (0, http_1.getHttpClient)();
|
package/dist/api/db/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pickTableDetail = exports.flattenSchemaList = exports.parseSqlResult = exports.SQLSTATE_MAP = exports.ensureInnerSuccess = exports.buildInnerUrl = exports.getDbQuota = exports.recover = exports.migrate = exports.migrationInit = exports.setAuditConfig = exports.listDDLChangelog = exports.exportData = exports.importData = exports.getSchema = exports.execSql = void 0;
|
|
3
|
+
exports.pickTableDetail = exports.flattenSchemaList = exports.parseSqlResult = exports.SQLSTATE_MAP = exports.ensureInnerSuccess = exports.buildInnerUrl = exports.getDbQuota = exports.recover = exports.migrate = exports.migrationInit = exports.setAuditConfig = exports.getAuditStatus = exports.listDDLChangelog = exports.exportData = exports.importData = exports.getSchema = exports.execSql = void 0;
|
|
4
4
|
var api_1 = require("./api");
|
|
5
5
|
Object.defineProperty(exports, "execSql", { enumerable: true, get: function () { return api_1.execSql; } });
|
|
6
6
|
Object.defineProperty(exports, "getSchema", { enumerable: true, get: function () { return api_1.getSchema; } });
|
|
7
7
|
Object.defineProperty(exports, "importData", { enumerable: true, get: function () { return api_1.importData; } });
|
|
8
8
|
Object.defineProperty(exports, "exportData", { enumerable: true, get: function () { return api_1.exportData; } });
|
|
9
9
|
Object.defineProperty(exports, "listDDLChangelog", { enumerable: true, get: function () { return api_1.listDDLChangelog; } });
|
|
10
|
+
Object.defineProperty(exports, "getAuditStatus", { enumerable: true, get: function () { return api_1.getAuditStatus; } });
|
|
10
11
|
Object.defineProperty(exports, "setAuditConfig", { enumerable: true, get: function () { return api_1.setAuditConfig; } });
|
|
11
12
|
Object.defineProperty(exports, "migrationInit", { enumerable: true, get: function () { return api_1.migrationInit; } });
|
|
12
13
|
Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return api_1.migrate; } });
|
|
@@ -47,34 +47,30 @@ const index_2 = require("../../../api/db/index");
|
|
|
47
47
|
const VALID_RETENTION = new Set(["7d", "30d", "180d", "360d", "forever"]);
|
|
48
48
|
async function handleDbAuditStatus(table, opts) {
|
|
49
49
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const results = await api.db.execSql({ appId, sql, dbBranch: opts.env });
|
|
54
|
-
const rows = collectSelectRows(results);
|
|
55
|
-
// 单表查询且 _dl_audit_config 没记录 → enabled=false 占位
|
|
50
|
+
const items = await api.db.getAuditStatus({ appId, table, dbBranch: opts.env });
|
|
51
|
+
const rows = items.map(toAuditStatus);
|
|
52
|
+
// 单表查询但后端没记录 → 占位 enabled=false
|
|
56
53
|
if (table !== undefined && table !== "" && rows.length === 0) {
|
|
57
|
-
rows.push({ table, enabled: false });
|
|
54
|
+
rows.push({ table, enabled: false, enabled_at: null, retention: null });
|
|
58
55
|
}
|
|
59
|
-
const items = rows.map(toAuditStatus);
|
|
60
56
|
// PRD JSON:单表返 object,多表返 array
|
|
61
57
|
if ((0, output_1.isJsonMode)()) {
|
|
62
|
-
if (table !== undefined &&
|
|
63
|
-
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(
|
|
58
|
+
if (table !== undefined && rows.length === 1) {
|
|
59
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(rows[0]));
|
|
64
60
|
}
|
|
65
61
|
else {
|
|
66
|
-
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(
|
|
62
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(rows));
|
|
67
63
|
}
|
|
68
64
|
return;
|
|
69
65
|
}
|
|
70
|
-
if (
|
|
66
|
+
if (rows.length === 0) {
|
|
71
67
|
(0, output_1.emit)("No audit configuration found.");
|
|
72
68
|
return;
|
|
73
69
|
}
|
|
74
70
|
const tty = (0, render_1.isStdoutTty)();
|
|
75
|
-
// 单表 → key:value
|
|
76
|
-
if (table !== undefined &&
|
|
77
|
-
const it =
|
|
71
|
+
// 单表 → key:value 形态
|
|
72
|
+
if (table !== undefined && rows.length === 1) {
|
|
73
|
+
const it = rows[0];
|
|
78
74
|
(0, output_1.emit)((0, render_1.renderKeyValue)([
|
|
79
75
|
["Table", it.table],
|
|
80
76
|
["Enabled", boolToYesNo(it.enabled)],
|
|
@@ -85,7 +81,7 @@ async function handleDbAuditStatus(table, opts) {
|
|
|
85
81
|
}
|
|
86
82
|
// 列表 → table 形态
|
|
87
83
|
const headers = ["table", "enabled", "enabled_at", "retention"];
|
|
88
|
-
const out =
|
|
84
|
+
const out = rows.map((it) => [
|
|
89
85
|
it.table,
|
|
90
86
|
boolToYesNo(it.enabled),
|
|
91
87
|
it.enabled_at ? (0, render_1.formatTime)(it.enabled_at, tty) : "—",
|
|
@@ -93,24 +89,12 @@ async function handleDbAuditStatus(table, opts) {
|
|
|
93
89
|
]);
|
|
94
90
|
(0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, out) : (0, render_1.renderTsv)(headers, out));
|
|
95
91
|
}
|
|
96
|
-
function toAuditStatus(
|
|
97
|
-
// retention 列存的是后端 ValidDay (int64 天数),按 sentinel 反向映射成 PRD 字符串
|
|
98
|
-
const rawRetention = row.retention;
|
|
99
|
-
let retention = null;
|
|
100
|
-
if (rawRetention != null) {
|
|
101
|
-
if (typeof rawRetention === "number") {
|
|
102
|
-
retention = retentionDaysToString(rawRetention);
|
|
103
|
-
}
|
|
104
|
-
else if (typeof rawRetention === "string") {
|
|
105
|
-
// 兼容存的就是字符串形态("7d" / "forever")
|
|
106
|
-
retention = rawRetention;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
92
|
+
function toAuditStatus(s) {
|
|
109
93
|
return {
|
|
110
|
-
table:
|
|
111
|
-
enabled:
|
|
112
|
-
enabled_at:
|
|
113
|
-
retention,
|
|
94
|
+
table: s.table,
|
|
95
|
+
enabled: s.enabled,
|
|
96
|
+
enabled_at: s.enabledAt ?? null,
|
|
97
|
+
retention: s.retention ?? null,
|
|
114
98
|
};
|
|
115
99
|
}
|
|
116
100
|
async function handleDbAuditEnable(table, opts) {
|
|
@@ -285,20 +269,6 @@ function escapeSqlLiteral(s) {
|
|
|
285
269
|
function boolToYesNo(b) {
|
|
286
270
|
return b ? "yes" : "no";
|
|
287
271
|
}
|
|
288
|
-
// 后端 ValidDay (int64 天数) → PRD retention 字符串。-1 = 永久(前端 / 后端约定)
|
|
289
|
-
function retentionDaysToString(days) {
|
|
290
|
-
if (days === -1)
|
|
291
|
-
return "forever";
|
|
292
|
-
if (days === 7)
|
|
293
|
-
return "7d";
|
|
294
|
-
if (days === 30)
|
|
295
|
-
return "30d";
|
|
296
|
-
if (days === 180)
|
|
297
|
-
return "180d";
|
|
298
|
-
if (days === 360)
|
|
299
|
-
return "360d";
|
|
300
|
-
return `${String(days)}d`;
|
|
301
|
-
}
|
|
302
272
|
function asString(v, fallback = "") {
|
|
303
273
|
if (v == null)
|
|
304
274
|
return fallback;
|
|
@@ -42,7 +42,17 @@ async function handleDbQuota(opts) {
|
|
|
42
42
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
43
43
|
const data = await api.db.getDbQuota({ appId, dbBranch: opts.env });
|
|
44
44
|
if ((0, output_1.isJsonMode)()) {
|
|
45
|
-
|
|
45
|
+
// 配额未对接(storageQuotaBytes=0)时,quota / usage_percent 字段都不输出
|
|
46
|
+
const out = {
|
|
47
|
+
storageUsedBytes: data.storageUsedBytes,
|
|
48
|
+
tables: data.tables,
|
|
49
|
+
views: data.views,
|
|
50
|
+
};
|
|
51
|
+
if (data.storageQuotaBytes > 0) {
|
|
52
|
+
out.storageQuotaBytes = data.storageQuotaBytes;
|
|
53
|
+
out.usagePercent = data.usagePercent;
|
|
54
|
+
}
|
|
55
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(out));
|
|
46
56
|
return;
|
|
47
57
|
}
|
|
48
58
|
// PRD:单行 "Storage: 14.9 MB / 1 GB (1.5%)";配额未对接时只显示 used
|
|
@@ -42,7 +42,16 @@ async function handleFileQuota(opts) {
|
|
|
42
42
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
43
43
|
const data = await api.file.getStorageQuota({ appId });
|
|
44
44
|
if ((0, output_1.isJsonMode)()) {
|
|
45
|
-
|
|
45
|
+
// 配额未对接(storageQuotaBytes=0)时,quota / usage_percent 字段都不输出
|
|
46
|
+
const out = {
|
|
47
|
+
storageUsedBytes: data.storageUsedBytes,
|
|
48
|
+
files: data.files,
|
|
49
|
+
};
|
|
50
|
+
if (data.storageQuotaBytes > 0) {
|
|
51
|
+
out.storageQuotaBytes = data.storageQuotaBytes;
|
|
52
|
+
out.usagePercent = data.usagePercent;
|
|
53
|
+
}
|
|
54
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(out));
|
|
46
55
|
return;
|
|
47
56
|
}
|
|
48
57
|
// PRD:单行 "Storage: 150 MB / 1 GB (15%)";配额未对接时只显示 used
|