# @product-live/data-factory-nest

> NestJS module to abtract using the SDK to run custom tasks in data factory

Latest version **1.0.1** (published 2023-08-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install @product-live/data-factory-nest
pnpm add @product-live/data-factory-nest
yarn add @product-live/data-factory-nest
bun add @product-live/data-factory-nest
```

## 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.1 |
| Published | 2023-08-09 |
| First published | 2023-08-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 192.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | product-live |
| Maintainers | sb566115, clementaubert |

## Links

- npm: https://www.npmjs.com/package/@product-live/data-factory-nest
- npm.io page: https://npm.io/package/@product-live/data-factory-nest

## Dependencies (10)

- [cron](https://npm.io/package/cron.md) ^2.4.0
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^10.1.2
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^10.1.2
- [@nestjs/config](https://npm.io/package/@nestjs/config.md) ^3.0.0
- [class-validator](https://npm.io/package/class-validator.md) ^0.14.0
- [@nestjs/schedule](https://npm.io/package/@nestjs/schedule.md) ^3.0.1
- [@nestjs/terminus](https://npm.io/package/@nestjs/terminus.md) ^10.0.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.5.1
- [@product-live/api-sdk](https://npm.io/package/@product-live/api-sdk.md) ^2.10.0

## Recent versions

- 1.0.1 (latest) — 2023-08-09

## README

### `Intro`
This NestJS module is an abstraction layer for running custom tasks on data-factory. This uses our SDK for interracting with our Public API.

### `Usage`
Simple example of the modules usage to process a custom task. There is also an example in `"./example"` that is used by tests.

``` bash
npm install --save @product-live/data-factory-nest
```

Import the module `"DataFactoryModule"` inside your main app module. You'll need to pass it a module or multiple modules that export the tasks you want to run.
``` typescript
import {Module} from '@nestjs/common';
import {PowerTask, WorkerModule} from './worker';
import {DataFactoryModule} from '@product-live/data-factory-nest';

@Module({
    imports: [
        WorkerModule,
        DataFactoryModule.forRootAsync({
            imports: [WorkerModule],
            tasks: [PowerTask] // list of tasks to handle should be exported by module inside "imports"
        })
    ],
    providers: []
})
export class AppModule {}
```

The `"WorkerModule"` should have all the task you want to process. Most situations it'll only be one task.
``` typescript
import {Module} from '@nestjs/common';
import {PowerTask} from './power.task';

@Module({
    providers: [PowerTask],
    exports: [PowerTask]
})
export class WorkerModule {}
```

The task should look something like this. Validation can be added to the input and output.
``` typescript
import {Injectable, Logger} from '@nestjs/common';
import {IsNumber} from 'class-validator';
import {TaskRunner, DataFactoryTaskResult} from '@product-live/data-factory-nest';

class PowerTaskInput {

    @IsNumber()
    power: number;

}

class PowerTaskOutput {

    result: number;

}

@Injectable()
export class PowerTask implements TaskRunner<PowerTaskInput, PowerTaskOutput> {

    private readonly logger = new Logger(PowerTask.name);
    readonly taskDefinitionId = '40977547f2646d13414a171a';
    readonly taskInput = PowerTaskInput;

    async run(input: PowerTaskInput, workdirector: string): Promise<DataFactoryTaskResult<PowerTaskOutput>> {
        this.logger.log({msg: 'started Power task', input: input});
        return new DataFactoryTaskResult<PowerTaskOutput>()
            .setResult({
                result: Math.pow(2, input.power)
            });
    }

}
```

---
_Source: https://npm.io/package/@product-live/data-factory-nest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
