@creatorem/next-trpc 1.0.15 → 1.0.17
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/create-trpc-api.js
CHANGED
|
@@ -58,6 +58,7 @@ const createTrpcAPI = ({ router, ctx, }) => {
|
|
|
58
58
|
return server_1.NextResponse.json({ data: result }, { status: 200 });
|
|
59
59
|
}
|
|
60
60
|
catch (error) {
|
|
61
|
+
console.error(error);
|
|
61
62
|
if (error instanceof Error && "issues" in error) {
|
|
62
63
|
// Zod validation error
|
|
63
64
|
return server_1.NextResponse.json({ data: null, error: "Invalid request data", details: error.message }, { status: 400 });
|
|
@@ -2,10 +2,12 @@ import { Router, type Endpoint, type router } from "./core";
|
|
|
2
2
|
import z from "zod";
|
|
3
3
|
export type EndpointClient<Input, Output> = Input extends undefined ? {
|
|
4
4
|
fetch: () => Promise<Output>;
|
|
5
|
+
key: string;
|
|
5
6
|
} : {
|
|
6
7
|
fetch: (input: Input extends import("zod").Schema ? z.infer<Input> : Input) => Promise<Output>;
|
|
8
|
+
key: string;
|
|
7
9
|
};
|
|
8
|
-
type TrpcClient<R extends Router<any>> = {
|
|
10
|
+
export type TrpcClient<R extends Router<any>> = {
|
|
9
11
|
[K in keyof R]: R[K] extends Endpoint<infer Output, infer Input, any> ? EndpointClient<Input, Output> : never;
|
|
10
12
|
};
|
|
11
13
|
export declare const getTrpcFetch: ({ endpointSlug, url, headers, }: {
|
|
@@ -16,4 +18,3 @@ export interface createTrpcClientOptions {
|
|
|
16
18
|
headers?: HeadersInit | (() => Promise<HeadersInit>);
|
|
17
19
|
}
|
|
18
20
|
export declare const createTrpcClient: <R extends ReturnType<typeof router<any, Router<any>>>>(opts: createTrpcClientOptions) => TrpcClient<R>;
|
|
19
|
-
export {};
|
|
@@ -26,6 +26,7 @@ const getTrpcFetch = ({ endpointSlug, url, headers, }) => async (input) => {
|
|
|
26
26
|
});
|
|
27
27
|
if (!response.ok) {
|
|
28
28
|
const errorData = await response.json();
|
|
29
|
+
console.error(errorData);
|
|
29
30
|
throw new Error(errorData.error || "Request failed");
|
|
30
31
|
}
|
|
31
32
|
const result = await response.json();
|
|
@@ -38,6 +39,7 @@ const createTrpcClient = (opts) => {
|
|
|
38
39
|
if (typeof prop === "string") {
|
|
39
40
|
return {
|
|
40
41
|
fetch: (0, exports.getTrpcFetch)(Object.assign({ endpointSlug: prop }, opts)),
|
|
42
|
+
key: (0, utils_1.kebabize)(prop)
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
return undefined;
|