Documentation
API
Output (tsdl.output)

Output

Outputs are seldom integral to an app but can be useful in specific situations.

An output is invoked after a query is completed. The output of the query along with the input and context are then passed to the output callback.

Example

fetchFruit: tsdl
  .input(z.literal("banana"))
  .use(() => "orange")
  .query(() => "apple")
  .output((res) => {
    res.input; // "banana"
    res.ctx; // "orange"
    res.output; // "potato"
  })
  .output(console.log),

Type

type Output = <TCtx, TInput, TOutput, TReturn>(res: {
  ctx: TCtx;
  input: TInput;
  output: TOutput;
} => TReturn);
The return value of the output is ignored

Outputs can throw errors and thereby modify the response. If one output throws, no further outputs will be invoked.

⚠️

All outputs will need to be resolved before a request is fulfilled, the output callbacks are run invoked parallel.