# @nodl/core

> Core implementation of the Nodl framework

Latest version **1.0.9** (published 2023-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nodl/core
pnpm add @nodl/core
yarn add @nodl/core
bun add @nodl/core
```

## 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.9 |
| Published | 2023-09-18 |
| First published | 2023-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1749 |
| Author | Emil Widlund |
| Maintainers | emilwidlund |

## Links

- npm: https://www.npmjs.com/package/@nodl/core
- Repository: https://github.com/emilwidlund/nodl
- Homepage: https://github.com/emilwidlund/nodl#readme
- Issues: https://github.com/emilwidlund/nodl/issues
- npm.io page: https://npm.io/package/@nodl/core

## Dependencies (4)

- [mobx](https://npm.io/package/mobx.md) ^6.8.0
- [rxjs](https://npm.io/package/rxjs.md) ^7.8.0
- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [typescript](https://npm.io/package/typescript.md) ^4.9.4

## Recent versions

- 1.0.9 (latest) — 2023-09-18
- 1.0.8 — 2023-09-15
- 1.0.7 — 2023-09-14
- 1.0.6 — 2023-09-14
- 1.0.5 — 2023-09-12
- 1.0.4 — 2023-09-12
- 1.0.3 — 2023-03-21
- 1.0.2 — 2023-03-15
- 1.0.1 — 2023-03-13
- 1.0.0 — 2023-03-12
- 0.1.6 — 2023-03-09
- 0.1.5 — 2023-03-08
- 0.1.4 — 2023-03-07
- 0.1.3 — 2023-02-23
- 0.1.2 — 2023-01-16
- … 1 more at https://npm.io/package/@nodl/core/versions

## README

# @nodl/core

The core implementation of the Nodl framework.

### Getting Started

#### Installation

```
# Using NPM
npm install @nodl/core

# Using Yarn
yarn add @nodl/core

# Using Bun
bun install @nodl/core
```

#### Additional dependencies

Make sure to also install the following packages:

```
# Using NPM
npm install rxjs zod

# Using Yarn
yarn add rxjs zod

# Using Bun
bun install rxjs zod
```

### API

#### Node

Nodes are units that consists of inputs and outputs. They're conceptually very similar to functions, with the difference that outputs may be multiple, compared to a function's single return value.

An Addition Node may for instance have two inputs and a single output, which computes the sum of the inputs.

```typescript
import { z } from 'zod';
import { Node, Input, Output, schema } from '@nodl/core';
import { combineLatest, map } from 'rxjs';

/** Declare a zod schema for value validation */
const NumberSchema = schema(z.number());

class Addition extends Node {
    name = 'Addition';

    inputs = {
        a: new Input({ name: 'A', type: NumberSchema, defaultValue: 0 }),
        b: new Input({ name: 'B', type: NumberSchema, defaultValue: 0 })
    };

    outputs = {
        output: new Output({
            name: 'Output',
            type: NumberSchema,
            observable: combineLatest([this.inputs.a, this.inputs.b]).pipe(
                map(inputs => inputs.reduce((sum, value) => sum + value), 0)
            )
        })
    };
}
```

### Example

```typescript
import { z } from 'zod';
import { Node, Input, Output, schema } from '@nodl/core';
import { combineLatest, map } from 'rxjs';

/** Declare a zod schema for value validation */
const NumberSchema = schema(z.number());

class Addition extends Node {
    name = 'Addition';

    inputs = {
        a: new Input({ name: 'A', type: NumberSchema, defaultValue: 0 }),
        b: new Input({ name: 'B', type: NumberSchema, defaultValue: 0 })
    };

    outputs = {
        output: new Output({
            name: 'Output',
            type: NumberSchema,
            observable: combineLatest([this.inputs.a, this.inputs.b]).pipe(
                map(inputs => inputs.reduce((sum, value) => sum + value), 0)
            )
        })
    };
}

/** Declare 3 addition nodes */
const additionNode1 = new Addition();
const additionNode2 = new Addition();
const additionNode3 = new Addition();

/** Connect them together */
additionNode1.outputs.output.connect(additionNode3.inputs.a);
additionNode2.outputs.output.connect(additionNode3.inputs.b);

/**
 * The output of AdditionNode3 will fire with a new sum
 * everytime the inputs of AdditionNode1 and AdditionNode2 changes
 */
additionNode3.outputs.output.subscribe(console.log);
```

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