import cytoscape from "cytoscape"; import Node from "@specs-feup/flow/graph/Node"; import BaseGraph from "@specs-feup/flow/graph/BaseGraph"; import BaseEdge from "@specs-feup/flow/graph/BaseEdge"; import { NodeCollection } from "@specs-feup/flow/graph/NodeCollection"; import { EdgeCollection } from "@specs-feup/flow/graph/EdgeCollection"; /** * The base {@link Node | node type}. All node types must be subtypes of this type. */ declare namespace BaseNode { /** * The class with functionality for the base node type. */ class Class { #private; /** * This constructor is for internal use only. Use {@link BaseGraph.Class.addNode} to create a new node instead. * * It is not possible to make the constructor private or protected as it is used * in other parts of this framework outside of this class (for instance, * {@link Node.Class}). However, it should not be used directly by user code. * * @param graph The graph that this node is a part of. * @param node The underlying cytoscape node object. * @param _d A hack to force typescript to typecheck D in {@link BaseNode.Class.as} method. * @param _sd A hack to force typescript to typecheck S in {@link BaseNode.Class.as} method. * @deprecated @hideconstructor */ constructor(graph: BaseGraph.Class, node: cytoscape.NodeSingular, _d?: D, _sd?: S); /** * Use the data object for JSON serializable data. * For temporary or non-serializable data, use {@link BaseNode.Class.scratchData}. * * @returns the data object associated with this node. */ get data(): D; /** * Use the scratch data object for temporary or non-serializable data. * For JSON serializable data, use {@link BaseEdge.Class.data}. * * The scratch data is stored under the {@link Graph.scratchNamespace | @specs-feup/flow namespace}. * * @returns the scratch data object associated with this node. */ get scratchData(): S; /** * @returns the unique identifier of this node. */ get id(): string; /** * @returns the parent node of this node. */ get parent(): BaseNode.Class | undefined; /** * Changes the parent node of this node. * * @param node The new parent node. If undefined, the node becomes orphan. */ set parent(node: BaseNode.Class | undefined); /** * @returns The ancestors (parents, parents' parents, etc.) of this node. */ get ancestors(): NodeCollection; /** * @return The children of this node. */ get children(): NodeCollection; /** * @returns The descendants (children, children's children, etc.) of this node. */ get descendants(): NodeCollection; /** * @returns whether this node is a parent node. */ get isParent(): boolean; /** * @returns whether this node is a child node. */ get isChild(): boolean; /** * Initializes the node with the information of a builder. This is effectively * extends the type of the node to include the data and scratch data of the builder. * * The same node may simultaneously be of multiple types, as long as the data and * scratch data are compatible with the types. The builder methods may overwrite * data and scratch data fields with names that collide with its type's fields. * * @param builder The builder to use to initialize the node. * @returns The same node, with the data and scratch data of the builder. * The node is downcasted to {@link BaseNode.Class} because the builder may * overwrite the data and scratch data fields, invalidating the current type. */ init(builder: Node.Builder): BaseNode.Class; /** * Checks if this node's data and scratch data are compatible * with a specific type. This is effectively a type guard function. * * @param NodeType The node type to check compatibility with. * @returns Whether the node is compatible with the given type. */ is>(NodeType: Node): this is BaseNode.Class; /** * Changes the functionality class of the current node. This is only * possible if the data and scratch data are compatible with the new class. * To assert that, use {@link BaseNode.Class.is}. * * @param NodeType The node type to change the functionality class into. * @returns The same node, wrapped in the new functionality class. */ as>(NodeType: { Class: Node.Class; }): N2; /** * Changes the functionality class of the current node. Should only be used * when it is known (but not statically provable) that the node is compatible * with the new class. If not, an error will be thrown. * * It is bad practice to try and catch the error thrown by this function. For * such cases, combine {@link BaseNode.Class.is} with {@link BaseNode.Class.as}, * or use {@link BaseNode.Class.switch} instead. * * @param NodeType The node type to change the functionality class into. * @param message The message to throw if the node is not compatible with the type. * @returns The node, wrapped in the new functionality class. * @throws {} {@link LaraFlowError} if the node is not compatible with the type. * This error should be seen as a logic error and not catched. */ expect>(NodeType: Node, message?: string): N2; /** * Tries to change the functionality class of the current node. If the node * is not compatible with the new class, undefined is returned. * * @example * ```typescript * if (node === undefined || !node.is(ControlFlowNode)) { * return undefined; * } * return node.as(ControlFlowNode); * ``` * * Can be simplified to: * ```typescript * return node?.tryAs(ControlFlowNode); * ``` * * @param NodeType The node type to change the functionality class into. * @returns The node, wrapped in the new functionality class, or undefined if * the node is not compatible with the type. */ tryAs>(NodeType: Node): N2 | undefined; /** * Checks if the type of the node is compatible with several * types, calling a callback for the first match. See * {@link Node.Case} for the syntax of each case. * * For a default case, match with {@link BaseNode}, * which will always be compatible with any node type. * * @param cases The cases to match against. */ switch(...cases: ReturnType[]): void; /** * Returns the number of edges connected to this node. * Loop edges are counted twice. * * @returns the degree of this node. */ get degree(): number; /** * Returns the number of edges connected to this node. * Loop edges are not counted. * * @returns the degree of this node, excluding loop edges. */ get degreeWithoutLoops(): number; /** * Returns the number of edges that are directed towards this node. * * @returns the indegree of this node. */ get indegree(): number; /** * Returns the number of edges that are directed towards this node. * Loop edges are not counted. * * @returns the indegree of this node, excluding loop edges. */ get indegreeWithoutLoops(): number; /** * Returns the number of edges that are directed away from this node. * * @returns the outdegree of this node. */ get outdegree(): number; /** * Returns the number of edges that are directed away from this node. * Loop edges are not counted. * * @returns the outdegree of this node, excluding loop edges. */ get outdegreeWithoutLoops(): number; /** * @returns The edges that connect to this node. */ get incomers(): EdgeCollection; /** * @returns The predecessors of this node. * This repeatedly follows the sources of incoming edges. */ get predecessors(): NodeCollection; /** * @returns The edges that connect from this node. */ get outgoers(): EdgeCollection; /** * @returns The successors of this node. * This repeatedly follows the targets of outgoing edges. */ get successors(): NodeCollection; /** * @returns The edges that are adjacent to this node. */ get adjacentEdges(): EdgeCollection; /** * @returns The nodes that are adjacent to this node. */ get adjacentNodes(): NodeCollection; /** * Retrieves the edges that connect this node with the given nodes. * Direction is not considered. * * @param nodes The node or collection of nodes to check for edges connected * with this node. * @returns The edges that connect this node with the given nodes. */ edgesWith(nodes: NodeCollection | BaseNode.Class): EdgeCollection; /** * Retrieves the edges from this node to the given nodes. * * @param nodes The node or collection of nodes to check for edges connected * with this node. * @returns The edges from this node to the given nodes. */ edgesTo(nodes: NodeCollection | BaseNode.Class): EdgeCollection; /** * Retrieves the edges from the given nodes to this node. * * @param nodes The node or collection of nodes to check for edges connected * with this node. * @returns The edges from the given nodes to this node. */ edgesFrom(nodes: NodeCollection | BaseNode.Class): EdgeCollection; search(algorithm: Node.Search): Generator; dfs(propagate?: (edge: BaseEdge.Class) => boolean): Generator; bfs(propagate?: (edge: BaseEdge.Class) => boolean): Generator; /** * Removes this node from the graph. */ remove(): void; /** * @returns whether this node has been removed from the graph. */ get isRemoved(): boolean; /** * Restores this node if it has been removed. See {@link BaseNode.Class.remove}. */ restore(): void; /** * @returns A collection containing only this node. */ toCollection(): NodeCollection; /** * @returns the graph that this node is a part of. */ get graph(): BaseGraph.Class; /** * @returns the underlying cytoscape node object. */ toCy(): cytoscape.NodeSingular; } /** * Type guards for {@link BaseNode}. Since this is the base class, data and scratch * are always assumed to be compatible. */ const TypeGuard: Node.TypeGuard; /** * Data contained in this node type. */ interface Data { /** * The unique identifier of this node. */ id: string; /** * The parent node of this node, if any. */ parent?: string; } /** * Scratch data contained in this node type. */ interface ScratchData { } } export default BaseNode; //# sourceMappingURL=BaseNode.d.ts.map