支持生成、发布 Typescript SDK
This commit is contained in:
21
templates/ts-package.json.tpl
Normal file
21
templates/ts-package.json.tpl
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "{{TS_PACKAGE_NAME}}",
|
||||
"version": "{{VERSION}}",
|
||||
"description": "自动生成的TypeScript SDK,用于与shenxianhe服务进行交互",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "{{TS_SDK_REPO}}"
|
||||
},
|
||||
"keywords": [
|
||||
"protobuf",
|
||||
"typescript",
|
||||
"sdk",
|
||||
"shenxianhe"
|
||||
],
|
||||
"author": "神仙盒团队",
|
||||
"license": "ISC",
|
||||
"type": "commonjs",
|
||||
"dependencies": {
|
||||
"@bufbuild/protobuf": "^2.7.0"
|
||||
}
|
||||
}
|
||||
56
templates/ts-sdk-readme.md
Normal file
56
templates/ts-sdk-readme.md
Normal file
@@ -0,0 +1,56 @@
|
||||
## 项目简介
|
||||
|
||||
这是由 protobuf 自动生成的 TypeScript SDK,用于与 shenxianhe 服务进行交互。
|
||||
|
||||
## SDK 版本与 API 版本的区别
|
||||
|
||||
**SDK 版本**:
|
||||
|
||||
- 由 Git tag 管理,格式为 vX.Y.Z
|
||||
- 表示生成的 SDK 代码的版本号
|
||||
- 每次重新生成并发布代码时会自增
|
||||
|
||||
**API 版本**:
|
||||
|
||||
- 体现在 proto 文件路径中,如 v1、v2 等
|
||||
- 表示服务接口的版本号
|
||||
- 由服务端定义和维护
|
||||
|
||||
两个版本号是相互独立的概念,同一 API 版本可能对应多个 SDK 版本。
|
||||
|
||||
## 使用示例
|
||||
|
||||
```typescript
|
||||
import { createClient } from "@connectrpc/connect";
|
||||
import { createConnectTransport } from "@connectrpc/connect-web";
|
||||
import { AccountService, AuthenticationType } from "@shenxianhe/sdk/account/v1/account_pb";
|
||||
|
||||
const transport = createConnectTransport({
|
||||
baseUrl: "https://your-service-url",
|
||||
});
|
||||
const client = createClient(AccountService, transport);
|
||||
|
||||
const res = await client.auth({
|
||||
authType: AuthenticationType.PHONE,
|
||||
authId: '13800138000',
|
||||
credential: '123456',
|
||||
});
|
||||
console.log(res.sentence);
|
||||
```
|
||||
|
||||
### 注意事项
|
||||
|
||||
- 本版本 SDK 仅包含 protobuf 类型定义,不包含服务客户端实现
|
||||
- 如需服务客户端功能,您需要:
|
||||
1. 安装@bufbuild/connect-es 和@bufbuild/connect-web 库
|
||||
2. 使用 protoc-gen-connect-es 插件重新生成代码
|
||||
3. 参考 Buf 官方文档实现客户端
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 本 SDK 由代码自动生成,请勿手动修改
|
||||
- 如有任何问题,请联系服务提供方
|
||||
|
||||
## 版权信息
|
||||
|
||||
© 2025 神仙盒团队. All rights reserved.
|
||||
Reference in New Issue
Block a user