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

corridore

v0.1.1

Published

Simple promise-based runner for tasks with chained api for abstracting varied processes into single actions

Downloads

1

Readme

🏃🏼‍♂️ Corridore

Corridore is a simple promise-based task runner with a chainable api

ts

Purpose

The purpose of this lib is to allow organization and simple abstraction for actions that can be varied by the tasks needed to complete each one. For example, perhaps you have to consume various (possibly third-party) services that all have their own methods of retrieval but want to transform uniformly each one and combine the results into a single set. You can easily create mini abstractions for each service as a task, and run them all at once.

Overview

The general idea centers around some action function (originally designed for API calls, but could be anything) that should be run in a task, which may or may not have one or more pre or post functions that should be run before or after the action completes. A corridore instance handles the running of multiple tasks and can additionally have its own pre and post functions as well. Think of it as a simple way to handle piping data from one function to another, grouping those pipelines and combining them with others, possibly running them in parallel.

The assumption is made that whatever your tasks and step functions are doing, you have strict types for the incoming and outgoing data from the task, and that your runner can handle multiple tasks, but all having the same incoming and outgoing types.

Concurrency

Where possible, you can specify using concurrency for tasks so that they may be run in parallel. Pre and post functions are always run synchronously, typically used for transform steps. However, you may also run tasks synchronously if you wish for very complex transform scenarios where you need more abstraction. When doing this, each subsequent task (or the first pre function of that task) receives as input the final output from the previous task, including any post functions.

Example Scenario

See example for more detail.

Let's say you have to provide a result set which is pulled from 2 different third-party APIs, each of which return their data in different shapes and formats.

Service A Example

// TASK STEP FUNCTIONS

const taskStepPre1 = (task: Task) => (data: IncomingTaskType): TypeForTaskAction => {
  //
};

const taskAction = (task: Task) => (data: TypeForTaskAction): TypeForStepPost1 => {
  //
};

const taskStepPost1 = (task: Task) => (data: TypeForStepPost1): OutgoingTaskType => {
  //
};

// CREATE TASK

const taskService1 = new Task<IncomingTaskType, OutgoingTaskType>('task1');

taskService1
  .pre([
    taskStepPre1,
    taskStepPre2,
    ...
  ])
  .action(taskAction)
  .post([
    taskStepPost1,
    ...
  ]);

Service B, Service C, etc. as above...

Corridore as Runner of All Tasks

// CREATE CORRIDORE INSTANCE
const runner = new Corridore('runner');

runner
  .concurrent(true) // allow tasks to run concurrently, see notes on what this means if false
  .pre([
    runnerStepPre1,
    ...
  ])
  .tasks([
    taskService1,
    taskService2,
    ...
  ])
  .post([
    runnerStepPost1,
    ...
  ]);

// execute it someplace
const results = await runner.exec<RunnerResultType>(initialDataPassedToPreStep1);

License

See LICENSE.md