diff --git a/package-lock.json b/package-lock.json index 97220d3..1f56439 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "create-sidebase", - "version": "0.2.5", + "version": "0.2.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "create-sidebase", - "version": "0.2.5", + "version": "0.2.6", "license": "MIT", "dependencies": { "@nuxt/schema": "^3.0.0", diff --git a/package.json b/package.json index cfedb4a..3e05249 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-sidebase", - "version": "0.2.5", + "version": "0.2.6", "description": "The productive way to build fullstack Nuxt 3 applications, like create-t3-app but for Nuxt.", "scripts": { "dev": "vite-node src/", diff --git a/src/steps/2.addModules/moduleConfigs.ts b/src/steps/2.addModules/moduleConfigs.ts index d449110..768bc9b 100644 --- a/src/steps/2.addModules/moduleConfigs.ts +++ b/src/steps/2.addModules/moduleConfigs.ts @@ -108,8 +108,11 @@ const nuxtTrpcRootConfig = `/** */ import { initTRPC } from '@trpc/server' import { Context } from '~/server/trpc/context' +import superjson from 'superjson'; -const t = initTRPC.context().create() +const t = initTRPC.context().create({ + transformer: superjson, +}) /** * Unprotected procedure @@ -132,6 +135,7 @@ export const appRouter = router({ .query(({ input }) => { return { greeting: \`hello \${input?.text ?? "world"}\`, + time: new Date() } }), }) @@ -141,12 +145,24 @@ export type AppRouter = typeof appRouter ` const nuxtTrpcContext = `import { inferAsyncReturnType } from '@trpc/server' +import type { H3Event } from 'h3' /** * Creates context for an incoming request * @link https://trpc.io/docs/context */ -export const createContext = () => {} +export async function createContext(event: H3Event) { + /** + * Add any trpc-request context here. E.g., you could add \`prisma\` like this if you've set it up: + * \`\`\` + * const prisma = usePrisma(event) + * return { prisma } + * \`\`\` + * + * You can import \`usePrisma\` like this: \`import { usePrisma } from '@sidebase/nuxt-prisma'\` + */ + return {} +} export type Context = inferAsyncReturnType; ` @@ -164,6 +180,7 @@ export default createNuxtApiHandler({ const nuxtTrpcPlugin = `import { createTRPCNuxtClient, httpBatchLink } from "trpc-nuxt/client" import type { AppRouter } from "~/server/trpc/routers" +import superjson from 'superjson'; export default defineNuxtPlugin(() => { /** @@ -171,6 +188,7 @@ export default defineNuxtPlugin(() => { * built on top of \`useAsyncData\`. */ const client = createTRPCNuxtClient({ + transformer: superjson, links: [ httpBatchLink({ url: "/api/trpc", @@ -194,7 +212,8 @@ const hello = await $client.hello.useQuery({ text: 'client' }) ` @@ -223,17 +242,17 @@ export const moduleConfigs: Record = { dependencies: [ { name: "prisma", - version: "^4.7.1", + version: "^4.8.0", isDev: true }, { name: "@prisma/client", - version: "^4.7.1", + version: "^4.8.0", isDev: false }, { name: "@sidebase/nuxt-prisma", - version: "^0.1.0", + version: "^0.1.2", isDev: false } ], @@ -297,6 +316,10 @@ export const moduleConfigs: Record = { name: "zod", version: "^3.20.2", isDev: false + }, { + name: "superjson", + version: "^1.12.1", + isDev: false }], nuxtConfig: { build: { diff --git a/src/steps/6.addReadme.ts b/src/steps/6.addReadme.ts index 44fc8f6..61fdd9f 100644 --- a/src/steps/6.addReadme.ts +++ b/src/steps/6.addReadme.ts @@ -50,7 +50,7 @@ This is a straight-forward setup with minimal templating and scaffolding. The op Some tasks you should probably do in the beginning are: - [ ] replace this generic README with a more specific one - [ ] install the Vue Volar extension -- [ ] enable [Volar takeover mode](https://nuxt.com/docs/getting-started/installation#prerequisites) +- [ ] enable [Volar takeover mode](https://nuxt.com/docs/getting-started/installation#prerequisites) to ensure a smooth editor setup ${tasksPostInstall.join("\n")} ### Setup