/*! * Copyright 2020 Ron Buckton * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { GraphSchema } from "./graphSchema"; import type { GraphCategory } from "./graphCategory"; import type { Graph } from "./graph"; import { GraphObject } from "./graphObject"; import { GraphLink } from "./graphLink"; import { GraphNodeIdLike } from "./graphNodeIdLike"; /** * Represents a node in the directed graph. */ export declare class GraphNode extends GraphObject { private _id; private _incomingLinks; private _outgoingLinks; private constructor(); /** * Gets the graph that this object belongs to. */ get owner(): Graph; /** * Gets the document schema for this object. */ get schema(): GraphSchema; /** * The unique identifier for the node. */ get id(): GraphNodeIdLike; /** * Gets a value indicating whether this node is a container (i.e., has any outgoing containment links). */ get isContainer(): boolean; /** * Gets a value indicating whether this node is contained by another node (i.e., has any incoming containment links). */ get isContained(): boolean; /** * Gets or sets a descriptive label to associate with this node. */ get label(): string | undefined; set label(label: string | undefined); /** * Gets the number of incoming links. */ get incomingLinkCount(): number; /** * Gets the number of outgoing links. */ get outgoingLinkCount(): number; /** * Gets the number of both incoming and outgoing links. */ get linkCount(): number; /** * Creates an iterator for links that have this node as their target. */ incomingLinks(...linkCategories: GraphCategory[]): IterableIterator; private _incomingLinksWorker; /** * Returns `true` if the node has at least one incoming link with one of the provided categories; otherwise, `false`. */ hasIncomingLinks(...linkCategories: GraphCategory[]): boolean; /** * Gets an incoming link from a source node to this node, if one exists. */ getIncomingLink(source: GraphNodeIdLike | GraphNodeIdLike, index?: number): GraphLink | undefined; /** * Deletes any incoming links to this node that have any of the provided categories. * If no categories are provided, all incoming links are deleted. * @returns The number of links that were deleted. */ deleteIncomingLinks(...linkCategories: GraphCategory[]): number; /** * Creates an iterator for links that have this node as their source. */ outgoingLinks(...linkCategories: GraphCategory[]): IterableIterator; /** * Returns `true` if the node has at least one outgoing link with one of the provided categories; otherwise, `false`. */ hasOutgoingLinks(...linkCategories: GraphCategory[]): boolean; /** * Gets an outgoing link from this node to a target node, if one exists. */ getOutgoingLink(target: GraphNodeIdLike | GraphNodeIdLike, index?: number): GraphLink | undefined; /** * Deletes any outgoing links from this node that have any of the provided categories. * If no categories are provided, all outgoing links are deleted. * @returns The number of links that were deleted. */ deleteOutgoingLinks(...linkCategories: GraphCategory[]): number; /** * Creates an iterator for links that have this node as either their source or their target. */ links(...linkCategories: GraphCategory[]): IterableIterator; /** * Deletes any links to or from this node that have any of the provided categories. * If no categories are provided, all links are deleted. * @returns The number of links that were deleted. */ deleteLinks(...linkCategories: GraphCategory[]): number; /** * Removes this node from the graph. */ deleteSelf(): boolean; /** * Finds the first node related to this node. * @param searchDirection Either `"source"` to find related links across the incoming links of sources, or `"target"` to find related links across the outgoing links of targets. * @param traversal An object that specifies callbacks used to control how nodes and links are traversed and which node should be returned. */ firstRelated(searchDirection: "source" | "target", traversal?: GraphNodeTraversal): GraphNode | undefined; /** * Creates an iterator for the nodes related to this node. * @param searchDirection Either `"source"` to find related links across the incoming links of sources, or `"target"` to find related links across the outgoing links of targets. * @param traversal An object that specifies callbacks used to control how nodes and links are traversed and which nodes are yielded during iteration. */ related(searchDirection: "source" | "target", traversal?: GraphNodeTraversal): IterableIterator; /** * Yields each node that either contains this node (if `searchDirection` is `"source"`), or is * contained by this node (if `searchDirection` is `"target"`). */ relatedContainmentNodes(searchDirection: "source" | "target"): IterableIterator; /** * Creates an iterator for the sources linked to this node. * @param linkCategories When specified, links must have at least one of the provided categories. */ sources(...linkCategories: GraphCategory[]): IterableIterator; /** * Creates an iterator for the targets linked to this node. * @param linkCategories When specified, links must have at least one of the provided categories. */ targets(...linkCategories: GraphCategory[]): IterableIterator; /** * Yields each node that contains this node */ ancestors(): IterableIterator; /** * Yields each node this node contains */ descendants(): IterableIterator; /** * Walks all incoming links to this node to determine if there are any circularities. * @param linkCategory The category of links to traverse. */ hasCircularity(...linkCategories: GraphCategory[]): boolean; /** * Creates a copy of the node (including its links) with a new id. */ copy(newId: GraphNodeIdLike): GraphNode; } export interface GraphNodeTraversal { /** * A callback used to determine whether a link should be traversed. If not specified, all links are traversed. */ traverseLink?: (link: GraphLink) => boolean; /** * A callback used to determine whether a node should be traversed. If not specified, all nodes are traversed. */ traverseNode?: (node: GraphNode, link: GraphLink) => boolean; /** * A callback used to determine whether a node should be yielded. If not specified, all nodes are yielded. */ acceptNode?: (node: GraphNode) => boolean; }