Skip to main content
zerotal

Documentation


Documentation / @zerotal/core / index / Pipe

Interface: Pipe<T>

Defined in: pipeline/types.ts:65

A single step in a middleware pipeline.

Contract

A pipe does exactly one of three things:

  • Continue: return next() to run the rest of the chain.
  • Short-circuit: produce a Response and stop. Either return it directly, or set ctx.response and return (void). Do NOT call next().
  • Wrap: const res = await next(), inspect/transform res, then return the (possibly new) Response — or just mutate ctx.response and return void.

ctx.response is the canonical store: returning a Response is sugar the pipeline mirrors onto it, and a void return leaves it untouched (so it can never erase a response a deeper pipe already set).

Example

class RequireAuth implements Pipe<HttpContext> {
  async handle(ctx: HttpContext, next: NextFn): Promise<Response | void> {
    if (!ctx.user) {
      return Response.json({ message: 'Unauthenticated.' }, { status: 401 });
    }
    return next();
  }
}

Type Parameters

T

T

Methods

handle()

handle(payload, next): Promise<void | Response>

Defined in: pipeline/types.ts:66

Parameters

payload

T

next

NextFn

Returns

Promise<void | Response>