T
tRPC

Is there a way to extract a procedure signature?

Is there a way to extract a procedure signature?

Zzomars10/17/2023
I'm looking into extracting certain handlers into functions to keep certain procedures more manageable. Is there a way to define a function that expects the same signature as a procedure? Here's an example of what I'm trying to achieve.
No description
Nnlucas10/17/2023
Best to keep it simple and request exactly what’s needed rather than coupling it to trpc. The code is more reusable that way
AKAlex / KATT 🐱10/17/2023
i'd probably make it independent of trpc too - perhaps even extracting the zod schema of the input like
const schema = z.object({ foo: z.string() })

function myFn(opts: {
input: typeof schema['_output']
user: { id: string }
}) {
/// ..
}

export const adminRouter = router({
toggleFeatureFlag: authedAdminProcedure.input(schema).mutation(async opts => { })
const schema = z.object({ foo: z.string() })

function myFn(opts: {
input: typeof schema['_output']
user: { id: string }
}) {
/// ..
}

export const adminRouter = router({
toggleFeatureFlag: authedAdminProcedure.input(schema).mutation(async opts => { })
another useful pattern in cases like this where you want to pass data deeply is to use async local storage in node i use it for logging and making sure that all logs, no matter how deep, have correlation ids example:
import { AsyncLocalStorage } from 'node:async_hooks';

interface LogStore {
correlationId: string;
user: {
id: string | null;
email: string | null;
} | null;
}
export const logStorage = new AsyncLocalStorage<LogStore>();
import { AsyncLocalStorage } from 'node:async_hooks';

interface LogStore {
correlationId: string;
user: {
id: string | null;
email: string | null;
} | null;
}
export const logStorage = new AsyncLocalStorage<LogStore>();
and i have a HOC around my API requests to attach data to the storage you could potentially do an AdminStore, call adminStorge.run() in the authedAdminProcedure and then those things will just magically exist anywhere down the stack of those functions
Zzomars10/18/2023
Some real wizardry in here Thanks 🙏
AKAlex / KATT 🐱10/18/2023
Don't hesitate to reach out if you wanna pair on anything You got my cal ☺

Looking for more? Join the community!

T
tRPC

Is there a way to extract a procedure signature?

Join Server
Recommended Posts
Is there a pattern for omitting certain types of errors from being returned in the API responseI'd prefer not to expose the ORM queries being used in my resolver. I'm already providing an `onErroDynamic input not leading to changes on the front endI'm building a dynamic procedure to access my database via Drizzle ORM. Ideally a developer would btRPC with with react-query prefetching in Next.js app directory.Hi. What is currently the best way to do prefetching in Next.js app directory when using @tanstack/rHello, is there any way to create a base router with common procedures? like an interfaceI want all routers that use it have the state procedure (subscriptions), so I can create a common hHelp Retrieving req.url from opts in useMutation from tRPCHello, i'm trying to essentially send a magiclink email using supabase client libraries, however, i'Express tRPC NextJSI've custom expressjs server with Nextjs + im using internal package for handling OneLogin (OIDC) hoDynamic links url dependent on next headers?Hi, We're currently explore if we can use trpc on a multi tenant next.js 13 application. But we cancalling TRPCProxyClient from inside trpc procedure fails on vercel route handlers edge runtimei setup my client as following: ``` export const serverToServerApi = createTRPCProxyClient<AppRouterPrivate procedures and serverside callsHello, I am just diving into trpc in my Next.js (app router) application and I am wondering if is thinferRouterOutputs ignore "complex data type" fields and only have primitive fields. Bug?Is this a bug ? I have done npx prisma db push, I have restarted VSCode and Typescript. Any commentsHow can i modify my URL using TRPCI did a simple pagination in react and trpc(a simple table), only problem is that: i want in my url TRPC EXPORT API TYPES BE to FEIs there a way I can automatically export my API types from the backend to the frontend? For examplehow to access body in middlewareHi, I’m using trpc with nextjs. Does anyone know how to access the request’s body in middleware? As Decreasing autocomplete performanceAnyone else suffering from increased latency (mostly on the front-end) when doing autocomplete with Error while creating a mutation in NextJSI am having the following error: ```"message": "No \"query\"-procedure on path \"checkout.stripe\"",trpc PaginationDoes somebody have any example how can i do pagination in trpc and react query?Auth through trpc proceduresHas Anyone Successfully Implemented Supabase Auth through tRPC Procedures in a Next.js App? Hello esupabase + trpcdid anyone handle to make it work -> context and all signup signin etc methods?How to update query data after mutationAny idea?standaloneMiddleware: Merge ctx/meta/input typesUsing standaloneMiddleware, it would be great to merge the types (ctx, input, meta) with what is alr