tRPCttRPC
Powered by
y_nkY
tRPC•7mo ago•
1 reply
y_nk

sanitizing output based on output schema

As i understand, the
.output
.output
will only ensure the schema is respected, but will not sanitize output on the go (even tho it could be possible with a
z.strictObject()
z.strictObject()
):

.output(someSchema) // <- does not sanitize data
// ---
.use(output(someSchema)) // <- should sanatize data

export function output<T extends ZodType>(schema: T) {
  return middleware(async ({ next }) => {
    const result = await next()
    return schema.parse(result)
  })
}
.output(someSchema) // <- does not sanitize data
// ---
.use(output(someSchema)) // <- should sanatize data

export function output<T extends ZodType>(schema: T) {
  return middleware(async ({ next }) => {
    const result = await next()
    return schema.parse(result)
  })
}


but for some reason the typing does not work. could somebody point out how to achieve similar but in a working way? is there no way to do what i want?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Discriminated output based on discrimiated input
Lautaro_dapinLLautaro_dapin / ❓-help
3y ago
Override output schema for certain mutations
shikishikichangchangSshikishikichangchang / ❓-help
17mo ago
Custom data transformer and input/output schema
Titouan Créac'hTTitouan Créac'h / ❓-help
2y ago
Create client based on OpenAPI
PieterPPieter / ❓-help
3y ago