Skip to content

Commit

Permalink
fix: h3 CompatibilityEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdiboomeri committed Oct 21, 2022
1 parent 9274771 commit 4ed504e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<inferAsyncReturnType<typeof createContext>>()

// Optional
// https://trpc.io/docs/context
export const createContext = (event: CompatibilityEvent) => {
export const createContext = (event: H3Event) => {
// ...
return {
/** context data */
Expand Down
4 changes: 2 additions & 2 deletions playground/server/trpc/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -37,7 +37,7 @@ export const router = trpc.router<Context>()
},
})

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

Expand Down
4 changes: 2 additions & 2 deletions recipes/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = T | Promise<T>

export type CreateContextFn<TRouter extends AnyRouter> = (event: CompatibilityEvent) => MaybePromise<inferRouterContext<TRouter>>
export type CreateContextFn<TRouter extends AnyRouter> = (event: H3Event) => MaybePromise<inferRouterContext<TRouter>>

export interface ResponseMetaFnPayload<TRouter extends AnyRouter> {
data: TRPCResponse<unknown, inferRouterError<TRouter>>[]
Expand All @@ -30,7 +30,7 @@ export interface OnErrorPayload<TRouter extends AnyRouter> {
error: TRPCError
type: ProcedureType | 'unknown'
path: string | undefined
req: CompatibilityEvent['req']
req: H3Event['req']
input: unknown
ctx: undefined | inferRouterContext<TRouter>
}
Expand Down

0 comments on commit 4ed504e

Please sign in to comment.