@lark-apaas/miaoda-cli 0.1.2-alpha.74c0e23 → 0.1.2-alpha.8bc93eb
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 +204 -6
- package/dist/api/db/client.js +36 -0
- package/dist/api/db/index.js +8 -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 +0 -6
- package/dist/cli/commands/shared.js +3 -37
- package/dist/cli/handlers/db/audit.js +289 -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 +145 -0
- package/dist/cli/handlers/{app/update.js → db/quota.js} +29 -20
- package/dist/cli/handlers/db/recovery.js +188 -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/utils/http.js +0 -32
- 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 -39
- 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 -139
- package/dist/cli/commands/observability/index.js +0 -227
- 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 -189
- 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/utils/devops-error.js +0 -28
- package/dist/utils/git.js +0 -29
- package/dist/utils/time.js +0 -132
package/dist/api/db/api.js
CHANGED
|
@@ -4,6 +4,13 @@ exports.execSql = execSql;
|
|
|
4
4
|
exports.getSchema = getSchema;
|
|
5
5
|
exports.importData = importData;
|
|
6
6
|
exports.exportData = exportData;
|
|
7
|
+
exports.listDDLChangelog = listDDLChangelog;
|
|
8
|
+
exports.getAuditStatus = getAuditStatus;
|
|
9
|
+
exports.setAuditConfig = setAuditConfig;
|
|
10
|
+
exports.migrationInit = migrationInit;
|
|
11
|
+
exports.migrate = migrate;
|
|
12
|
+
exports.recover = recover;
|
|
13
|
+
exports.getDbQuota = getDbQuota;
|
|
7
14
|
const http_1 = require("../../utils/http");
|
|
8
15
|
const error_1 = require("../../utils/error");
|
|
9
16
|
const http_client_1 = require("@lark-apaas/http-client");
|
|
@@ -247,10 +254,14 @@ async function exportData(opts) {
|
|
|
247
254
|
await mapDbHttpError(err, url, "Failed to export data");
|
|
248
255
|
throw err; // 不可达
|
|
249
256
|
}
|
|
250
|
-
// 成功路径:响应 body 通常是原始 CSV/JSON 字节,但部分错误场景下网关会返
|
|
257
|
+
// 成功路径:响应 body 通常是原始 CSV/SQL/JSON 字节,但部分错误场景下网关会返
|
|
251
258
|
// HTTP 200 + JSON envelope(status_code != "0"),需要在这里嗅探兜底。
|
|
252
|
-
const
|
|
253
|
-
|
|
259
|
+
const defaultContentType = {
|
|
260
|
+
csv: "text/csv",
|
|
261
|
+
sql: "text/plain",
|
|
262
|
+
json: "application/json",
|
|
263
|
+
};
|
|
264
|
+
const contentType = response.headers.get("Content-Type") ?? defaultContentType[opts.format];
|
|
254
265
|
const ab = await response.arrayBuffer();
|
|
255
266
|
const buf = Buffer.from(new Uint8Array(ab));
|
|
256
267
|
if (buf.length === 0) {
|
|
@@ -258,8 +269,9 @@ async function exportData(opts) {
|
|
|
258
269
|
}
|
|
259
270
|
// Envelope sniff:HTTP 200 + Content-Type 为 application/json + body 解析得到
|
|
260
271
|
// InnerEnvelope 且 status_code 非 "0" 时,按业务错误抛出。
|
|
261
|
-
//
|
|
262
|
-
|
|
272
|
+
// CSV / SQL 都是非 JSON 输出,application/json 响应必是错误信封;JSON 格式
|
|
273
|
+
// 成功响应自身就是 application/json,跳过 sniff 避免误判。
|
|
274
|
+
if (opts.format !== "json" && /application\/json/i.test(contentType)) {
|
|
263
275
|
try {
|
|
264
276
|
const parsed = JSON.parse(buf.toString("utf8"));
|
|
265
277
|
if (parsed.status_code != null && parsed.status_code !== "0") {
|
|
@@ -269,7 +281,7 @@ async function exportData(opts) {
|
|
|
269
281
|
}
|
|
270
282
|
catch (err) {
|
|
271
283
|
// 已经被 extractData 抛成 AppError → 透传;否则 JSON.parse 失败说明 body
|
|
272
|
-
// 真的是 CSV 文本,继续按成功流程走
|
|
284
|
+
// 真的是 CSV / SQL 文本,继续按成功流程走
|
|
273
285
|
if (err instanceof error_1.AppError)
|
|
274
286
|
throw err;
|
|
275
287
|
}
|
|
@@ -286,3 +298,189 @@ async function exportData(opts) {
|
|
|
286
298
|
recordCount,
|
|
287
299
|
};
|
|
288
300
|
}
|
|
301
|
+
// ── db changelog → InnerAdminListDDLChangelog ──
|
|
302
|
+
/**
|
|
303
|
+
* 后端:GET /v1/dataloom/app/{appId}/db/changelog?table=&since=&until=&limit=&cursor=&dbBranch=
|
|
304
|
+
*
|
|
305
|
+
* 时间字段 since/until 由 CLI 端归一化为 ISO 8601 UTC 后透传;后端按 created_at 比较。
|
|
306
|
+
*/
|
|
307
|
+
async function listDDLChangelog(opts) {
|
|
308
|
+
const client = (0, http_1.getHttpClient)();
|
|
309
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/changelog", {
|
|
310
|
+
table: opts.table,
|
|
311
|
+
since: opts.since,
|
|
312
|
+
until: opts.until,
|
|
313
|
+
limit: opts.limit !== undefined ? String(opts.limit) : undefined,
|
|
314
|
+
cursor: opts.cursor,
|
|
315
|
+
dbBranch: opts.dbBranch,
|
|
316
|
+
});
|
|
317
|
+
const start = Date.now();
|
|
318
|
+
let response;
|
|
319
|
+
try {
|
|
320
|
+
response = await client.get(url);
|
|
321
|
+
(0, client_1.traceHttp)("GET", url, start, response);
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
(0, client_1.traceHttp)("GET", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
325
|
+
await mapDbHttpError(err, url, "Failed to list DDL changelog");
|
|
326
|
+
throw err; // 不可达
|
|
327
|
+
}
|
|
328
|
+
const body = (await response.json());
|
|
329
|
+
const data = (0, client_1.extractData)(body);
|
|
330
|
+
return {
|
|
331
|
+
items: data.items ?? [],
|
|
332
|
+
nextCursor: data.nextCursor && data.nextCursor !== "" ? data.nextCursor : null,
|
|
333
|
+
hasMore: Boolean(data.hasMore),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
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
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 后端:POST /v1/dataloom/app/{appId}/db/audit/config
|
|
364
|
+
* 写:enabled=true 开启 / false 关闭。retention 仅 enabled=true 生效。
|
|
365
|
+
*/
|
|
366
|
+
async function setAuditConfig(opts) {
|
|
367
|
+
const client = (0, http_1.getHttpClient)();
|
|
368
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/audit/config");
|
|
369
|
+
const body = {
|
|
370
|
+
table: opts.table,
|
|
371
|
+
enabled: opts.enabled,
|
|
372
|
+
};
|
|
373
|
+
if (opts.retention !== undefined && opts.retention !== "")
|
|
374
|
+
body.retention = opts.retention;
|
|
375
|
+
if (opts.dbBranch !== undefined && opts.dbBranch !== "")
|
|
376
|
+
body.dbBranch = opts.dbBranch;
|
|
377
|
+
const start = Date.now();
|
|
378
|
+
let response;
|
|
379
|
+
try {
|
|
380
|
+
response = await client.post(url, body);
|
|
381
|
+
(0, client_1.traceHttp)("POST", url, start, response);
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
(0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
385
|
+
await mapDbHttpError(err, url, "Failed to set audit config");
|
|
386
|
+
throw err; // 不可达
|
|
387
|
+
}
|
|
388
|
+
const respBody = (await response.json());
|
|
389
|
+
const data = (0, client_1.extractData)(respBody);
|
|
390
|
+
if (!data.status) {
|
|
391
|
+
throw new error_1.AppError("INTERNAL_DB_ERROR", "audit config response missing status field");
|
|
392
|
+
}
|
|
393
|
+
return data.status;
|
|
394
|
+
}
|
|
395
|
+
// ── db migration → InnerAdminMigrationInit / InnerAdminMigrate ──
|
|
396
|
+
/**
|
|
397
|
+
* 后端:POST /v1/dataloom/app/{appId}/db/enableMultiEnv
|
|
398
|
+
* 单库 → dev/online 双库初始化,不可逆。对应公开 API EnableMultiEnvDB 的 admin-inner 通道。
|
|
399
|
+
*/
|
|
400
|
+
async function migrationInit(opts) {
|
|
401
|
+
const client = (0, http_1.getHttpClient)();
|
|
402
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/enableMultiEnv");
|
|
403
|
+
const body = {};
|
|
404
|
+
if (opts.syncData !== undefined)
|
|
405
|
+
body.syncData = opts.syncData;
|
|
406
|
+
const start = Date.now();
|
|
407
|
+
let response;
|
|
408
|
+
try {
|
|
409
|
+
response = await client.post(url, body);
|
|
410
|
+
(0, client_1.traceHttp)("POST", url, start, response);
|
|
411
|
+
}
|
|
412
|
+
catch (err) {
|
|
413
|
+
(0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
414
|
+
await mapDbHttpError(err, url, "Failed to init migration");
|
|
415
|
+
throw err; // 不可达
|
|
416
|
+
}
|
|
417
|
+
const respBody = (await response.json());
|
|
418
|
+
return (0, client_1.extractData)(respBody);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* 后端:POST /v1/dataloom/app/{appId}/db/migration
|
|
422
|
+
* 合并 diff + apply:dryRun=true 只返 changes 不下发;dryRun=false 才执行。
|
|
423
|
+
*/
|
|
424
|
+
async function migrate(opts) {
|
|
425
|
+
const client = (0, http_1.getHttpClient)();
|
|
426
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/migration");
|
|
427
|
+
const start = Date.now();
|
|
428
|
+
let response;
|
|
429
|
+
try {
|
|
430
|
+
response = await client.post(url, { dryRun: opts.dryRun });
|
|
431
|
+
(0, client_1.traceHttp)("POST", url, start, response);
|
|
432
|
+
}
|
|
433
|
+
catch (err) {
|
|
434
|
+
(0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
435
|
+
await mapDbHttpError(err, url, "Failed to migrate");
|
|
436
|
+
throw err; // 不可达
|
|
437
|
+
}
|
|
438
|
+
const respBody = (await response.json());
|
|
439
|
+
return (0, client_1.extractData)(respBody);
|
|
440
|
+
}
|
|
441
|
+
// ── db recovery → InnerAdminRecover ──
|
|
442
|
+
/**
|
|
443
|
+
* 后端:POST /v1/dataloom/app/{appId}/db/recovery
|
|
444
|
+
* 合并 PITR diff + apply:dryRun=true 预览影响;dryRun=false 触发恢复。
|
|
445
|
+
*/
|
|
446
|
+
async function recover(opts) {
|
|
447
|
+
const client = (0, http_1.getHttpClient)();
|
|
448
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/recovery");
|
|
449
|
+
const start = Date.now();
|
|
450
|
+
let response;
|
|
451
|
+
try {
|
|
452
|
+
response = await client.post(url, {
|
|
453
|
+
target: opts.target,
|
|
454
|
+
dryRun: opts.dryRun,
|
|
455
|
+
});
|
|
456
|
+
(0, client_1.traceHttp)("POST", url, start, response);
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
(0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
460
|
+
await mapDbHttpError(err, url, "Failed to recover");
|
|
461
|
+
throw err; // 不可达
|
|
462
|
+
}
|
|
463
|
+
const respBody = (await response.json());
|
|
464
|
+
return (0, client_1.extractData)(respBody);
|
|
465
|
+
}
|
|
466
|
+
// ── db quota → InnerAdminGetDbQuota ──
|
|
467
|
+
/**
|
|
468
|
+
* 后端:GET /v1/dataloom/app/{appId}/db/quota?dbBranch=
|
|
469
|
+
*/
|
|
470
|
+
async function getDbQuota(opts) {
|
|
471
|
+
const client = (0, http_1.getHttpClient)();
|
|
472
|
+
const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/quota", { dbBranch: opts.dbBranch });
|
|
473
|
+
const start = Date.now();
|
|
474
|
+
let response;
|
|
475
|
+
try {
|
|
476
|
+
response = await client.get(url);
|
|
477
|
+
(0, client_1.traceHttp)("GET", url, start, response);
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
(0, client_1.traceHttp)("GET", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
|
|
481
|
+
await mapDbHttpError(err, url, "Failed to get db quota");
|
|
482
|
+
throw err; // 不可达
|
|
483
|
+
}
|
|
484
|
+
const respBody = (await response.json());
|
|
485
|
+
return (0, client_1.extractData)(respBody);
|
|
486
|
+
}
|
package/dist/api/db/client.js
CHANGED
|
@@ -129,6 +129,42 @@ const BIZ_ERR_MAP = new Map(Object.entries({
|
|
|
129
129
|
// k_dl_1300015:SELECT 结果超过 1000 行硬拦;多行 hint 由 output.ts 的
|
|
130
130
|
// SERVER_ERROR_HINTS 按语义 code 兜底,这里只做 code 改名
|
|
131
131
|
k_dl_1300015: { code: "RESULT_SET_TOO_LARGE" },
|
|
132
|
+
// audit
|
|
133
|
+
k_dl_1310001: {
|
|
134
|
+
code: "AUDIT_ALREADY_ENABLED",
|
|
135
|
+
hint: "Use `miaoda db audit status <table>` to confirm current state.",
|
|
136
|
+
},
|
|
137
|
+
k_dl_1310002: {
|
|
138
|
+
code: "AUDIT_NOT_ENABLED",
|
|
139
|
+
hint: "Run `miaoda db audit enable <table>` first.",
|
|
140
|
+
},
|
|
141
|
+
k_dl_1310003: {
|
|
142
|
+
code: "INVALID_RETENTION",
|
|
143
|
+
hint: "Allowed values: 7d, 30d, 180d, 360d, forever.",
|
|
144
|
+
},
|
|
145
|
+
// migration
|
|
146
|
+
k_dl_1320001: {
|
|
147
|
+
code: "MIGRATION_NOT_AVAILABLE",
|
|
148
|
+
hint: "Migration commands require an expert-mode application.",
|
|
149
|
+
},
|
|
150
|
+
k_dl_1320002: { code: "MULTI_ENV_ALREADY_INITIALIZED" },
|
|
151
|
+
k_dl_1320003: {
|
|
152
|
+
code: "NO_PENDING_CHANGES",
|
|
153
|
+
hint: "dev and online schemas are already in sync.",
|
|
154
|
+
},
|
|
155
|
+
// recovery
|
|
156
|
+
k_dl_1330001: {
|
|
157
|
+
code: "RECOVERY_WINDOW_EXCEEDED",
|
|
158
|
+
hint: "Pick a timestamp inside the supported recovery window.",
|
|
159
|
+
},
|
|
160
|
+
k_dl_1330002: {
|
|
161
|
+
code: "RECOVERY_IN_PROGRESS",
|
|
162
|
+
hint: "Wait for the running recovery to finish, or check its status.",
|
|
163
|
+
},
|
|
164
|
+
k_dl_1330003: {
|
|
165
|
+
code: "INVALID_TIMESTAMP",
|
|
166
|
+
hint: "Use ISO 8601 / yyyy-mm-dd / yyyy-mm-dd HH:MM:SS.",
|
|
167
|
+
},
|
|
132
168
|
}));
|
|
133
169
|
/** PG SQLSTATE → CLI code(当前 dataloom 不一定透传,预留未来使用) */
|
|
134
170
|
exports.SQLSTATE_MAP = {
|
package/dist/api/db/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
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.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
|
+
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; } });
|
|
11
|
+
Object.defineProperty(exports, "setAuditConfig", { enumerable: true, get: function () { return api_1.setAuditConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "migrationInit", { enumerable: true, get: function () { return api_1.migrationInit; } });
|
|
13
|
+
Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return api_1.migrate; } });
|
|
14
|
+
Object.defineProperty(exports, "recover", { enumerable: true, get: function () { return api_1.recover; } });
|
|
15
|
+
Object.defineProperty(exports, "getDbQuota", { enumerable: true, get: function () { return api_1.getDbQuota; } });
|
|
9
16
|
var client_1 = require("./client");
|
|
10
17
|
Object.defineProperty(exports, "buildInnerUrl", { enumerable: true, get: function () { return client_1.buildInnerUrl; } });
|
|
11
18
|
Object.defineProperty(exports, "ensureInnerSuccess", { enumerable: true, get: function () { return client_1.ensureInnerSuccess; } });
|
package/dist/api/file/api.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.uploadFile = uploadFile;
|
|
|
8
8
|
exports.signDownload = signDownload;
|
|
9
9
|
exports.downloadFile = downloadFile;
|
|
10
10
|
exports.deleteFiles = deleteFiles;
|
|
11
|
+
exports.getStorageQuota = getStorageQuota;
|
|
11
12
|
const error_1 = require("../../utils/error");
|
|
12
13
|
const logger_1 = require("../../utils/logger");
|
|
13
14
|
const client_1 = require("./client");
|
|
@@ -519,3 +520,17 @@ async function deleteFiles(opts) {
|
|
|
519
520
|
}
|
|
520
521
|
return { deleted, failed };
|
|
521
522
|
}
|
|
523
|
+
// ── storage quota ──
|
|
524
|
+
/**
|
|
525
|
+
* 后端:GET /v1/storage/app/{appId}/bucket/{bucketId}/quota
|
|
526
|
+
* 单 bucket 用量;StorageQuotaBytes 暂未对接,CLI 拿到 0 时按 "—" 渲染。
|
|
527
|
+
* bucketId 缺省时走默认 bucket(与 ls / stat / cp 等一致)。
|
|
528
|
+
*/
|
|
529
|
+
async function getStorageQuota(opts) {
|
|
530
|
+
const bucketId = opts.bucketId ?? (await (0, client_1.getDefaultBucketId)(opts.appId));
|
|
531
|
+
const url = `/v1/storage/app/${encodeURIComponent(opts.appId)}/bucket/${encodeURIComponent(bucketId)}/quota`;
|
|
532
|
+
const body = await (0, client_1.doGet)(url, {
|
|
533
|
+
errorContext: `fetch storage quota for app '${opts.appId}' bucket '${bucketId}'`,
|
|
534
|
+
});
|
|
535
|
+
return extractEnvelope(body);
|
|
536
|
+
}
|
package/dist/api/file/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toAbsolutePath = exports.looksLikePath = exports.resetBucketCache = exports.getDefaultBucketId = exports.parseTimeFilterMs = exports.resolveInputs = exports.deleteFiles = exports.downloadFile = exports.signDownload = exports.uploadFile = exports.statFile = exports.listFiles = void 0;
|
|
3
|
+
exports.toAbsolutePath = exports.looksLikePath = exports.resetBucketCache = exports.getDefaultBucketId = exports.getStorageQuota = exports.parseTimeFilterMs = exports.resolveInputs = exports.deleteFiles = exports.downloadFile = exports.signDownload = exports.uploadFile = exports.statFile = exports.listFiles = void 0;
|
|
4
4
|
var api_1 = require("./api");
|
|
5
5
|
Object.defineProperty(exports, "listFiles", { enumerable: true, get: function () { return api_1.listFiles; } });
|
|
6
6
|
Object.defineProperty(exports, "statFile", { enumerable: true, get: function () { return api_1.statFile; } });
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function
|
|
|
10
10
|
Object.defineProperty(exports, "deleteFiles", { enumerable: true, get: function () { return api_1.deleteFiles; } });
|
|
11
11
|
Object.defineProperty(exports, "resolveInputs", { enumerable: true, get: function () { return api_1.resolveInputs; } });
|
|
12
12
|
Object.defineProperty(exports, "parseTimeFilterMs", { enumerable: true, get: function () { return api_1.parseTimeFilterMs; } });
|
|
13
|
+
Object.defineProperty(exports, "getStorageQuota", { enumerable: true, get: function () { return api_1.getStorageQuota; } });
|
|
13
14
|
var client_1 = require("./client");
|
|
14
15
|
Object.defineProperty(exports, "getDefaultBucketId", { enumerable: true, get: function () { return client_1.getDefaultBucketId; } });
|
|
15
16
|
Object.defineProperty(exports, "resetBucketCache", { enumerable: true, get: function () { return client_1.resetBucketCache; } });
|
package/dist/api/index.js
CHANGED
|
@@ -33,16 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.db = exports.file = exports.plugin = void 0;
|
|
37
37
|
const _plugin = __importStar(require("../api/plugin/index"));
|
|
38
38
|
const _file = __importStar(require("../api/file/index"));
|
|
39
39
|
const _db = __importStar(require("../api/db/index"));
|
|
40
|
-
const _observability = __importStar(require("../api/observability/index"));
|
|
41
|
-
const _app = __importStar(require("../api/app/index"));
|
|
42
|
-
const _deploy = __importStar(require("../api/deploy/index"));
|
|
43
40
|
exports.plugin = { ..._plugin };
|
|
44
41
|
exports.file = { ..._file };
|
|
45
42
|
exports.db = { ..._db };
|
|
46
|
-
exports.observability = { ..._observability };
|
|
47
|
-
exports.app = { ..._app };
|
|
48
|
-
exports.deploy = { ..._deploy };
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerDbCommands = registerDbCommands;
|
|
4
|
+
const error_1 = require("../../../utils/error");
|
|
4
5
|
const index_1 = require("../../../cli/handlers/db/index");
|
|
6
|
+
function parsePositiveInt(raw) {
|
|
7
|
+
const n = Number(raw);
|
|
8
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
9
|
+
throw new error_1.AppError("ARGS_INVALID", `--limit must be a positive integer (got '${raw}')`);
|
|
10
|
+
}
|
|
11
|
+
return n;
|
|
12
|
+
}
|
|
5
13
|
function registerDbCommands(program) {
|
|
6
14
|
const dbCmd = program
|
|
7
15
|
.command("db")
|
|
@@ -206,4 +214,133 @@ Examples:
|
|
|
206
214
|
Error: Output file 'users.csv' already exists
|
|
207
215
|
hint: Use -f to specify a different path, or --force to overwrite.
|
|
208
216
|
`);
|
|
217
|
+
// ── changelog ──
|
|
218
|
+
dbCmd
|
|
219
|
+
.command("changelog")
|
|
220
|
+
.summary("查看 DDL 变更历史")
|
|
221
|
+
.description("列出 DDL 变更(CREATE / ALTER / DROP),支持按表、时间窗筛选与游标分页。")
|
|
222
|
+
.usage("[flags]")
|
|
223
|
+
.option("--table <name>", "只看某张表的 DDL 变更")
|
|
224
|
+
.option("--since <time>", "起始时间(含),相对 1h/2d / 日期 YYYY-MM-DD / ISO 8601")
|
|
225
|
+
.option("--until <time>", "结束时间(含),同 --since 格式")
|
|
226
|
+
.option("--limit <n>", "单次返回上限(默认 20)", parsePositiveInt, 20)
|
|
227
|
+
.option("--cursor <token>", "分页游标,从上次响应的 next_cursor 取值")
|
|
228
|
+
.option("--all", "自动翻页直到取完所有记录")
|
|
229
|
+
.action(async function () {
|
|
230
|
+
await (0, index_1.handleDbChangelog)(this.optsWithGlobals());
|
|
231
|
+
});
|
|
232
|
+
// ── audit ──
|
|
233
|
+
const auditCmd = dbCmd
|
|
234
|
+
.command("audit")
|
|
235
|
+
.summary("表级数据审计开关与查询")
|
|
236
|
+
.description("配置表的数据审计 (enable/disable/retention),查询审计状态与日志。")
|
|
237
|
+
.usage("<command> [flags]");
|
|
238
|
+
auditCmd.action(() => {
|
|
239
|
+
auditCmd.outputHelp();
|
|
240
|
+
});
|
|
241
|
+
auditCmd
|
|
242
|
+
.command("status")
|
|
243
|
+
.summary("查看审计开关状态(不传 table 返列表)")
|
|
244
|
+
.usage("[table] [flags]")
|
|
245
|
+
.argument("[table]", "表名;省略时返所有已配置审计的表")
|
|
246
|
+
.action(async function (table) {
|
|
247
|
+
await (0, index_1.handleDbAuditStatus)(table, this.optsWithGlobals());
|
|
248
|
+
});
|
|
249
|
+
auditCmd
|
|
250
|
+
.command("enable")
|
|
251
|
+
.summary("启用表审计")
|
|
252
|
+
.usage("<table> [flags]")
|
|
253
|
+
.argument("<table>", "目标表名")
|
|
254
|
+
.option("--retention <ttl>", "保留时长 7d / 30d / 180d / 360d / forever", "7d")
|
|
255
|
+
.action(async function (table) {
|
|
256
|
+
await (0, index_1.handleDbAuditEnable)(table, this.optsWithGlobals());
|
|
257
|
+
});
|
|
258
|
+
auditCmd
|
|
259
|
+
.command("disable")
|
|
260
|
+
.summary("关闭表审计")
|
|
261
|
+
.usage("<table> [flags]")
|
|
262
|
+
.argument("<table>", "目标表名")
|
|
263
|
+
.action(async function (table) {
|
|
264
|
+
await (0, index_1.handleDbAuditDisable)(table, this.optsWithGlobals());
|
|
265
|
+
});
|
|
266
|
+
auditCmd
|
|
267
|
+
.command("list")
|
|
268
|
+
.summary("查询审计日志")
|
|
269
|
+
.description("按表 + 时间窗查询审计日志(INSERT / UPDATE / DELETE)。")
|
|
270
|
+
.usage("<table...> [flags]")
|
|
271
|
+
.argument("<tables...>", "一个或多个表名(多表时空表会汇总到 stderr)")
|
|
272
|
+
.option("--since <time>", "起始时间")
|
|
273
|
+
.option("--until <time>", "结束时间")
|
|
274
|
+
.option("--limit <n>", "单次返回上限(默认 50)", parsePositiveInt, 50)
|
|
275
|
+
.option("--cursor <ts>", "分页游标,传上一页末条 event_time")
|
|
276
|
+
.action(async function (tables) {
|
|
277
|
+
await (0, index_1.handleDbAuditList)(tables, this.optsWithGlobals());
|
|
278
|
+
});
|
|
279
|
+
// ── migration ──
|
|
280
|
+
const migrationCmd = dbCmd
|
|
281
|
+
.command("migration")
|
|
282
|
+
.summary("多环境管理(dev / online,仅专家模式应用)")
|
|
283
|
+
.description("init 拆分双环境,diff 预览待发布变更,apply 把 dev 同步到 online。")
|
|
284
|
+
.usage("<command> [flags]");
|
|
285
|
+
migrationCmd.action(() => {
|
|
286
|
+
migrationCmd.outputHelp();
|
|
287
|
+
});
|
|
288
|
+
migrationCmd
|
|
289
|
+
.command("init")
|
|
290
|
+
.summary("初始化多环境(不可逆)")
|
|
291
|
+
.usage("[flags]")
|
|
292
|
+
.option("--sync-data", "同时把现有数据复制到 dev")
|
|
293
|
+
.option("--yes", "跳过 TTY 确认")
|
|
294
|
+
.action(async function () {
|
|
295
|
+
await (0, index_1.handleDbMigrationInit)(this.optsWithGlobals());
|
|
296
|
+
});
|
|
297
|
+
migrationCmd
|
|
298
|
+
.command("diff")
|
|
299
|
+
.summary("预览 dev → online 待发布变更")
|
|
300
|
+
.usage("[flags]")
|
|
301
|
+
.action(async function () {
|
|
302
|
+
await (0, index_1.handleDbMigrationDiff)(this.optsWithGlobals());
|
|
303
|
+
});
|
|
304
|
+
migrationCmd
|
|
305
|
+
.command("apply")
|
|
306
|
+
.summary("应用 dev 变更到 online(多 DDL 单事务原子)")
|
|
307
|
+
.usage("[flags]")
|
|
308
|
+
.option("--yes", "跳过 TTY 二次确认")
|
|
309
|
+
.action(async function () {
|
|
310
|
+
await (0, index_1.handleDbMigrationApply)(this.optsWithGlobals());
|
|
311
|
+
});
|
|
312
|
+
// ── recovery(PITR)──
|
|
313
|
+
const recoveryCmd = dbCmd
|
|
314
|
+
.command("recovery")
|
|
315
|
+
.summary("基于时间点恢复(PITR)")
|
|
316
|
+
.description("把数据库整体恢复到指定时间点,diff 预览影响范围,apply 不可逆覆盖。")
|
|
317
|
+
.usage("<command> [flags]");
|
|
318
|
+
recoveryCmd.action(() => {
|
|
319
|
+
recoveryCmd.outputHelp();
|
|
320
|
+
});
|
|
321
|
+
recoveryCmd
|
|
322
|
+
.command("diff")
|
|
323
|
+
.summary("预览恢复到指定时间点的影响范围")
|
|
324
|
+
.usage("<timestamp> [flags]")
|
|
325
|
+
.argument("<timestamp>", "目标时间,YYYY-MM-DD / YYYY-MM-DD HH:MM[:SS] / ISO 8601")
|
|
326
|
+
.action(async function (target) {
|
|
327
|
+
await (0, index_1.handleDbRecoveryDiff)(target, this.optsWithGlobals());
|
|
328
|
+
});
|
|
329
|
+
recoveryCmd
|
|
330
|
+
.command("apply")
|
|
331
|
+
.summary("触发恢复到指定时间点(不可逆覆盖)")
|
|
332
|
+
.usage("<timestamp> [flags]")
|
|
333
|
+
.argument("<timestamp>", "目标时间,YYYY-MM-DD / YYYY-MM-DD HH:MM[:SS] / ISO 8601")
|
|
334
|
+
.option("--yes", "跳过 TTY 二次确认")
|
|
335
|
+
.action(async function (target) {
|
|
336
|
+
await (0, index_1.handleDbRecoveryApply)(target, this.optsWithGlobals());
|
|
337
|
+
});
|
|
338
|
+
// ── quota ──
|
|
339
|
+
dbCmd
|
|
340
|
+
.command("quota")
|
|
341
|
+
.summary("查看数据库用量与限额")
|
|
342
|
+
.usage("[flags]")
|
|
343
|
+
.action(async function () {
|
|
344
|
+
await (0, index_1.handleDbQuota)(this.optsWithGlobals());
|
|
345
|
+
});
|
|
209
346
|
}
|
|
@@ -209,4 +209,11 @@ Examples:
|
|
|
209
209
|
Error: Expires duration '60d' exceeds the maximum of 30d
|
|
210
210
|
hint: Maximum allowed value is 30d. Use \`--expires 30d\` for the longest link.
|
|
211
211
|
`);
|
|
212
|
+
fileCmd
|
|
213
|
+
.command("quota")
|
|
214
|
+
.summary("查看文件存储用量与限额")
|
|
215
|
+
.usage("[flags]")
|
|
216
|
+
.action(async function () {
|
|
217
|
+
await (0, index_1.handleFileQuota)(this.optsWithGlobals());
|
|
218
|
+
});
|
|
212
219
|
}
|
|
@@ -4,14 +4,8 @@ exports.registerCommands = registerCommands;
|
|
|
4
4
|
const index_1 = require("../../cli/commands/plugin/index");
|
|
5
5
|
const index_2 = require("../../cli/commands/file/index");
|
|
6
6
|
const index_3 = require("../../cli/commands/db/index");
|
|
7
|
-
const index_4 = require("../../cli/commands/observability/index");
|
|
8
|
-
const index_5 = require("../../cli/commands/app/index");
|
|
9
|
-
const index_6 = require("../../cli/commands/deploy/index");
|
|
10
7
|
function registerCommands(program) {
|
|
11
8
|
(0, index_1.registerPluginCommands)(program);
|
|
12
9
|
(0, index_2.registerFileCommands)(program);
|
|
13
10
|
(0, index_3.registerDbCommands)(program);
|
|
14
|
-
(0, index_4.registerObservabilityCommands)(program);
|
|
15
|
-
(0, index_5.registerAppCommands)(program);
|
|
16
|
-
(0, index_6.registerDeployCommands)(program);
|
|
17
11
|
}
|
|
@@ -1,21 +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.rejectCliOverride = rejectCliOverride;
|
|
10
7
|
const commander_1 = require("commander");
|
|
11
8
|
const error_1 = require("../../utils/error");
|
|
12
|
-
/** --app-id option,需要应用上下文的命令自行 .addOption(appIdOption()) */
|
|
13
|
-
function appIdOption() {
|
|
14
|
-
return new commander_1.Option("--app-id <id>", "指定目标应用").env("MIAODA_APP_ID");
|
|
15
|
-
}
|
|
16
|
-
function branchOption() {
|
|
17
|
-
return new commander_1.Option("--branch <branch>", "分支(优先级:--branch > 当前仓库 HEAD 分支;非 git 目录回退应用默认分支)").env("LOCAL_MOCK_MIAODA_DEPLOY_BRANCH");
|
|
18
|
-
}
|
|
19
9
|
/**
|
|
20
10
|
* soft-required: Commander 类型上 optional,runtime 校验必填。
|
|
21
11
|
*/
|
|
@@ -37,15 +27,11 @@ function resolveAppId(opts) {
|
|
|
37
27
|
}
|
|
38
28
|
return id;
|
|
39
29
|
}
|
|
40
|
-
/**
|
|
41
|
-
* 包裹 handler,缺 soft-required 参数 / 自定义校验失败时打 help 并退出。
|
|
42
|
-
*
|
|
43
|
-
* 兼容带位置参数的 action 签名(如 `(arg1: string, opts) => ...`)。
|
|
44
|
-
*/
|
|
30
|
+
/** 包裹 handler,缺 soft-required 参数时打 help 并退出 */
|
|
45
31
|
function withHelp(cmd, handler) {
|
|
46
|
-
return async (
|
|
32
|
+
return async (opts) => {
|
|
47
33
|
try {
|
|
48
|
-
await handler(
|
|
34
|
+
await handler(opts);
|
|
49
35
|
}
|
|
50
36
|
catch (err) {
|
|
51
37
|
if (err instanceof error_1.AppError && err.code === "ARGS_INVALID") {
|
|
@@ -62,23 +48,3 @@ function withHelp(cmd, handler) {
|
|
|
62
48
|
function failArgs(message) {
|
|
63
49
|
throw new error_1.AppError("ARGS_INVALID", message);
|
|
64
50
|
}
|
|
65
|
-
/**
|
|
66
|
-
* 拒绝 CLI 显式覆盖:用于 hideHelp() + .env() 的"沙箱注入参数"(如 --app-id / --branch)。
|
|
67
|
-
*
|
|
68
|
-
* Commander 的 getOptionValueSource() 区分来源(cli / env / default / config / undefined);
|
|
69
|
-
* 用户在 CLI 上显式传时 source === "cli",此时抛 ARGS_INVALID(exit 2 + help)。
|
|
70
|
-
*
|
|
71
|
-
* 用法:在 action 头部一行调用——
|
|
72
|
-
* cmd.action(withHelp(cmd, async (rawOpts) => {
|
|
73
|
-
* rejectCliOverride(cmd, "appId", "branch");
|
|
74
|
-
* ...
|
|
75
|
-
* }));
|
|
76
|
-
*/
|
|
77
|
-
function rejectCliOverride(cmd, ...optNames) {
|
|
78
|
-
for (const name of optNames) {
|
|
79
|
-
if (cmd.getOptionValueSource(name) === "cli") {
|
|
80
|
-
const flag = "--" + name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
81
|
-
failArgs(`${flag} 由沙箱/本地配置注入,不允许显式传递`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|