rete-engine
packageDataflowEngine is a plugin that integrates Dataflow with NodeEditor making it easy to use. Additionally, it provides a cache for the data of each node in order to avoid recurring calculations.
class DataflowEngine<Schemes extends DataflowEngineScheme>
Parameter | Extends | Description |
---|---|---|
Schemes | DataflowEngineScheme |
Extends Scope<never, Root
Listens nodecreated
noderemoved
Fetches output data of the node
fetch(nodeId: string): Promise<Record<string, any>>
Throws Cancelled
when reset
is called while fetching data
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id to fetch data from |
Returns Promise<Record<string, any>>
Fetches input data for the node by fetching data for all its predecessors recursively.
fetchInputs(nodeId: string): Promise<Record<string, any>>
Throws Cancelled when
reset` is called while fetching data
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id to fetch input data for |
Returns Promise<Record<string, any>>
Resets the cache of the node and all its predecessors.
reset(nodeId: string): void
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id to reset. If not specified, all nodes will be reset. |
Returns void
ControlFlowEngine is a plugin that integrates ControlFlow with NodeEditor making it easy to use
class ControlFlowEngine<Schemes extends ControlFlowEngineScheme>
Parameter | Extends | Description |
---|---|---|
Schemes | ControlFlowEngineScheme |
Extends Scope<never, Root
Listens nodecreated
noderemoved
constructor(configure: Configure<Schemes>): ControlFlowEngine<Schemes>
Parameter | Type | Description |
---|---|---|
configure | Configure<Schemes> | Allows to specify which inputs and outputs are part of the control flow |
Returns ControlFlowEngine<Schemes>
Trigger execution starting from the specified node.
execute(nodeId: string, input: string): void
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id |
input | string | Input key that will be considered as the initiator of the execution |
Returns void
Dataflow is a class that allows to process nodes in a graph using Dataflow approach.
class Dataflow<Schemes extends ClassicScheme>
Parameter | Extends | Description |
---|---|---|
Schemes | ClassicScheme |
constructor(editor: NodeEditor<Schemes>): Dataflow<Schemes>
Parameter | Type | Description |
---|---|---|
editor | NodeEditor<Schemes> | NodeEditor instance |
Returns Dataflow<Schemes>
Adds the node to the dataflow.
add(node: T, setup: DataflowNodeSetup<T, any, any>): void
Parameter | Type | Description |
---|---|---|
node | T | Node instance |
setup | DataflowNodeSetup<T, any, any> | Set of functions that define how to process the node |
Returns void
Fetches outputs of the node.
This method recursively calls data
function of the predecessor nodes until receives all of the required inputs and calls data
function of the specified node.
fetch(nodeId: string): Promise<Record<string, any>>
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id |
Returns Promise<Record<string, any>>
Object with outputs
Fetches inputs of the node.
Unlike fetch
method, this method doesn't call data
function of the specified node (but does call data
for predecessor nodes recursively).
fetchInputs(nodeId: string): Promise<Record<string, any>>
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id |
Returns Promise<Record<string, any>>
Object with inputs
Removes the node from the dataflow.
remove(nodeId: string): void
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id |
Returns void
ControlFlow is a class that allows to execute nodes in a graph using Control flow approach.
class ControlFlow<Schemes extends ClassicScheme>
Parameter | Extends | Description |
---|---|---|
Schemes | ClassicScheme |
constructor(editor: NodeEditor<Schemes>): ControlFlow<Schemes>
Parameter | Type | Description |
---|---|---|
editor | NodeEditor<Schemes> | NodeEditor instance |
Returns ControlFlow<Schemes>
Adds the node to the control flow.
add(node: T, setup: ControlFlowNodeSetup<T, (keyof T["inputs"])[], (keyof T["outputs"])[]>): void
Parameter | Type | Description |
---|---|---|
node | T | Node instance |
setup | ControlFlowNodeSetup<T, (keyof T["inputs"])[], (keyof T["outputs"])[]> | Set of functions that define how to execute the node |
Returns void
Execute the node and its successors (in case forward
is called for some output).
execute(nodeId: string, input: string): void
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id |
input | string | Input key that will be considered as the initiator of the execution |
Returns void
Removes the node from the control flow.
remove(nodeId: string): void
Parameter | Type | Description |
---|---|---|
nodeId | string | Node id |
Returns void
Cancelled exception. Thrown when reset
is called while fetching data.
class Cancelled
Extends Error
ControlFlowNodeSetup is a set of functions that define how to execute a node.
type ControlFlowNodeSetup<
T extends ClassicScheme["Node"],
I extends (keyof T["inputs"])[],
O extends (keyof T["outputs"])[],
> = { inputs: Function; outputs: Function; execute: unknown };
Parameter | Extends | Description |
---|---|---|
T | ClassicScheme["Node"] | |
I | (keyof T["inputs"])[] | |
O | (keyof T["outputs"])[] |
DataflowNodeSetup is a set of functions that define how to process a node.
type DataflowNodeSetup<
T extends ClassicScheme["Node"],
I extends { [key in keyof T["inputs"]]: any },
O extends { [key in keyof T["outputs"]]: any },
> = { inputs: Function; outputs: Function; data: unknown };
Parameter | Extends | Description |
---|---|---|
T | ClassicScheme["Node"] | |
I | { [key in keyof T["inputs"]]: any } | |
O | { [key in keyof T["outputs"]]: any } |