@cvtoolman/huawei-lts-cli 1.0.3 → 2.0.0

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.
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cursorDirection = cursorDirection;
4
+ exports.nextCursor = nextCursor;
5
+ exports.fetchAllPages = fetchAllPages;
6
+ /** 倒序(新到旧)→ 往更早读;正序 → 往更晚读。 */
7
+ function cursorDirection(reverse) {
8
+ return reverse ? 'backwards' : 'forwards';
9
+ }
10
+ /** 游标取本页最后一条的 line_num;拿不到就返回 undefined(调用方据此停止)。 */
11
+ function nextCursor(logs) {
12
+ if (logs.length === 0)
13
+ return undefined;
14
+ const last = logs[logs.length - 1].lineNum;
15
+ return last ? last : undefined;
16
+ }
17
+ async function fetchAllPages(fetchPage, params, options = {}) {
18
+ const max = options.max ?? 10000;
19
+ const pageSize = options.pageSize ?? params.limit ?? 100;
20
+ const direction = cursorDirection(params.reverse);
21
+ const collected = [];
22
+ let cursor;
23
+ let isQueryComplete;
24
+ let truncated = false;
25
+ while (collected.length < max) {
26
+ const page = await fetchPage({
27
+ ...params,
28
+ limit: pageSize,
29
+ lineNum: cursor,
30
+ searchType: cursor ? direction : undefined,
31
+ });
32
+ if (page.isQueryComplete === false) {
33
+ isQueryComplete = false;
34
+ }
35
+ else if (isQueryComplete === undefined && page.isQueryComplete === true) {
36
+ isQueryComplete = true;
37
+ }
38
+ if (page.logs.length === 0)
39
+ break;
40
+ const next = nextCursor(page.logs);
41
+ // 服务端把同一段原样又给了一遍:整页丢弃并停止。
42
+ // 先判游标再入账,否则重放的一页会被当成新数据拼进结果。
43
+ if (cursor !== undefined && next === cursor)
44
+ break;
45
+ collected.push(...page.logs);
46
+ // 不满一页 = 没有更多了;拿不到游标则无法继续翻页
47
+ if (page.logs.length < pageSize || !next)
48
+ break;
49
+ cursor = next;
50
+ if (collected.length >= max) {
51
+ truncated = true;
52
+ }
53
+ }
54
+ const logs = collected.slice(0, max);
55
+ return { logs, total: logs.length, isQueryComplete, truncated };
56
+ }
@@ -27,7 +27,7 @@ function formatPretty(data) {
27
27
  lines.push(chalk_1.default.bold.green(`Found ${data.total} logs:`));
28
28
  lines.push('');
29
29
  for (const log of data.logs) {
30
- lines.push(chalk_1.default.cyan(`[${log.logTime}]`));
30
+ lines.push(chalk_1.default.cyan(`[${log.lineNum}]`));
31
31
  lines.push(chalk_1.default.white(log.content));
32
32
  if (Object.keys(log.labels).length > 0) {
33
33
  const labels = Object.entries(log.labels)
@@ -10,7 +10,7 @@ function formatTable(data) {
10
10
  return 'No logs found.';
11
11
  }
12
12
  const table = new cli_table3_1.default({
13
- head: ['Time', 'Content', 'Labels'],
13
+ head: ['Line', 'Content', 'Labels'],
14
14
  colWidths: [25, 50, 30],
15
15
  wordWrap: true,
16
16
  });
@@ -18,7 +18,7 @@ function formatTable(data) {
18
18
  const labelsStr = Object.entries(log.labels)
19
19
  .map(([k, v]) => `${k}=${v}`)
20
20
  .join(', ');
21
- table.push([log.logTime, log.content, labelsStr]);
21
+ table.push([log.lineNum, log.content, labelsStr]);
22
22
  }
23
23
  return table.toString();
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cvtoolman/huawei-lts-cli",
3
- "version": "1.0.3",
3
+ "version": "2.0.0",
4
4
  "description": "Command-line tool for querying Huawei Cloud Log Tank Service (LTS) logs",
5
5
  "main": "dist/cli/index.js",
6
6
  "bin": {
@@ -13,6 +13,8 @@
13
13
  "build": "tsc",
14
14
  "dev": "tsx src/cli/index.ts",
15
15
  "start": "node dist/cli/index.js",
16
+ "test": "node --import tsx --test \"test/**/*.test.ts\"",
17
+ "typecheck": "tsc --noEmit",
16
18
  "clean": "node -e \"require('fs').rmSync('dist', {recursive: true, force: true})\"",
17
19
  "prepublishOnly": "npm run clean && npm run build"
18
20
  },
@@ -37,19 +39,19 @@
37
39
  },
38
40
  "homepage": "https://github.com/jcxy/huawei-lts-cli#readme",
39
41
  "engines": {
40
- "node": ">=16.0.0"
42
+ "node": ">=18.0.0"
41
43
  },
42
44
  "dependencies": {
43
- "@huaweicloud/huaweicloud-sdk-core": "latest",
44
- "@huaweicloud/huaweicloud-sdk-lts": "latest",
45
+ "@huaweicloud/huaweicloud-sdk-core": "^3.1.200",
46
+ "@huaweicloud/huaweicloud-sdk-lts": "^3.1.200",
45
47
  "chalk": "^4.1.2",
46
- "cli-table3": "latest",
47
- "commander": "latest",
48
+ "cli-table3": "^0.6.5",
49
+ "commander": "^15.0.0",
48
50
  "uuid": "^9.0.0"
49
51
  },
50
52
  "devDependencies": {
51
- "@types/node": "latest",
52
- "tsx": "latest",
53
- "typescript": "latest"
53
+ "@types/node": "^26.0.0",
54
+ "tsx": "^4.22.4",
55
+ "typescript": "^6.0.3"
54
56
  }
55
57
  }