@longzai-intelligence-transport/http-core 0.1.2 → 0.1.4
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/index.d.ts +205 -122
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -620,7 +620,10 @@ type InferRouteBody<T extends RouteDefinition> = T extends JsonResponseRoute<Htt
|
|
|
620
620
|
/**
|
|
621
621
|
* 从路由定义中推断响应数据类型
|
|
622
622
|
*
|
|
623
|
-
* 自动解包 ApiResponse 和 PaginatedResponse
|
|
623
|
+
* 自动解包 ApiResponse 和 PaginatedResponse。
|
|
624
|
+
* 对联合别名形态鲁棒:当 T 为 tsgo/tsc 类型规范化产物(RouteDefinition 联合别名)时,
|
|
625
|
+
* JSON 路由不联合 BinaryStreamMarker,stream 路由保留 BinaryStreamMarker(不退化为 unknown)。
|
|
626
|
+
* 实现详见 ADR-0005。
|
|
624
627
|
*
|
|
625
628
|
* @example
|
|
626
629
|
* type Data = InferRouteResponse<typeof routes.detail>;
|
|
@@ -628,15 +631,13 @@ type InferRouteBody<T extends RouteDefinition> = T extends JsonResponseRoute<Htt
|
|
|
628
631
|
*
|
|
629
632
|
* @typeParam T - 路由定义类型
|
|
630
633
|
*/
|
|
631
|
-
type InferRouteResponse<T extends RouteDefinition> = T extends
|
|
632
|
-
responseType: 'stream';
|
|
633
|
-
} ? BinaryStreamMarker : T extends {
|
|
634
|
-
response: infer R;
|
|
635
|
-
} ? R extends ZodType ? ExtractData<R['_output']> : never : never;
|
|
634
|
+
type InferRouteResponse<T extends RouteDefinition> = [Extract<T, JsonResponseRoute>] extends [never] ? BinaryStreamMarker : Extract<T, JsonResponseRoute> extends JsonResponseRoute<HttpMethod, string, ZodType | undefined, ZodType | undefined, ZodType | undefined, infer R> ? [ZodType] extends [R] ? BinaryStreamMarker : ExtractData<R['_output']> : never;
|
|
636
635
|
/**
|
|
637
636
|
* 从路由定义中推断完整的响应类型
|
|
638
637
|
*
|
|
639
|
-
* 包含 ApiResponse
|
|
638
|
+
* 包含 ApiResponse 包装。
|
|
639
|
+
* 对联合别名形态鲁棒:JSON 路由不联合 BinaryStreamMarker,stream 路由保留 BinaryStreamMarker。
|
|
640
|
+
* 实现详见 ADR-0005。
|
|
640
641
|
*
|
|
641
642
|
* @example
|
|
642
643
|
* type Response = InferRouteFullResponse<typeof routes.detail>;
|
|
@@ -644,11 +645,7 @@ type InferRouteResponse<T extends RouteDefinition> = T extends {
|
|
|
644
645
|
*
|
|
645
646
|
* @typeParam T - 路由定义类型
|
|
646
647
|
*/
|
|
647
|
-
type InferRouteFullResponse<T extends RouteDefinition> = T extends
|
|
648
|
-
responseType: 'stream';
|
|
649
|
-
} ? BinaryStreamMarker : T extends {
|
|
650
|
-
response: infer R;
|
|
651
|
-
} ? R extends ZodType ? ApiResponse<ExtractData<R['_output']>> : never : never;
|
|
648
|
+
type InferRouteFullResponse<T extends RouteDefinition> = [Extract<T, JsonResponseRoute>] extends [never] ? BinaryStreamMarker : Extract<T, JsonResponseRoute> extends JsonResponseRoute<HttpMethod, string, ZodType | undefined, ZodType | undefined, ZodType | undefined, infer R> ? [ZodType] extends [R] ? BinaryStreamMarker : ApiResponse<ExtractData<R['_output']>> : never;
|
|
652
649
|
/**
|
|
653
650
|
* 从路由定义中推断分页响应的项类型
|
|
654
651
|
*
|
|
@@ -2007,7 +2004,7 @@ declare function buildQuery(query?: Record<string, string | number | boolean | u
|
|
|
2007
2004
|
*/
|
|
2008
2005
|
declare function concatPath<T extends string, U extends string>(a: T, b: U): `${T}${U}`;
|
|
2009
2006
|
//#endregion
|
|
2010
|
-
//#region src/routes/route-group.
|
|
2007
|
+
//#region src/routes/route-group.types.d.ts
|
|
2011
2008
|
/**
|
|
2012
2009
|
* API 版本号类型
|
|
2013
2010
|
*
|
|
@@ -2029,134 +2026,76 @@ type DefaultAuthStrategy = 'public' | 'user' | 'admin' | (string & {});
|
|
|
2029
2026
|
*/
|
|
2030
2027
|
type VersionedPrefix<TVersion extends ApiVersion | undefined, TPrefix extends string> = TVersion extends ApiVersion ? TPrefix extends `/${string}` ? `/${TVersion}${TPrefix}` : TPrefix extends '' ? `/${TVersion}` : `/${TVersion}/${TPrefix}` : TPrefix;
|
|
2031
2028
|
/**
|
|
2032
|
-
*
|
|
2029
|
+
* 路由定义配置(用于分组内定义)
|
|
2033
2030
|
*
|
|
2034
|
-
* @typeParam
|
|
2035
|
-
* @typeParam
|
|
2036
|
-
* @typeParam
|
|
2031
|
+
* @typeParam TMethod - HTTP 方法类型
|
|
2032
|
+
* @typeParam TPath - 路径模板字符串
|
|
2033
|
+
* @typeParam TParams - 路径参数 Schema 类型
|
|
2034
|
+
* @typeParam TQuery - 查询参数 Schema 类型
|
|
2035
|
+
* @typeParam TBody - 请求体 Schema 类型
|
|
2036
|
+
* @typeParam TResponse - 响应 Schema 类型
|
|
2037
2037
|
*/
|
|
2038
|
-
type
|
|
2038
|
+
type RouteDefineConfig<TMethod extends HttpMethod = HttpMethod, TPath extends string = string, TParams extends ZodType | undefined = ZodType | undefined, TQuery extends ZodType | undefined = ZodType | undefined, TBody extends ZodType | undefined = ZodType | undefined, TResponse extends ZodType = ZodType> = {
|
|
2039
2039
|
/**
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
2042
|
-
* 指定父分组时,当前分组会继承父分组的配置并追加路径
|
|
2043
|
-
* - prefix 会追加到父分组的 prefix 后面
|
|
2044
|
-
* - auth 和 tags 会继承父分组的值(如果未指定)
|
|
2040
|
+
* HTTP 方法
|
|
2045
2041
|
*/
|
|
2046
|
-
|
|
2042
|
+
method: TMethod;
|
|
2047
2043
|
/**
|
|
2048
|
-
*
|
|
2049
|
-
*
|
|
2050
|
-
* 所有子路由的路径都会自动拼接此前缀
|
|
2051
|
-
* 如果指定了 parent,此前缀会追加到父分组的 prefix 后面
|
|
2052
|
-
* 如果指定了 version,版本前缀会自动添加到 prefix 前面
|
|
2053
|
-
* 如果未指定,默认为空字符串
|
|
2044
|
+
* 路径模板,会自动拼接分组前缀
|
|
2054
2045
|
*/
|
|
2055
|
-
|
|
2046
|
+
path: TPath;
|
|
2056
2047
|
/**
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2059
|
-
* 版本前缀会自动添加到 prefix 前面,格式为 /{version}
|
|
2060
|
-
* 例如:version: 'v1', prefix: 'client' -> 实际前缀: /v1/client
|
|
2061
|
-
* 例如:version: 'v1', prefix: '' -> 实际前缀: /v1
|
|
2062
|
-
*
|
|
2063
|
-
* 注意:如果指定了 parent,version 应该在父分组中指定,子分组会自动继承
|
|
2048
|
+
* 路径参数 Schema
|
|
2064
2049
|
*/
|
|
2065
|
-
|
|
2050
|
+
params?: TParams;
|
|
2066
2051
|
/**
|
|
2067
|
-
*
|
|
2068
|
-
*
|
|
2069
|
-
* 标识分组内路由的认证要求,可由适配器读取并应用相应的中间件
|
|
2070
|
-
* 如果指定了 parent 且未设置此字段,会继承父分组的 auth
|
|
2052
|
+
* 查询参数 Schema
|
|
2071
2053
|
*/
|
|
2072
|
-
|
|
2054
|
+
query?: TQuery;
|
|
2073
2055
|
/**
|
|
2074
|
-
*
|
|
2075
|
-
*
|
|
2076
|
-
* TypedController 装饰器会使用这些标签设置 @ApiTags()
|
|
2077
|
-
* 子路由会继承这些标签,并可追加自己的标签
|
|
2078
|
-
* 如果指定了 parent 且未设置此字段,会继承父分组的 tags
|
|
2056
|
+
* 请求体 Schema
|
|
2079
2057
|
*/
|
|
2080
|
-
|
|
2058
|
+
body?: TBody;
|
|
2081
2059
|
/**
|
|
2082
|
-
*
|
|
2083
|
-
*
|
|
2084
|
-
* 提供 routes 时,defineRouteGroup 返回 RouteGroup & { routes },
|
|
2085
|
-
* 可直接用于 TypedController 和 TypedRoute。
|
|
2086
|
-
* 不提供 routes 时,返回纯 RouteGroup,可用于 defineRoute 拆分定义。
|
|
2087
|
-
*
|
|
2088
|
-
* 接受两种输入:
|
|
2089
|
-
* - 内联原始配置对象(简单场景,少量路由)
|
|
2090
|
-
* - group.defineRoute() 的返回值(复杂场景,拆分定义)
|
|
2060
|
+
* 响应 Schema
|
|
2091
2061
|
*/
|
|
2092
|
-
|
|
2093
|
-
};
|
|
2094
|
-
/**
|
|
2095
|
-
* 路由分组
|
|
2096
|
-
*
|
|
2097
|
-
* 提供路由分组功能,子路由自动继承分组的配置
|
|
2098
|
-
*
|
|
2099
|
-
* @typeParam TPrefix - 路径前缀类型
|
|
2100
|
-
* @typeParam TVersion - API 版本号类型
|
|
2101
|
-
* @typeParam TAuthStrategy - 认证策略类型
|
|
2102
|
-
*/
|
|
2103
|
-
type RouteGroup<TPrefix extends string = string, TVersion extends ApiVersion | undefined = undefined, TAuthStrategy extends string = DefaultAuthStrategy> = {
|
|
2062
|
+
response: TResponse;
|
|
2104
2063
|
/**
|
|
2105
|
-
*
|
|
2106
|
-
*
|
|
2107
|
-
* 如果指定了 version,格式为 /{version}/{prefix}
|
|
2108
|
-
* 如果未指定 version,则为原始 prefix
|
|
2064
|
+
* 接口摘要描述
|
|
2109
2065
|
*/
|
|
2110
|
-
|
|
2066
|
+
summary?: string;
|
|
2111
2067
|
/**
|
|
2112
|
-
*
|
|
2068
|
+
* 接口标签,会与分组标签合并
|
|
2113
2069
|
*/
|
|
2114
|
-
|
|
2070
|
+
tags?: string[];
|
|
2115
2071
|
/**
|
|
2116
|
-
*
|
|
2117
|
-
*
|
|
2118
|
-
* 标识分组内路由的认证要求
|
|
2072
|
+
* 是否需要 CSRF 令牌保护
|
|
2119
2073
|
*/
|
|
2120
|
-
|
|
2074
|
+
csrf?: boolean;
|
|
2121
2075
|
/**
|
|
2122
|
-
*
|
|
2123
|
-
*
|
|
2124
|
-
* 用于接口分组和文档生成
|
|
2076
|
+
* 请求内容类型
|
|
2125
2077
|
*/
|
|
2126
|
-
|
|
2078
|
+
contentType?: 'json' | 'formData';
|
|
2127
2079
|
/**
|
|
2128
|
-
*
|
|
2129
|
-
*
|
|
2130
|
-
* 语法糖,用于需要单独引用某条路由或拆分复杂路由定义的场景。
|
|
2131
|
-
* 子路由的路径会自动拼接分组前缀,并继承分组的认证策略和标签。
|
|
2080
|
+
* 覆盖分组的认证策略
|
|
2132
2081
|
*
|
|
2133
|
-
*
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
* @typeParam TQuery - 查询参数 Zod Schema
|
|
2137
|
-
* @typeParam TBody - 请求体 Zod Schema
|
|
2138
|
-
* @typeParam TResponse - 响应 Zod Schema
|
|
2139
|
-
* @param config - 路由配置对象
|
|
2140
|
-
* @returns 类型安全的路由定义,路径已拼接前缀
|
|
2141
|
-
*/
|
|
2142
|
-
defineRoute: <TMethod extends HttpMethod = HttpMethod, TPath extends string = string, TParams extends ZodType | undefined = undefined, TQuery extends ZodType | undefined = undefined, TBody extends ZodType | undefined = undefined, TResponse extends ZodType = ZodType>(config: RouteDefineConfig<TMethod, TPath, TParams, TQuery, TBody, TResponse>) => RouteDefinition<TMethod, `${VersionedPrefix<TVersion, TPrefix>}${TPath}`, TParams, TQuery, TBody, TResponse> & {
|
|
2143
|
-
/**
|
|
2144
|
-
* 认证策略
|
|
2145
|
-
*/
|
|
2146
|
-
auth?: TAuthStrategy;
|
|
2147
|
-
};
|
|
2082
|
+
* 用于覆盖父路由分组的认证设置
|
|
2083
|
+
*/
|
|
2084
|
+
auth?: string;
|
|
2148
2085
|
};
|
|
2149
2086
|
/**
|
|
2150
|
-
*
|
|
2087
|
+
* 流式路由分组定义配置
|
|
2088
|
+
*
|
|
2089
|
+
* 用于 RouteGroup.defineRoute 创建流式响应路由,responseType 必填 'stream',
|
|
2090
|
+
* stream 字段描述响应元数据。
|
|
2151
2091
|
*
|
|
2152
2092
|
* @typeParam TMethod - HTTP 方法类型
|
|
2153
2093
|
* @typeParam TPath - 路径模板字符串
|
|
2154
2094
|
* @typeParam TParams - 路径参数 Schema 类型
|
|
2155
2095
|
* @typeParam TQuery - 查询参数 Schema 类型
|
|
2156
2096
|
* @typeParam TBody - 请求体 Schema 类型
|
|
2157
|
-
* @typeParam TResponse - 响应 Schema 类型
|
|
2158
2097
|
*/
|
|
2159
|
-
type
|
|
2098
|
+
type StreamRouteGroupDefineConfig<TMethod extends HttpMethod = HttpMethod, TPath extends string = string, TParams extends ZodType | undefined = ZodType | undefined, TQuery extends ZodType | undefined = ZodType | undefined, TBody extends ZodType | undefined = ZodType | undefined> = {
|
|
2160
2099
|
/**
|
|
2161
2100
|
* HTTP 方法
|
|
2162
2101
|
*/
|
|
@@ -2178,9 +2117,13 @@ type RouteDefineConfig<TMethod extends HttpMethod = HttpMethod, TPath extends st
|
|
|
2178
2117
|
*/
|
|
2179
2118
|
body?: TBody;
|
|
2180
2119
|
/**
|
|
2181
|
-
*
|
|
2120
|
+
* 响应类型标记:二进制流,显式必填
|
|
2182
2121
|
*/
|
|
2183
|
-
|
|
2122
|
+
responseType: 'stream';
|
|
2123
|
+
/**
|
|
2124
|
+
* 流式响应元数据
|
|
2125
|
+
*/
|
|
2126
|
+
stream: StreamResponseMeta;
|
|
2184
2127
|
/**
|
|
2185
2128
|
* 接口摘要描述
|
|
2186
2129
|
*/
|
|
@@ -2199,30 +2142,77 @@ type RouteDefineConfig<TMethod extends HttpMethod = HttpMethod, TPath extends st
|
|
|
2199
2142
|
contentType?: 'json' | 'formData';
|
|
2200
2143
|
/**
|
|
2201
2144
|
* 覆盖分组的认证策略
|
|
2202
|
-
*
|
|
2203
|
-
* 用于覆盖父路由分组的认证设置
|
|
2204
2145
|
*/
|
|
2205
2146
|
auth?: string;
|
|
2206
2147
|
};
|
|
2207
2148
|
/**
|
|
2208
|
-
*
|
|
2149
|
+
* defineRoute 重载类型
|
|
2209
2150
|
*
|
|
2210
|
-
*
|
|
2151
|
+
* stream config 返回精确的 StreamResponseRoute,
|
|
2152
|
+
* JSON config 返回精确的 JsonResponseRoute。
|
|
2211
2153
|
*
|
|
2212
|
-
* @typeParam TMethod - HTTP 方法类型
|
|
2213
2154
|
* @typeParam TVersion - API 版本号类型
|
|
2214
2155
|
* @typeParam TPrefix - 路径前缀类型
|
|
2215
|
-
* @typeParam
|
|
2216
|
-
* @typeParam TParams - 路径参数 Schema 类型
|
|
2217
|
-
* @typeParam TQuery - 查询参数 Schema 类型
|
|
2218
|
-
* @typeParam TBody - 请求体 Schema 类型
|
|
2219
|
-
* @typeParam TResponse - 响应 Schema 类型
|
|
2156
|
+
* @typeParam TAuthStrategy - 认证策略类型
|
|
2220
2157
|
*/
|
|
2221
|
-
type
|
|
2158
|
+
type DefineRouteOverloads<TVersion extends ApiVersion | undefined, TPrefix extends string, TAuthStrategy extends string> = {
|
|
2159
|
+
/**
|
|
2160
|
+
* 定义单条路由(流式响应)
|
|
2161
|
+
*/
|
|
2162
|
+
<TMethod extends HttpMethod, TPath extends string, TParams extends ZodType | undefined, TQuery extends ZodType | undefined, TBody extends ZodType | undefined, TLocalAuth extends string | undefined = undefined>(config: StreamRouteGroupDefineConfig<TMethod, TPath, TParams, TQuery, TBody> & {
|
|
2163
|
+
auth?: TLocalAuth;
|
|
2164
|
+
}): StreamResponseRoute<TMethod, `${VersionedPrefix<TVersion, TPrefix>}${TPath}`, TParams, TQuery, TBody> & {
|
|
2165
|
+
auth?: TLocalAuth extends string ? TLocalAuth : TAuthStrategy;
|
|
2166
|
+
};
|
|
2167
|
+
/**
|
|
2168
|
+
* 定义单条路由(JSON 响应)
|
|
2169
|
+
*/
|
|
2170
|
+
<TMethod extends HttpMethod = HttpMethod, TPath extends string = string, TParams extends ZodType | undefined = undefined, TQuery extends ZodType | undefined = undefined, TBody extends ZodType | undefined = undefined, TResponse extends ZodType = ZodType, TLocalAuth extends string | undefined = undefined>(config: RouteDefineConfig<TMethod, TPath, TParams, TQuery, TBody, TResponse> & {
|
|
2171
|
+
auth?: TLocalAuth;
|
|
2172
|
+
}): JsonResponseRoute<TMethod, `${VersionedPrefix<TVersion, TPrefix>}${TPath}`, TParams, TQuery, TBody, TResponse> & {
|
|
2173
|
+
auth?: TLocalAuth extends string ? TLocalAuth : TAuthStrategy;
|
|
2174
|
+
};
|
|
2175
|
+
};
|
|
2176
|
+
/**
|
|
2177
|
+
* 路由分组
|
|
2178
|
+
*
|
|
2179
|
+
* 提供路由分组功能,子路由自动继承分组的配置
|
|
2180
|
+
*
|
|
2181
|
+
* @typeParam TPrefix - 路径前缀类型
|
|
2182
|
+
* @typeParam TVersion - API 版本号类型
|
|
2183
|
+
* @typeParam TAuthStrategy - 认证策略类型
|
|
2184
|
+
*/
|
|
2185
|
+
type RouteGroup<TPrefix extends string = string, TVersion extends ApiVersion | undefined = undefined, TAuthStrategy extends string = DefaultAuthStrategy> = {
|
|
2186
|
+
/**
|
|
2187
|
+
* 完整路径前缀(包含版本)
|
|
2188
|
+
*
|
|
2189
|
+
* 如果指定了 version,格式为 /{version}/{prefix}
|
|
2190
|
+
* 如果未指定 version,则为原始 prefix
|
|
2191
|
+
*/
|
|
2192
|
+
readonly prefix: VersionedPrefix<TVersion, TPrefix>;
|
|
2193
|
+
/**
|
|
2194
|
+
* API 版本号
|
|
2195
|
+
*/
|
|
2196
|
+
readonly version?: TVersion;
|
|
2222
2197
|
/**
|
|
2223
2198
|
* 认证策略
|
|
2199
|
+
*
|
|
2200
|
+
* 标识分组内路由的认证要求
|
|
2224
2201
|
*/
|
|
2225
|
-
auth?:
|
|
2202
|
+
readonly auth?: TAuthStrategy;
|
|
2203
|
+
/**
|
|
2204
|
+
* API 标签(用于 Swagger 分组和 TypedController)
|
|
2205
|
+
*
|
|
2206
|
+
* 用于接口分组和文档生成
|
|
2207
|
+
*/
|
|
2208
|
+
readonly tags?: string[];
|
|
2209
|
+
/**
|
|
2210
|
+
* 定义单条路由(支持 JSON 响应和流式响应)
|
|
2211
|
+
*
|
|
2212
|
+
* stream config → 精确的 StreamResponseRoute
|
|
2213
|
+
* JSON config → 精确的 JsonResponseRoute
|
|
2214
|
+
*/
|
|
2215
|
+
defineRoute: DefineRouteOverloads<TVersion, TPrefix, TAuthStrategy>;
|
|
2226
2216
|
};
|
|
2227
2217
|
/**
|
|
2228
2218
|
* 已处理的路由类型
|
|
@@ -2332,6 +2322,99 @@ T extends {
|
|
|
2332
2322
|
* @typeParam TRoutes - 路由定义集合类型
|
|
2333
2323
|
*/
|
|
2334
2324
|
type ProcessRoutes<TRoutes extends Record<string, RouteDefineConfig | ProcessedRoute<RouteDefinition>>> = { [K in keyof TRoutes]: ProcessedRoute<InferRouteDefinitionFromValue<TRoutes[K]>> };
|
|
2325
|
+
/**
|
|
2326
|
+
* 路由分组配置
|
|
2327
|
+
*
|
|
2328
|
+
* @typeParam TPrefix - 路径前缀类型
|
|
2329
|
+
* @typeParam TVersion - API 版本号类型
|
|
2330
|
+
* @typeParam TAuthStrategy - 认证策略类型
|
|
2331
|
+
*/
|
|
2332
|
+
type RouteGroupConfig<TPrefix extends string = '', TVersion extends ApiVersion | undefined = undefined, TAuthStrategy extends string = DefaultAuthStrategy> = {
|
|
2333
|
+
/**
|
|
2334
|
+
* 父路由分组(可选)
|
|
2335
|
+
*
|
|
2336
|
+
* 指定父分组时,当前分组会继承父分组的配置并追加路径
|
|
2337
|
+
* - prefix 会追加到父分组的 prefix 后面
|
|
2338
|
+
* - auth 和 tags 会继承父分组的值(如果未指定)
|
|
2339
|
+
*/
|
|
2340
|
+
parent?: RouteGroup<string, ApiVersion | undefined, TAuthStrategy>;
|
|
2341
|
+
/**
|
|
2342
|
+
* 路径前缀(可选)
|
|
2343
|
+
*
|
|
2344
|
+
* 所有子路由的路径都会自动拼接此前缀
|
|
2345
|
+
* 如果指定了 parent,此前缀会追加到父分组的 prefix 后面
|
|
2346
|
+
* 如果指定了 version,版本前缀会自动添加到 prefix 前面
|
|
2347
|
+
* 如果未指定,默认为空字符串
|
|
2348
|
+
*/
|
|
2349
|
+
prefix?: TPrefix;
|
|
2350
|
+
/**
|
|
2351
|
+
* API 版本号
|
|
2352
|
+
*
|
|
2353
|
+
* 版本前缀会自动添加到 prefix 前面,格式为 /{version}
|
|
2354
|
+
* 例如:version: 'v1', prefix: 'client' -> 实际前缀: /v1/client
|
|
2355
|
+
* 例如:version: 'v1', prefix: '' -> 实际前缀: /v1
|
|
2356
|
+
*
|
|
2357
|
+
* 注意:如果指定了 parent,version 应该在父分组中指定,子分组会自动继承
|
|
2358
|
+
*/
|
|
2359
|
+
version?: TVersion;
|
|
2360
|
+
/**
|
|
2361
|
+
* 认证策略
|
|
2362
|
+
*
|
|
2363
|
+
* 标识分组内路由的认证要求,可由适配器读取并应用相应的中间件
|
|
2364
|
+
* 如果指定了 parent 且未设置此字段,会继承父分组的 auth
|
|
2365
|
+
*/
|
|
2366
|
+
auth?: TAuthStrategy;
|
|
2367
|
+
/**
|
|
2368
|
+
* API 标签(用于 Swagger 分组和 TypedController)
|
|
2369
|
+
*
|
|
2370
|
+
* TypedController 装饰器会使用这些标签设置 @ApiTags()
|
|
2371
|
+
* 子路由会继承这些标签,并可追加自己的标签
|
|
2372
|
+
* 如果指定了 parent 且未设置此字段,会继承父分组的 tags
|
|
2373
|
+
*/
|
|
2374
|
+
tags?: string[];
|
|
2375
|
+
/**
|
|
2376
|
+
* 路由定义集合(可选)
|
|
2377
|
+
*
|
|
2378
|
+
* 提供 routes 时,defineRouteGroup 返回 RouteGroup & { routes },
|
|
2379
|
+
* 可直接用于 TypedController 和 TypedRoute。
|
|
2380
|
+
* 不提供 routes 时,返回纯 RouteGroup,可用于 defineRoute 拆分定义。
|
|
2381
|
+
*
|
|
2382
|
+
* 接受两种输入:
|
|
2383
|
+
* - 内联原始配置对象(简单场景,少量路由)
|
|
2384
|
+
* - group.defineRoute() 的返回值(复杂场景,拆分定义)
|
|
2385
|
+
*/
|
|
2386
|
+
routes?: Record<string, RouteDefineConfig | ProcessedRoute<RouteDefinition>>;
|
|
2387
|
+
};
|
|
2388
|
+
/**
|
|
2389
|
+
* defineRouteGroup 函数配置类型
|
|
2390
|
+
*
|
|
2391
|
+
* @typeParam TPrefix - 路径前缀类型
|
|
2392
|
+
* @typeParam TVersion - API 版本号类型
|
|
2393
|
+
* @typeParam TAuthStrategy - 认证策略类型
|
|
2394
|
+
* @typeParam TRoutes - 路由定义集合类型
|
|
2395
|
+
*/
|
|
2396
|
+
/**
|
|
2397
|
+
* 路由定义结果类型
|
|
2398
|
+
*
|
|
2399
|
+
* defineRoute 返回的类型,包含完整的路由定义和可选的 auth 属性
|
|
2400
|
+
*
|
|
2401
|
+
* @typeParam TMethod - HTTP 方法类型
|
|
2402
|
+
* @typeParam TVersion - API 版本号类型
|
|
2403
|
+
* @typeParam TPrefix - 路径前缀类型
|
|
2404
|
+
* @typeParam TPath - 路径模板字符串
|
|
2405
|
+
* @typeParam TParams - 路径参数 Schema 类型
|
|
2406
|
+
* @typeParam TQuery - 查询参数 Schema 类型
|
|
2407
|
+
* @typeParam TBody - 请求体 Schema 类型
|
|
2408
|
+
* @typeParam TResponse - 响应 Schema 类型
|
|
2409
|
+
*/
|
|
2410
|
+
type RouteDefineResult<TMethod extends HttpMethod, TVersion extends ApiVersion | undefined, TPrefix extends string, TPath extends string, TParams extends ZodType | undefined, TQuery extends ZodType | undefined, TBody extends ZodType | undefined, TResponse extends ZodType> = RouteDefinition<TMethod, `${VersionedPrefix<TVersion, TPrefix>}${TPath}`, TParams, TQuery, TBody, TResponse> & {
|
|
2411
|
+
/**
|
|
2412
|
+
* 认证策略
|
|
2413
|
+
*/
|
|
2414
|
+
auth?: string;
|
|
2415
|
+
};
|
|
2416
|
+
//#endregion
|
|
2417
|
+
//#region src/routes/route-group.utils.d.ts
|
|
2335
2418
|
/**
|
|
2336
2419
|
* 定义路由分组(含 routes,保留具体键类型)
|
|
2337
2420
|
*
|