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.
Files changed (2) hide show
  1. package/README.md +22 -10
  2. 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 -g @vafast/cli
976
+ npm install -D @vafast/cli
977
977
 
978
978
  # 从服务端同步类型
979
- vafast sync --url http://api.example.com --out src/api.generated.ts
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
- export interface Api {
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 { eden } from '@vafast/api-client'
995
- import type { Api } from './api.generated'
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 api = eden<Api>('http://api.example.com')
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
  ## 📊 内置监控
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vafast",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "极简结构化Web框架,支持 Bun 和 Node.js。Go风格,函数优先。",
5
5
  "type": "module",
6
6
  "repository": {