@@ -8,41 +8,42 @@ import {
88} from "./create-trpc-client" ;
99import type { Router , Endpoint , router } from "./core" ;
1010import z from "zod" ;
11+ import { kebabize } from "./utils" ;
1112
1213export type TrpcClientWithQuery < R extends Router < any > > = {
1314 [ K in keyof R ] : R [ K ] extends Endpoint < infer Output , infer Input , any >
14- ? EndpointClient < Input , Output > & {
15- useQuery : Input extends import ( "zod" ) . Schema
16- ? (
17- queryOptions : Omit <
18- Parameters < typeof useQueryType > [ 0 ] ,
19- "queryKey" | "queryFn"
20- > & {
21- input : z . infer < Input > ;
22- }
23- ) => ReturnType <
24- typeof useQueryType <
25- Awaited < Output > ,
26- Error ,
27- Awaited < Output > ,
28- string [ ]
29- >
30- >
31- : (
32- queryOptions ?: Omit <
33- Parameters < typeof useQueryType > [ 0 ] ,
34- "queryKey" | "queryFn"
35- >
36- ) => ReturnType <
37- typeof useQueryType <
38- Awaited < Output > ,
39- Error ,
40- Awaited < Output > ,
41- string [ ]
42- >
43- > ;
15+ ? EndpointClient < Input , Output > & {
16+ useQuery : Input extends import ( "zod" ) . Schema
17+ ? (
18+ queryOptions : Omit <
19+ Parameters < typeof useQueryType > [ 0 ] ,
20+ "queryKey" | "queryFn"
21+ > & {
22+ input : z . infer < Input > ;
4423 }
45- : never ;
24+ ) => ReturnType <
25+ typeof useQueryType <
26+ Awaited < Output > ,
27+ Error ,
28+ Awaited < Output > ,
29+ string [ ]
30+ >
31+ >
32+ : (
33+ queryOptions ?: Omit <
34+ Parameters < typeof useQueryType > [ 0 ] ,
35+ "queryKey" | "queryFn"
36+ >
37+ ) => ReturnType <
38+ typeof useQueryType <
39+ Awaited < Output > ,
40+ Error ,
41+ Awaited < Output > ,
42+ string [ ]
43+ >
44+ > ;
45+ }
46+ : never ;
4647} ;
4748
4849export const createTrpcQueryClient = <
@@ -66,7 +67,7 @@ export const createTrpcQueryClient = <
6667 input ?: any ;
6768 }
6869 ) => {
69- const endpointName = prop . replace ( / ( [ A - Z ] ) / g , "-$1" ) . toLowerCase ( ) ;
70+ const endpointName = kebabize ( prop ) ;
7071 return opts . useQuery ( {
7172 ...queryOptions ,
7273 queryKey : [ endpointName ] ,
@@ -79,6 +80,7 @@ export const createTrpcQueryClient = <
7980 } ,
8081 } ) ;
8182 } ,
83+ key : kebabize ( prop )
8284 } ;
8385 }
8486 return undefined ;
0 commit comments