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

redpipe

v1.0.3

Published

Javascript - Simple PIPE

Downloads

13

Readme

RedPipe

license

Install

NPM

npm i redpipe

Github Project

git clone https://github.com/Yarflam/redpipe.git

Run test.cjs:

npm test

You should have something like that:

[OUT] 11
[ERR] Error: 10 items or greater are not supported
    at Array.<anonymous> (test.cjs:29:19)
    at RedPipe.run (RedPipe.cjs:48:55)
    at Timeout._onTimeout (RedPipe.cjs:66:31)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7)
[OUT] 5
[OUT] 9
topic: Awesome
payload: 1
[OUT] 1
[ERR] Error: 10 items or greater are not supported
    at Array.<anonymous> (test.cjs:29:19)
    at RedPipe.run (RedPipe.cjs:48:55)
    at Timeout._onTimeout (RedPipe.cjs:66:31)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7)
topic: Awesome
payload: 7
[OUT] 7
topic: Awesome
payload: 13
[OUT] 13
topic: Awesome
payload: 3
[OUT] 3
FINISHED: IN 1 -> OUT 7
  /!\ 2 error(s) /!\

The errors are trigger by the JS script.

Usages

Import the library:

const RedPipe = require('redpipe');

Create a new pipeline:

const flow = new RedPipe();

Add a simple pipe (return same object):

flow.pipe(msg => {
    msg.payload = 'Hello World';
    return msg; // return the current object
});

Add a separation pipe (multiple objects):

flow.pipe((msg, node) => {
    node.send({ ...msg, payload: 'First' });
    node.send({ ...msg, payload: 'Second' });
    return; // no return (= useless)
});

Add a bridge pipe (send to another pipeline):

flow.pipe((msg, node) => {
    secondFlow.send({ ...msg, payload: 'Hello' });
});

Add an async pipe:

flow.pipe((msg, node) => {
    node.async(); // lock
    setTimeout(() => {
        node.async(true); // unlock
        node.send(msg);
    }, 42);
});

Retry (use it with a Promise):

flow.pipe((msg, node) => {
    node.async();
    new Promise((resolve, reject) => {
        if(!msg.noRetry) {
            msg.noRetry = true;
            return reject(); // First call
        }
        resolve(); // Second call
    }).then(() => {
        node.async(true);
        node.send(msg); // next pipe
    }).catch(() => {
        node.async(true);
        node.retry(); // retrying
    })
});

Events

Capture the errors:

flow.on(
    RedPipe.EVENT_ERROR,
    ({ payload: e }) => {
        console.error('[ERR]', e);
    }
)

Capture the finished state:

flow.on(
    RedPipe.EVENT_FINISHED,
    ({ payload }) => {
        const { inputs, outputs, errors } = payload;
        console.log(`FINISHED: IN ${inputs} -> OUT ${outputs}`);
        if(errors) console.log(`  /!\\ ${errors} error(s) /!\\`);
    }
)

Retrieve output data:

flow.on(
    RedPipe.EVENT_DATA,
    ({ payload }) => {
        console.log('[OUT]', payload);
        // Keep them somewhere
    }
)

Subscribers (Queue)

Subscribe to a specific topic:

flow.subscribe('MyTopic', ({ payload }) => {
    console.log('[MyTopic]', payload);
});

Subscribe to all topics:

flow.subscribe(
    RedPipe.TOPIC_ANY,
    ({ topic, payload }) => {
        if(RedPipe.TOPIC_ENUM.indexOf(topic) >= 0)
            return; // Ignore the events
        console.log(`[${topic}]`, payload);
    }
);

Execute the pipeline

Send a new message:

flow.send({
    topic: 'MyTopic',
    payload: 42
});

Message Object

Structure:

  • topic: string
  • payload: string | number | array | object | boolean
  • ... support any other attributes ...

Inspired by the Node-RED model. See more

Authors

  • Yarflam - initial work

License

The project is licensed under Creative Commons Zero (CC0).