@vafast/cli 0.1.5 → 0.1.6
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/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{sync-CS1-nDMt.js → sync-LIyNoB1P.js} +26 -4
- package/package.json +1 -2
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -113,9 +113,19 @@ function generateTypeDefinition(contract, stripPrefix) {
|
|
|
113
113
|
lines.push(" * ⚠️ 请勿手动修改此文件,使用 `vafast sync` 重新生成");
|
|
114
114
|
lines.push(" */");
|
|
115
115
|
lines.push("");
|
|
116
|
-
lines.push("import type { ApiResponse, RequestConfig, Client, EdenClient } from '@vafast/api-client'");
|
|
116
|
+
lines.push("import type { ApiResponse, RequestConfig, Client, EdenClient, SSESubscription, SSESubscribeOptions } from '@vafast/api-client'");
|
|
117
117
|
lines.push("import { eden } from '@vafast/api-client'");
|
|
118
118
|
lines.push("");
|
|
119
|
+
lines.push("/** SSE 回调接口 */");
|
|
120
|
+
lines.push("interface SSECallbacks<T> {");
|
|
121
|
+
lines.push(" onMessage: (data: T) => void");
|
|
122
|
+
lines.push(" onError?: (error: { code: number; message: string }) => void");
|
|
123
|
+
lines.push(" onOpen?: () => void");
|
|
124
|
+
lines.push(" onClose?: () => void");
|
|
125
|
+
lines.push(" onReconnect?: (attempt: number, maxAttempts: number) => void");
|
|
126
|
+
lines.push(" onMaxReconnects?: () => void");
|
|
127
|
+
lines.push("}");
|
|
128
|
+
lines.push("");
|
|
119
129
|
const routeTree = buildRouteTree(contract.routes, stripPrefix);
|
|
120
130
|
lines.push("/** API 契约类型 */");
|
|
121
131
|
lines.push("export type Api = {");
|
|
@@ -181,6 +191,16 @@ function generateClientType(tree, indent) {
|
|
|
181
191
|
*/
|
|
182
192
|
function generateMethodSignature(route, method) {
|
|
183
193
|
const params = [];
|
|
194
|
+
const returnType = route.schema?.response ? schemaToType(route.schema.response) : "any";
|
|
195
|
+
if (route.sse) {
|
|
196
|
+
if (route.schema?.query) {
|
|
197
|
+
const queryType = schemaToType(route.schema.query);
|
|
198
|
+
params.push(`query: ${queryType}`);
|
|
199
|
+
}
|
|
200
|
+
params.push(`callbacks: SSECallbacks<${returnType}>`);
|
|
201
|
+
params.push("options?: SSESubscribeOptions");
|
|
202
|
+
return `(${params.join(", ")}) => SSESubscription<${returnType}>`;
|
|
203
|
+
}
|
|
184
204
|
if (route.schema?.body) {
|
|
185
205
|
const bodyType = schemaToType(route.schema.body);
|
|
186
206
|
params.push(`body: ${bodyType}`);
|
|
@@ -190,7 +210,6 @@ function generateMethodSignature(route, method) {
|
|
|
190
210
|
params.push(`query?: ${queryType}`);
|
|
191
211
|
}
|
|
192
212
|
params.push("config?: RequestConfig");
|
|
193
|
-
const returnType = route.schema?.response ? schemaToType(route.schema.response) : "any";
|
|
194
213
|
return `(${params.join(", ")}) => Promise<ApiResponse<${returnType}>>`;
|
|
195
214
|
}
|
|
196
215
|
/**
|
|
@@ -215,7 +234,10 @@ function buildRouteTree(routes, stripPrefix) {
|
|
|
215
234
|
isDynamic
|
|
216
235
|
});
|
|
217
236
|
const node = current.get(key);
|
|
218
|
-
if (i === segments.length - 1)
|
|
237
|
+
if (i === segments.length - 1) {
|
|
238
|
+
const methodName = route.sse ? "sse" : route.method.toLowerCase();
|
|
239
|
+
node.methods.set(methodName, route);
|
|
240
|
+
}
|
|
219
241
|
current = node.children;
|
|
220
242
|
}
|
|
221
243
|
}
|
|
@@ -253,7 +275,7 @@ function generateMethodType(route) {
|
|
|
253
275
|
const queryType = schemaToType(route.schema.query);
|
|
254
276
|
parts.push(`query: ${queryType}`);
|
|
255
277
|
}
|
|
256
|
-
if (route.schema?.body) {
|
|
278
|
+
if (route.schema?.body && !route.sse) {
|
|
257
279
|
const bodyType = schemaToType(route.schema.body);
|
|
258
280
|
parts.push(`body: ${bodyType}`);
|
|
259
281
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vafast/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Vafast CLI - 类型同步和开发工具",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"@types/node": "^22.0.0",
|
|
40
40
|
"tsdown": "^0.2.0",
|
|
41
41
|
"typescript": "^5.4.5",
|
|
42
|
-
"vafast": "^0.5.1",
|
|
43
42
|
"vitest": "^2.0.0"
|
|
44
43
|
}
|
|
45
44
|
}
|