@energyweb/node-red-contrib-green-proof-worker
Version:
## Peer dependencies
46 lines (45 loc) • 1.81 kB
TypeScript
import type { NodeAPI, NodeStatus, Node as NRNode } from 'node-red';
import type { Node } from './node';
import type { NodeMessage } from './types';
export type DoneCb = (err?: Error) => void;
export type SentMessage = NodeMessage<any> | (NodeMessage<any> | null)[];
/**
* Interface to separate our nodes from Node Red APIs
*/
export interface Api {
send(msg: SentMessage): void;
error(log: string): void;
log(log: string): void;
warn(log: string): void;
on(event: 'input', cb: (msg: NodeMessage<any>, done: DoneCb) => void): void;
on(event: 'close', cb: (done: VoidFunction) => void): void;
status(status: string | NodeStatus): void;
getNode<T extends (...args: any[]) => new (...args: any[]) => Node<any>>(id: string): InstanceType<ReturnType<T>> | undefined;
findNodeIdByType(type: string): string | undefined;
/**
* Due to how bamboozled node initialization flow is we need to create copy of API
* in each Node instance
*/
cloneAndInstantiate(node: Node<any>, config: any): Api;
}
export declare class NodeRedApi implements Api {
protected RED: NodeAPI;
protected instance: {
node: NRNode;
config: any;
} | null;
constructor(RED: NodeAPI, instance?: {
node: NRNode;
config: any;
} | null);
cloneAndInstantiate(node: Node<any>, config: any): NodeRedApi;
send(msg: SentMessage): void;
error(log: string): void;
log(log: string): void;
warn(log: string): void;
findNodeIdByType(type: string): string | undefined;
getNode<T extends Node<any>>(id: string): T | undefined;
on(event: 'input', cb: (msg: NodeMessage<any>, done: DoneCb) => void): void;
on(event: 'close', cb: (done: VoidFunction) => void): void;
status(status: string | NodeStatus): void;
}