UNPKG

pipeline-builder-demo

Version:
454 lines (387 loc) 11.8 kB
declare module "pipeline-builder" { interface IPortDesc { } /** * Interface for the class representing a binding of inputs and outputs of workflow steps. */ interface IPort { /** * Create a port. * @param {string} name * @param {Step} step * @param {PortDesc} desc */ new(name: string, step: IStep, desc: IPortDesc); /** * The name of this port. * @type {string} */ name: string; /** * Step this port belong to. * @type {Step} */ step: IStep; /** * Port description. * @type {PortDesc} */ desc: IPortDesc; /** * A list of incoming connections. * @type {Connection[]} */ inputs: IConnection[]; /** * A list of outgoing connections. * @type {Connection[]} */ outputs: IConnection[]; /** * Bind this target port to a source one. * @param {Port|*} source - Source of the data. * @returns {Connection} - created connection object */ bind(source: IPort | any): IConnection; /** * Unbind this target port from a source one. * @param {Port|*} source - Source of the data. */ unbind(source: IPort | any): void; /** * Unbind all input connections from this port. */ unbindAll(): void; /** * Unbind all connections for this port. */ disconnect(): void; } /** * Interface for the class representing a binding of inputs and outputs of workflow steps. */ interface IConnection { /** * Create a connection between two ports. * @param {Port|*} from - Source port or constant. * @param {Port} to - Destination port. */ new(from: IPort | any, to: IPort); /** * Source port or constant. * @type {Port|*} */ from: IPort | any; /** * Destination port. * @type {Port} */ to: IPort; /** * Unbinds this connection. */ unbind(): void; /** * Function tells whether or not this connection is still valid. * @returns {boolean} */ isValid(): boolean; } /** * Interface for the class representing a specific step in a workflow */ export interface IStep { /** * Create a workflow step. * * @param {string} name - Step name. * @param {Action=} action - Action to execute during the step. If no action is specified it will * automatically be created based on the configuration. * @param {object} [config={}] - Action configuration containing input bindings. * It should include action description in case the action is missing. * */ new(name: string, action: IAction, config?: any); /** * Step name. * @type {string} */ name: string; /** * Action performed during the step. * @type {Action} */ action: IAction; /** * Parent step. A step can only have a single parent. * @type {?Step} */ parent: IStep | null; /** * Child steps. * @type {Object.<string, Step>} */ children: any; /** * Input ports. * @type {Object.<string, Port>} */ i: any; o: any; /** * Add a child step. * * @param {Step} child * @returns {Step} */ add(child: IStep): IStep; /** * Remove a child. * @param {string} name */ remove(name: string): void; /** * Retrieve a workflow this step belongs to. * @returns {?Workflow} */ workflow(): IWorkflow | null; /** * Walk down the step hierarchy applying a callback. * @param {function|{before:function=, after:function=}} callback * @returns {*} */ walk(callback: any): any; } /** * Interface for the class representing the entire workflow */ export interface IWorkflow extends IStep { /** * Create a workflow. * @param {string} name - Workflow name. * @param {object} [config={}] - Workflow configuration containing input bindings. */ new(name: string, config?: any); /** * A list of actions to be (probably) used in the workflow. * @type {Object.<string, Action>} */ actions: any; /** * Add an action. * @param {Action} action * @returns {Action} */ addAction(action: IAction): IAction; /** * Remove an action. * @param {string} name */ removeAction(name: string, force?: boolean): void; /** * Removes actions that are used in no step. */ removeUnusedActions(): void; } /** * Interface for the class representing a generic action to be referenced in specific steps */ export interface IAction { /** * Create a generic action. * @param {string} name - Action name. * @param {object} desc - Action description. * @param {Object.<string, PortDesc>} [desc.i={}] - Input ports description. * @param {Object.<string, PortDesc>} [desc.o={}] - Output ports description. * @param {Object.<string, *>} desc.data - Arbitrary metadata associated with the action * (e.g. shell command). */ new(name: string, desc: any); /** * Action name. * @type {string} */ name: string; /** * Input ports description. * @type {Object.<string, PortDesc>} */ i: any; /** * Output ports description. * @type {Object.<string, PortDesc>} */ o: any; /** * Arbitrary metadata associated with the action * @type {Object.<string, *>} */ data: any; /** * Adds new ports or mutates already existing ones. * @param {object=} portDesc - Ports description. * @param {Object.<string, PortDesc>} [portDesc.i={}] - Input ports description. * @param {Object.<string, PortDesc>} [portDesc.o={}] - Output ports description. */ addPorts(portDesc: any): void; /** * Removes ports. * @param {object=} ports - Port description. * @param {Object.<string, string[]>} [ports.i=[]] - Array of input ports names. * @param {Object.<string, string[]>} [ports.o=[]] - Array of output ports names. */ removePorts(ports: any): void; /** * Renames single input port. * @param {string} oldName - current name. * @param {string} newName - new name. * @example * helloAction.renameIPort('name', 'theName'); */ renameIPort(oldName: string, newName: string): void; /** * Renames single output port * @param {string} oldName - current name. * @param {string} newName - new name. * @example * helloAction.renameOPort('response', 'result'); */ renameOPort(oldName: string, newName: string); } export interface IZoom { /** * Creates zoom component and attaches it to the paper. * @param {joint.dia.Paper} paper * @param {number} [zoomMultiplier=1.1] Multiplier */ new(paper: any, zoomMultiplier?: number); /** * Performs zoom-in action. */ zoomIn(): void; /** * Performs zoom-out action. */ zoomOut(): void; /** * Scales diagram contents to widget size. * @param {Object|*} opt - optional argument identical to * options in joint.dia.Paper.scaleContentToFit */ fitToPage(opt?: any): void; /** * Returns the currents scale of the component. * @returns {number} */ getCurrentScale(): number; } export interface IPaper { /** * Generate PNG data and return in by calling the callback * @param callback Callback where PNG data is going to be passed to/ * @param {object=} opts - Options * @param {string=} opts.bgrColor - background color. */ getPNG(callback: any, opts?: any): void; /** * Obtain svg string. * @returns {string} SVG contents. */ getSVG(): string; } /** * Interface for the class that allows to work with graphical pipeline representation */ export interface IVisualizer { /** * Create a pipeline visualizer. * @param the HTML page element to attach. */ new(element: HTMLElement): IVisualizer; /** * JointJS paper object. * @type {joint.dia.Paper} */ paper: IPaper | any; /** * Array of currently selected states. * @type {Array} */ selection: any[]; /** Public member to access zoom object * @type {Zoom} */ zoom: IZoom; /** * Clear the contents of component. */ clear(): void; /** * Attaches visualizer component to specific step. * All step's children are rendered upon attachment. * @param step */ attachTo(step: any): void; /** * Layout the contents automatically. */ layout(): void; /** * Updates the component. */ update(): void; } export interface IParseResult { status: boolean, message: string, model: IWorkflow[], actions: IAction[] } // /** // * Interface for the main namespace of a Pipeline Builder // */ // export interface IPipeline { /** * Package version. * @type {string} */ export const VERSION: string; /** * Link to class representing the entire workflow */ export const Workflow: IWorkflow; /** * Link to class representing a generic action to be referenced in specific steps */ export const Action: IAction; /** * Link to class representing a specific step in a workflow */ export const Step: IStep; /** * Link to class that allows to work with graphical pipeline representation */ export const Visualizer: IVisualizer; /** * Parse workflow definition file. * * @memberOf pipeline * @param {string} text - Text file contents to parse. * @param {object} [opts={}] - Parser options. * @param {string} [opts.format='wdl'] - Workflow definition format ('wdl', 'cwl'). * @returns {IWorkflow[]} A list of workflows. */ export function parse(text: string, opts?: any): IParseResult; /** * Generate workflow definition file. * * @memberOf pipeline * @param {IWorkflow} flow - Workflow being converted to a text file. * @param {object} [opts={}] - Generator options. * @param {string} [opts.format='wdl'] - Workflow definition format ('wdl', 'cwl'). * @returns {string} Textual representation of the workflow. */ export function generate(flow: IWorkflow, opts?: any): string; // } }