Skip to content

Commit dd60bb2

Browse files
committed
feature: add key endpoint to the createTrpcQueryClient returned value in the returned function
1 parent 6aa4c44 commit dd60bb2

2 files changed

Lines changed: 35 additions & 33 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@creatorem/next-trpc",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/creatorem/next-trpc"

src/create-trpc-query-client.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,42 @@ import {
88
} from "./create-trpc-client";
99
import type { Router, Endpoint, router } from "./core";
1010
import z from "zod";
11+
import { kebabize } from "./utils";
1112

1213
export 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

4849
export 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

Comments
 (0)