snan-cli 1.0.0 → 1.0.2
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 +74 -109
- package/bin/astro +1 -2
- package/package.json +14 -2
- package/src/index.js +9 -2
- package/src/modules/asset.js +15 -1
- package/src/modules/data.js +2 -2
- package/src/modules/metadata.js +5 -6
package/README.md
CHANGED
|
@@ -1,168 +1,133 @@
|
|
|
1
1
|
# Astro CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Astro 数据查询命令行工具。通过统一的 `astro <module> <action>` 命令调用 Astro OpenAPI。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
需要 Node.js 16 或更高版本。
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
npm install -g snan-cli
|
|
11
|
+
astro --version
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
npm 包名是 `snan-cli`,安装后的可执行命令是 `astro`。
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
## 配置
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
推荐使用交互式配置:
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
```bash
|
|
21
|
+
astro setup
|
|
22
|
+
```
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
也可以使用环境变量:
|
|
20
25
|
|
|
21
26
|
```bash
|
|
27
|
+
export ASTRO_BASE_URL=https://data.snanai.com
|
|
22
28
|
export ASTRO_TOKEN=your-bearer-token
|
|
23
|
-
export ASTRO_BASE_URL=http://127.0.0.1:8080
|
|
24
|
-
export ASTRO_PREFIX=/astro-server/mcp
|
|
25
29
|
export ASTRO_TIMEOUT=30000
|
|
26
30
|
```
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
PowerShell 不支持 `export`。在当前会话中设置环境变量请使用 `$env:NAME = "value"`(关闭终端后失效):
|
|
31
|
-
|
|
32
|
-
```powershell
|
|
33
|
-
$env:ASTRO_TOKEN = "your-bearer-token"
|
|
34
|
-
$env:ASTRO_BASE_URL = "http://127.0.0.1:8080"
|
|
35
|
-
$env:ASTRO_PREFIX = "/astro-server/mcp"
|
|
36
|
-
$env:ASTRO_TIMEOUT = "30000"
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
检查是否生效:`$env:ASTRO_TOKEN`
|
|
40
|
-
|
|
41
|
-
若要在 **用户级永久** 生效(新开 PowerShell 仍有效),可使用:
|
|
32
|
+
或写入 `~/.astrorc`:
|
|
42
33
|
|
|
43
|
-
```powershell
|
|
44
|
-
[System.Environment]::SetEnvironmentVariable('ASTRO_TOKEN', 'your-bearer-token', 'User')
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
(`ASTRO_BASE_URL` 等同理替换变量名与值。)
|
|
48
|
-
|
|
49
|
-
### 2. Configuration File (~/.astrorc)
|
|
50
34
|
```json
|
|
51
35
|
{
|
|
52
|
-
"baseUrl": "
|
|
53
|
-
"token": "your-bearer-token
|
|
54
|
-
"prefix": "/astro-server/mcp",
|
|
36
|
+
"baseUrl": "https://data.snanai.com",
|
|
37
|
+
"token": "your-bearer-token",
|
|
55
38
|
"timeout": 30000
|
|
56
39
|
}
|
|
57
40
|
```
|
|
58
41
|
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
ASTRO_TOKEN=your-bearer-token
|
|
62
|
-
ASTRO_BASE_URL=http://127.0.0.1:8080
|
|
63
|
-
ASTRO_PREFIX=/astro-server/mcp
|
|
64
|
-
ASTRO_TIMEOUT=30000
|
|
65
|
-
```
|
|
42
|
+
配置优先级为环境变量、`~/.astrorc`、默认配置。默认服务地址是 `https://data.snanai.com`。
|
|
66
43
|
|
|
67
|
-
##
|
|
44
|
+
## 命令
|
|
68
45
|
|
|
69
|
-
|
|
46
|
+
查看帮助:
|
|
70
47
|
|
|
71
48
|
```bash
|
|
72
|
-
# View available commands
|
|
73
49
|
astro --help
|
|
50
|
+
astro metadata --help
|
|
51
|
+
astro metadata tables --help
|
|
52
|
+
```
|
|
74
53
|
|
|
75
|
-
|
|
76
|
-
astro data --help
|
|
54
|
+
### 元数据
|
|
77
55
|
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
```bash
|
|
57
|
+
# 获取数据来源;结果包含 serviceName、dsCode、sourceType 和 dbType
|
|
58
|
+
astro metadata sources
|
|
80
59
|
|
|
81
|
-
#
|
|
82
|
-
astro
|
|
60
|
+
# serviceName 必须来自 metadata sources
|
|
61
|
+
astro metadata tables --serviceName=tenant-doris_prod --keyword="订单|order"
|
|
83
62
|
|
|
84
|
-
#
|
|
85
|
-
astro
|
|
63
|
+
# fqn 为 serviceName.database.schema.table
|
|
64
|
+
astro metadata tableDetail --fqn=tenant-doris_prod.default.prod_dwi.dwi_order
|
|
86
65
|
```
|
|
87
66
|
|
|
88
|
-
###
|
|
67
|
+
### 数据资产
|
|
89
68
|
|
|
90
|
-
|
|
69
|
+
```bash
|
|
70
|
+
# 查询 L3 业务模型;结果包含所属业务域、业务阶段及关联资产概要
|
|
71
|
+
astro asset businessModels --keyword="销售|订单"
|
|
91
72
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
- **Options**: `--body <json>` for request payload, `--raw` for compact output
|
|
73
|
+
# name 必须来自 businessModels 返回结果
|
|
74
|
+
astro asset businessModelDetail --name="销售订单处理"
|
|
95
75
|
|
|
96
|
-
|
|
76
|
+
astro asset dataModels --keyword="销售|订单"
|
|
77
|
+
astro asset dataModelDetail --nameEn=SalesOrder
|
|
78
|
+
astro asset indicators --keyword="GMV|成交额"
|
|
79
|
+
```
|
|
97
80
|
|
|
98
|
-
|
|
99
|
-
- Missing token configuration
|
|
100
|
-
- Invalid JSON in `--body`
|
|
101
|
-
- HTTP errors (with status code and response details)
|
|
102
|
-
- Network errors
|
|
81
|
+
### 数仓数据
|
|
103
82
|
|
|
104
|
-
|
|
83
|
+
```bash
|
|
84
|
+
astro data queryDw --body="{\"sql\":\"SELECT order_date, COUNT(*) AS order_count FROM prod_dwi.dwi_order GROUP BY order_date LIMIT 100\",\"env\":\"prod\"}"
|
|
85
|
+
```
|
|
105
86
|
|
|
106
|
-
|
|
87
|
+
请求体字段:
|
|
107
88
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
description: 'Query data with filters',
|
|
116
|
-
},
|
|
117
|
-
transform: {
|
|
118
|
-
description: 'Transform data format',
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
};
|
|
89
|
+
- `sql`:必填,只读 SQL。
|
|
90
|
+
- `env`:可选,支持 `dev` 或 `prod`,默认 `prod`。
|
|
91
|
+
|
|
92
|
+
### 源数据库数据
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
astro data queryOrigin --body="{\"dsCode\":\"erp_prod\",\"sql\":\"SELECT order_no, amount FROM sale_order LIMIT 50\"}"
|
|
122
96
|
```
|
|
123
97
|
|
|
124
|
-
|
|
98
|
+
`dsCode` 必须来自 `metadata sources`,并且对应 `sourceType=DATASOURCE` 的来源。
|
|
125
99
|
|
|
126
|
-
###
|
|
100
|
+
### 数据标准
|
|
127
101
|
|
|
128
102
|
```bash
|
|
129
|
-
astro standard
|
|
130
|
-
astro standard
|
|
103
|
+
astro standard dataStandard --body='{"nameCn":"客户编码"}'
|
|
104
|
+
astro standard nameRoot --body='{"nameCn":"客户"}'
|
|
131
105
|
```
|
|
132
106
|
|
|
133
|
-
|
|
107
|
+
具体请求字段以服务端 `DataStandardRequestDTO` 和 `StandardDictRequestDTO` 为准。
|
|
134
108
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
│ ├── config/
|
|
142
|
-
│ │ └── loader.js # Configuration reader
|
|
143
|
-
│ ├── http/
|
|
144
|
-
│ │ └── client.js # HTTP client with axios
|
|
145
|
-
│ ├── modules/
|
|
146
|
-
│ │ ├── index.js # Module auto-loader
|
|
147
|
-
│ │ └── data.js # Example data module
|
|
148
|
-
│ └── output/
|
|
149
|
-
│ └── formatter.js # Output formatting & error handling
|
|
150
|
-
├── .astrorc.example # Configuration template
|
|
151
|
-
└── package.json
|
|
109
|
+
## 输出
|
|
110
|
+
|
|
111
|
+
默认输出格式化 JSON。添加 `--raw` 输出紧凑 JSON:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
astro metadata sources --raw
|
|
152
115
|
```
|
|
153
116
|
|
|
154
|
-
##
|
|
117
|
+
## Shell 补全
|
|
155
118
|
|
|
156
|
-
|
|
119
|
+
```bash
|
|
120
|
+
astro --setup-completion
|
|
121
|
+
```
|
|
157
122
|
|
|
158
|
-
|
|
123
|
+
执行后重新打开终端,或重新加载对应的 shell 配置文件。
|
|
159
124
|
|
|
160
|
-
##
|
|
125
|
+
## 请求地址
|
|
161
126
|
|
|
162
|
-
|
|
163
|
-
- **commander**: CLI argument parsing
|
|
164
|
-
- **dotenv**: Environment variable loading
|
|
127
|
+
各模块请求当前版本的 Astro OpenAPI:
|
|
165
128
|
|
|
166
|
-
|
|
129
|
+
```text
|
|
130
|
+
{baseUrl}/astro-server/openapi/v1/{module}/{action}
|
|
131
|
+
```
|
|
167
132
|
|
|
168
|
-
|
|
133
|
+
所有请求使用 `Authorization: Bearer <token>` 认证。
|
package/bin/astro
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snan-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "CLI tool to expose backend HTTP interfaces as command-line commands",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"astro": "bin/astro"
|
|
8
8
|
},
|
|
9
9
|
"main": "src/index.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src",
|
|
13
|
+
".astrorc.example",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
10
16
|
"scripts": {
|
|
11
17
|
"start": "node bin/astro",
|
|
12
|
-
"test": "
|
|
18
|
+
"test": "node test/cli.test.js"
|
|
13
19
|
},
|
|
14
20
|
"keywords": [
|
|
15
21
|
"cli",
|
|
@@ -18,6 +24,12 @@
|
|
|
18
24
|
],
|
|
19
25
|
"author": "",
|
|
20
26
|
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=16"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"registry": "https://registry.npmjs.org/"
|
|
32
|
+
},
|
|
21
33
|
"dependencies": {
|
|
22
34
|
"axios": "^1.6.0",
|
|
23
35
|
"commander": "^11.0.0",
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const { createHttpClient } = require('./http/client');
|
|
|
5
5
|
const { loadModules } = require('./modules');
|
|
6
6
|
const { print, error: printError } = require('./output/formatter');
|
|
7
7
|
const { runSetup } = require('./commands/setup');
|
|
8
|
+
const { version } = require('../package.json');
|
|
8
9
|
|
|
9
10
|
function setupCompletion(modules) {
|
|
10
11
|
const completionTree = {};
|
|
@@ -42,7 +43,7 @@ async function main() {
|
|
|
42
43
|
program
|
|
43
44
|
.name('astro')
|
|
44
45
|
.description('CLI tool to expose backend HTTP interfaces')
|
|
45
|
-
.version(
|
|
46
|
+
.version(version);
|
|
46
47
|
|
|
47
48
|
program
|
|
48
49
|
.command('setup')
|
|
@@ -91,7 +92,13 @@ async function main() {
|
|
|
91
92
|
cmd.option(`--${p.name} <value>`, p.description);
|
|
92
93
|
});
|
|
93
94
|
} else {
|
|
94
|
-
|
|
95
|
+
const bodyParam = paramDefs.find(p => p.name === 'body');
|
|
96
|
+
const bodyDescription = bodyParam?.description || 'JSON body for the request';
|
|
97
|
+
if (bodyParam?.required) {
|
|
98
|
+
cmd.requiredOption('--body <json>', bodyDescription);
|
|
99
|
+
} else {
|
|
100
|
+
cmd.option('--body <json>', bodyDescription);
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
cmd.option('--raw', 'Output compact JSON');
|
package/src/modules/asset.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
name: 'asset',
|
|
3
|
-
description: '
|
|
3
|
+
description: '数据资产:业务模型、数据模型和指标查询',
|
|
4
4
|
urlPrefix: '/astro-server/openapi/v1/asset',
|
|
5
5
|
actions: {
|
|
6
|
+
businessModels: {
|
|
7
|
+
description: '获取 L3 业务模型列表(含所属业务域、业务阶段及关联资产概要)',
|
|
8
|
+
method: 'GET',
|
|
9
|
+
params: [
|
|
10
|
+
{ name: 'keyword', description: '查询关键字,多个关键字用空格或|分隔,为空查询全部', required: false },
|
|
11
|
+
],
|
|
12
|
+
},
|
|
13
|
+
businessModelDetail: {
|
|
14
|
+
description: '根据业务模型名称获取详情(含业务定义、层级及关联资产)',
|
|
15
|
+
method: 'GET',
|
|
16
|
+
params: [
|
|
17
|
+
{ name: 'name', description: '业务模型名称(唯一标识),必须来自 businessModels 返回结果', required: true },
|
|
18
|
+
],
|
|
19
|
+
},
|
|
6
20
|
dataModels: {
|
|
7
21
|
description: '获取数据资产模型列表(含可用表信息)',
|
|
8
22
|
method: 'GET',
|
package/src/modules/data.js
CHANGED
|
@@ -12,11 +12,11 @@ module.exports = {
|
|
|
12
12
|
],
|
|
13
13
|
},
|
|
14
14
|
queryDw: {
|
|
15
|
-
description: '
|
|
15
|
+
description: '查询治理好的数仓资产数据(env 支持 dev/prod,不传默认为 prod)',
|
|
16
16
|
method: 'POST',
|
|
17
17
|
path: '/queryDw',
|
|
18
18
|
params: [
|
|
19
|
-
{ name: 'body', description: 'JSON body: { "sql": "SQL查询语句", "
|
|
19
|
+
{ name: 'body', description: 'JSON body: { "sql": "SQL查询语句", "env": "dev或prod(可选,默认prod)" }', required: true },
|
|
20
20
|
],
|
|
21
21
|
},
|
|
22
22
|
},
|
package/src/modules/metadata.js
CHANGED
|
@@ -4,24 +4,23 @@ module.exports = {
|
|
|
4
4
|
urlPrefix: '/astro-server/openapi/v1/metadata',
|
|
5
5
|
actions: {
|
|
6
6
|
sources: {
|
|
7
|
-
description: '
|
|
7
|
+
description: '获取当前租户下所有元数据来源列表(查表前先获取 serviceName,查源数据时使用 dsCode)',
|
|
8
8
|
method: 'GET',
|
|
9
9
|
params: [],
|
|
10
10
|
},
|
|
11
11
|
tables: {
|
|
12
|
-
description: '
|
|
12
|
+
description: '根据元数据来源 serviceName 和关键字查询表列表(最多 200 条)',
|
|
13
13
|
method: 'GET',
|
|
14
14
|
params: [
|
|
15
|
-
{ name: '
|
|
15
|
+
{ name: 'serviceName', description: '元数据来源唯一标识,通过 metadata sources 获取', required: true },
|
|
16
16
|
{ name: 'keyword', description: '查询关键字,匹配表名或描述,多关键字用空格或|分隔,为空返回全部', required: false },
|
|
17
17
|
],
|
|
18
18
|
},
|
|
19
19
|
tableDetail: {
|
|
20
|
-
description: '获取表详情,包含字段列表和字段类型',
|
|
20
|
+
description: '根据四段式 FQN 获取表详情,包含字段列表和字段类型',
|
|
21
21
|
method: 'GET',
|
|
22
22
|
params: [
|
|
23
|
-
{ name: '
|
|
24
|
-
{ name: 'schemaTable', description: '表引用,schema.tablename 形式,如 ods.ods_order', required: true },
|
|
23
|
+
{ name: 'fqn', description: '完全限定名,格式 serviceName.database.schema.table,通过 metadata tables 结果构造', required: true },
|
|
25
24
|
],
|
|
26
25
|
},
|
|
27
26
|
},
|