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