Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jigawatt

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jigawatt

Influential's Functional, Promise-based Express Middleware

  • 0.1.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status codecov Code Climate

jigawatt

Influential's Functional, Promise-based Express Middleware

Installation

npm install jigawatt

Middleware Structure

Properties

Jigawatt Middleware must consist of at least one of three properties:

  • awesomize: (Validator -> AwesomizeSpec) -> Request -> Object a

  • io: Request, Data -> Object a

    • returns an object that is merged into req.data
  • transform: Request, Data -> Object a

    • returns an object to become the new req.data value

Example Middleware

const _         = require('ramda')
const Bluebird  = require('bluebird')

const Order = require('../domain/order.js')

const getById = {
  awesomize: (v) => ({
    order_id: {
      read: _.path(['params', 'orderId'])
    , validation: [ v.required ]
    }
  })

  io: (req, data) => {
    return Bluebird.props({
      order : Order.getById(data.order_id)
    })
  }
};

const uniteDetails = {
  transform: (req, data) => {
    return {
      order     : data.order
    , customer  : data.customer
    , product   : data.product
    , shipping  : data.shipping  
    }
  }
}

module.exports = {
  getById
, uniteDetails
}

Example Usage

const router     = require('express').Router()
const JW         = require('jigawatt')

// MIDDLEWARE
const Order      = require('../middleware/order.js')
const Customer   = require('../middleare/customer.js')
const Product    = require('../middleware/product.js')
const Shipping   = require('../middleare/shipping.js')


// ROUTES
router.get('order/:orderId', JW(Order.getById));

router.get('order/:orderId/detail', JW(

  [ Order.getById             // call all of these promise
  , Customer.getByOrderId     // functions at the same time
  , Product.getByOrderId      // and merge request.data when
  , Shipping.getByOrderId     // all are complete
  ]

, Order.uniteDetails          // transform-only middleware
                              // to aggregate details and
                              // present to user
))

Keywords

FAQs

Package last updated on 29 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