@creatorem/next-trpc 1.0.10 → 1.0.11
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.
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { useQuery as useQueryType } from "@tanstack/react-query";
|
|
2
2
|
import { type EndpointClient, createTrpcClientOptions } from "./create-trpc-client";
|
|
3
3
|
import type { Router, Endpoint, router } from "./core";
|
|
4
|
+
import z from "zod";
|
|
4
5
|
type TrpcClientWithQuery<R extends Router<any>> = {
|
|
5
6
|
[K in keyof R]: R[K] extends Endpoint<infer Output, infer Input, any> ? EndpointClient<Input, Output> & {
|
|
6
|
-
useQuery: (queryOptions
|
|
7
|
+
useQuery: Input extends import("zod").Schema ? (queryOptions: Omit<Parameters<typeof useQueryType>[0], "queryKey" | "queryFn"> & {
|
|
8
|
+
input: z.infer<Input>;
|
|
9
|
+
}) => ReturnType<typeof useQueryType<Awaited<Output>, Error, Awaited<Output>, string[]>> : (queryOptions?: Omit<Parameters<typeof useQueryType>[0], "queryKey" | "queryFn">) => ReturnType<typeof useQueryType<Awaited<Output>, Error, Awaited<Output>, string[]>>;
|
|
7
10
|
} : never;
|
|
8
11
|
};
|
|
9
12
|
export declare const createTrpcQueryClient: <R extends ReturnType<typeof router<any, Router<any>>>>(opts: createTrpcClientOptions & {
|
|
@@ -11,7 +11,10 @@ const createTrpcQueryClient = (opts) => {
|
|
|
11
11
|
fetch: (0, create_trpc_client_1.getTrpcFetch)(Object.assign({ endpointSlug: prop }, opts)),
|
|
12
12
|
useQuery: (queryOptions) => {
|
|
13
13
|
const endpointName = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
14
|
-
return opts.useQuery(Object.assign(Object.assign({}, queryOptions), { queryKey: [endpointName], queryFn: (
|
|
14
|
+
return opts.useQuery(Object.assign(Object.assign({}, queryOptions), { queryKey: [endpointName], queryFn: async () => {
|
|
15
|
+
const fetcher = (0, create_trpc_client_1.getTrpcFetch)(Object.assign({ endpointSlug: prop }, opts));
|
|
16
|
+
return await fetcher(queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.input);
|
|
17
|
+
} }));
|
|
15
18
|
},
|
|
16
19
|
};
|
|
17
20
|
}
|