@lark-apaas/miaoda-cli 0.1.2-alpha.ccfdc05 → 0.1.2-alpha.d0d2ae1
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/README.md +7 -8
- package/dist/api/db/api.js +250 -6
- package/dist/api/db/client.js +36 -0
- package/dist/api/db/index.js +9 -1
- package/dist/api/file/api.js +15 -0
- package/dist/api/file/index.js +2 -1
- package/dist/api/index.js +1 -7
- package/dist/cli/commands/db/index.js +137 -0
- package/dist/cli/commands/file/index.js +7 -0
- package/dist/cli/commands/index.js +6 -10
- package/dist/cli/commands/shared.js +3 -81
- package/dist/cli/handlers/db/audit.js +285 -0
- package/dist/cli/handlers/db/changelog.js +117 -0
- package/dist/cli/handlers/db/data.js +1 -1
- package/dist/cli/handlers/db/index.js +17 -1
- package/dist/cli/handlers/db/migration.js +213 -0
- package/dist/cli/handlers/{app/update.js → db/quota.js} +29 -20
- package/dist/cli/handlers/db/recovery.js +228 -0
- package/dist/cli/handlers/file/index.js +3 -1
- package/dist/cli/handlers/{deploy/error-log.js → file/quota.js} +27 -22
- package/dist/main.js +7 -27
- package/dist/utils/http.js +0 -118
- package/dist/utils/index.js +1 -13
- package/dist/utils/output.js +29 -338
- package/package.json +5 -7
- package/dist/api/app/api.js +0 -25
- package/dist/api/app/index.js +0 -15
- package/dist/api/app/schemas.js +0 -79
- package/dist/api/app/types.js +0 -58
- package/dist/api/deploy/api.js +0 -60
- package/dist/api/deploy/index.js +0 -16
- package/dist/api/deploy/schemas.js +0 -103
- package/dist/api/deploy/types.js +0 -22
- package/dist/api/observability/api.js +0 -52
- package/dist/api/observability/index.js +0 -16
- package/dist/api/observability/schemas.js +0 -60
- package/dist/api/observability/types.js +0 -27
- package/dist/cli/commands/app/index.js +0 -62
- package/dist/cli/commands/deploy/index.js +0 -145
- package/dist/cli/commands/observability/index.js +0 -237
- package/dist/cli/handlers/app/get.js +0 -48
- package/dist/cli/handlers/app/index.js +0 -7
- package/dist/cli/handlers/deploy/deploy.js +0 -83
- package/dist/cli/handlers/deploy/get.js +0 -70
- package/dist/cli/handlers/deploy/helpers.js +0 -41
- package/dist/cli/handlers/deploy/history.js +0 -70
- package/dist/cli/handlers/deploy/index.js +0 -14
- package/dist/cli/handlers/deploy/polling.js +0 -139
- package/dist/cli/handlers/observability/analytics.js +0 -212
- package/dist/cli/handlers/observability/helpers.js +0 -66
- package/dist/cli/handlers/observability/index.js +0 -12
- package/dist/cli/handlers/observability/log.js +0 -94
- package/dist/cli/handlers/observability/metric.js +0 -208
- package/dist/cli/handlers/observability/trace.js +0 -102
- package/dist/cli/version.js +0 -15
- package/dist/utils/devops-error.js +0 -28
- package/dist/utils/git.js +0 -29
- package/dist/utils/time.js +0 -203
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appIdOption = appIdOption;
|
|
4
|
-
exports.branchOption = branchOption;
|
|
5
3
|
exports.softRequiredOption = softRequiredOption;
|
|
6
4
|
exports.resolveAppId = resolveAppId;
|
|
7
5
|
exports.withHelp = withHelp;
|
|
8
6
|
exports.failArgs = failArgs;
|
|
9
|
-
exports.caseInsensitiveChoice = caseInsensitiveChoice;
|
|
10
|
-
exports.validateTimeOptions = validateTimeOptions;
|
|
11
|
-
exports.rejectCliOverride = rejectCliOverride;
|
|
12
7
|
const commander_1 = require("commander");
|
|
13
8
|
const error_1 = require("../../utils/error");
|
|
14
|
-
const time_1 = require("../../utils/time");
|
|
15
|
-
/** --app-id option,需要应用上下文的命令自行 .addOption(appIdOption()) */
|
|
16
|
-
function appIdOption() {
|
|
17
|
-
return new commander_1.Option("--app-id <id>", "指定目标应用").env("MIAODA_APP_ID");
|
|
18
|
-
}
|
|
19
|
-
function branchOption() {
|
|
20
|
-
return new commander_1.Option("--branch <branch>", "分支(优先级:--branch > 当前仓库 HEAD 分支;非 git 目录回退应用默认分支)").env("LOCAL_MOCK_MIAODA_DEPLOY_BRANCH");
|
|
21
|
-
}
|
|
22
9
|
/**
|
|
23
10
|
* soft-required: Commander 类型上 optional,runtime 校验必填。
|
|
24
11
|
*/
|
|
@@ -40,15 +27,11 @@ function resolveAppId(opts) {
|
|
|
40
27
|
}
|
|
41
28
|
return id;
|
|
42
29
|
}
|
|
43
|
-
/**
|
|
44
|
-
* 包裹 handler,缺 soft-required 参数 / 自定义校验失败时打 help 并退出。
|
|
45
|
-
*
|
|
46
|
-
* 兼容带位置参数的 action 签名(如 `(arg1: string, opts) => ...`)。
|
|
47
|
-
*/
|
|
30
|
+
/** 包裹 handler,缺 soft-required 参数时打 help 并退出 */
|
|
48
31
|
function withHelp(cmd, handler) {
|
|
49
|
-
return async (
|
|
32
|
+
return async (opts) => {
|
|
50
33
|
try {
|
|
51
|
-
await handler(
|
|
34
|
+
await handler(opts);
|
|
52
35
|
}
|
|
53
36
|
catch (err) {
|
|
54
37
|
if (err instanceof error_1.AppError && err.code === "ARGS_INVALID") {
|
|
@@ -65,64 +48,3 @@ function withHelp(cmd, handler) {
|
|
|
65
48
|
function failArgs(message) {
|
|
66
49
|
throw new error_1.AppError("ARGS_INVALID", message);
|
|
67
50
|
}
|
|
68
|
-
/**
|
|
69
|
-
* 大小写不敏感的 choice argParser:把用户输入按 lowerCase 匹配回 canonical 数组里
|
|
70
|
-
* 的同名值(保留 canonical 大小写),未命中抛 Commander 的 InvalidArgumentError
|
|
71
|
-
* (exit code 1,自带友好错误)。
|
|
72
|
-
*
|
|
73
|
-
* 必须先 .choices(canonical)、再 .argParser()——Commander 内部 .choices() 会
|
|
74
|
-
* 重置 parseArg,反过来调会让 argParser 失效。.choices() 仅留给 help 渲染
|
|
75
|
-
* "choices: A, B, C",实际白名单校验由 argParser 接管。
|
|
76
|
-
*
|
|
77
|
-
* new Option("--level <level>", "日志级别(不区分大小写)")
|
|
78
|
-
* .choices(["DEBUG", "INFO", "WARN", "ERROR"])
|
|
79
|
-
* .argParser(caseInsensitiveChoice(["DEBUG", "INFO", "WARN", "ERROR"]));
|
|
80
|
-
*/
|
|
81
|
-
function caseInsensitiveChoice(canonical) {
|
|
82
|
-
const map = new Map(canonical.map((v) => [v.toLowerCase(), v]));
|
|
83
|
-
return (raw) => {
|
|
84
|
-
const hit = map.get(raw.toLowerCase());
|
|
85
|
-
if (hit === undefined) {
|
|
86
|
-
throw new commander_1.InvalidArgumentError(`Allowed choices are ${canonical.join(", ")} (case-insensitive).`);
|
|
87
|
-
}
|
|
88
|
-
return hit;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* --since / --until 等时间参数的 action 阶段校验。
|
|
93
|
-
*
|
|
94
|
-
* Commander 的 argParser 会在 action 前直接按 parser error 退出(exit 1),
|
|
95
|
-
* 绕过 withHelp 的 ARGS_INVALID → exit 2 路径;所以时间参数在 action 内先
|
|
96
|
-
* 校验一遍,再把原始字符串交给 handler 解析成接口需要的单位。
|
|
97
|
-
*/
|
|
98
|
-
function validateTimeOptions(opts, ...names) {
|
|
99
|
-
for (const name of names) {
|
|
100
|
-
const value = opts[name];
|
|
101
|
-
if (value === undefined)
|
|
102
|
-
continue;
|
|
103
|
-
if (typeof value !== "string") {
|
|
104
|
-
failArgs(`--${name.replace(/([A-Z])/g, "-$1").toLowerCase()} 必须是时间字符串`);
|
|
105
|
-
}
|
|
106
|
-
(0, time_1.parseTimeToMs)(value);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* 拒绝 CLI 显式覆盖:用于 hideHelp() + .env() 的"沙箱注入参数"(如 --app-id / --branch)。
|
|
111
|
-
*
|
|
112
|
-
* Commander 的 getOptionValueSource() 区分来源(cli / env / default / config / undefined);
|
|
113
|
-
* 用户在 CLI 上显式传时 source === "cli",此时抛 ARGS_INVALID(exit 2 + help)。
|
|
114
|
-
*
|
|
115
|
-
* 用法:在 action 头部一行调用——
|
|
116
|
-
* cmd.action(withHelp(cmd, async (rawOpts) => {
|
|
117
|
-
* rejectCliOverride(cmd, "appId", "branch");
|
|
118
|
-
* ...
|
|
119
|
-
* }));
|
|
120
|
-
*/
|
|
121
|
-
function rejectCliOverride(cmd, ...optNames) {
|
|
122
|
-
for (const name of optNames) {
|
|
123
|
-
if (cmd.getOptionValueSource(name) === "cli") {
|
|
124
|
-
const flag = "--" + name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
125
|
-
failArgs(`${flag} 由沙箱/本地配置注入,不允许显式传递`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.handleDbAuditStatus = handleDbAuditStatus;
|
|
37
|
+
exports.handleDbAuditEnable = handleDbAuditEnable;
|
|
38
|
+
exports.handleDbAuditDisable = handleDbAuditDisable;
|
|
39
|
+
exports.handleDbAuditList = handleDbAuditList;
|
|
40
|
+
const api = __importStar(require("../../../api/index"));
|
|
41
|
+
const index_1 = require("../../../api/file/index");
|
|
42
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
43
|
+
const colors_1 = require("../../../utils/colors");
|
|
44
|
+
const error_1 = require("../../../utils/error");
|
|
45
|
+
const output_1 = require("../../../utils/output");
|
|
46
|
+
const render_1 = require("../../../utils/render");
|
|
47
|
+
const VALID_RETENTION = new Set(["7d", "30d", "180d", "360d", "forever"]);
|
|
48
|
+
async function handleDbAuditStatus(table, opts) {
|
|
49
|
+
const appId = (0, shared_1.resolveAppId)(opts);
|
|
50
|
+
const items = await api.db.getAuditStatus({ appId, table, dbBranch: opts.env });
|
|
51
|
+
const rows = items.map(toAuditStatus);
|
|
52
|
+
// 单表查询但后端没记录 → 占位 enabled=false
|
|
53
|
+
if (table !== undefined && table !== "" && rows.length === 0) {
|
|
54
|
+
rows.push({ table, enabled: false, enabled_at: null, retention: null });
|
|
55
|
+
}
|
|
56
|
+
// PRD JSON:单表返 object,多表返 array
|
|
57
|
+
if ((0, output_1.isJsonMode)()) {
|
|
58
|
+
if (table !== undefined && rows.length === 1) {
|
|
59
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(rows[0]));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)(rows));
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (rows.length === 0) {
|
|
67
|
+
(0, output_1.emit)("No audit configuration found.");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const tty = (0, render_1.isStdoutTty)();
|
|
71
|
+
// 单表 → key:value 形态
|
|
72
|
+
if (table !== undefined && rows.length === 1) {
|
|
73
|
+
const it = rows[0];
|
|
74
|
+
(0, output_1.emit)((0, render_1.renderKeyValue)([
|
|
75
|
+
["Table", it.table],
|
|
76
|
+
["Enabled", boolToYesNo(it.enabled)],
|
|
77
|
+
["Enabled at", it.enabled_at ? (0, render_1.formatTime)(it.enabled_at, tty) : "—"],
|
|
78
|
+
["Retention", it.retention ?? "—"],
|
|
79
|
+
], tty));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// 列表 → table 形态
|
|
83
|
+
const headers = ["table", "enabled", "enabled_at", "retention"];
|
|
84
|
+
const out = rows.map((it) => [
|
|
85
|
+
it.table,
|
|
86
|
+
boolToYesNo(it.enabled),
|
|
87
|
+
it.enabled_at ? (0, render_1.formatTime)(it.enabled_at, tty) : "—",
|
|
88
|
+
it.retention ?? "—",
|
|
89
|
+
]);
|
|
90
|
+
(0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, out) : (0, render_1.renderTsv)(headers, out));
|
|
91
|
+
}
|
|
92
|
+
function toAuditStatus(s) {
|
|
93
|
+
return {
|
|
94
|
+
table: s.table,
|
|
95
|
+
enabled: s.enabled,
|
|
96
|
+
enabled_at: s.enabledAt ?? null,
|
|
97
|
+
retention: s.retention ?? null,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function handleDbAuditEnable(table, opts) {
|
|
101
|
+
if (!table) {
|
|
102
|
+
throw new error_1.AppError("ARGS_INVALID", "table name is required", {
|
|
103
|
+
next_actions: [
|
|
104
|
+
"Usage: miaoda db audit enable <table> [--retention 7d|30d|180d|360d|forever]",
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const retention = opts.retention ?? "7d";
|
|
109
|
+
if (!VALID_RETENTION.has(retention)) {
|
|
110
|
+
throw new error_1.AppError("INVALID_RETENTION", `Invalid retention '${retention}'`, {
|
|
111
|
+
next_actions: ["Allowed values: 7d, 30d, 180d, 360d, forever."],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const appId = (0, shared_1.resolveAppId)(opts);
|
|
115
|
+
let status;
|
|
116
|
+
try {
|
|
117
|
+
status = await api.db.setAuditConfig({
|
|
118
|
+
appId,
|
|
119
|
+
table,
|
|
120
|
+
enabled: true,
|
|
121
|
+
retention,
|
|
122
|
+
dbBranch: opts.env,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
// PRD: 重复 enable 报错时附带 hint,引导用户去 status 看 retention 或换值更新
|
|
127
|
+
if (err instanceof error_1.AppError && err.code === "DB_API_k_dl_1300030") {
|
|
128
|
+
throw new error_1.AppError(err.code, err.message, {
|
|
129
|
+
next_actions: [
|
|
130
|
+
`Use \`miaoda db audit status ${table}\` to check current retention, or run this command with a different --retention to update.`,
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
136
|
+
// PRD JSON:{"data": {"table": "...", "enabled": true, "retention": "..."}}
|
|
137
|
+
if ((0, output_1.isJsonMode)()) {
|
|
138
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)({
|
|
139
|
+
table: status.table,
|
|
140
|
+
enabled: status.enabled,
|
|
141
|
+
retention: status.retention ?? retention,
|
|
142
|
+
}));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const tty = (0, render_1.isStdoutTty)();
|
|
146
|
+
const prefix = tty ? "✓" : "OK";
|
|
147
|
+
// c.highlight 内部按 TTY/NO_COLOR/FORCE_COLOR 自动决定是否染色,无需再判 tty
|
|
148
|
+
const tableLabel = colors_1.c.highlight(`'${status.table}'`);
|
|
149
|
+
(0, output_1.emit)(`${prefix} Audit enabled for table ${tableLabel} (retention: ${status.retention ?? retention})`);
|
|
150
|
+
}
|
|
151
|
+
async function handleDbAuditDisable(table, opts) {
|
|
152
|
+
if (!table) {
|
|
153
|
+
throw new error_1.AppError("ARGS_INVALID", "table name is required", {
|
|
154
|
+
next_actions: ["Usage: miaoda db audit disable <table>"],
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const appId = (0, shared_1.resolveAppId)(opts);
|
|
158
|
+
let status;
|
|
159
|
+
try {
|
|
160
|
+
status = await api.db.setAuditConfig({
|
|
161
|
+
appId,
|
|
162
|
+
table,
|
|
163
|
+
enabled: false,
|
|
164
|
+
dbBranch: opts.env,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
// PRD: 重复 disable / 未启用就 disable 报错时附带 hint,引导用户去看哪些表已开启
|
|
169
|
+
if (err instanceof error_1.AppError && err.code === "DB_API_k_dl_1300031") {
|
|
170
|
+
throw new error_1.AppError(err.code, err.message, {
|
|
171
|
+
next_actions: ["Use `miaoda db audit status` to see which tables have audit enabled."],
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
throw err;
|
|
175
|
+
}
|
|
176
|
+
if ((0, output_1.isJsonMode)()) {
|
|
177
|
+
(0, output_1.emitOk)((0, output_1.snakeCaseKeys)({
|
|
178
|
+
table: status.table,
|
|
179
|
+
enabled: status.enabled,
|
|
180
|
+
}));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const tty = (0, render_1.isStdoutTty)();
|
|
184
|
+
const prefix = tty ? "✓" : "OK";
|
|
185
|
+
(0, output_1.emit)(`${prefix} Audit disabled for table ${colors_1.c.highlight(`'${status.table}'`)}`);
|
|
186
|
+
}
|
|
187
|
+
async function handleDbAuditList(tables, opts) {
|
|
188
|
+
if (tables.length === 0) {
|
|
189
|
+
throw new error_1.AppError("ARGS_INVALID", "at least one table is required", {
|
|
190
|
+
next_actions: [
|
|
191
|
+
"Usage: miaoda db audit list <table> [<table>...] [--since ...] [--until ...]",
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
const appId = (0, shared_1.resolveAppId)(opts);
|
|
196
|
+
const limit = opts.limit ?? 20;
|
|
197
|
+
// 时间字段归一化为 ISO 8601 UTC(服务端按 event_time 字段比较)。cursor 由
|
|
198
|
+
// 后端管理(本质也是 ISO 时间),CLI 不再混用 cursor/since。
|
|
199
|
+
const since = normalizeTime(opts.since, "--since");
|
|
200
|
+
const until = normalizeTime(opts.until, "--until");
|
|
201
|
+
const result = await api.db.listAuditLog({
|
|
202
|
+
appId,
|
|
203
|
+
tables,
|
|
204
|
+
since,
|
|
205
|
+
until,
|
|
206
|
+
limit,
|
|
207
|
+
cursor: opts.cursor,
|
|
208
|
+
dbBranch: opts.env,
|
|
209
|
+
});
|
|
210
|
+
const visible = result.items;
|
|
211
|
+
const skipped = result.skipped;
|
|
212
|
+
// PRD JSON:data 是数组,元素是事件对象(snake_case),分页信封 next_cursor / has_more
|
|
213
|
+
if ((0, output_1.isJsonMode)()) {
|
|
214
|
+
const items = visible.map((it) => ({
|
|
215
|
+
event_id: it.eventId,
|
|
216
|
+
event_time: it.eventTime,
|
|
217
|
+
target_table: it.targetTable,
|
|
218
|
+
type: it.type,
|
|
219
|
+
operator: it.operator,
|
|
220
|
+
summary: it.summary,
|
|
221
|
+
// before/after 服务端是 JSON 字符串,反序列化回结构化对象供下游消费
|
|
222
|
+
...(it.before !== undefined ? { before: safeParseJson(it.before) } : {}),
|
|
223
|
+
...(it.after !== undefined ? { after: safeParseJson(it.after) } : {}),
|
|
224
|
+
}));
|
|
225
|
+
(0, output_1.emitPaged)(items, result.nextCursor, result.hasMore);
|
|
226
|
+
if (skipped.length > 0) {
|
|
227
|
+
process.stderr.write(`(${String(skipped.length)} table(s) skipped: ${skipped.join(", ")})\n`);
|
|
228
|
+
}
|
|
229
|
+
if (visible.length === 0)
|
|
230
|
+
process.exitCode = 1;
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (visible.length === 0) {
|
|
234
|
+
(0, output_1.emit)("No audit log entries found.");
|
|
235
|
+
if (skipped.length > 0) {
|
|
236
|
+
process.stderr.write(`(${String(skipped.length)} table(s) skipped: ${skipped.join(", ")})\n`);
|
|
237
|
+
}
|
|
238
|
+
process.exitCode = 1;
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const tty = (0, render_1.isStdoutTty)();
|
|
242
|
+
// PRD:多表渲染时第一列是 target_table,单表时去掉这一列
|
|
243
|
+
const isMultiTable = tables.length > 1;
|
|
244
|
+
const headers = isMultiTable
|
|
245
|
+
? ["target_table", "event_time", "type", "event_id", "operator", "summary"]
|
|
246
|
+
: ["event_time", "type", "event_id", "operator", "summary"];
|
|
247
|
+
const rows = visible.map((it) => {
|
|
248
|
+
const eventTime = (0, render_1.formatTime)(it.eventTime, tty);
|
|
249
|
+
// event_id 完整透传——PRD 截图里的 "..." 只是文档省略写法,不是 CLI 行为
|
|
250
|
+
const cells = [eventTime, it.type, it.eventId, it.operator || "—", it.summary];
|
|
251
|
+
return isMultiTable ? [it.targetTable, ...cells] : cells;
|
|
252
|
+
});
|
|
253
|
+
(0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, rows) : (0, render_1.renderTsv)(headers, rows));
|
|
254
|
+
if (skipped.length > 0) {
|
|
255
|
+
process.stderr.write(`(${String(skipped.length)} table(s) skipped: ${skipped.join(", ")})\n`);
|
|
256
|
+
}
|
|
257
|
+
if (result.hasMore && result.nextCursor) {
|
|
258
|
+
process.stderr.write(`(more results; use --cursor '${result.nextCursor}')\n`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// ── helpers ──
|
|
262
|
+
function normalizeTime(input, flagName) {
|
|
263
|
+
if (input === undefined || input === "")
|
|
264
|
+
return undefined;
|
|
265
|
+
// ISO 8601 直接透传,避免 parseTimeFilterMs 在严格 ISO 上重做一次损精度
|
|
266
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})$/.test(input)) {
|
|
267
|
+
return new Date(input).toISOString();
|
|
268
|
+
}
|
|
269
|
+
const ms = (0, index_1.parseTimeFilterMs)(input, flagName);
|
|
270
|
+
return new Date(ms).toISOString();
|
|
271
|
+
}
|
|
272
|
+
// 服务端 before/after 是 JSON 字符串透传,CLI JSON 输出再反序列化回对象,
|
|
273
|
+
// 给下游 jq 等工具消费。失败时透传原始字符串避免数据丢失。
|
|
274
|
+
function safeParseJson(s) {
|
|
275
|
+
try {
|
|
276
|
+
return JSON.parse(s);
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
return s;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// PRD 输出 enabled 列用 yes/no 而非 true/false
|
|
283
|
+
function boolToYesNo(b) {
|
|
284
|
+
return b ? "yes" : "no";
|
|
285
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.handleDbChangelog = handleDbChangelog;
|
|
37
|
+
const api = __importStar(require("../../../api/index"));
|
|
38
|
+
const index_1 = require("../../../api/file/index");
|
|
39
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
40
|
+
const output_1 = require("../../../utils/output");
|
|
41
|
+
const render_1 = require("../../../utils/render");
|
|
42
|
+
function toRow(it) {
|
|
43
|
+
return {
|
|
44
|
+
change_id: it.changeId,
|
|
45
|
+
changed_at: it.changedAt,
|
|
46
|
+
operator: it.operator,
|
|
47
|
+
target_table: it.targetTable,
|
|
48
|
+
change_type: it.changeType,
|
|
49
|
+
summary: it.summary,
|
|
50
|
+
statement: it.statement,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** 把用户传入的 since/until 归一成 ISO 8601 UTC 字符串;空串返 undefined。 */
|
|
54
|
+
function normalizeTime(input, flagName) {
|
|
55
|
+
if (input === undefined || input === "")
|
|
56
|
+
return undefined;
|
|
57
|
+
const ms = (0, index_1.parseTimeFilterMs)(input, flagName);
|
|
58
|
+
return new Date(ms).toISOString();
|
|
59
|
+
}
|
|
60
|
+
async function handleDbChangelog(opts) {
|
|
61
|
+
const appId = (0, shared_1.resolveAppId)(opts);
|
|
62
|
+
const since = normalizeTime(opts.since, "--since");
|
|
63
|
+
const until = normalizeTime(opts.until, "--until");
|
|
64
|
+
const allItems = [];
|
|
65
|
+
let cursor = opts.cursor;
|
|
66
|
+
let lastCursor = null;
|
|
67
|
+
let lastHasMore = false;
|
|
68
|
+
// --all:循环到 hasMore=false;否则只拉一页
|
|
69
|
+
// 没传 --all 时翻页由调用方自己用 --cursor 串
|
|
70
|
+
for (;;) {
|
|
71
|
+
const page = await api.db.listDDLChangelog({
|
|
72
|
+
appId,
|
|
73
|
+
table: opts.table,
|
|
74
|
+
since,
|
|
75
|
+
until,
|
|
76
|
+
limit: opts.limit,
|
|
77
|
+
cursor,
|
|
78
|
+
dbBranch: opts.env,
|
|
79
|
+
});
|
|
80
|
+
allItems.push(...page.items);
|
|
81
|
+
lastCursor = page.nextCursor;
|
|
82
|
+
lastHasMore = page.hasMore;
|
|
83
|
+
if (!opts.all || !page.hasMore || !page.nextCursor)
|
|
84
|
+
break;
|
|
85
|
+
cursor = page.nextCursor;
|
|
86
|
+
}
|
|
87
|
+
if ((0, output_1.isJsonMode)()) {
|
|
88
|
+
const rows = allItems.map(toRow);
|
|
89
|
+
// --all 时已经把所有页合一起返,has_more=false / next_cursor=null
|
|
90
|
+
if (opts.all) {
|
|
91
|
+
(0, output_1.emitPaged)((0, output_1.snakeCaseKeys)(rows), null, false);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
(0, output_1.emitPaged)((0, output_1.snakeCaseKeys)(rows), lastCursor, lastHasMore);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (allItems.length === 0) {
|
|
99
|
+
(0, output_1.emit)("No DDL changes found.");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const tty = (0, render_1.isStdoutTty)();
|
|
103
|
+
// PRD: change_id / changed_at / operator / target_table / change_type / summary
|
|
104
|
+
const headers = ["change_id", "changed_at", "operator", "target_table", "change_type", "summary"];
|
|
105
|
+
const rows = allItems.map((it) => [
|
|
106
|
+
it.changeId,
|
|
107
|
+
(0, render_1.formatTime)(it.changedAt, tty),
|
|
108
|
+
it.operator || "—",
|
|
109
|
+
it.targetTable || "—",
|
|
110
|
+
it.changeType,
|
|
111
|
+
it.summary || "—",
|
|
112
|
+
]);
|
|
113
|
+
(0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, rows) : (0, render_1.renderTsv)(headers, rows));
|
|
114
|
+
if (!opts.all && lastHasMore && lastCursor) {
|
|
115
|
+
process.stderr.write(`(more results; use --cursor ${lastCursor} or --all)\n`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -42,7 +42,7 @@ const error_1 = require("../../../utils/error");
|
|
|
42
42
|
const output_1 = require("../../../utils/output");
|
|
43
43
|
const shared_1 = require("../../../cli/commands/shared");
|
|
44
44
|
const render_1 = require("../../../utils/render");
|
|
45
|
-
//
|
|
45
|
+
// import / export 体积上限
|
|
46
46
|
const MAX_SIZE_BYTES = 1 * 1024 * 1024; // 1 MB
|
|
47
47
|
const MAX_ROWS = 5000;
|
|
48
48
|
async function handleDbDataImport(file, opts) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleDbDataExport = exports.handleDbDataImport = exports.handleDbSchemaGet = exports.handleDbSchemaList = exports.handleDbSql = void 0;
|
|
3
|
+
exports.handleDbQuota = exports.handleDbRecoveryApply = exports.handleDbRecoveryDiff = exports.handleDbMigrationApply = exports.handleDbMigrationDiff = exports.handleDbMigrationInit = exports.handleDbAuditList = exports.handleDbAuditDisable = exports.handleDbAuditEnable = exports.handleDbAuditStatus = exports.handleDbChangelog = exports.handleDbDataExport = exports.handleDbDataImport = exports.handleDbSchemaGet = exports.handleDbSchemaList = exports.handleDbSql = void 0;
|
|
4
4
|
var sql_1 = require("./sql");
|
|
5
5
|
Object.defineProperty(exports, "handleDbSql", { enumerable: true, get: function () { return sql_1.handleDbSql; } });
|
|
6
6
|
var schema_1 = require("./schema");
|
|
@@ -9,3 +9,19 @@ Object.defineProperty(exports, "handleDbSchemaGet", { enumerable: true, get: fun
|
|
|
9
9
|
var data_1 = require("./data");
|
|
10
10
|
Object.defineProperty(exports, "handleDbDataImport", { enumerable: true, get: function () { return data_1.handleDbDataImport; } });
|
|
11
11
|
Object.defineProperty(exports, "handleDbDataExport", { enumerable: true, get: function () { return data_1.handleDbDataExport; } });
|
|
12
|
+
var changelog_1 = require("./changelog");
|
|
13
|
+
Object.defineProperty(exports, "handleDbChangelog", { enumerable: true, get: function () { return changelog_1.handleDbChangelog; } });
|
|
14
|
+
var audit_1 = require("./audit");
|
|
15
|
+
Object.defineProperty(exports, "handleDbAuditStatus", { enumerable: true, get: function () { return audit_1.handleDbAuditStatus; } });
|
|
16
|
+
Object.defineProperty(exports, "handleDbAuditEnable", { enumerable: true, get: function () { return audit_1.handleDbAuditEnable; } });
|
|
17
|
+
Object.defineProperty(exports, "handleDbAuditDisable", { enumerable: true, get: function () { return audit_1.handleDbAuditDisable; } });
|
|
18
|
+
Object.defineProperty(exports, "handleDbAuditList", { enumerable: true, get: function () { return audit_1.handleDbAuditList; } });
|
|
19
|
+
var migration_1 = require("./migration");
|
|
20
|
+
Object.defineProperty(exports, "handleDbMigrationInit", { enumerable: true, get: function () { return migration_1.handleDbMigrationInit; } });
|
|
21
|
+
Object.defineProperty(exports, "handleDbMigrationDiff", { enumerable: true, get: function () { return migration_1.handleDbMigrationDiff; } });
|
|
22
|
+
Object.defineProperty(exports, "handleDbMigrationApply", { enumerable: true, get: function () { return migration_1.handleDbMigrationApply; } });
|
|
23
|
+
var recovery_1 = require("./recovery");
|
|
24
|
+
Object.defineProperty(exports, "handleDbRecoveryDiff", { enumerable: true, get: function () { return recovery_1.handleDbRecoveryDiff; } });
|
|
25
|
+
Object.defineProperty(exports, "handleDbRecoveryApply", { enumerable: true, get: function () { return recovery_1.handleDbRecoveryApply; } });
|
|
26
|
+
var quota_1 = require("./quota");
|
|
27
|
+
Object.defineProperty(exports, "handleDbQuota", { enumerable: true, get: function () { return quota_1.handleDbQuota; } });
|