T

tRPC

โ“-help

Join Server

Meta - unable to create default meta

MMugetsu3/20/2023
Trying to follow https://trpc.io/docs/server/metadata#default-meta-chaining-and-shallow-merging
I set the type of the meta add it to the builder and want to set default but seems there is no typing for the meta in the create to set the default. Am I missing something ?
"@trpc/client": "10.16.0",
    "@trpc/react-query": "10.16.0",
    "@trpc/server": "10.16.0",

type CreateContextOptions = {
  req: express.Request
  res: express.Response
  currentSchema: any
}

type MetaOptions = {
  roles: string[]
}

export const createInnerTRPCContext = async (opts: CreateContextOptions) => ({
  req: opts.req,
  res: opts.res,
  currentSchema: opts.currentSchema,
})

export const createTRPCContext = async (
  opts: trpcExpress.CreateExpressContextOptions,
) => {
  const { req, res } = opts
  const currentSchema =
    req.locationSchemas?.find(({ id }) => id === req.schemaId) || {}

  return createInnerTRPCContext({
    req,
    res,
    currentSchema,
  })
}

const t = initTRPC
  .context<typeof createTRPCContext>()
  .meta<MetaOptions>()
  .create({
/// defaultMeta <------------------------- MISSING TYPING
    transformer: superjson,
    errorFormatter({ shape, ctx }) {
      const { data, ...rest } = shape

      return {
        ...rest,
        data: {
          ...data,
          traceId: ctx?.req?.traceId,
          schemaId: ctx?.req?.schemaId,
        },
      }
    },
  })
Nnlucas3/20/2023
Have you reloaded your language server since upgrading?
Nnlucas3/20/2023
the defaultMeta key should be there whether you set .meta<>() or not, so this is a weird one unless you just need to reload
MMugetsu3/20/2023
Yeah, I've restarted TS, Invalidated all cache and restarted IDE. Doesn't seem to pick it up
MMugetsu3/20/2023
I can't even find any definition in source code about defaultMeta
Nnlucas3/20/2023
In the source code in node modules, whatโ€™s the package.json version?
MMugetsu3/20/2023
MMugetsu3/20/2023
10.16.0
MMugetsu3/20/2023
And yeah if I even define it it seems not working meta is undefined
MMugetsu3/20/2023
{
  type: 'query',
  path: 'locations.searchLocations',
  rawInput: {
    search: '',
    limit: 10,
    offset: 0,
    'filter:type': undefined,
    'filter:storeFormat': undefined,
    'filter:tradingStatus': undefined,
    'filter:region': undefined
  },
  meta: undefined,
  input: undefined
}
-----------------------END-----------------------
Nnlucas3/20/2023
Oh you know what
Nnlucas3/20/2023
I donโ€™t think we released that yet
MMugetsu3/20/2023
Aaaa I seee ๐Ÿ˜„
Nnlucas3/20/2023
Let me ping Alex
MMugetsu3/20/2023
sure no worries
Nnlucas3/20/2023
Thanks for flagging it, I think there was an internal issue after the release last week so probably this got forgotten
Nnlucas3/20/2023
Looks like 10.17 is out now ๐Ÿ™‚
MMugetsu3/20/2023
Sweet. Will chceck in a moment
MMugetsu3/20/2023
Nice. Working as expected now. Thanks !