From 4ed504e1e9530a5793fb0f9ff4383d273f183c88 Mon Sep 17 00:00:00 2001 From: Mahdi Boomeri Date: Fri, 21 Oct 2022 16:56:09 +0330 Subject: [PATCH] fix: h3 CompatibilityEvent --- README.md | 4 ++-- playground/server/trpc/index.ts | 4 ++-- recipes/authorization.md | 4 ++-- src/runtime/api.ts | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d061bc6..11d553d 100644 --- a/README.md +++ b/README.md @@ -120,14 +120,14 @@ trpc-nuxt accepts the following options exposed under `~/server/trpc/index.ts`: ```ts import * as trpc from '@trpc/server' import type { inferAsyncReturnType } from '@trpc/server' -import type { CompatibilityEvent } from 'h3' +import type { H3Event } from 'h3' import type { OnErrorPayload } from 'trpc-nuxt/api' export const router = trpc.router>() // Optional // https://trpc.io/docs/context -export const createContext = (event: CompatibilityEvent) => { +export const createContext = (event: H3Event) => { // ... return { /** context data */ diff --git a/playground/server/trpc/index.ts b/playground/server/trpc/index.ts index 2a72244..fab7a96 100644 --- a/playground/server/trpc/index.ts +++ b/playground/server/trpc/index.ts @@ -1,7 +1,7 @@ import * as trpc from '@trpc/server' import type { inferAsyncReturnType } from '@trpc/server' import { z } from 'zod' -import type { CompatibilityEvent } from 'h3' +import type { H3Event } from 'h3' const baseURL = 'https://jsonplaceholder.typicode.com' @@ -37,7 +37,7 @@ export const router = trpc.router() }, }) -export async function createContext(event: CompatibilityEvent) { +export async function createContext(event: H3Event) { // Create your context based on the request object // Will be available as `ctx` in all your resolvers diff --git a/recipes/authorization.md b/recipes/authorization.md index ab09f89..3d83b83 100644 --- a/recipes/authorization.md +++ b/recipes/authorization.md @@ -7,11 +7,11 @@ The `createContext`-function is called for each incoming request so here you can ```ts // ~/server/trpc/index.ts import type { inferAsyncReturnType } from '@trpc/server' -import type { CompatibilityEvent } from 'h3' +import type { H3Event } from 'h3' import { decodeAndVerifyJwtToken } from '~/somewhere/in/your/app/utils' // The app's context - is generated for each incoming request -export async function createContext({ req }: CompatibilityEvent) { +export async function createContext({ req }: H3Event) { // Create your context based on the request object // Will be available as `ctx` in all your resolvers diff --git a/src/runtime/api.ts b/src/runtime/api.ts index 53266a9..c2c4562 100644 --- a/src/runtime/api.ts +++ b/src/runtime/api.ts @@ -8,13 +8,13 @@ import type { inferRouterError, } from '@trpc/server' import { createURL } from 'ufo' -import type { CompatibilityEvent } from 'h3' +import type { H3Event } from 'h3' import { defineEventHandler, isMethod, readBody } from 'h3' import type { TRPCResponse } from '@trpc/server/dist/declarations/src/rpc' type MaybePromise = T | Promise -export type CreateContextFn = (event: CompatibilityEvent) => MaybePromise> +export type CreateContextFn = (event: H3Event) => MaybePromise> export interface ResponseMetaFnPayload { data: TRPCResponse>[] @@ -30,7 +30,7 @@ export interface OnErrorPayload { error: TRPCError type: ProcedureType | 'unknown' path: string | undefined - req: CompatibilityEvent['req'] + req: H3Event['req'] input: unknown ctx: undefined | inferRouterContext }