eslint fixes

This commit is contained in:
wobsoriano
2022-11-05 11:56:14 -07:00
parent e9081d00ad
commit e359702c41
7 changed files with 25 additions and 25 deletions

View File

@@ -3,25 +3,25 @@ import { createTRPCNuxtProxyClient } from 'trpc-nuxt/client'
import superjson from 'superjson' import superjson from 'superjson'
import type { AppRouter } from '~~/server/trpc/routers' import type { AppRouter } from '~~/server/trpc/routers'
export default defineNuxtPlugin((nuxtApp) => { export default defineNuxtPlugin(() => {
const client = createTRPCNuxtProxyClient<AppRouter>({ const client = createTRPCNuxtProxyClient<AppRouter>({
transformer: superjson, transformer: superjson,
links: [ links: [
// adds pretty logs to your console in development and logs errors in production // adds pretty logs to your console in development and logs errors in production
loggerLink({ loggerLink({
enabled: opts => enabled: opts =>
process.env.NODE_ENV === 'development' process.env.NODE_ENV === 'development' ||
|| (opts.direction === 'down' && opts.result instanceof Error), (opts.direction === 'down' && opts.result instanceof Error)
}), }),
httpBatchLink({ httpBatchLink({
url: 'http://localhost:3000/api/trpc', url: 'http://localhost:3000/api/trpc'
}), })
], ]
}) })
return { return {
provide: { provide: {
client, client
}, }
} }
}) })

View File

@@ -8,12 +8,12 @@ export default createNuxtApiHandler({
* @link https://trpc.io/docs/context * @link https://trpc.io/docs/context
*/ */
createContext, createContext,
onError({ error }) { onError ({ error }) {
if (error.code === 'INTERNAL_SERVER_ERROR') { if (error.code === 'INTERNAL_SERVER_ERROR') {
// send to bug reporting // send to bug reporting
console.error('Something went wrong', error) console.error('Something went wrong', error)
} }
}, }
/** /**
* @link https://trpc.io/docs/caching#api-response-caching * @link https://trpc.io/docs/caching#api-response-caching
*/ */

View File

@@ -8,8 +8,8 @@ export type Context = inferAsyncReturnType<typeof createContext>
* Creates context for an incoming request * Creates context for an incoming request
* @link https://trpc.io/docs/context * @link https://trpc.io/docs/context
*/ */
export async function createContext( export function createContext (
opts: H3Event, opts: H3Event
) { ) {
// for API-response caching see https://trpc.io/docs/caching // for API-response caching see https://trpc.io/docs/caching

View File

@@ -4,7 +4,7 @@ import { userRouter } from './user'
export const appRouter = router({ export const appRouter = router({
todo: todoRouter, todo: todoRouter,
user: userRouter, user: userRouter
}) })
export type AppRouter = typeof appRouter export type AppRouter = typeof appRouter

View File

@@ -7,7 +7,7 @@ const TodoShape = z.object({
userId: z.number(), userId: z.number(),
id: z.number(), id: z.number(),
title: z.string(), title: z.string(),
completed: z.boolean(), completed: z.boolean()
}) })
export type Todo = z.infer<typeof TodoShape> export type Todo = z.infer<typeof TodoShape>
@@ -27,7 +27,7 @@ export const todoRouter = router({
.mutation((req) => { .mutation((req) => {
return $fetch<Todo>(`${baseURL}/todos`, { return $fetch<Todo>(`${baseURL}/todos`, {
method: 'POST', method: 'POST',
body: req.input, body: req.input
}) })
}), })
}) })

View File

@@ -7,7 +7,7 @@ const UserShape = z.object({
id: z.number(), id: z.number(),
name: z.string(), name: z.string(),
username: z.string(), username: z.string(),
email: z.string(), email: z.string()
}) })
export type User = z.infer<typeof UserShape> export type User = z.infer<typeof UserShape>
@@ -27,7 +27,7 @@ export const userRouter = router({
.mutation((req) => { .mutation((req) => {
return $fetch<User>(`${baseURL}/users`, { return $fetch<User>(`${baseURL}/users`, {
method: 'POST', method: 'POST',
body: req.input, body: req.input
}) })
}), })
}) })

View File

@@ -5,19 +5,19 @@ import type { Context } from './context'
const t = initTRPC.context<Context>().create({ const t = initTRPC.context<Context>().create({
transformer: superjson, transformer: superjson,
errorFormatter({ shape, error }) { errorFormatter ({ shape, error }) {
return { return {
...shape, ...shape,
data: { data: {
...shape.data, ...shape.data,
zodError: zodError:
error.code === 'BAD_REQUEST' error.code === 'BAD_REQUEST' &&
&& error.cause instanceof ZodError error.cause instanceof ZodError
? error.cause!.flatten() ? error.cause!.flatten()
: null, : null
}, }
} }
}, }
}) })
/** /**