[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/core](../../README) / [index](../README) / Pipeline

# Class: Pipeline\<T\>

Defined in: [pipeline/Pipeline.ts:32](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/pipeline/Pipeline.ts#L32)

Generic middleware pipeline: sends a payload through an ordered list of pipe
classes and hands the final payload to a destination.

Pipes are resolved from the container when `.via()` is called; otherwise each
is instantiated directly with `new PipeClass()`.

## Examples

```ts
const result = await Pipeline.send(ctx)
  .through([AuthMiddleware, ThrottleMiddleware])
  .via(container)           // optional — resolves pipes from container
  .then((ctx) => ctx.response);
```

```ts
// Run the chain and read the mutated payload back:
const finished = await Pipeline.send(ctx).through(pipes).via(container).thenReturn();
return finished.response;
```

## Type Parameters

### T

`T`

The payload type carried through the pipes (typically [HttpContext](HttpContext)).

## Methods

### send()

> `static` **send**\<`T`\>(`payload`): `Pipeline`\<`T`\>

Defined in: [pipeline/Pipeline.ts:42](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/pipeline/Pipeline.ts#L42)

Begin a pipeline carrying `payload` through the pipes added by `through()`.

#### Type Parameters

##### T

`T`

#### Parameters

##### payload

`T`

#### Returns

`Pipeline`\<`T`\>

***

### through()

> **through**(`pipes`): `this`

Defined in: [pipeline/Pipeline.ts:49](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/pipeline/Pipeline.ts#L49)

Set the ordered list of pipe classes the payload travels through.

#### Parameters

##### pipes

`PipeClass`\<`T`\>[]

#### Returns

`this`

***

### via()

> **via**(`container`): `this`

Defined in: [pipeline/Pipeline.ts:55](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/pipeline/Pipeline.ts#L55)

Inject a container so pipes are resolved from it (supports `@inject`).

#### Parameters

##### container

[`Container`](Container)

#### Returns

`this`

***

### then()

> **then**\<`R`\>(`destination`): `Promise`\<`R`\>

Defined in: [pipeline/Pipeline.ts:66](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/pipeline/Pipeline.ts#L66)

Execute the pipeline and pass the final payload to `destination`.
Returns whatever `destination` returns.

#### Type Parameters

##### R

`R`

#### Parameters

##### destination

(`payload`) => `R` \| `Promise`\<`R`\>

#### Returns

`Promise`\<`R`\>

***

### thenReturn()

> **thenReturn**(): `Promise`\<`T`\>

Defined in: [pipeline/Pipeline.ts:78](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/pipeline/Pipeline.ts#L78)

Execute the pipeline and return the final payload unchanged.

The pipeline mutates the payload in-place: every pipe shares the one
`payload` (the request `HttpContext`), and the canonical `Response` is
written to `payload.response`. Read it back from there.

#### Returns

`Promise`\<`T`\>
