tobrut.js
v1.2.1
Published
Turbulent Object Builder Ready Using Taskflows - A modern async workflow library for Node.js
Maintainers
Readme
tobrut.js - Turbulent Object Builder Ready Using Taskflows
tobrut.js is a modern Node.js library for creating and running asynchronous workflows in a fast and efficient way. This library is designed to build complex objects dynamically through a series of tasks that can be executed sequentially or in parallel.
Installation
npm install tobrut.jsBasic Usage
const TurbulentBuilder = require('tobrut.js');
// Creating taskflows
const userDataTask = async (currentObj) => {
// Do something with currentObj
return { userId: 123, username: 'example' };
};
const processingTask = async (currentObj) => {
// Do further processing
return { processed: true };
};
// Running taskflows
const result = await new TurbulentBuilder({ initial: 'data' })
.addTask('Fetch Data', userDataTask)
.addTask('Process Data', processingTask)
.run();
console.log(result); // { initial: 'data', userId: 123, username: 'example', processed: true }Main Features
1. Sequential and Parallel Taskflows
addTask(name, taskFn): Adds a task that runs sequentiallyaddParallelTask(name, taskFn): Adds a task that runs in parallel with other tasksaddConditionalTask(name, taskFn, condition): Adds a task that only runs if a condition is met
2. Configuration Options
setOptions({ verbose, failFast, maxRetries }): Configure the builder behaviorverbose: Show detailed logging (default: false)failFast: Stop when there's an error (default: true)maxRetries: Maximum number of retries for failed tasks (default: 0)
3. Error Handling and Retry
failFastoption to control whether the flow should stop when there's an error- Support for automatic retry by specifying the number of retries per task
4. Chaining
- Supports method chaining to create clean and readable workflow definitions
Complete Example
const TurbulentBuilder = require('tobrut.js');
async function runExample() {
const result = await new TurbulentBuilder({ input: 'data' })
.setOptions({
verbose: true,
failFast: false,
maxRetries: 2
})
.addTask('Fetch Data', async (obj) => {
return { userId: 42, username: 'user' };
})
.addTask('Validate Data', async (obj) => {
return { validated: true };
})
.addConditionalTask('Optional Task', async (obj) => {
return { optional: 'data' };
}, (obj) => obj.userId === 42)
.addTask('Process Data', async (obj) => {
return { processed: true };
})
.addParallelTask('Parallel Process 1', async (obj) => {
return { parallel1: 'done' };
})
.addParallelTask('Parallel Process 2', async (obj) => {
return { parallel2: 'done' };
})
.run();
console.log(result);
}
runExample();Use Cases
tobrut.js is perfect for:
- Data processing pipelines
- Complex API integrations
- Automation workflows
- AI/machine learning data processing
- ETL (Extract, Transform, Load) systems
- Data validation and transformation flows
API
new TurbulentBuilder(initialObject = {})
Creates a new instance of TurbulentBuilder with an optional initial object.
addTask(name, taskFn, opts = {})
Adds a sequential task to the flow.
addParallelTask(name, taskFn, opts = {})
Adds a parallel task to the flow.
addConditionalTask(name, taskFn, condition)
Adds a conditional task that only runs if the condition function returns true.
setOptions(opts)
Configures options for the builder.
run()
Runs all taskflows and returns a Promise of the final object result.
Advanced Features
Automatic Retry
You can specify retry attempts for specific tasks:
.addTask('Unstable Task', unreliableTask, { retry: 3 })Validation and Logging
Enable detailed logging and validation settings with:
.setOptions({ verbose: true })Contributing
Contributions are welcome! Please create an issue or pull request in our repository.
License
MIT
