@vafast/cli 0.1.6 → 0.1.8
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-LIyNoB1P.js → sync-CroyE4Do.js} +15 -11
- package/package.json +1 -1
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -105,6 +105,7 @@ async function syncTypes(options) {
|
|
|
105
105
|
*/
|
|
106
106
|
function generateTypeDefinition(contract, stripPrefix) {
|
|
107
107
|
const lines = [];
|
|
108
|
+
const hasSSE = contract.routes.some((route) => route.sse);
|
|
108
109
|
lines.push("/**");
|
|
109
110
|
lines.push(" * 自动生成的 API 类型定义");
|
|
110
111
|
lines.push(` * 生成时间: ${contract.generatedAt}`);
|
|
@@ -113,19 +114,22 @@ function generateTypeDefinition(contract, stripPrefix) {
|
|
|
113
114
|
lines.push(" * ⚠️ 请勿手动修改此文件,使用 `vafast sync` 重新生成");
|
|
114
115
|
lines.push(" */");
|
|
115
116
|
lines.push("");
|
|
116
|
-
lines.push("import type { ApiResponse, RequestConfig, Client, EdenClient, SSESubscription, SSESubscribeOptions } from '@vafast/api-client'");
|
|
117
|
+
if (hasSSE) lines.push("import type { ApiResponse, RequestConfig, Client, EdenClient, SSESubscription, SSESubscribeOptions } from '@vafast/api-client'");
|
|
118
|
+
else lines.push("import type { ApiResponse, RequestConfig, Client, EdenClient } from '@vafast/api-client'");
|
|
117
119
|
lines.push("import { eden } from '@vafast/api-client'");
|
|
118
120
|
lines.push("");
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
121
|
+
if (hasSSE) {
|
|
122
|
+
lines.push("/** SSE 回调接口 */");
|
|
123
|
+
lines.push("interface SSECallbacks<T> {");
|
|
124
|
+
lines.push(" onMessage: (data: T) => void");
|
|
125
|
+
lines.push(" onError?: (error: { code: number; message: string }) => void");
|
|
126
|
+
lines.push(" onOpen?: () => void");
|
|
127
|
+
lines.push(" onClose?: () => void");
|
|
128
|
+
lines.push(" onReconnect?: (attempt: number, maxAttempts: number) => void");
|
|
129
|
+
lines.push(" onMaxReconnects?: () => void");
|
|
130
|
+
lines.push("}");
|
|
131
|
+
lines.push("");
|
|
132
|
+
}
|
|
129
133
|
const routeTree = buildRouteTree(contract.routes, stripPrefix);
|
|
130
134
|
lines.push("/** API 契约类型 */");
|
|
131
135
|
lines.push("export type Api = {");
|