### Run the development server Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/test-app/README.md Starts the application in development mode using pnpm. ```sh pnpm dev ``` -------------------------------- ### Install preview release Source: https://github.com/aidansunbury/trpc-ui/blob/main/CONTRIBUTING.md Install a specific preview release from a pull request for testing. ```sh pnpm add https://pkg.pr.new/aidansunbury/trpc-ui@40 ``` -------------------------------- ### Install dependencies Source: https://github.com/aidansunbury/trpc-ui/blob/main/CONTRIBUTING.md Install all dependencies for the monorepo packages. ```sh pnpm install ``` -------------------------------- ### Run development app Source: https://github.com/aidansunbury/trpc-ui/blob/main/CONTRIBUTING.md Commands to start the development application for local testing. ```sh pnpm dev:dev-app # Run at base of monorepo ``` ```sh cd packages/dev-app && pnpm dev # To run in the dev-app directory ``` -------------------------------- ### Configure environment variables Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/test-app/README.md Copies the example environment file to create a local configuration file. ```sh cp .env.example .env ``` -------------------------------- ### Install trpc-ui Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Install the package as a development dependency using your preferred package manager. ```sh npm install -D trpc-ui ``` ```sh yarn add -D trpc-ui ``` ```sh pnpm install -D trpc-ui ``` ```sh bun add -d trpc-ui ``` -------------------------------- ### Run test app Source: https://github.com/aidansunbury/trpc-ui/blob/main/CONTRIBUTING.md Commands to start the test application for showcasing new functionality. ```sh pnpm dev:test-app # Run at base of monorepo ``` ```sh cd packages/test-app && pnpm dev # To run in the test-app directory ``` -------------------------------- ### Superjson serialized input example Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Example of how to format complex data types for the superjson input editor. ```json { "json": { "id": "9007199254740991", "name": "John Doe", "createdAt": "2025-03-16T12:00:00.000Z", "tags": ["admin", "active"], "metadata": [["tier", "gold"]] }, "meta": { "values": { "id": ["bigint"], "createdAt": ["Date"], "tags": ["set"], "metadata": ["map"] } } } ``` -------------------------------- ### Define Zod schema with complex types Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Example of a Zod schema supporting data types not natively supported by JSON, such as BigInt, Date, Set, and Map. ```ts import { z } from "zod"; const UserSchema = z.object({ id: z.bigint(), name: z.string(), createdAt: z.date(), tags: z.set(z.string()), metadata: z.map(z.string(), z.string()), }); type User = z.infer; const user: User = { id: BigInt("9007199254740991"), name: "John Doe", createdAt: new Date("2025-03-16T12:00:00Z"), tags: new Set(["admin", "active"]), metadata: new Map([ ["lastLogin", new Date("2025-03-15T08:30:00Z")], ["loginCount", 42], ["isPremium", true], ["tier", "gold"], ]), }; ``` -------------------------------- ### Configure tRPC instance with TRPCPanelMeta Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Initialize the tRPC instance with the TRPCPanelMeta type to enable documentation support. ```ts import { initTRPC } from "@trpc/server"; import { TRPCPanelMeta } from "trpc-ui"; const t = initTRPC.meta().create(); ``` -------------------------------- ### Add procedure description via meta Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Use the meta property within a procedure definition to provide a description that appears in the UI. ```ts export const appRouter = t.router({ sayHello: t.procedure .meta({ /* 👉 */ description: "This shows in the panel." }) .input(z.object({ name: z.string() })) .query(({ input }) => { return { greeting: `Hello ${input.name}!` }; }); }); ``` -------------------------------- ### Document input parameters with Zod Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Use Zod's .describe() method on input schemas to document individual parameters. ```ts export const appRouter = t.router({ sayHello: t.procedure .input(z.object({ name: z.string().describe("The name to say hello too.") })) .query(({ input }) => { return { greeting: `Hello ${input.name}!` }; }); }); ``` -------------------------------- ### Lint and format code Source: https://github.com/aidansunbury/trpc-ui/blob/main/CONTRIBUTING.md Commands to check or fix code style and linting errors using Biome. ```bash pnpm biome:check ``` ```bash pnpm biome:check:fix ``` -------------------------------- ### Run parser tests Source: https://github.com/aidansunbury/trpc-ui/blob/main/CONTRIBUTING.md Execute Jest tests for the parser logic. ```sh pnpm test:panel ``` -------------------------------- ### Use Markdown in procedure descriptions Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Markdown syntax can be included in the description string for formatted text and links. ```ts .meta({ /* 👉 */ description: "# H1 heading\nSome normal, or maybe **bold** text below, and a [link](https://trpc.io/docs) to something important" }) ``` -------------------------------- ### Render Panel in Next.js App Router Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Create a route handler to serve the tRPC panel in a Next.js application using the App Router. ```ts import { NextResponse } from "next/server"; import { appRouter } from "~/server/api/root"; export async function GET() { if (process.env.NODE_ENV !== "development") { return new NextResponse("Not Found", { status: 404 }); } const { renderTrpcPanel } = await import("trpc-ui"); return new NextResponse( renderTrpcPanel(appRouter, { url: "/api/trpc", // Default trpc route in nextjs transformer: "superjson", // Enabled by default with create-t3-app }), { status: 200, headers: [["Content-Type", "text/html"] as [string, string]], } ); } ``` -------------------------------- ### Render Panel in Express Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Render the tRPC panel as a text response in an Express application, ensuring it is only available in development environments. ```js app.use("/panel", (_, res) => { if (process.env.NODE_ENV !== "development") { return res.status(404).send("Not Found"); } // Dynamically import renderTrpcPanel only in development const { renderTrpcPanel } = await import("trpc-ui"); return res.send( renderTrpcPanel(myTrpcRouter, { url: "http://localhost:4000/trpc", // Base url of your trpc server meta: { title: "My Backend Title", description: "This is a description of my API, which supports [markdown](https://en.wikipedia.org/wiki/Markdown).", }, }) ); }); ``` -------------------------------- ### Render Panel in Next.js Pages Router Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Create an API route to serve the tRPC panel in a Next.js application using the Pages Router. ```ts import type { NextApiRequest, NextApiResponse } from "next"; import { appRouter } from "../../server/api/root"; export default async function handler(_: NextApiRequest, res: NextApiResponse) { if (process.env.NODE_ENV !== "development") { return res.status(404).send("Not Found"); } const { renderTrpcPanel } = await import("trpc-ui"); res.status(200).send( renderTrpcPanel(appRouter, { url: "/api/trpc", transformer: "superjson", }) ); } ``` -------------------------------- ### Configure superjson in trpc-ui Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md Pass the transformer option to the renderTrpcPanel function to enable superjson support. ```js app.use("/panel", (_, res) => { return res.send( renderTrpcPanel(myTrpcRouter, { url: "http://localhost:4000/trpc", transformer: "superjson", }) ); }); ``` -------------------------------- ### Superjson input structure Source: https://github.com/aidansunbury/trpc-ui/blob/main/packages/trpc-ui/README.md The required JSON structure for superjson inputs, separating the data under the json key and metadata under the meta key. ```json { "json": {}, "meta": { "values": {} } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.