{"id":15007689,"url":"https://github.com/tilfin/transgate","last_synced_at":"2025-10-30T11:31:58.439Z","repository":{"id":57379080,"uuid":"111048108","full_name":"tilfin/transgate","owner":"tilfin","description":"Agent-based task flow framework for Node.js","archived":false,"fork":false,"pushed_at":"2020-01-13T13:18:22.000Z","size":656,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T08:12:16.259Z","etag":null,"topics":["agent-based-framework","nodejs","npmjs","taskflow"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tilfin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-17T02:34:36.000Z","updated_at":"2024-08-03T08:18:18.000Z","dependencies_parsed_at":"2022-09-02T20:41:20.096Z","dependency_job_id":null,"html_url":"https://github.com/tilfin/transgate","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tilfin%2Ftransgate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tilfin%2Ftransgate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tilfin%2Ftransgate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tilfin%2Ftransgate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tilfin","download_url":"https://codeload.github.com/tilfin/transgate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238960787,"owners_count":19559342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-based-framework","nodejs","npmjs","taskflow"],"created_at":"2024-09-24T19:13:25.818Z","updated_at":"2025-10-30T11:31:55.832Z","avatar_url":"https://github.com/tilfin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Transgate\n\n[![npm](https://img.shields.io/npm/v/transgate.svg)](https://www.npmjs.com/package/transgate)\n[![Node](https://img.shields.io/node/v/transgate.svg)]()\n[![document](https://img.shields.io/badge/document-0.6.0-orange.svg)](https://tilfin.github.io/transgate/transgate/0.6.0/)\n[![License](https://img.shields.io/github/license/tilfin/transgate.svg)]()\n[![dependencies Status](https://david-dm.org/tilfin/transgate/status.svg)](https://david-dm.org/tilfin/transgate)\n[![Build Status](https://travis-ci.org/tilfin/transgate.svg?branch=master)](https://travis-ci.org/tilfin/transgate)\n[![Coverage Status](https://coveralls.io/repos/github/tilfin/transgate/badge.svg?branch=master)](https://coveralls.io/github/tilfin/transgate?branch=master)\n\nAgent-based task flow framework for Node.js\n\n## Install\n\n```\nnpm install -save transgate\n```\n\n## Actors in this framework\n\n* **Gate** is an endpoint of Input/Output. For example, file storage, database, queue or API service.\n* **Agent** is a worker to process an **item** between Input/Output **gates** and does not know anything opposite **gates**.\n* **Item** is an entity as each task target, to be exchanged between **gates**, and an *Object* or a *JSON*. `null` indicates the terminator.\n\n## How it works\n\n1. A **agent** receives an **item** from a **gate** for Input.\n2. The **agent** processes an **item**.\n3. According to need the **Agent** sends the results as next **item(s)** to some gate(s) for Output.\n\nIf the **agent** receives `null` as an **item**, sends `null` to all next **gates** and closes itself.\n\n* All agents must be given gates for input and output in the constructor and run independently.\n* A gate is easy to replace because the interface of the item is a simple *Object*.\n\n## Implements\n\n### Gate\n\n* A gate for Input must implement `receive` *Promise* method that resolves an **item**.\n* A gate for Output must implement `send` *Promise* method with argument an **item**. `send` resolves when completes to write the item.\n\n### Agent\n\n* An agent inherits `Agent` class and overrides `async main(item, outGate)` method to process an `item` and send it to `outGate`.\n* 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 })`.\n* If the agent uses any daemon, overrides `async before()` to launch it and `async after()` to shut down it.\n\n### Starting\n\nTo 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.\n\n## Standard Gate classes\n\nThere are the following gates in this library.\n\n* MemoryGate - Supports both Input/Output for test\n* ReadFileGate - Reading each line as an item from a file for Input\n* WriteFileGate - Writing sended items to a file for Output\n* HttpServerGate - Receiving an item that is a body POSTed by HTTP client for Input\n* HttpClientGate - Sending an item as POST request body to fixed HTTP server endpoint for Output\n* IntervalGate - Providing an item contains the time every interval passing for Input\n* StdinGate - Reading each line as an item from stdin for Input\n* StdoutGate - Writing sended items to stdout for Output\n* JointGate - Pipes an agent to another one\n\n## Converter for Gate\n* mixer - Receiving items from some gates for Input\n* duplicator - Sending an item the multiple gates for Output\n\n## An example\n\n### About agents\n1. (No name)   : item.value x 2\n2. `ValueAdd1` : item.value + 1\n\n### About connections between agent and gates\n* memory --\u003e Agent1 --\u003e joint\n* joint  --\u003e Agent2 --\u003e stdout\n\n```javascript\nconst {\n  Agent,\n  JointGate,\n  MemoryGate,\n  StdoutGate,\n} = require('transgate');\n\nclass ValueAdd1 extends Agent {\n  async main(item, stdoutGate) {\n    item.value += 1;\n    stdoutGate.send(item);\n  }\n}\n\nconst inputGate = new MemoryGate([\n  { value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }\n]);\nconst joint = new JointGate();\nconst stdoutGate = new StdoutGate();\n\nAgent.all(\n  Agent.create(inputGate, joint, async (item) =\u003e {\n    item.value *= 2;\n    return item;\n  }),\n  new ValueAdd1(joint, stdoutGate),\n)\n.catch(err =\u003e {\n  console.error(err);\n});\n```\n\n#### The result stdout\n\n```json\n{\"value\":3}\n{\"value\":5}\n{\"value\":7}\n{\"value\":9}\n```\n\n## Reference articles\n- [Transgate is Agent-based taskflow framework for Node.js - dev.to](https://dev.to/tilfin/transgate-is-agent-based-taskflow-framework-for-nodejs-58b)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftilfin%2Ftransgate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftilfin%2Ftransgate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftilfin%2Ftransgate/lists"}