vafast 0.5.9 → 0.5.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/README.md +22 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -973,29 +973,41 @@ const response = await openai.chat.completions.create({
|
|
|
973
973
|
|
|
974
974
|
```bash
|
|
975
975
|
# 安装 CLI
|
|
976
|
-
npm install -
|
|
976
|
+
npm install -D @vafast/cli
|
|
977
977
|
|
|
978
978
|
# 从服务端同步类型
|
|
979
|
-
vafast sync --url http://
|
|
979
|
+
npx vafast sync --url http://localhost:9002 \
|
|
980
|
+
--endpoint /restfulApi/api-spec \
|
|
981
|
+
--out src/types/api/ones.generated.ts \
|
|
982
|
+
--strip-prefix /restfulApi
|
|
980
983
|
```
|
|
981
984
|
|
|
982
985
|
**生成的类型文件:**
|
|
983
986
|
|
|
984
987
|
```typescript
|
|
985
|
-
// src/api.generated.ts
|
|
986
|
-
|
|
988
|
+
// src/types/api/ones.generated.ts
|
|
989
|
+
import type { Client, EdenClient } from '@vafast/api-client'
|
|
990
|
+
import { eden } from '@vafast/api-client'
|
|
991
|
+
|
|
992
|
+
export type Api = {
|
|
987
993
|
users: {
|
|
988
|
-
get: { query: { page?: number } }
|
|
989
|
-
post: { body: { name: string; email: string } }
|
|
994
|
+
get: { query: { page?: number }; return: any }
|
|
995
|
+
post: { body: { name: string; email: string }; return: any }
|
|
990
996
|
}
|
|
991
997
|
}
|
|
992
998
|
|
|
999
|
+
export function createApiClient(client: Client): EdenClient<Api> {
|
|
1000
|
+
return eden<Api>(client)
|
|
1001
|
+
}
|
|
1002
|
+
|
|
993
1003
|
// 使用
|
|
994
|
-
import {
|
|
995
|
-
import
|
|
1004
|
+
import { createClient } from '@vafast/api-client'
|
|
1005
|
+
import { createApiClient } from './types/api/ones.generated'
|
|
1006
|
+
|
|
1007
|
+
const client = createClient({ baseURL: '/restfulApi', timeout: 30000 })
|
|
1008
|
+
const api = createApiClient(client)
|
|
996
1009
|
|
|
997
|
-
const
|
|
998
|
-
const { data } = await api.users.get({ query: { page: 1 } })
|
|
1010
|
+
const { data, error } = await api.users.get({ page: 1 })
|
|
999
1011
|
```
|
|
1000
1012
|
|
|
1001
1013
|
## 📊 内置监控
|