From 5c06bd292f972558ec8b1d1af4d1dc581a184089 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 3 Oct 2024 12:21:22 +0200 Subject: [PATCH] fix(core): Update trpc middleware types (#13859) --- .../test-applications/nextjs-t3/src/server/api/trpc.ts | 10 +++++----- .../test-applications/node-express/src/app.ts | 4 +--- packages/core/src/trpc.ts | 8 ++++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/nextjs-t3/src/server/api/trpc.ts b/dev-packages/e2e-tests/test-applications/nextjs-t3/src/server/api/trpc.ts index 0bc74b51243e..779fb43a78a5 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-t3/src/server/api/trpc.ts +++ b/dev-packages/e2e-tests/test-applications/nextjs-t3/src/server/api/trpc.ts @@ -70,8 +70,8 @@ export const createCallerFactory = t.createCallerFactory; */ export const createTRPCRouter = t.router; -const sentryMiddleware = Sentry.trpcMiddleware({ - attachRpcInput: true, -}); - -export const publicProcedure = t.procedure.use(async opts => sentryMiddleware(opts)); +export const publicProcedure = t.procedure.use( + Sentry.trpcMiddleware({ + attachRpcInput: true, + }), +); diff --git a/dev-packages/e2e-tests/test-applications/node-express/src/app.ts b/dev-packages/e2e-tests/test-applications/node-express/src/app.ts index 4fa07d82ff6d..de240b761df0 100644 --- a/dev-packages/e2e-tests/test-applications/node-express/src/app.ts +++ b/dev-packages/e2e-tests/test-applications/node-express/src/app.ts @@ -105,9 +105,7 @@ Sentry.addEventProcessor(event => { export const t = initTRPC.context().create(); -const sentryMiddleware = Sentry.trpcMiddleware({ attachRpcInput: true }); - -const procedure = t.procedure.use(async opts => sentryMiddleware(opts)); +const procedure = t.procedure.use(Sentry.trpcMiddleware({ attachRpcInput: true })); export const appRouter = t.router({ getSomething: procedure.input(z.string()).query(opts => { diff --git a/packages/core/src/trpc.ts b/packages/core/src/trpc.ts index a3101d793a31..366a0ba9aa62 100644 --- a/packages/core/src/trpc.ts +++ b/packages/core/src/trpc.ts @@ -33,11 +33,15 @@ function captureIfError(nextResult: unknown): void { } } +type SentryTrpcMiddleware = T extends Promise ? T : Promise; + /** * Sentry tRPC middleware that captures errors and creates spans for tRPC procedures. */ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) { - return async function (opts: SentryTrpcMiddlewareArguments): Promise { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return async function (opts: SentryTrpcMiddlewareArguments): SentryTrpcMiddleware { const { path, type, next, rawInput, getRawInput } = opts; const client = getClient(); @@ -85,6 +89,6 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) { throw e; } }, - ); + ) as SentryTrpcMiddleware; }; }