npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mintsauce

v0.1.1

Published

Makes lamb(da) more delicious

Downloads

13

Readme

mintsauce

Makes lamb(da) more delicious.

Express inspired middleware chains for AWS Lamdba functions.

Usage:

const sauce = require('mintsauce');
const lambda = sauce();

lambda.use((call, response, next) => {
  // ... your code here
  next();
});
lambda.use((call, response, next) => {
  response.send({ ok: true });
});

module.exports = lambda;

Middleware

Middleware functions take three arguments - call, response, next.

call

Contains metadata based on the parameters with which the lambda was called.

Properties

  • name - The lambda function name
  • version - The lambda function version
  • arn - The ARN of the invoked function
  • region The AWS region of the lambda
  • account - The account id of the lambda function

Additionally the original event and context are available on properties with the same names.

response

An object containing helper functions for sending a response to the lambda's callback function.

Methods

  • send - Sends a successful response to the lambda's callback. Passes the first argument to the callback. Any other arguments are ignored.
  • error - Sends a failure response to the lambda's callback. The first argument can be an Error, String or any object with a message property. If no argument is provided (or invalid argument is provided) then a generic error will be returned.

next

A callback function used to pass execution to the next function in the middleware stack.

Error Handling

As with express, error handlers are simply middlewares with an additional first argument representing the error. When a function with 4 arguments is passed to use it is automatically mounted as an error handler.

Error handlers may pass the error to subsequent handlers by passing it to next as any other middleware.

Example:

const sauce = require('mintsauce');
const lambda = sauce();

lambda.use((call, response, next) => {
  next(new Error('example error'));
});
lambda.use((err, call, response, next) => {
  // error thrown in an earlier middleware is caught here
  response.error(err);
});

module.exports = lambda;

Alternatively, a function with any number of arguments can be passed to the catch method of a lambda or middleware stack.

const sauce = require('mintsauce');
const lambda = sauce();

lambda.use((call, response, next) => {
  next(new Error('example error'));
});
lambda.catch((err) => {
  // error thrown in an earlier middleware is caught here
  response.error(err);
});

module.exports = lambda;

Promises

If a middleware returns an object that implements a Promise-like interface then this will be used to handle progression to the next middleware layer. These can either be native Promises, or a third-party library.

Example:

const sauce = require('mintsauce');
const lambda = sauce();
const BluebirdPromise = require('bluebird');

lambda.use((call, response) => {
  return new Promise((resolve, reject) => {
    // ..
    resolve();
  });
});
lambda.use((call, response) => {
  return BluebirdPromise.resolve()
    .then(() => {
      // your code here
    });
});

module.exports = lambda;

Note that the resolved value of a promise is discarded, and will not be used for anything.