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

magicpipes

v2.0.1

Published

Decorator pattern and middleware for javascript

Downloads

1

Readme

magicpipes

CircleCI Coverage Status

Provides a decorator pattern implementation and several useful filters.

Usage

const pipes = require('magicpipes');

const customFilter = async (context, next) => {
  context.someProperty = await someWorker();
  await next(context);
};

let pipeline = pipes(pipes.circuitBreaker({ interval: 3 }), customFilter);
pipeline.send({ some: 'context' })
  .then(/* called when pipeline finishes */)
  .catch(/* called if pipeline cannot finish */);

Pipeline API

Pipeline factory

let pipeline = pipes(filter1, filter2 /*, ... */) The main export of the pipeline api is the pipeline factory function. It takes as its arguments 0 or more filter functions to be called in the pipe.

Use your own promise implementation

magicpipes uses the global Promise. To use a different Promise implementation, set the global Promise variable before requiring magicpipes

Included Filters

Circuit Breaker

pipes.circuitBreaker({ errorFilter, trackingPeriod, resetTimeout, tripThreshold, activeThreshold })

  • errorFilter - function to filter errors (for example of a specific type). Must return a truthy value when an error should impact the circuit breaker. Defaults to a function that always returns true.
  • trackingPeriod - time in seconds to track errors before they fall off of the breaker state. Defaults to 60 (1 minute).
  • resetTimeout - time in seconds to wait after the breaker has been opened to attempt closing it. Defaults to 300 (5 minutes).
  • activeThreshold - Number of executions required to enable the circuit breaker. Defaults to 0.
  • tripThreshold - percentage (0-100) of failures required to trip the breaker. Defaults to 0 (any failure trips the breaker).

Concurrency Limit

pipes.concurrency({ limit })

  • limit - number of items allowed to be executing (waiting for promise fulfillment) at once. Required.

Log

pipes.log({ logger })

  • logger - logger instance. Must implement log(level, message, error). Required.
  • level - log level. Defaults to "info".

Rate Limit

pipes.rateLimit({ limit, interval })

  • limit - number of items allowed to execute in the specified time frame. Required.
  • interval - time in seconds executions are counted before falling off the limit state. Defaults to 60 (1 minute).

Repeat

pipes.repeat({ until })

  • until - function that returns a promise. When that promise is fulfilled, repetition of the subsequent pipe is finished. Required.

NOTE until will be called after the first execution of the subsequent pipeline succeeds.

Rescue

pipes.rescue({ rescuePipe, rescueContextFactory, errorFilter })

  • rescuePipe - pipeline to be called when subsequent pipe raises exception or Promise rejections. Required.
  • rescueContextFactory - function which takes the error and pipe context and returns a context object passed to the rescue pipe. Defaults to (context, error) => { context, error }
  • errorFilter - function to filter errors (for example of a specific type). Must return a truthy value when a pipeline should be rescued. Defaults to a function that always returns true.

Retry

pipes.retry({ times, interval, before })

  • times - number of times to retry. Defaults to 0 (infinite).
  • interval - time in seconds to wait before executing a retry. Defaults to 1. Ignored if before is provided.
  • before - function called before each retry occurs. Use to implement an exponential retry, for example. Must return a promise to be fulfilled before retry occurs.
  • errorFilter - function to filter errors (for example of a specific type). Must return a truthy value when a pipeline should be retried. Defaults to a function that always returns true.

Credits

  • Heavily inspired by https://github.com/phatboyg/GreenPipes