node-cnb 1.2.8 → 1.2.10
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/LICENSE +20 -0
- package/README.md +5 -0
- package/package.json +1 -1
- package/.cnb.yml +0 -31
- package/.ide/Dockerfile +0 -20
- package/CHANGELOG.md +0 -68
- package/build.js +0 -156
- package/cache.dockerfile +0 -14
- package/openapi_swagger.json +0 -17663
- package/src/client.d.ts +0 -970
- package/src/index.d.ts +0 -3
- package/src/index.ts +0 -94
- package/src/paths.json +0 -8826
- package/src/types.d.ts +0 -3642
- package/types.d.ts +0 -3678
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present, cnb.cool
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the “Software”),
|
|
7
|
+
to deal in the Software without restriction, including without limitation
|
|
8
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom
|
|
10
|
+
the Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
19
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/package.json
CHANGED
package/.cnb.yml
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
.install: &install
|
|
2
|
-
- name: build cache image
|
|
3
|
-
type: docker:cache
|
|
4
|
-
options:
|
|
5
|
-
dockerfile: cache.dockerfile
|
|
6
|
-
by:
|
|
7
|
-
- package.json
|
|
8
|
-
- package-lock.json
|
|
9
|
-
exports:
|
|
10
|
-
name: DOCKER_CACHE_IMAGE_NAME
|
|
11
|
-
- name: copy node_modules
|
|
12
|
-
image: $DOCKER_CACHE_IMAGE_NAME
|
|
13
|
-
commands:
|
|
14
|
-
- cp -r "$NODE_PATH" ./node_modules
|
|
15
|
-
- name: build
|
|
16
|
-
image: $DOCKER_CACHE_IMAGE_NAME
|
|
17
|
-
script: npm run build
|
|
18
|
-
$:
|
|
19
|
-
tag_push:
|
|
20
|
-
- stages:
|
|
21
|
-
- *install
|
|
22
|
-
- name: npm publish
|
|
23
|
-
image: tencentcom/npm
|
|
24
|
-
imports: https://cnb.cool/folger/folger-secret/-/blob/main/npm_secret.yml
|
|
25
|
-
settings:
|
|
26
|
-
username: $NPM_USER
|
|
27
|
-
token: $NPM_TOKEN
|
|
28
|
-
email: $NPM_EMAIL
|
|
29
|
-
folder: ./
|
|
30
|
-
fail_on_version_conflict: true
|
|
31
|
-
|
package/.ide/Dockerfile
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# .ide/Dockerfile
|
|
2
|
-
FROM node:20
|
|
3
|
-
|
|
4
|
-
# 以及按需安装其他软件
|
|
5
|
-
RUN apt-get update && apt-get install -y git
|
|
6
|
-
|
|
7
|
-
# 安装 code-server 和 vscode 常用插件
|
|
8
|
-
RUN curl -fsSL https://code-server.dev/install.sh | sh \
|
|
9
|
-
&& code-server --install-extension redhat.vscode-yaml \
|
|
10
|
-
&& code-server --install-extension dbaeumer.vscode-eslint \
|
|
11
|
-
&& code-server --install-extension eamodio.gitlens \
|
|
12
|
-
&& code-server --install-extension tencent-cloud.coding-copilot \
|
|
13
|
-
&& echo done
|
|
14
|
-
|
|
15
|
-
# 安装 ssh 服务,用于支持 VSCode 客户端通过 Remote-SSH 访问开发环境
|
|
16
|
-
RUN apt-get update && apt-get install -y wget unzip openssh-server
|
|
17
|
-
|
|
18
|
-
# 指定字符集支持命令行输入中文(根据需要选择字符集)
|
|
19
|
-
ENV LANG C.UTF-8
|
|
20
|
-
ENV LANGUAGE C.UTF-8
|
package/CHANGELOG.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [1.2.8](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.7...v1.2.8) (2025-02-12)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* 更正ci配置 ([e4ee23d](https://cnb.cool/cnb/sdk/node-cnb/commit/e4ee23d2eb5459cda2582974d921943d17fcbcef))
|
|
11
|
-
|
|
12
|
-
### [1.2.7](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.6...v1.2.7) (2025-02-12)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### Bug Fixes
|
|
16
|
-
|
|
17
|
-
* npm publish换用token ([debb51a](https://cnb.cool/cnb/sdk/node-cnb/commit/debb51ae93b6e8d1384e4f4519c745aac0507847))
|
|
18
|
-
|
|
19
|
-
### [1.2.6](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.5...v1.2.6) (2025-02-12)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
* 更换npm插件修复npm发布报错 ([82ebce5](https://cnb.cool/cnb/sdk/node-cnb/commit/82ebce59059d40c3f941954c0437fc071362d7bb))
|
|
25
|
-
|
|
26
|
-
### [1.2.5](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.4...v1.2.5) (2025-02-12)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### Bug Fixes
|
|
30
|
-
|
|
31
|
-
* 修复构建报错 ([240069a](https://cnb.cool/cnb/sdk/node-cnb/commit/240069afb3eb18e49d231f80470e813fdc856dbc))
|
|
32
|
-
|
|
33
|
-
### [1.2.4](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.3...v1.2.4) (2025-02-12)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Bug Fixes
|
|
37
|
-
|
|
38
|
-
* 更正流水线报错 ([80500ac](https://cnb.cool/cnb/sdk/node-cnb/commit/80500acf043a91366209bd0261df20ba60a28765))
|
|
39
|
-
|
|
40
|
-
### [1.2.3](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.2...v1.2.3) (2025-02-12)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Bug Fixes
|
|
44
|
-
|
|
45
|
-
* 修复流水线报错 ([26f01b2](https://cnb.cool/cnb/sdk/node-cnb/commit/26f01b2e33a1a9cad2e54406aed28e4859546c8f))
|
|
46
|
-
|
|
47
|
-
### [1.2.2](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.1...v1.2.2) (2025-02-12)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
### Bug Fixes
|
|
51
|
-
|
|
52
|
-
* 更正缓存镜像的node版本 ([5384a07](https://cnb.cool/cnb/sdk/node-cnb/commit/5384a070c4c1552566bec5c2d0433c750a4bcc4b))
|
|
53
|
-
|
|
54
|
-
### [1.2.1](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.0...v1.2.1) (2025-02-12)
|
|
55
|
-
|
|
56
|
-
## 1.2.0 (2025-02-12)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
### Features
|
|
60
|
-
|
|
61
|
-
* 编写文档以及修复post参数不生效问题 ([d65cc4f](https://cnb.cool/cnb/sdk/node-cnb/commit/d65cc4f51e1068c9e6b190df3328a1021342bf63))
|
|
62
|
-
* 初步完成代码编译 ([be40568](https://cnb.cool/cnb/sdk/node-cnb/commit/be40568efb7a2debefeef0e036acd7fc05082797))
|
|
63
|
-
* 初始提交 ([f3e6333](https://cnb.cool/cnb/sdk/node-cnb/commit/f3e6333e488417bb66dfa342ff57ca727e5f12f1))
|
|
64
|
-
* 生成类型声明和ts代码初稿 ([1ff64fd](https://cnb.cool/cnb/sdk/node-cnb/commit/1ff64fd4efc9971bcece7a42c8f021f405e57671))
|
|
65
|
-
|
|
66
|
-
# Changelog
|
|
67
|
-
|
|
68
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
package/build.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const cp = require('child_process');
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const apiSwagger = require('./openapi_swagger.json');
|
|
5
|
-
const { definitions } = apiSwagger;
|
|
6
|
-
const pathMethodNameMap = require('./pathMethodMap.json');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 实现原理
|
|
10
|
-
*
|
|
11
|
-
* cnb 会编译出 open api 的 [swagger json](https://api.cnb.cool/swagger.json),并生成 api 页面。
|
|
12
|
-
*
|
|
13
|
-
* 本仓库依据 swagger json 编译生成对应的 typescript 代码。
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const pathMethodsMap = {}
|
|
17
|
-
|
|
18
|
-
const buildPathMethods = () => {
|
|
19
|
-
Object.keys(apiSwagger.paths).forEach(path => {
|
|
20
|
-
const pathValue = apiSwagger.paths[path];
|
|
21
|
-
Object.keys(pathValue).forEach(method => {
|
|
22
|
-
const methodValue = pathValue[method];
|
|
23
|
-
methodValue.path = path;
|
|
24
|
-
methodValue.method = method;
|
|
25
|
-
|
|
26
|
-
const pathMethod = method === 'get' && methodValue.responses['200']?.schema?.type === 'array' ? 'list' : method;
|
|
27
|
-
const methodPath = pathMethodNameMap[path] ? pathMethodNameMap[path] : [...path.replace(/\/\{([^\}]+)\}\/-\//g, '/$1/').replace(/\/\{[^\}]+\}/g, '/').split('/').map(item => _.camelCase(item)).filter(Boolean), pathMethod].join('.');
|
|
28
|
-
const methodValues = pathMethodsMap[methodPath] || []
|
|
29
|
-
methodValues.push(methodValue)
|
|
30
|
-
pathMethodsMap[methodPath] = methodValues;
|
|
31
|
-
if (methodValues.length > 1) {
|
|
32
|
-
console.log('重复的path', methodPath, methodValues.map(item => item.path))
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
fs.writeFileSync('./src/paths.json', JSON.stringify(pathMethodsMap, null, 2));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const convertTypeName = (type) => {
|
|
41
|
-
let typeName = _.camelCase(type.split('.').join('-'));
|
|
42
|
-
typeName = typeName.charAt(0).toUpperCase() + typeName.slice(1);
|
|
43
|
-
return typeName;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const typeMap = {
|
|
47
|
-
'integer': 'number',
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function convertSchemaToType(schema) {
|
|
51
|
-
if (schema.type === 'object') {
|
|
52
|
-
let properties = '';
|
|
53
|
-
if (!schema.properties) {
|
|
54
|
-
return 'any'
|
|
55
|
-
}
|
|
56
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
57
|
-
const typeName = key.includes('-') ? `'${key}'` : key;
|
|
58
|
-
if (typeName !== key) {
|
|
59
|
-
console.log('typeName', key, typeName)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (value.description) {
|
|
63
|
-
properties += `\n /**${value.description}*/\n`
|
|
64
|
-
}
|
|
65
|
-
properties += ` ${typeName}: ${convertSchemaToType(value)};\n`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return `{\n${properties}}`;
|
|
69
|
-
} else if (schema.type === 'array') {
|
|
70
|
-
return `${convertSchemaToType(schema.items)}[]`;
|
|
71
|
-
} else if (schema['$ref']) {
|
|
72
|
-
return convertTypeName(schema['$ref'].replace('#/definitions/', ''))
|
|
73
|
-
} else {
|
|
74
|
-
return typeMap[schema.type] || schema.type || 'any';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const buildDefinitions = () => {
|
|
79
|
-
function convertDefinitionsToTypes(definitions) {
|
|
80
|
-
let types = '';
|
|
81
|
-
|
|
82
|
-
for (const [key, value] of Object.entries(definitions)) {
|
|
83
|
-
|
|
84
|
-
const convetValue = convertSchemaToType(value);
|
|
85
|
-
if (!convetValue) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
types += `export type ${convertTypeName(key)} = ${convetValue};\n\n`;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return types;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 提取 definitions 并转换为类型声明
|
|
95
|
-
const types = convertDefinitionsToTypes(definitions);
|
|
96
|
-
|
|
97
|
-
// 将类型声明写入 TypeScript 文件
|
|
98
|
-
fs.writeFileSync('./src/types.d.ts', types, 'utf8');
|
|
99
|
-
}
|
|
100
|
-
const importTypes = [];
|
|
101
|
-
const buildClientInterface = () => {
|
|
102
|
-
const pathTree = {};
|
|
103
|
-
Object.keys(pathMethodsMap).forEach(methodPath => {
|
|
104
|
-
let currentSub = pathTree;
|
|
105
|
-
const methodList = methodPath.split('.');
|
|
106
|
-
methodList.forEach((method) => {
|
|
107
|
-
currentSub[method] = currentSub[method] || {};
|
|
108
|
-
currentSub = currentSub[method];
|
|
109
|
-
})
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const getMethodContent = (tree, path) => {
|
|
113
|
-
let content = '';
|
|
114
|
-
Object.keys(tree).forEach(method => {
|
|
115
|
-
content += `
|
|
116
|
-
${_.camelCase(method)}: ${getMethodContent(tree[method], [path, method].filter(Boolean).join('.'))}
|
|
117
|
-
`;
|
|
118
|
-
})
|
|
119
|
-
if (!content) {
|
|
120
|
-
const methodValue = pathMethodsMap[path]?.[0] || {};
|
|
121
|
-
const resultType = convertSchemaToType(methodValue.responses?.['200']?.schema || {});
|
|
122
|
-
importTypes.push(resultType.replace('[]', ''))
|
|
123
|
-
|
|
124
|
-
content = `(params: {${(methodValue.parameters || []).map(param => {
|
|
125
|
-
|
|
126
|
-
return param.name + (param.required ? '' : '?') + ': ' + convertSchemaToType(param)
|
|
127
|
-
})}}) => Promise<${resultType}>`
|
|
128
|
-
} else {
|
|
129
|
-
content = `{
|
|
130
|
-
${content}
|
|
131
|
-
}`
|
|
132
|
-
}
|
|
133
|
-
return content;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
let interfaceContent = `
|
|
137
|
-
export interface Client ${getMethodContent(pathTree, '')}
|
|
138
|
-
`;
|
|
139
|
-
const distinctImportTypes = _.uniq(importTypes.filter(item => !/^[a-z]+$/.test(item))).join(', ');
|
|
140
|
-
interfaceContent = `import {${distinctImportTypes}} from './types';
|
|
141
|
-
${interfaceContent}`
|
|
142
|
-
fs.writeFileSync('./src/client.d.ts', interfaceContent, 'utf8');
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const prettier = () => {
|
|
147
|
-
cp.execSync('npx prettier --write ./src/*.ts');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
buildPathMethods();
|
|
151
|
-
|
|
152
|
-
buildDefinitions();
|
|
153
|
-
|
|
154
|
-
buildClientInterface();
|
|
155
|
-
|
|
156
|
-
prettier();
|