trpc / v10-playground

tRPC v10 procedure play
https://stackblitz.com/github/trpc/v10-playground?file=src%2Fserver%2Findex.ts,src%2Fclient.ts,src%2Fserver%2Frouters%2FpostRouter.ts&view=editor
13 stars 3 forks source link

Naming functions that return middlewares (and beyond) #3

Closed KATT closed 2 years ago

KATT commented 2 years ago

Naming of functions that returns functions and naming of functions that returns functions that return middlewares 🤦

What to name the createUseNewContext middleware?

Current usage:

const useNewContextFactory = createUseNewContext<TestContext>();
const useIsAuthed = useNewContextFactory((params) => {
  if (!params.ctx.user) {
    return {
      error: {
        code: 'UNAUTHORIZED',
      },
    };
  }
  return {
    ctx: {
      ...params.ctx,
      user: params.ctx.user,
    },
  };
});

// in resolver
const procedure = resolver(
  useIsAuthed(),
  () => {
    // ..
  }
)

~Do we like the useX format?~ useX format needs changing

useZod() returns a middleware for zod.

KATT commented 2 years ago

Created a helper function, idea by @mmkal, that seem to have removed the debate for now https://github.com/KATT/trpc-v10-playground/commit/7501de3a16038763101f0f8102e2d5b23c8b61d0