@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
77 lines (76 loc) • 2.49 kB
TypeScript
import { ContextType, ErrorCallback } from '../shared/types';
import { PinLike } from '../pin/pin-like';
import { Control } from '../pin/control';
import { Signature } from './signature';
import { Agent } from './agent';
import { NodeLike } from './node-like';
export declare type NodeInputs = ContextType;
export declare type NodeOutput = (out: string, data?: any) => void;
/**
*
* Denotes the signature of a [node](https://connective.dev/docs/node).
*
*/
export interface NodeSignature extends Signature {
/**
*
* The list of inputs that are required for the node to run
*
*/
required?: string[];
}
/**
*
* Represents a [node](https://connective.dev/docs/node).
*
*/
export declare abstract class Node extends Agent implements NodeLike {
private _control;
private _res;
private _control_required;
/**
*
* @param signature the [signature](https://connective.dev/docs/agent#signature) of the node.
*
*/
constructor(signature: NodeSignature);
/**
*
* A node waits for its `.control` before each execution, if any pins are
* connected to `.control`.
*
*/
get control(): Control;
/**
*
* Override this to outline what should your node do during each execution.
*
* @param inputs a named map of inputs
* @param output a callback to emit outputs
* @param error a callback to emit errors
* @param context the context of the execution
*
*/
protected abstract run(inputs: NodeInputs, output: NodeOutput, error: ErrorCallback, context: ContextType): void;
protected createOutput(label: string): PinLike;
protected createEntries(): PinLike[];
protected createExits(): PinLike[];
clear(): this;
}
export declare type NodeRunFunc = (inputs: NodeInputs, output: NodeOutput, error: ErrorCallback, context: ContextType) => void;
declare class _CodeNode extends Node {
private _run;
constructor(signature: Signature, _run: NodeRunFunc);
protected run(inputs: NodeInputs, output: NodeOutput, error: ErrorCallback, context: ContextType): void;
}
/**
*
* Creates a [node](https://connective.dev/docs/node).
* [Checkout the docs](https://connective.dev/docs/node) for examples and further information.
*
* @param signature the signature of the node
* @param run the execution function of the node
*
*/
export declare function node(signature: Signature, run: NodeRunFunc): () => _CodeNode;
export default node;