@lark-apaas/miaoda-cli 0.1.2 → 0.1.3-alpha.40be425
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 +8 -7
- package/dist/api/app/api.js +25 -0
- package/dist/api/app/index.js +15 -0
- package/dist/api/app/schemas.js +79 -0
- package/dist/api/app/types.js +58 -0
- package/dist/api/db/api.js +331 -24
- package/dist/api/db/client.js +36 -0
- package/dist/api/db/index.js +11 -1
- package/dist/api/deploy/api.js +60 -0
- package/dist/api/deploy/index.js +16 -0
- package/dist/api/deploy/schemas.js +105 -0
- package/dist/api/deploy/types.js +22 -0
- package/dist/api/file/api.js +25 -23
- package/dist/api/file/index.js +2 -1
- package/dist/api/file/parsers.js +14 -3
- package/dist/api/index.js +7 -1
- package/dist/api/observability/api.js +52 -0
- package/dist/api/observability/index.js +16 -0
- package/dist/api/observability/schemas.js +60 -0
- package/dist/api/observability/types.js +27 -0
- package/dist/cli/commands/app/index.js +62 -0
- package/dist/cli/commands/db/index.js +577 -5
- package/dist/cli/commands/deploy/index.js +155 -0
- package/dist/cli/commands/file/index.js +22 -7
- package/dist/cli/commands/index.js +10 -6
- package/dist/cli/commands/observability/index.js +240 -0
- package/dist/cli/commands/shared.js +83 -7
- package/dist/cli/handlers/app/get.js +47 -0
- package/dist/cli/handlers/app/index.js +7 -0
- package/dist/cli/handlers/app/update.js +59 -0
- package/dist/cli/handlers/db/audit.js +294 -0
- package/dist/cli/handlers/db/changelog.js +130 -0
- package/dist/cli/handlers/db/data.js +6 -6
- package/dist/cli/handlers/db/index.js +17 -1
- package/dist/cli/handlers/db/migration.js +235 -0
- package/dist/cli/handlers/db/quota.js +68 -0
- package/dist/cli/handlers/db/recovery.js +357 -0
- package/dist/cli/handlers/db/schema.js +2 -3
- package/dist/cli/handlers/db/sql.js +2 -3
- package/dist/cli/handlers/deploy/deploy.js +84 -0
- package/dist/cli/handlers/deploy/error-log.js +60 -0
- package/dist/cli/handlers/deploy/format.js +39 -0
- package/dist/cli/handlers/deploy/get.js +71 -0
- package/dist/cli/handlers/deploy/helpers.js +41 -0
- package/dist/cli/handlers/deploy/history.js +70 -0
- package/dist/cli/handlers/deploy/index.js +14 -0
- package/dist/cli/handlers/deploy/polling.js +162 -0
- package/dist/cli/handlers/file/cp.js +1 -2
- package/dist/cli/handlers/file/index.js +3 -1
- package/dist/cli/handlers/file/ls.js +1 -2
- package/dist/cli/handlers/file/quota.js +66 -0
- package/dist/cli/handlers/file/rm.js +1 -2
- package/dist/cli/handlers/file/sign.js +1 -2
- package/dist/cli/handlers/file/stat.js +3 -3
- package/dist/cli/handlers/observability/analytics.js +212 -0
- package/dist/cli/handlers/observability/helpers.js +66 -0
- package/dist/cli/handlers/observability/index.js +12 -0
- package/dist/cli/handlers/observability/log.js +94 -0
- package/dist/cli/handlers/observability/metric.js +208 -0
- package/dist/cli/handlers/observability/trace.js +102 -0
- package/dist/main.js +6 -2
- package/dist/utils/args.js +8 -0
- package/dist/utils/devops-error.js +28 -0
- package/dist/utils/git.js +29 -0
- package/dist/utils/http.js +118 -0
- package/dist/utils/index.js +15 -1
- package/dist/utils/output.js +360 -7
- package/dist/utils/poll.js +27 -0
- package/dist/utils/time.js +208 -0
- package/package.json +7 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleAppUpdate = exports.handleAppGet = void 0;
|
|
4
|
+
var get_1 = require("./get");
|
|
5
|
+
Object.defineProperty(exports, "handleAppGet", { enumerable: true, get: function () { return get_1.handleAppGet; } });
|
|
6
|
+
var update_1 = require("./update");
|
|
7
|
+
Object.defineProperty(exports, "handleAppUpdate", { enumerable: true, get: function () { return update_1.handleAppUpdate; } });
|
|
@@ -0,0 +1,59 @@
|
|
|
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.handleAppUpdate = handleAppUpdate;
|
|
37
|
+
const api = __importStar(require("../../../api/index"));
|
|
38
|
+
const output_1 = require("../../../utils/output");
|
|
39
|
+
const args_1 = require("../../../utils/args");
|
|
40
|
+
const index_1 = require("../../../api/app/index");
|
|
41
|
+
/** miaoda app update [--app-id <id>] [--name <n>] [--description <d>] */
|
|
42
|
+
async function handleAppUpdate(opts) {
|
|
43
|
+
if (opts.name === undefined && opts.description === undefined) {
|
|
44
|
+
(0, args_1.failArgs)("至少需要 --name 或 --description 中的一个");
|
|
45
|
+
}
|
|
46
|
+
const appID = opts.appId;
|
|
47
|
+
await api.app.updateAppMeta({
|
|
48
|
+
appID,
|
|
49
|
+
name: opts.name,
|
|
50
|
+
description: opts.description,
|
|
51
|
+
});
|
|
52
|
+
// 服务端不回写新 meta,本地再 fetch 一次拿最新值给用户
|
|
53
|
+
const resp = await api.app.getAppInfo(appID);
|
|
54
|
+
const meta = resp.appInfo?.appMeta ?? {};
|
|
55
|
+
if (!(0, output_1.isJsonMode)()) {
|
|
56
|
+
process.stdout.write("✓ App updated successfully\n");
|
|
57
|
+
}
|
|
58
|
+
(0, output_1.emit)({ data: meta }, index_1.appMetaSchema);
|
|
59
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
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 shared_1 = require("../../../cli/commands/shared");
|
|
42
|
+
const colors_1 = require("../../../utils/colors");
|
|
43
|
+
const error_1 = require("../../../utils/error");
|
|
44
|
+
const output_1 = require("../../../utils/output");
|
|
45
|
+
const render_1 = require("../../../utils/render");
|
|
46
|
+
const time_1 = require("../../../utils/time");
|
|
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
|
+
// c.highlight 内部按 TTY/NO_COLOR/FORCE_COLOR 自动决定是否染色,无需再判 tty
|
|
147
|
+
const tableLabel = colors_1.c.highlight(`'${status.table}'`);
|
|
148
|
+
const body = `Audit enabled for table ${tableLabel} (retention: ${status.retention ?? retention})`;
|
|
149
|
+
(0, output_1.emit)(tty ? colors_1.c.success(`✓ ${body}`) : `OK ${body}`);
|
|
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 body = `Audit disabled for table ${colors_1.c.highlight(`'${status.table}'`)}`;
|
|
185
|
+
(0, output_1.emit)(tty ? colors_1.c.success(`✓ ${body}`) : `OK ${body}`);
|
|
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
|
+
/**
|
|
263
|
+
* 把用户传入的 since/until 归一成 ISO 8601 UTC 字符串;空串返 undefined。
|
|
264
|
+
* 支持格式见 utils/time.ts::TIMESTAMP_HELP(相对时间 / 日期 / 本地 datetime / ISO 8601)。
|
|
265
|
+
*/
|
|
266
|
+
function normalizeTime(input, flagName) {
|
|
267
|
+
if (input === undefined || input === "")
|
|
268
|
+
return undefined;
|
|
269
|
+
try {
|
|
270
|
+
return new Date((0, time_1.parseTimeToMs)(input)).toISOString();
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
if (err instanceof error_1.AppError) {
|
|
274
|
+
throw new error_1.AppError(err.code, `${flagName}: ${err.message}`, {
|
|
275
|
+
next_actions: err.next_actions,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
throw err;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// 服务端 before/after 是 JSON 字符串透传,CLI JSON 输出再反序列化回对象,
|
|
282
|
+
// 给下游 jq 等工具消费。失败时透传原始字符串避免数据丢失。
|
|
283
|
+
function safeParseJson(s) {
|
|
284
|
+
try {
|
|
285
|
+
return JSON.parse(s);
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
return s;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// PRD 输出 enabled 列用 yes/no 而非 true/false
|
|
292
|
+
function boolToYesNo(b) {
|
|
293
|
+
return b ? "yes" : "no";
|
|
294
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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 shared_1 = require("../../../cli/commands/shared");
|
|
39
|
+
const error_1 = require("../../../utils/error");
|
|
40
|
+
const output_1 = require("../../../utils/output");
|
|
41
|
+
const render_1 = require("../../../utils/render");
|
|
42
|
+
const time_1 = require("../../../utils/time");
|
|
43
|
+
function toRow(it) {
|
|
44
|
+
return {
|
|
45
|
+
change_id: it.changeId,
|
|
46
|
+
changed_at: it.changedAt,
|
|
47
|
+
operator: it.operator,
|
|
48
|
+
target_table: it.targetTable,
|
|
49
|
+
change_type: it.changeType,
|
|
50
|
+
summary: it.summary,
|
|
51
|
+
statement: it.statement,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 把用户传入的 since/until 归一成 ISO 8601 UTC 字符串;空串返 undefined。
|
|
56
|
+
* 支持格式见 utils/time.ts::TIMESTAMP_HELP(相对时间 / 日期 / 本地 datetime / ISO 8601)。
|
|
57
|
+
*/
|
|
58
|
+
function normalizeTime(input, flagName) {
|
|
59
|
+
if (input === undefined || input === "")
|
|
60
|
+
return undefined;
|
|
61
|
+
try {
|
|
62
|
+
return new Date((0, time_1.parseTimeToMs)(input)).toISOString();
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err instanceof error_1.AppError) {
|
|
66
|
+
throw new error_1.AppError(err.code, `${flagName}: ${err.message}`, {
|
|
67
|
+
next_actions: err.next_actions,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function handleDbChangelog(opts) {
|
|
74
|
+
const appId = (0, shared_1.resolveAppId)(opts);
|
|
75
|
+
const since = normalizeTime(opts.since, "--since");
|
|
76
|
+
const until = normalizeTime(opts.until, "--until");
|
|
77
|
+
const allItems = [];
|
|
78
|
+
let cursor = opts.cursor;
|
|
79
|
+
let lastCursor = null;
|
|
80
|
+
let lastHasMore = false;
|
|
81
|
+
// --all:循环到 hasMore=false;否则只拉一页
|
|
82
|
+
// 没传 --all 时翻页由调用方自己用 --cursor 串
|
|
83
|
+
for (;;) {
|
|
84
|
+
const page = await api.db.listDDLChangelog({
|
|
85
|
+
appId,
|
|
86
|
+
table: opts.table,
|
|
87
|
+
since,
|
|
88
|
+
until,
|
|
89
|
+
limit: opts.limit,
|
|
90
|
+
cursor,
|
|
91
|
+
dbBranch: opts.env,
|
|
92
|
+
});
|
|
93
|
+
allItems.push(...page.items);
|
|
94
|
+
lastCursor = page.nextCursor;
|
|
95
|
+
lastHasMore = page.hasMore;
|
|
96
|
+
if (!opts.all || !page.hasMore || !page.nextCursor)
|
|
97
|
+
break;
|
|
98
|
+
cursor = page.nextCursor;
|
|
99
|
+
}
|
|
100
|
+
if ((0, output_1.isJsonMode)()) {
|
|
101
|
+
const rows = allItems.map(toRow);
|
|
102
|
+
// --all 时已经把所有页合一起返,has_more=false / next_cursor=null
|
|
103
|
+
if (opts.all) {
|
|
104
|
+
(0, output_1.emitPaged)((0, output_1.snakeCaseKeys)(rows), null, false);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
(0, output_1.emitPaged)((0, output_1.snakeCaseKeys)(rows), lastCursor, lastHasMore);
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (allItems.length === 0) {
|
|
112
|
+
(0, output_1.emit)("No DDL changes found.");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const tty = (0, render_1.isStdoutTty)();
|
|
116
|
+
// PRD: change_id / changed_at / operator / target_table / change_type / summary
|
|
117
|
+
const headers = ["change_id", "changed_at", "operator", "target_table", "change_type", "summary"];
|
|
118
|
+
const rows = allItems.map((it) => [
|
|
119
|
+
it.changeId,
|
|
120
|
+
(0, render_1.formatTime)(it.changedAt, tty),
|
|
121
|
+
it.operator || "—",
|
|
122
|
+
it.targetTable || "—",
|
|
123
|
+
it.changeType,
|
|
124
|
+
it.summary || "—",
|
|
125
|
+
]);
|
|
126
|
+
(0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, rows) : (0, render_1.renderTsv)(headers, rows));
|
|
127
|
+
if (!opts.all && lastHasMore && lastCursor) {
|
|
128
|
+
process.stderr.write(`(more results; use --cursor ${lastCursor} or --all)\n`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -38,15 +38,15 @@ exports.handleDbDataExport = handleDbDataExport;
|
|
|
38
38
|
const fs = __importStar(require("node:fs/promises"));
|
|
39
39
|
const path = __importStar(require("node:path"));
|
|
40
40
|
const api = __importStar(require("../../../api/index"));
|
|
41
|
+
const colors_1 = require("../../../utils/colors");
|
|
41
42
|
const error_1 = require("../../../utils/error");
|
|
42
43
|
const output_1 = require("../../../utils/output");
|
|
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) {
|
|
49
|
-
const appId =
|
|
49
|
+
const appId = opts.appId;
|
|
50
50
|
const ext = path.extname(file).toLowerCase();
|
|
51
51
|
const format = resolveFormat(opts.format, ext, "import");
|
|
52
52
|
let body;
|
|
@@ -91,11 +91,11 @@ async function handleDbDataImport(file, opts) {
|
|
|
91
91
|
}
|
|
92
92
|
const tty = (0, render_1.isStdoutTty)();
|
|
93
93
|
(0, output_1.emit)(tty
|
|
94
|
-
? `✓ Imported ${file} → table '${result.tableName}' (${String(result.recordCount)} rows)`
|
|
94
|
+
? colors_1.c.success(`✓ Imported ${file} → table '${result.tableName}' (${String(result.recordCount)} rows)`)
|
|
95
95
|
: `OK Imported ${file} -> table '${result.tableName}' (${String(result.recordCount)} rows)`);
|
|
96
96
|
}
|
|
97
97
|
async function handleDbDataExport(table, opts) {
|
|
98
|
-
const appId =
|
|
98
|
+
const appId = opts.appId;
|
|
99
99
|
const format = resolveFormat(opts.format, undefined, "export", "csv");
|
|
100
100
|
const outputPath = opts.file ?? `${table}.${format}`;
|
|
101
101
|
const limit = opts.limit ? Number(opts.limit) : MAX_ROWS;
|
|
@@ -145,7 +145,7 @@ async function handleDbDataExport(table, opts) {
|
|
|
145
145
|
}
|
|
146
146
|
const tty = (0, render_1.isStdoutTty)();
|
|
147
147
|
(0, output_1.emit)(tty
|
|
148
|
-
? `✓ Exported ${table} → ${outputPath} (${String(rows)} rows)`
|
|
148
|
+
? colors_1.c.success(`✓ Exported ${table} → ${outputPath} (${String(rows)} rows)`)
|
|
149
149
|
: `OK Exported ${table} -> ${outputPath} (${String(rows)} rows)`);
|
|
150
150
|
}
|
|
151
151
|
// ── 共用辅助 ──
|
|
@@ -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; } });
|