import { Map as ImmutableMap } from 'immutable'; import { BranchId, StateHash, StateId } from './interfaces'; /** * A convenient wrapper around the ImmutableJS-based Dag-History data structure */ export default class DagGraph { graph: ImmutableMap; /** * Constructs a new instance * @param graph The immutableJS instance */ constructor(graph: ImmutableMap); /** * Print out the state graph in the console, for debug purposes */ print(): string; /** * Gets the current state ID */ readonly currentStateId: StateId; /** * Gets the start depth of the current branch * (i.e. how many commits it took from the dag root to reach the start of the current branch) * @param branch The BranchId to get the starting depth of */ branchStartDepth(branch: BranchId): number; /** * Gets the ending depth of the current branch * (i.e. how many commits it took from the dag root to reach the end of the current branch) * @param branch The BranchId to get the starting depth of */ branchEndDepth(branch: BranchId): number; /** * Gets the depth of a specific state * (i.e. how many commits it took from the root to reach the state) * @param branch The BranchId to get the starting depth of */ stateDepth(commit: StateId): number; /** * Gets the depth of a commit on a branch * (i.e. how many commits it took from the root to reach the commit on the branch) * @param branch The branch to qualify the commit * @param commit The commit to get the depth of */ depthIndexOf(branch: BranchId, commit: StateId): number | undefined; /** * Gets the maximum depth of the graph */ readonly maxDepth: number; /** * Mutate the current state id * @param stateId The new state id */ setCurrentStateId(stateId: StateId): this; /** * Get the current branch id */ readonly currentBranch: BranchId; /** * Get the last-generated state id */ readonly lastStateId: StateId; /** * Set the last-generated state id */ setLastStateId(value: StateId): this; /** * Get the last-generated branch id */ readonly lastBranchId: StateId; /** * Set the last-generated branch id */ setLastBranchId(value: BranchId): this; /** * Mutate the current branch id * @param branchId The new branch id */ setCurrentBranch(branchId: BranchId): this; /** * Gets the latest state id on a given branch * @param branch The branch to search on */ latestOn(branch: BranchId): StateId; /** * Gets the 'committed' state id on a given branch. * Pushing new states bumps the committed state id. The 'committed' state is the most recently visited in a branch. * @param branch The branch to search on */ committedOn(branch: BranchId): StateId; /** * Updates the latest state on the branch * @param branch The branch id * @param commit The new latest commit on the branchd */ setLatest(branch: BranchId, commit: StateId): this; /** * Updates the committed state on the branch * @param branch The branch id * @param commit The committed state id */ setCommitted(branch: BranchId, commit: StateId): this; /** * Each state is mapped to a single branch. This updates the branch for a state. * @param commit The state id * @param branch The branch that is now associated with the state. */ markStateForBranch(commit: StateId, branch: BranchId): this; /** * Sets the first state id of a branch * @param branch The branch id * @param commit The first state id on the branch */ setFirst(branch: BranchId, commit: StateId): this; /** * Gets the first state id on a branch * @param branch The branch to search on */ firstOn(branch: BranchId): StateId; /** * Update the name of a state * @param commit The id of the state to rename * @param name The new name of the state */ renameState(commit: StateId, name: string): this; /** * Gets the name of a given state * @param commit The state id to get the name of */ stateName(commit: StateId): any; /** * Gets the name of a branch * @param branch The branch to get the name of */ getBranchName(branch: BranchId): string; /** * Sets the name of a branch * @param branch The branch to set the name of * @param name The new branch name */ setBranchName(branch: BranchId, name: string): this; /** * Retrieve the physical state of a state id * @param commit The state id to get the physical state of */ getState(commit: StateId): T; /** * Inserts a new state * @param commit The new state id * @param parent The parent state id * @param state The physical state * @param name The name of the state */ insertState(commit: StateId, parent: StateId, state: T, name: string): this; /** * Logs a state visitation into the chronological state array */ logVisit(state: StateId): this; /** * Get child state ids of a given state id. * @param commit The parent state id */ childrenOf(commit: StateId): StateId[]; /** * Gets the parent state id of a given state id * @param commit The state id to get the parent state id of */ parentOf(commit: StateId): StateId; /** * Gets 'alternate parents' for a given state. As the graph is expanded, * and if state equality is enabled, then we can determine optimal paths to a given state as * it is re-discovered through alternative means. * * i.e. When this happens * * Original Visitiation * * a -> b -> c -> D // orginal path * \--> D' // branched path * * And D and D' are considered logically equivalent, then the parent state of D remains * 'c', but 'b' is added as an 'alternate parent' * * @param commit The state id to find "alternate parents" of */ alternateParentsOf(commit: StateId): StateId[]; /** * Gets the shallowest parent of a commit. Compares the graph-depth of the parent and * alternate parents. * @param commit The state id to search on */ shallowestParentOf(commit: StateId): StateId; /** * Replace the physical state of a stateId * @param commit The state ID to replace * @param state The new state */ replaceState(commit: StateId, state: T): this; /** * Gets the state-id path of a state id * @param commit The state id to get the commit path of */ commitPath(commit: StateId): StateId[]; /** * Gets the shortest path of a state id, considering alternate parentage * @param commit The state id to get the commit path of */ shortestCommitPath(commit: StateId): StateId[]; /** * Gets a path of all state ids on a branch * @param branch The branch to get the commit path on */ branchCommitPath(branch: BranchId): StateId[]; /** * Sets the parent state id of a child state * @param commit The child state id * @param parent The parent state id */ setParent(commit: StateId, parent: StateId): void; /** * Adds an alternate parent to a state id * @param commit The state id * @param parent The new alternate parent */ setAlternateParent(commit: StateId, parent: StateId): void; /** * Gets the list of branch ids available */ readonly branches: BranchId[]; /** * Gets the branch a state is associated with * @param commit The state id */ branchOf(commit: StateId): BranchId; /** * Gets all of the branches that a given state id is ancestral for. * * i.e. search all children and aggregate branch ids * * @param commit The state id to search on */ branchesOf(commit: StateId): BranchId[]; /** * Squash a branch down to one commit */ squashCurrentBranch(): this; /** * Search for a state by hash code * @param hash The hash code to search for */ getStateForHash(hash: StateHash): StateId; /** * Registers a state with a hash code. Existing hashes are removed * @param hash The hash code to register. */ setHashForState(hash: StateHash, state: StateId): void; /** * Remove a state from the graph * @param commit The state to remove */ private remove(commit); }