New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

app-builder

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-builder

Simple, Composable, promise based middleware pipelines

  • 5.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
increased by25.35%
Maintainers
1
Weekly downloads
 
Created
Source

app-builder

Create composable promise based middleware pipelines.

npm install app-builder

circle-ci

Example

import { compose } from 'app-builder'

const app = compose([
  async function (ctx, next) {
    ctx.value += 1
    await next()
    ctx.value += 4
  },
  async function (ctx, next) {
    ctx.value += 2
    await next()
    ctx.value += 3
  }
]);

const context = { value: '' }
app(context).then(() => console.log(context.value)) // --> '1234'

Exports (3)

default - createAppBuilder() : AppBuilder

compose - Function(...middleware[] : Function[]|Function) : Function

AppBuilder - Class


AppBuilder#use(mw: Function) : AppBuilder

Add a middleware function to the builder. A middleware function can accept two arguments; context : any and next : Function. next must be invoked to continue the pipeline. If the middleware function returns a promise the pipeline will end only after all returned promises have been resolved.

AppBuilder#build() : Function

Get a function made up of all used middleware functions (returned function is also valid middleware)

AppBuilder Usage:
import createAppBuilder from 'app-builder'

const builder = createAppBuilder()

async function first (context, next) {
  context.value += 1
  await next()
  context.value += 4
}

async function second (context, next) {
  context.value += 2
  await next()
  context.value += 3
}

builder.use(first)
builder.use(second)

applicationFunction = builder.build()

const context = { value: '' }
applicationFunction(context).then(() => console.log(context.value)) // --> '1234'

Notes

  • next() must always have a modifier, that is, it must always be awaited or yielded or returned. If it isn't, there is a strong possibility you will encounter race conditions

Keywords

FAQs

Package last updated on 05 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc