import type { MiddlewareResult } from '@trpc/server'
import { initTRPC } from '@trpc/server'
import type { Context } from '../context'
type Action<C, R> = (opts: {
ctx: C
result: MiddlewareResult<R>
}) => unknown | Promise<unknown>
export function post<C, R>(action: Action<C, R>) {
const t = initTRPC.context<Pick<Context, 'get'>>().create()
return t.procedure
.use(async ({ ctx, next }) => {
const result = await next()
action({ ctx, result })
return result
})
}
import type { MiddlewareResult } from '@trpc/server'
import { initTRPC } from '@trpc/server'
import type { Context } from '../context'
type Action<C, R> = (opts: {
ctx: C
result: MiddlewareResult<R>
}) => unknown | Promise<unknown>
export function post<C, R>(action: Action<C, R>) {
const t = initTRPC.context<Pick<Context, 'get'>>().create()
return t.procedure
.use(async ({ ctx, next }) => {
const result = await next()
action({ ctx, result })
return result
})
}