diff --git a/examples/custom/.gitignore b/examples/custom/.gitignore deleted file mode 100644 index d233591..0000000 --- a/examples/custom/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -node_modules -*.log* -.nuxt -.nitro -.cache -.output -.env \ No newline at end of file diff --git a/examples/custom/README.md b/examples/custom/README.md deleted file mode 100644 index 7257bce..0000000 --- a/examples/custom/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# dev playground - -## Setup - -Make sure to install the dependencies: - -```bash -pnpm install -``` - -## Development Server - -Start the development server on http://localhost:3000 - -```bash -pnpm dev -``` - -## Production - -Build the application for production: - -```bash -pnpm build -``` - -Locally preview production build: - -```bash -pnpm preview -``` diff --git a/examples/custom/app.vue b/examples/custom/app.vue deleted file mode 100644 index 2b1be09..0000000 --- a/examples/custom/app.vue +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/examples/custom/nuxt.config.ts b/examples/custom/nuxt.config.ts deleted file mode 100644 index 21768db..0000000 --- a/examples/custom/nuxt.config.ts +++ /dev/null @@ -1,7 +0,0 @@ -// https://v3.nuxtjs.org/api/configuration/nuxt.config -export default defineNuxtConfig({ - modules: ['trpc-nuxt'], - trpc: { - enableFileRouting: false - } -}) diff --git a/examples/custom/package.json b/examples/custom/package.json deleted file mode 100644 index 8dc9eae..0000000 --- a/examples/custom/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "custom", - "private": true, - "scripts": { - "build": "nuxt build", - "dev": "nuxt dev", - "generate": "nuxt generate", - "preview": "nuxt preview" - }, - "dependencies": { - "@trpc/client": "10.0.0-rc.4", - "@trpc/server": "10.0.0-rc.4", - "superjson": "^1.11.0", - "trpc-nuxt": "workspace:*", - "zod": "^3.19.1" - }, - "devDependencies": { - "nuxt": "3.0.0-rc.13" - } -} diff --git a/examples/custom/pages/index.vue b/examples/custom/pages/index.vue deleted file mode 100644 index d3c3baa..0000000 --- a/examples/custom/pages/index.vue +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - Loading... - - - Error: {{ error.data.code }} - - - - - - Title: {{ t.title }} - - - - - Add Todo - - refresh()"> - Refresh - - - - - - diff --git a/examples/custom/pages/todo/[id].vue b/examples/custom/pages/todo/[id].vue deleted file mode 100644 index 5c251cc..0000000 --- a/examples/custom/pages/todo/[id].vue +++ /dev/null @@ -1,19 +0,0 @@ - - - - - Loading... - - - {{ error.data.code }} - - - ID: {{ todo?.id }} - Title: {{ todo?.title }} - Completed: {{ todo?.completed }} - - diff --git a/examples/custom/plugins/trpc-client.ts b/examples/custom/plugins/trpc-client.ts deleted file mode 100644 index 93e715d..0000000 --- a/examples/custom/plugins/trpc-client.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { httpBatchLink, loggerLink } from '@trpc/client' -import { createTRPCNuxtProxyClient } from 'trpc-nuxt/client' -import superjson from 'superjson' -import { AppRouter } from '~~/server/trpc/routers' - -export default defineNuxtPlugin(() => { - const client = createTRPCNuxtProxyClient({ - transformer: superjson, - links: [ - // adds pretty logs to your console in development and logs errors in production - loggerLink({ - enabled: opts => - process.env.NODE_ENV === 'development' || - (opts.direction === 'down' && opts.result instanceof Error) - }), - httpBatchLink({ - url: 'http://localhost:3000/api/trpc' - }) - ] - }) - - return { - provide: { - client - } - } -}) diff --git a/examples/custom/server/api/trpc/[trpc].ts b/examples/custom/server/api/trpc/[trpc].ts deleted file mode 100644 index 8fde704..0000000 --- a/examples/custom/server/api/trpc/[trpc].ts +++ /dev/null @@ -1,23 +0,0 @@ -import { createNuxtApiHandler } from 'trpc-nuxt/handler' -import { appRouter } from '@/server/trpc/routers' -import { createContext } from '@/server/trpc/context' - -export default createNuxtApiHandler({ - router: appRouter, - /** - * @link https://trpc.io/docs/context - */ - createContext, - onError ({ error }) { - if (error.code === 'INTERNAL_SERVER_ERROR') { - // send to bug reporting - console.error('Something went wrong', error) - } - } - /** - * @link https://trpc.io/docs/caching#api-response-caching - */ - // responseMeta() { - // // ... - // }, -}) diff --git a/examples/custom/server/trpc/context.ts b/examples/custom/server/trpc/context.ts deleted file mode 100644 index cd78756..0000000 --- a/examples/custom/server/trpc/context.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import type { inferAsyncReturnType } from '@trpc/server' -import type { H3Event } from 'h3' - -export type Context = inferAsyncReturnType - -/** - * Creates context for an incoming request - * @link https://trpc.io/docs/context - */ -export function createContext ( - opts: H3Event -) { - // for API-response caching see https://trpc.io/docs/caching - - return {} -} diff --git a/examples/custom/server/trpc/routers/index.ts b/examples/custom/server/trpc/routers/index.ts deleted file mode 100644 index b552e46..0000000 --- a/examples/custom/server/trpc/routers/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { router } from '../trpc' -import { todoRouter } from './todo' -import { userRouter } from './user' - -export const appRouter = router({ - todo: todoRouter, - user: userRouter -}) - -export type AppRouter = typeof appRouter diff --git a/examples/custom/server/trpc/routers/todo.ts b/examples/custom/server/trpc/routers/todo.ts deleted file mode 100644 index 5f6ef0e..0000000 --- a/examples/custom/server/trpc/routers/todo.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { z } from 'zod' -import { publicProcedure, router } from '../trpc' - -const baseURL = 'https://jsonplaceholder.typicode.com' - -const TodoShape = z.object({ - userId: z.number(), - id: z.number(), - title: z.string(), - completed: z.boolean() -}) - -export type Todo = z.infer - -export const todoRouter = router({ - getTodos: publicProcedure - .query(() => { - return $fetch(`${baseURL}/todos`) - }), - getTodo: publicProcedure - .input(z.number()) - .query((req) => { - return $fetch(`${baseURL}/todos/${req.input}`) - }), - addTodo: publicProcedure - .input(TodoShape) - .mutation((req) => { - return $fetch(`${baseURL}/todos`, { - method: 'POST', - body: req.input - }) - }) -}) diff --git a/examples/custom/server/trpc/routers/user.ts b/examples/custom/server/trpc/routers/user.ts deleted file mode 100644 index b3b9486..0000000 --- a/examples/custom/server/trpc/routers/user.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { z } from 'zod' -import { publicProcedure, router } from '../trpc' - -const baseURL = 'https://jsonplaceholder.typicode.com' - -const UserShape = z.object({ - id: z.number(), - name: z.string(), - username: z.string(), - email: z.string() -}) - -export type User = z.infer - -export const userRouter = router({ - getUsers: publicProcedure - .query(() => { - return $fetch(`${baseURL}/users`) - }), - getUser: publicProcedure - .input(z.number()) - .query((req) => { - return $fetch(`${baseURL}/users/${req.input}`) - }), - addUser: publicProcedure - .input(UserShape) - .mutation((req) => { - return $fetch(`${baseURL}/users`, { - method: 'POST', - body: req.input - }) - }) -}) diff --git a/examples/custom/server/trpc/trpc.ts b/examples/custom/server/trpc/trpc.ts deleted file mode 100644 index 600f632..0000000 --- a/examples/custom/server/trpc/trpc.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { initTRPC } from '@trpc/server' -import superjson from 'superjson' -import { ZodError } from 'zod' -import type { Context } from './context' - -const t = initTRPC.context().create({ - transformer: superjson, - errorFormatter ({ shape, error }) { - return { - ...shape, - data: { - ...shape.data, - zodError: - error.code === 'BAD_REQUEST' && - error.cause instanceof ZodError - ? error.cause!.flatten() - : null - } - } - } -}) - -/** - * Create a router - * @see https://trpc.io/docs/v10/router - */ -export const router = t.router - -/** - * Create an unprotected procedure - * @see https://trpc.io/docs/v10/procedures - **/ -export const publicProcedure = t.procedure - -/** - * @see https://trpc.io/docs/v10/middlewares - */ -export const middleware = t.middleware - -/** - * @see https://trpc.io/docs/v10/merging-routers - */ -export const mergeRouters = t.mergeRouters diff --git a/examples/custom/tsconfig.json b/examples/custom/tsconfig.json deleted file mode 100644 index a7bfa18..0000000 --- a/examples/custom/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - // https://v3.nuxtjs.org/concepts/typescript - "extends": "./.nuxt/tsconfig.json" -} diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index ef2dea3..677997a 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -1,4 +1,7 @@ // https://v3.nuxtjs.org/api/configuration/nuxt.config export default defineNuxtConfig({ - modules: ['trpc-nuxt'] + modules: ['trpc-nuxt'], + trpc: { + enableFileRouting: true + } }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e3846e4..77c14d0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,23 +63,6 @@ importers: nuxt: 3.0.0-rc.13 vue-plausible: 1.3.2 - examples/custom: - specifiers: - '@trpc/client': 10.0.0-rc.4 - '@trpc/server': 10.0.0-rc.4 - nuxt: 3.0.0-rc.13 - superjson: ^1.11.0 - trpc-nuxt: workspace:* - zod: ^3.19.1 - dependencies: - '@trpc/client': 10.0.0-rc.4_@trpc+server@10.0.0-rc.4 - '@trpc/server': 10.0.0-rc.4 - superjson: 1.11.0 - trpc-nuxt: link:../.. - zod: 3.19.1 - devDependencies: - nuxt: 3.0.0-rc.13 - playground: specifiers: '@trpc/client': 10.0.0-rc.4