# x-middleware-composite

> [Build Status](https://travis-ci.org/x-component/x-middleware-composite.png?v1.0.0)](https://travis-ci.org/x-component/x-middleware-composite)

Latest version **1.0.0** (published 2015-12-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install x-middleware-composite
pnpm add x-middleware-composite
yarn add x-middleware-composite
bun add x-middleware-composite
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-12-06 |
| First published | 2015-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | maurice.schoenmakers |

## Links

- npm: https://www.npmjs.com/package/x-middleware-composite
- npm.io page: https://npm.io/package/x-middleware-composite

## Dependencies (4)

- [x-log](https://npm.io/package/x-log.md) 1.x.x
- [x-common](https://npm.io/package/x-common.md) 1.x.x
- [x-select](https://npm.io/package/x-select.md) 1.x.x
- [function-inspector](https://npm.io/package/function-inspector.md) git://github.com/mheyse/node-function-inspector.git#master

## Recent versions

- 1.0.0 (latest) — 2015-12-06
- 0.0.1 — 2015-11-08

## README

# x-middleware-composite

[Build Status](https://travis-ci.org/x-component/x-middleware-composite.png?v1.0.0)](https://travis-ci.org/x-component/x-middleware-composite)

- [./composite.js](#compositejs) 

# ./composite.js

  - [global_log](#global_log)

## global_log

  Concate middleware to function and handle errors
  
  Composition
  -----------
  call composite(...) with a list of middlewares(req,res,next){..} or an array to compose them into a single composite middleware.
  
  you cann add labels into the list by using a object with a single property:
  
```js
  '''
  var pipeline=composite([,,,{ name: middleware },,,]);
  '''
```

  
  The order is significant.
  
  Nesting
  -------
  Multiple composite pipelines can be nested: p.e.  composite([,,,{ name : composite([...]) },,]), as each composite is just
  a normal middleware. It is also allowed to use an array directly: composite([,,,{ name : [...] },,,,]),
  
  
  Injection
  ---------
  One can inject middlewares in an existing pipeline at the position 'name', *before* or *after* the current middleware at that position:
  
```js
  '''
  pipeline.after(name:extra_middleware);
  '''
```

  
  The modified pipeline then has a { name: [middleware,extra_middleware] } element.
  
  To allow a more felixble namin / injection on can also access nested composites using before by passing
  as name in before /after a JSON selector:
  
  Example:
```js
  '''
  var pipeline=composite([,,,{ transform: [,,,{ dom: middlewares },,,] },,,,]);
```

  
```js
  pipeline.after('.transform .dom':extra_middleware); // inserts it at the nested position
  '''
```

  
  Design Rationale:
  -------
  Often pipelines and request handlers can be reused. One can define generic functions seting up a url request handler with a default pipeline.
  or just returning a default pipeline. The caller then modifiy the returned pipeline by injection.
  For example to add some extra handling for a specific application/url
  without creating a complete copy of the generic pipeline.
  
  Alternatives would have been:
   - offer functions which return just building blocks of pipelines and and some function delivering some predefined ones
```js
 positive: no declerative magic involded. Using code explicitly requests building blocks and composes them.
 negative: lots of array composition logic, lots of functions for each eventual possibility.
 This approach is still usable and usefull.
```

  
   - event hooks
```js
 one could mix middlewares with events, and prove hooks forcertain phases within the pipeline.
 For events how ever the order is conceptionally not defined and it results in a mixing of event concepts and middleware concepts.
```

---
_Source: https://npm.io/package/x-middleware-composite · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
