From e5e4c9b494c82c1cb37dc205a8203761e1270fd9 Mon Sep 17 00:00:00 2001 From: c-ehrlich Date: Wed, 3 Jul 2024 09:41:53 +0200 Subject: [PATCH 1/2] update trpc example --- examples/trpc-app-router/.eslintrc.cjs | 26 +++++------ examples/trpc-app-router/.prettierrc.mjs | 9 ++++ examples/trpc-app-router/next.config.mjs | 8 +--- examples/trpc-app-router/package-lock.json | 26 +++++------ examples/trpc-app-router/package.json | 1 + .../src/app/_components/create-post.tsx | 22 ++++++---- .../src/app/api/trpc/[trpc]/route.ts | 22 +++++----- examples/trpc-app-router/src/app/layout.tsx | 16 ++++--- examples/trpc-app-router/src/app/page.tsx | 8 ++-- examples/trpc-app-router/src/env.mjs | 6 +-- .../src/server/api/axiom-trpc.ts | 10 ++--- .../trpc-app-router/src/server/api/root.ts | 4 +- .../src/server/api/routers/post.ts | 43 +++++++++++-------- .../trpc-app-router/src/server/api/trpc.ts | 12 +++--- examples/trpc-app-router/src/trpc/react.tsx | 22 +++++----- examples/trpc-app-router/src/trpc/server.ts | 14 +++--- examples/trpc-app-router/src/trpc/shared.ts | 10 ++--- 17 files changed, 140 insertions(+), 119 deletions(-) create mode 100644 examples/trpc-app-router/.prettierrc.mjs diff --git a/examples/trpc-app-router/.eslintrc.cjs b/examples/trpc-app-router/.eslintrc.cjs index 79cb5118..1ba088dc 100644 --- a/examples/trpc-app-router/.eslintrc.cjs +++ b/examples/trpc-app-router/.eslintrc.cjs @@ -1,30 +1,30 @@ /** @type {import("eslint").Linter.Config} */ const config = { - parser: "@typescript-eslint/parser", + parser: '@typescript-eslint/parser', parserOptions: { project: true, }, - plugins: ["@typescript-eslint"], + plugins: ['@typescript-eslint'], extends: [ - "next/core-web-vitals", - "plugin:@typescript-eslint/recommended-type-checked", - "plugin:@typescript-eslint/stylistic-type-checked", + 'next/core-web-vitals', + 'plugin:@typescript-eslint/recommended-type-checked', + 'plugin:@typescript-eslint/stylistic-type-checked', ], rules: { // These opinionated rules are enabled in stylistic-type-checked above. // Feel free to reconfigure them to your own preference. - "@typescript-eslint/array-type": "off", - "@typescript-eslint/consistent-type-definitions": "off", + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/consistent-type-definitions': 'off', - "@typescript-eslint/consistent-type-imports": [ - "warn", + '@typescript-eslint/consistent-type-imports': [ + 'warn', { - prefer: "type-imports", - fixStyle: "inline-type-imports", + prefer: 'type-imports', + fixStyle: 'inline-type-imports', }, ], - "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], - "@typescript-eslint/no-misused-promises": [ + '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], + '@typescript-eslint/no-misused-promises': [ 2, { checksVoidReturn: { attributes: false }, diff --git a/examples/trpc-app-router/.prettierrc.mjs b/examples/trpc-app-router/.prettierrc.mjs new file mode 100644 index 00000000..4e38f19d --- /dev/null +++ b/examples/trpc-app-router/.prettierrc.mjs @@ -0,0 +1,9 @@ +/** @type {import("prettier").Config} */ +const config = { + trailingComma: 'all', + tabWidth: 2, + semi: true, + singleQuote: true, +}; + +export default config; diff --git a/examples/trpc-app-router/next.config.mjs b/examples/trpc-app-router/next.config.mjs index 2d22f543..1b9713f4 100644 --- a/examples/trpc-app-router/next.config.mjs +++ b/examples/trpc-app-router/next.config.mjs @@ -1,10 +1,4 @@ -import { withAxiomNextConfig } from "next-axiom"; - -/** - * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful - * for Docker builds. - */ -await import("./src/env.mjs"); +import { withAxiomNextConfig } from 'next-axiom'; /** @type {import("next").NextConfig} */ const config = {}; diff --git a/examples/trpc-app-router/package-lock.json b/examples/trpc-app-router/package-lock.json index a915da6f..f38286d3 100644 --- a/examples/trpc-app-router/package-lock.json +++ b/examples/trpc-app-router/package-lock.json @@ -1454,9 +1454,9 @@ } }, "node_modules/acorn": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", - "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "bin": { "acorn": "bin/acorn" }, @@ -1832,9 +1832,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001639", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001639.tgz", - "integrity": "sha512-eFHflNTBIlFwP2AIKaYuBQN/apnUoKNhBdza8ZnW/h2di4LCZ4xFqYlxUxo+LQ76KFI1PGcC1QDxMbxTZpSCAg==", + "version": "1.0.30001640", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001640.tgz", + "integrity": "sha512-lA4VMpW0PSUrFnkmVuEKBUovSWKhj7puyCg8StBChgu298N1AtuF1sKWEvfDuimSEDbhlb/KqPKC3fs1HbuQUA==", "funding": [ { "type": "opencollective", @@ -4582,9 +4582,9 @@ } }, "node_modules/pkg-types": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.1.2.tgz", - "integrity": "sha512-VEGf1he2DR5yowYRl0XJhWJq5ktm9gYIsH+y8sNJpHlxch7JPDaufgrsl4vYjd9hMUY8QVjoNncKbow9I7exyA==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.1.3.tgz", + "integrity": "sha512-+JrgthZG6m3ckicaOB74TwQ+tBWsFl3qVQg7mN8ulwSOElJ7gBhKzj2VkCPnZ4NlF6kEquYU+RIYNVAvzd54UA==", "dependencies": { "confbox": "^0.1.7", "mlly": "^1.7.1", @@ -5645,12 +5645,12 @@ } }, "node_modules/vite": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.3.2.tgz", - "integrity": "sha512-6lA7OBHBlXUxiJxbO5aAY2fsHHzDr1q7DvXYnyZycRs2Dz+dXBWuhpWHvmljTRTpQC2uvGmUFFkSHF2vGo90MA==", + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.3.3.tgz", + "integrity": "sha512-NPQdeCU0Dv2z5fu+ULotpuq5yfCS1BzKUIPhNbP3YBfAMGJXbt2nS+sbTFu+qchaqWTD+H3JK++nRwr6XIcp6A==", "dependencies": { "esbuild": "^0.21.3", - "postcss": "^8.4.38", + "postcss": "^8.4.39", "rollup": "^4.13.0" }, "bin": { diff --git a/examples/trpc-app-router/package.json b/examples/trpc-app-router/package.json index 5c84c366..cac6a92e 100644 --- a/examples/trpc-app-router/package.json +++ b/examples/trpc-app-router/package.json @@ -7,6 +7,7 @@ "dev": "next dev", "lint": "next lint", "start": "next start", + "format": "prettier --write .", "typecheck": "tsc --noEmit" }, "dependencies": { diff --git a/examples/trpc-app-router/src/app/_components/create-post.tsx b/examples/trpc-app-router/src/app/_components/create-post.tsx index 280c2184..a4a3d22f 100644 --- a/examples/trpc-app-router/src/app/_components/create-post.tsx +++ b/examples/trpc-app-router/src/app/_components/create-post.tsx @@ -1,18 +1,24 @@ -"use client"; +'use client'; -import { useRouter } from "next/navigation"; -import { useState } from "react"; +import { useRouter } from 'next/navigation'; +import { useState } from 'react'; +import { useLogger } from 'next-axiom'; -import { api } from "~/trpc/react"; +import { api } from '~/trpc/react'; export function CreatePost() { const router = useRouter(); - const [name, setName] = useState(""); + const logger = useLogger(); + const [name, setName] = useState(''); const createPost = api.post.create.useMutation({ - onSuccess: () => { + onSuccess: (input, res) => { router.refresh(); - setName(""); + logger.info( + 'Sending a multiline log from the frontend\nThis is the second line', + { input, res }, + ); + setName(''); }, }); @@ -30,7 +36,7 @@ export function CreatePost() { onChange={(e) => setName(e.target.value)} /> ); diff --git a/examples/trpc-app-router/src/app/api/trpc/[trpc]/route.ts b/examples/trpc-app-router/src/app/api/trpc/[trpc]/route.ts index 4e263c9b..83865ffa 100644 --- a/examples/trpc-app-router/src/app/api/trpc/[trpc]/route.ts +++ b/examples/trpc-app-router/src/app/api/trpc/[trpc]/route.ts @@ -1,26 +1,28 @@ -import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; -import { withAxiomRouteHandler } from "next-axiom"; -import { type NextRequest } from "next/server"; +import { fetchRequestHandler } from '@trpc/server/adapters/fetch'; +import { withAxiomRouteHandler } from 'next-axiom'; +import { type NextRequest } from 'next/server'; -import { env } from "~/env.mjs"; -import { appRouter } from "~/server/api/root"; -import { createTRPCContext } from "~/server/api/trpc"; +import { appRouter } from '~/server/api/root'; +import { createTRPCContext } from '~/server/api/trpc'; + +export const dynamic = 'force-dynamic'; +export const revalidate = 0; const handler = withAxiomRouteHandler((req: NextRequest) => fetchRequestHandler({ - endpoint: "/api/trpc", + endpoint: '/api/trpc', req, router: appRouter, createContext: () => createTRPCContext({ req }), onError: - env.NODE_ENV === "development" + process.env.NODE_ENV === 'development' ? ({ path, error }) => { console.error( - `❌ tRPC failed on ${path ?? ""}: ${error.message}` + `❌ tRPC failed on ${path ?? ''}: ${error.message}`, ); } : undefined, - }) + }), ); export { handler as GET, handler as POST }; diff --git a/examples/trpc-app-router/src/app/layout.tsx b/examples/trpc-app-router/src/app/layout.tsx index 4b37732b..0f6832fa 100644 --- a/examples/trpc-app-router/src/app/layout.tsx +++ b/examples/trpc-app-router/src/app/layout.tsx @@ -1,18 +1,20 @@ -import { Inter } from "next/font/google"; -import { cookies } from "next/headers"; +import { Inter } from 'next/font/google'; +import { cookies } from 'next/headers'; -import { TRPCReactProvider } from "~/trpc/react"; +import { TRPCReactProvider } from '~/trpc/react'; const inter = Inter({ - subsets: ["latin"], + subsets: ['latin'], }); export const metadata = { - title: "Create T3 App", - description: "Generated by create-t3-app", - icons: [{ rel: "icon", url: "/favicon.ico" }], + title: 'Create T3 App', + description: 'Generated by create-t3-app', + icons: [{ rel: 'icon', url: '/favicon.ico' }], }; +export const dynamic = 'force-dynamic'; + export default function RootLayout({ children, }: { diff --git a/examples/trpc-app-router/src/app/page.tsx b/examples/trpc-app-router/src/app/page.tsx index 960bb0e8..f40099ca 100644 --- a/examples/trpc-app-router/src/app/page.tsx +++ b/examples/trpc-app-router/src/app/page.tsx @@ -1,8 +1,8 @@ -import { CreatePost } from "~/app/_components/create-post"; -import { api } from "~/trpc/server"; +import { CreatePost } from '~/app/_components/create-post'; +import { api } from '~/trpc/server'; export default async function Home() { - const hello = await api.post.hello.query({ text: "from tRPC" }); + const hello = await api.post.hello.query({ text: 'from tRPC' }); return (
@@ -10,7 +10,7 @@ export default async function Home() {

Create T3 App (App Router)

-

{hello ? hello.greeting : "Loading tRPC query..."}

+

{hello ? hello.greeting : 'Loading tRPC query...'}

diff --git a/examples/trpc-app-router/src/env.mjs b/examples/trpc-app-router/src/env.mjs index faf3efef..a6fd4b7c 100644 --- a/examples/trpc-app-router/src/env.mjs +++ b/examples/trpc-app-router/src/env.mjs @@ -1,5 +1,5 @@ -import { createEnv } from "@t3-oss/env-nextjs"; -import { z } from "zod"; +import { createEnv } from '@t3-oss/env-nextjs'; +import { z } from 'zod'; export const env = createEnv({ /** @@ -7,7 +7,7 @@ export const env = createEnv({ * isn't built with invalid env vars. */ server: { - NODE_ENV: z.enum(["development", "test", "production"]), + NODE_ENV: z.enum(['development', 'test', 'production']), }, /** diff --git a/examples/trpc-app-router/src/server/api/axiom-trpc.ts b/examples/trpc-app-router/src/server/api/axiom-trpc.ts index ed601196..c9cae0d9 100644 --- a/examples/trpc-app-router/src/server/api/axiom-trpc.ts +++ b/examples/trpc-app-router/src/server/api/axiom-trpc.ts @@ -1,7 +1,7 @@ -import { initTRPC } from "@trpc/server"; -import { type NextRequest } from "next/server"; -import { type AxiomRequest, Logger } from "next-axiom"; -import { type createTRPCContext } from "./trpc"; +import { initTRPC } from '@trpc/server'; +import { type NextRequest } from 'next/server'; +import { type AxiomRequest, Logger } from 'next-axiom'; +import { type createTRPCContext } from './trpc'; export type NextAxiomTRPCMiddlewareCtx = { /** @@ -34,7 +34,7 @@ export function createAxiomPlugin() { if (!isAxiomRequest(req)) { throw new Error( - "`nextAxiomTRPCMiddleware` could not find logger. Did you forget to wrap your route handler in `withAxiom`? See: TODO: link to docs" + '`nextAxiomTRPCMiddleware` could not find logger. Did you forget to wrap your route handler in `withAxiom`? See: TODO: link to docs', ); } diff --git a/examples/trpc-app-router/src/server/api/root.ts b/examples/trpc-app-router/src/server/api/root.ts index 3d629a7a..d371a724 100644 --- a/examples/trpc-app-router/src/server/api/root.ts +++ b/examples/trpc-app-router/src/server/api/root.ts @@ -1,5 +1,5 @@ -import { postRouter } from "~/server/api/routers/post"; -import { createTRPCRouter } from "~/server/api/trpc"; +import { postRouter } from '~/server/api/routers/post'; +import { createTRPCRouter } from '~/server/api/trpc'; /** * This is the primary router for your server. diff --git a/examples/trpc-app-router/src/server/api/routers/post.ts b/examples/trpc-app-router/src/server/api/routers/post.ts index 90f67755..9a178802 100644 --- a/examples/trpc-app-router/src/server/api/routers/post.ts +++ b/examples/trpc-app-router/src/server/api/routers/post.ts @@ -8,24 +8,31 @@ let post = { }; export const postRouter = createTRPCRouter({ - hello: publicProcedure.input(z.object({ text: z.string() })).query(({ ctx, input }) => { - ctx.log.info('Hello from `hello` procedure', { input }); - - return { - greeting: `Hello ${input.text}`, - }; - }), - - create: publicProcedure.input(z.object({ name: z.string().min(1) })).mutation(async ({ ctx, input }) => { - // simulate a slow db call - await new Promise((resolve) => setTimeout(resolve, 1000)); - - post = { id: ++post.id, name: input.name }; - - ctx.log.info('Hello from `create` procedure', { post }); - - return post; - }), + hello: publicProcedure + .input(z.object({ text: z.string() })) + .query(({ ctx, input }) => { + ctx.log.info('Hello from `hello` procedure', { input }); + + return { + greeting: `Hello ${input.text}`, + }; + }), + + create: publicProcedure + .input(z.object({ name: z.string().min(1) })) + .mutation(async ({ ctx, input }) => { + // simulate a slow db call + await new Promise((resolve) => setTimeout(resolve, 1000)); + + post = { id: ++post.id, name: input.name }; + + ctx.log.info( + 'Hello from `create` procedure\nSecond line from the `create` procedure', + { post }, + ); + + return post; + }), getLatest: publicProcedure.query(({ ctx }) => { ctx.log.info('Hello from `getLatest` procedure', { post }); diff --git a/examples/trpc-app-router/src/server/api/trpc.ts b/examples/trpc-app-router/src/server/api/trpc.ts index f05fc1fa..8c144eab 100644 --- a/examples/trpc-app-router/src/server/api/trpc.ts +++ b/examples/trpc-app-router/src/server/api/trpc.ts @@ -6,14 +6,14 @@ * TL;DR - This is where all the tRPC server stuff is created and plugged in. The pieces you will * need to use are documented accordingly near the end. */ -import { initTRPC } from "@trpc/server"; -import { type NextRequest } from "next/server"; -import superjson from "superjson"; -import { ZodError } from "zod"; +import { initTRPC } from '@trpc/server'; +import { type NextRequest } from 'next/server'; +import superjson from 'superjson'; +import { ZodError } from 'zod'; import { createAxiomPlugin, type NextAxiomTRPCMiddlewareCtx, -} from "./axiom-trpc"; +} from './axiom-trpc'; /** * 1. CONTEXT @@ -55,7 +55,7 @@ export const createTRPCContext = (opts: { req: NextRequest }) => { return { req: opts.req, axiomTRPCMeta: { - foo: "bar", + foo: 'bar', randomNumber: Math.random(), }, ...createInnerTRPCContext({ diff --git a/examples/trpc-app-router/src/trpc/react.tsx b/examples/trpc-app-router/src/trpc/react.tsx index beb3e03c..6f929f2a 100644 --- a/examples/trpc-app-router/src/trpc/react.tsx +++ b/examples/trpc-app-router/src/trpc/react.tsx @@ -1,12 +1,12 @@ -"use client"; +'use client'; -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -import { loggerLink, unstable_httpBatchStreamLink } from "@trpc/client"; -import { createTRPCReact } from "@trpc/react-query"; -import { useState } from "react"; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { loggerLink, unstable_httpBatchStreamLink } from '@trpc/client'; +import { createTRPCReact } from '@trpc/react-query'; +import { useState } from 'react'; -import { type AppRouter } from "~/server/api/root"; -import { getUrl, transformer } from "./shared"; +import { type AppRouter } from '~/server/api/root'; +import { getUrl, transformer } from './shared'; export const api = createTRPCReact(); @@ -22,20 +22,20 @@ export function TRPCReactProvider(props: { links: [ loggerLink({ enabled: (op) => - process.env.NODE_ENV === "development" || - (op.direction === "down" && op.result instanceof Error), + process.env.NODE_ENV === 'development' || + (op.direction === 'down' && op.result instanceof Error), }), unstable_httpBatchStreamLink({ url: getUrl(), headers() { return { cookie: props.cookies, - "x-trpc-source": "react", + 'x-trpc-source': 'react', }; }, }), ], - }) + }), ); return ( diff --git a/examples/trpc-app-router/src/trpc/server.ts b/examples/trpc-app-router/src/trpc/server.ts index db30f1e7..743e6f79 100644 --- a/examples/trpc-app-router/src/trpc/server.ts +++ b/examples/trpc-app-router/src/trpc/server.ts @@ -2,26 +2,26 @@ import { createTRPCProxyClient, loggerLink, unstable_httpBatchStreamLink, -} from "@trpc/client"; -import { cookies } from "next/headers"; +} from '@trpc/client'; +import { cookies } from 'next/headers'; -import { type AppRouter } from "~/server/api/root"; -import { getUrl, transformer } from "./shared"; +import { type AppRouter } from '~/server/api/root'; +import { getUrl, transformer } from './shared'; export const api = createTRPCProxyClient({ transformer, links: [ loggerLink({ enabled: (op) => - process.env.NODE_ENV === "development" || - (op.direction === "down" && op.result instanceof Error), + process.env.NODE_ENV === 'development' || + (op.direction === 'down' && op.result instanceof Error), }), unstable_httpBatchStreamLink({ url: getUrl(), headers() { return { cookie: cookies().toString(), - "x-trpc-source": "rsc", + 'x-trpc-source': 'rsc', }; }, }), diff --git a/examples/trpc-app-router/src/trpc/shared.ts b/examples/trpc-app-router/src/trpc/shared.ts index 46005045..bacb83ed 100644 --- a/examples/trpc-app-router/src/trpc/shared.ts +++ b/examples/trpc-app-router/src/trpc/shared.ts @@ -1,18 +1,18 @@ -import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server"; -import superjson from "superjson"; +import { type inferRouterInputs, type inferRouterOutputs } from '@trpc/server'; +import superjson from 'superjson'; -import { type AppRouter } from "~/server/api/root"; +import { type AppRouter } from '~/server/api/root'; export const transformer = superjson; function getBaseUrl() { - if (typeof window !== "undefined") return ""; + if (typeof window !== 'undefined') return ''; if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; return `http://localhost:${process.env.PORT ?? 3000}`; } export function getUrl() { - return getBaseUrl() + "/api/trpc"; + return getBaseUrl() + '/api/trpc'; } /** From 15dafc40421fc42d6ff29294c86afd6f813b4769 Mon Sep 17 00:00:00 2001 From: c-ehrlich Date: Wed, 3 Jul 2024 09:44:26 +0200 Subject: [PATCH 2/2] uninstall t3-env --- examples/trpc-app-router/package-lock.json | 34 +---------------- examples/trpc-app-router/package.json | 1 - examples/trpc-app-router/src/env.mjs | 44 ---------------------- 3 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 examples/trpc-app-router/src/env.mjs diff --git a/examples/trpc-app-router/package-lock.json b/examples/trpc-app-router/package-lock.json index f38286d3..36815f68 100644 --- a/examples/trpc-app-router/package-lock.json +++ b/examples/trpc-app-router/package-lock.json @@ -8,7 +8,6 @@ "name": "trpc-app-router", "version": "0.1.0", "dependencies": { - "@t3-oss/env-nextjs": "^0.7.3", "@tanstack/react-query": "^4.36.1", "@trpc/client": "^10.45.2", "@trpc/next": "^10.45.2", @@ -984,37 +983,6 @@ "tslib": "^2.4.0" } }, - "node_modules/@t3-oss/env-core": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/@t3-oss/env-core/-/env-core-0.7.3.tgz", - "integrity": "sha512-hhtj59TKC6TKVdwJ0CcbKsvkr9R8Pc/SNKd4IgGUIC9T9X6moB8EZZ3FTJdABA/h9UABCK4J+KsF8gzmvMvHPg==", - "peerDependencies": { - "typescript": ">=4.7.2", - "zod": "^3.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/@t3-oss/env-nextjs": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/@t3-oss/env-nextjs/-/env-nextjs-0.7.3.tgz", - "integrity": "sha512-90TNffS17vjkQwfYyMUb4Zw9yqHwFV40f78qFug4JiQa5+N6DydTdlLOpzOcj8Cna/qpAVDwMSypofF/TVQDuA==", - "dependencies": { - "@t3-oss/env-core": "0.7.3" - }, - "peerDependencies": { - "typescript": ">=4.7.2", - "zod": "^3.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "node_modules/@tanstack/query-core": { "version": "4.36.1", "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-4.36.1.tgz", @@ -5592,7 +5560,7 @@ "version": "5.5.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", - "devOptional": true, + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/examples/trpc-app-router/package.json b/examples/trpc-app-router/package.json index cac6a92e..9abd76b6 100644 --- a/examples/trpc-app-router/package.json +++ b/examples/trpc-app-router/package.json @@ -11,7 +11,6 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@t3-oss/env-nextjs": "^0.7.3", "@tanstack/react-query": "^4.36.1", "@trpc/client": "^10.45.2", "@trpc/next": "^10.45.2", diff --git a/examples/trpc-app-router/src/env.mjs b/examples/trpc-app-router/src/env.mjs deleted file mode 100644 index a6fd4b7c..00000000 --- a/examples/trpc-app-router/src/env.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import { createEnv } from '@t3-oss/env-nextjs'; -import { z } from 'zod'; - -export const env = createEnv({ - /** - * Specify your server-side environment variables schema here. This way you can ensure the app - * isn't built with invalid env vars. - */ - server: { - NODE_ENV: z.enum(['development', 'test', 'production']), - }, - - /** - * Specify your client-side environment variables schema here. This way you can ensure the app - * isn't built with invalid env vars. To expose them to the client, prefix them with - * `NEXT_PUBLIC_`. - */ - client: { - // NEXT_PUBLIC_CLIENTVAR: z.string(), - NEXT_PUBLIC_AXIOM_DATASET: z.string(), - NEXT_PUBLIC_AXIOM_TOKEN: z.string(), - }, - - /** - * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g. - * middlewares) or client-side so we need to destruct manually. - */ - runtimeEnv: { - NODE_ENV: process.env.NODE_ENV, - // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR, - NEXT_PUBLIC_AXIOM_DATASET: process.env.NEXT_PUBLIC_AXIOM_DATASET, - NEXT_PUBLIC_AXIOM_TOKEN: process.env.NEXT_PUBLIC_AXIOM_TOKEN, - }, - /** - * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. - * This is especially useful for Docker builds. - */ - skipValidation: !!process.env.SKIP_ENV_VALIDATION, - /** - * Makes it so that empty strings are treated as undefined. - * `SOME_VAR: z.string()` and `SOME_VAR=''` will throw an error. - */ - emptyStringAsUndefined: true, -});