# @marble-seeds/task

> ## Install with

Latest version **1.0.0-rc.8** (published 2024-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @marble-seeds/task
pnpm add @marble-seeds/task
yarn add @marble-seeds/task
bun add @marble-seeds/task
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.8 |
| Published | 2024-03-24 |
| First published | 2022-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 210.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Siedrix |
| Maintainers | siedrix |

## Links

- npm: https://www.npmjs.com/package/@marble-seeds/task
- Repository: https://github.com/latteware/marble-mono-repo
- Homepage: https://github.com/latteware/marble-mono-repo/tree/main/packages/backend/task#readme
- Issues: https://github.com/latteware/marble-mono-repo/issues
- npm.io page: https://npm.io/package/@marble-seeds/task

## Dependencies (2)

- [minimist](https://npm.io/package/minimist.md) ^1.2.6
- [@marble-seeds/schema](https://npm.io/package/@marble-seeds/schema.md) ^0.1.1

## Recent versions

- 1.0.0-rc.8 (latest) — 2024-03-24
- 1.0.0-rc.7 — 2024-03-16
- 1.0.0-rc.6 — 2023-10-22
- 1.0.0-rc.5 — 2023-07-23
- 1.0.0-rc.4 — 2023-04-16
- 1.0.0-rc.3 — 2023-01-16
- 1.0.0-rc.2 — 2023-01-16
- 1.0.0-rc.1 — 2023-01-16
- 0.11.0 — 2022-10-09
- 0.10.0 — 2022-09-25
- 0.9.7 — 2022-09-25
- 0.9.6 — 2022-09-17
- 0.9.5 — 2022-09-16
- 0.9.4 — 2022-09-10
- 0.9.3 — 2022-09-04
- … 3 more at https://npm.io/package/@marble-seeds/task/versions

## README

## Marble seeds Tasks module

## Install with

```
npm i @marble-seeds/@marble-seeds/tasks
```

## Docs

In your tasks folder create your file with

```
const Task = require('@marble-seeds/tasks')

const task = new Task(async function (argv) {
  console.log(argv)

  return { foo: true }
})

if (require.main === module) {
  task.setCliHandlers()
  task.run()
} else {
  module.exports = task
}
```

The last part will allow you to call it as a CLI or be loaded on your app and run as part of you app

## Task philosophy

Task are small units of logic that should be repetable and composable.

Task to be able have repetable tasks, we need to care about 2 concepts:
- *Input/Output*: To handle the inputs and outputs of a task in a easy way, task are build to be black boxes.
- *Boundaries of the box*

By carring about this elements logs test of task can be created by recording the 3 elements and then replay them.

### boundary

To be able to treat task as black boxes, all the interactions to fetch data, save elements need to be moved to boundaries.

```
const task = new Task(async function (argv, { getData }) {
  const data = async getData()
  console.log(argv, data)

  return { ...data, ...argv }
}, {
  boundaries : {
    getData: async () => {
      // someting
      return data
    }
  }
})
```

By defining bounderies in this form, we can record the interactions from the task with other elements allowing to track them and mock them.

Boundary have 4 modes:

- Proxy: execute the function and records it
- Proxy-pass: review if the input exist, it it exist returns the previous value and if not execute the functions
- Proxy-catch: executes the function and if it throws and error, it tries to use a previews output if it exists for the input.
- Replay: review if the input exist and if it doesnt throws and error.

With this modes bounderies can be used as cache or to generate test by passing the data to a RecordTape to re-run the calls.

## Task API

### constructor

Takes a task action(function) and a timeout as params.

### run

Runs the task action asynchronously. Takes the function arguments and a config object with a timeout option.

### setCliHandlers

Lets the taks that it will run as a CLI program.


# ToDos

- CLI run test and argv handler
- Document boundaries

---
_Source: https://npm.io/package/@marble-seeds/task · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
