@longzai-intelligence-transport/http-core 0.1.1 → 0.1.2

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/dist/index.d.ts +10 -9
  2. 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
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-transport/http-core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "keywords": [
5
5
  "api",
6
6
  "contract",