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

transgate

v0.6.3

Published

Agent-based task flow framework

Downloads

5

Readme

Transgate

npm Node document License dependencies Status Build Status Coverage Status

Agent-based task flow framework for Node.js

Install

npm install -save transgate

Actors in this framework

  • Gate is an endpoint of Input/Output. For example, file storage, database, queue or API service.
  • Agent is a worker to process an item between Input/Output gates and does not know anything opposite gates.
  • Item is an entity as each task target, to be exchanged between gates, and an Object or a JSON. null indicates the terminator.

How it works

  1. A agent receives an item from a gate for Input.
  2. The agent processes an item.
  3. According to need the Agent sends the results as next item(s) to some gate(s) for Output.

If the agent receives null as an item, sends null to all next gates and closes itself.

  • All agents must be given gates for input and output in the constructor and run independently.
  • A gate is easy to replace because the interface of the item is a simple Object.

Implements

Gate

  • A gate for Input must implement receive Promise method that resolves an item.
  • A gate for Output must implement send Promise method with argument an item. send resolves when completes to write the item.

Agent

  • An agent inherits Agent class and overrides async main(item, outGate) method to process an item and send it to outGate.
  • To create an agent instance is to call new YourAgent(inGate, outGate). If the outGate is plural, it need be replaced with key-value-based { outGate1, outGate2 } in order to have async main(item, { outGate1, outGate2 }).
  • If the agent uses any daemon, overrides async before() to launch it and async after() to shut down it.

Starting

To start agents is calling Agent.all(...yourAgents) Promise method. If you use any daemons in some gates, They should be shut down after all Promise has done.

Standard Gate classes

There are the following gates in this library.

  • MemoryGate - Supports both Input/Output for test
  • ReadFileGate - Reading each line as an item from a file for Input
  • WriteFileGate - Writing sended items to a file for Output
  • HttpServerGate - Receiving an item that is a body POSTed by HTTP client for Input
  • HttpClientGate - Sending an item as POST request body to fixed HTTP server endpoint for Output
  • IntervalGate - Providing an item contains the time every interval passing for Input
  • StdinGate - Reading each line as an item from stdin for Input
  • StdoutGate - Writing sended items to stdout for Output
  • JointGate - Pipes an agent to another one

Converter for Gate

  • mixer - Receiving items from some gates for Input
  • duplicator - Sending an item the multiple gates for Output

An example

About agents

  1. (No name) : item.value x 2
  2. ValueAdd1 : item.value + 1

About connections between agent and gates

  • memory --> Agent1 --> joint
  • joint --> Agent2 --> stdout
const {
  Agent,
  JointGate,
  MemoryGate,
  StdoutGate,
} = require('transgate');

class ValueAdd1 extends Agent {
  async main(item, stdoutGate) {
    item.value += 1;
    stdoutGate.send(item);
  }
}

const inputGate = new MemoryGate([
  { value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }
]);
const joint = new JointGate();
const stdoutGate = new StdoutGate();

Agent.all(
  Agent.create(inputGate, joint, async (item) => {
    item.value *= 2;
    return item;
  }),
  new ValueAdd1(joint, stdoutGate),
)
.catch(err => {
  console.error(err);
});

The result stdout

{"value":3}
{"value":5}
{"value":7}
{"value":9}

Reference articles