Skip to content

Commit 3fb4da0

Browse files
committed
fix: export issue
1 parent f25108b commit 3fb4da0

File tree

12 files changed

+79
-25
lines changed

12 files changed

+79
-25
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# production
1616
/build
1717

18+
.turbo
19+
1820
# misc
1921
.DS_Store
2022
*.pem

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ export const createContext = async () => {
173173
const ctx = new CtxRouter<Awaited<ReturnType<typeof createContext>>>();
174174

175175
export const appRouter = ctx.router({
176-
getUser: endpoint.action(async ({ db }) => {
176+
getUser: ctx.endpoint.action(async ({ db }) => {
177177
return await db.user.get();
178178
}),
179-
greeting: endpoint
179+
greeting: ctx.endpoint
180180
.input(
181181
// you can add zod typechecking to your entry params
182182
z.object({
@@ -192,6 +192,9 @@ export const appRouter = ctx.router({
192192
export type AppRouter = typeof appRouter;
193193
```
194194

195+
> [!NOTE]
196+
> Param types are serialized during the http request to the api. You need to use `z.coerce` for non-string types.
197+
195198
Next pass your context to the nextjs api endpoint.
196199

197200
`app/api/trpc/[trpc]/route.ts`

example/app/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Metadata } from "next";
22
import { Geist, Geist_Mono } from "next/font/google";
33
import "./globals.css";
4+
import { ReactQueryProvider } from "~/components/query-client";
45

56
const geistSans = Geist({
67
variable: "--font-geist-sans",
@@ -27,7 +28,7 @@ export default function RootLayout({
2728
<body
2829
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
2930
>
30-
{children}
31+
<ReactQueryProvider>{children}</ReactQueryProvider>
3132
</body>
3233
</html>
3334
);

example/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22

33
import { serverTrpc } from "~/trpc/server-client";
4-
import { ClientComp } from "./client-comp";
4+
import { ClientComp } from "../components/client-comp";
55

66
export default async function Home() {
77
const user = await serverTrpc.getUser.fetch();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use client';
2+
3+
import { useState } from 'react';
4+
5+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
6+
7+
export function ReactQueryProvider(props: React.PropsWithChildren) {
8+
const [queryClient] = useState(
9+
() =>
10+
new QueryClient({
11+
defaultOptions: {
12+
queries: {
13+
// With SSR, we usually want to set some default staleTime
14+
// above 0 to avoid refetching immediately on the client
15+
staleTime: 60 * 1000,
16+
},
17+
},
18+
}),
19+
);
20+
21+
return (
22+
<QueryClientProvider client={queryClient}>
23+
{props.children}
24+
</QueryClientProvider>
25+
);
26+
}

example/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
"lint": "eslint"
1111
},
1212
"dependencies": {
13+
"@tanstack/react-query": "^5.90.12",
1314
"next": "16.0.8",
1415
"react": "19.2.1",
15-
"react-dom": "19.2.1"
16+
"react-dom": "19.2.1",
17+
"zod": "^3.25.76"
1618
},
1719
"devDependencies": {
1820
"@tailwindcss/postcss": "^4",
@@ -22,6 +24,6 @@
2224
"eslint": "^9",
2325
"eslint-config-next": "16.0.8",
2426
"tailwindcss": "^4",
25-
"typescript": "^5"
27+
"typescript": "^5.9.3"
2628
}
2729
}

example/trpc/router.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CtxRouter, endpoint } from "../../src/core";
1+
import { CtxRouter } from "../../src/core";
22
import z from "zod";
33

44
export const createContext = async () => {
@@ -11,7 +11,7 @@ export const createContext = async () => {
1111
const ctx = new CtxRouter<Awaited<ReturnType<typeof createContext>>>();
1212

1313
export const appRouter = ctx.router({
14-
getUser: endpoint.action(async ({ hello, howAreYou, request }) => {
14+
getUser: ctx.endpoint.action(async ({ hello, howAreYou, request }) => {
1515
console.log({
1616
myCustomContext: {
1717
hello,
@@ -31,7 +31,7 @@ export const appRouter = ctx.router({
3131
}, 1000);
3232
});
3333
}),
34-
greeting: endpoint
34+
greeting: ctx.endpoint
3535
.input(
3636
z.object({
3737
name: z.string(),
@@ -42,7 +42,7 @@ export const appRouter = ctx.router({
4242
console.log({ howAreYou });
4343
return `Hi my name is ${name}, and I am ${age} years old.`;
4444
}),
45-
test: endpoint.action(async ({ hello, howAreYou, request }) => {
45+
test: ctx.endpoint.action(async ({ hello, howAreYou, request }) => {
4646

4747
return new Promise((resolve) => {
4848
setTimeout(() => {

example/trpc/server-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "server-only";
33
import { createTrpcClient } from "../../src/create-trpc-client";
44
import { AppRouter } from "./router";
55

6-
const url = "https://localhost:3000/api/trpc";
6+
const url = "http://localhost:3000/api/trpc";
77

88
export const serverTrpc = createTrpcClient<AppRouter>({
99
url,

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "@creatorem/next-trpc",
3-
"type": "module",
4-
"version": "1.0.3",
3+
"version": "1.0.4",
54
"repository": {
65
"type": "git",
76
"url": "git+https://github.com/creatorem/next-trpc"
@@ -24,7 +23,7 @@
2423
"dist"
2524
],
2625
"scripts": {
27-
"build": "tsc --noEmit false --outDir dist --declaration",
26+
"build": "tsc --noEmit false --outDir dist --declaration --module commonjs --target ES2017",
2827
"clean": "git clean -xdf .turbo dist node_modules",
2928
"format": "prettier --check \"**/*.{ts,tsx}\"",
3029
"lint": "eslint .",
@@ -35,18 +34,22 @@
3534
},
3635
"exports": {
3736
".": {
37+
"import": "./dist/core.js",
3838
"require": "./dist/core.js",
3939
"types": "./dist/core.d.ts"
4040
},
4141
"./server": {
42+
"import": "./dist/create-trpc-api.js",
4243
"require": "./dist/create-trpc-api.js",
4344
"types": "./dist/create-trpc-api.d.ts"
4445
},
4546
"./client": {
47+
"import": "./dist/create-trpc-client.js",
4648
"require": "./dist/create-trpc-client.js",
4749
"types": "./dist/create-trpc-client.d.ts"
4850
},
4951
"./query-client": {
52+
"import": "./dist/create-trpc-query-client.js",
5053
"require": "./dist/create-trpc-query-client.js",
5154
"types": "./dist/create-trpc-query-client.d.ts"
5255
}
@@ -64,7 +67,7 @@
6467
"typesVersions": {
6568
"*": {
6669
"*": [
67-
"src/*"
70+
"dist/*"
6871
]
6972
}
7073
}

0 commit comments

Comments
 (0)