@dwp/govuk-casa
Version:
A framework for building GOVUK Collect-And-Submit-Applications
232 lines (231 loc) • 9.01 kB
TypeScript
/** @memberof module:@dwp/govuk-casa */
export default class Plan {
/**
* Waypoints using the url:// protocol are known as "exit nodes" as they
* indicate an exit point to another Plan.
*
* @param {string} name Waypoint name
* @returns {boolean} True if the waypoint is a url:// type
*/
static isExitNode(name: string): boolean;
/**
* Create a Plan.
*
* @param {PlanConstructorOptions} opts Options
*/
constructor(opts?: PlanConstructorOptions);
/**
* Retrieve the options set on this Plan.
*
* @returns {PlanConstructorOptions} Options map
*/
getOptions(): PlanConstructorOptions;
/**
* Retrieve the list of skippable waypoints.
*
* @returns {string[]} List of skippable waypoints
*/
getSkippables(): string[];
/**
* Add one or more skippable waypoints.
*
* @param {...string} waypoints Waypoints
* @returns {Plan} Chain
*/
addSkippables(...waypoints: string[]): Plan;
/**
* Check if the user can skip the named waypoint.
*
* @param {string} waypoint Waypoint
* @returns {boolean} True if waypoint can be skipped
*/
isSkippable(waypoint: string): boolean;
/**
* Retrieve all waypoints in this Plan (order is arbitrary).
*
* @returns {string[]} List of waypoints
*/
getWaypoints(): string[];
/**
* Determine if the given waypoint exists in this Plan.
*
* @param {string} waypoint Waypoint to search for
* @returns {boolean} Result
*/
containsWaypoint(waypoint: string): boolean;
/**
* Get all route information.
*
* @returns {PlanRoute[]} Routes
*/
getRoutes(): PlanRoute[];
/**
* Get the condition function for the given parameters.
*
* @param {string} src Source waypoint
* @param {string} tgt Target waypoint
* @param {string} name Route name
* @returns {PlanRouteCondition} Route condition function
*/
getRouteCondition(src: string, tgt: string, name: string): PlanRouteCondition;
/**
* Return all outward routes (out-edges) from the given waypoint, to the
* optional target waypoint.
*
* @param {string} src Source waypoint.
* @param {string} [tgt] Target waypoint.
* @returns {PlanRoute[]} Route objects found.
*/
getOutwardRoutes(src: string, tgt?: string): PlanRoute[];
/**
* Return all outward routes (out-edges) from the given waypoint, to the
* optional target waypoint, matching the "prev" name.
*
* @param {string} src Source waypoint.
* @param {string} [tgt] Target waypoint.
* @returns {PlanRoute[]} Route objects found.
*/
getPrevOutwardRoutes(src: string, tgt?: string): PlanRoute[];
/**
* Add a sequence of waypoints that will follow on from each other, with no
* routing logic between them.
*
* @param {...string} waypoints Waypoints to add
* @returns {void}
*/
addSequence(...waypoints: string[]): void;
/**
* Create a new directed route between two waypoints, labelled as "next".
*
* @param {string} src Source waypoint
* @param {string} tgt Target waypoint
* @param {PlanRouteCondition} follow Route condition function
* @returns {Plan} Chain
*/
setNextRoute(src: string, tgt: string, follow: PlanRouteCondition): Plan;
/**
* Create a new directed route between two waypoints, labelled as "prev".
*
* @param {string} src Source waypoint
* @param {string} tgt Target waypoint
* @param {PlanRouteCondition} follow Route condition function
* @returns {Plan} Chain
*/
setPrevRoute(src: string, tgt: string, follow: PlanRouteCondition): Plan;
/**
* Adds both a "next" and "prev" route between the two waypoints.
*
* By default, the "prev" route will use the same "follow" condition as the
* "next" route. This makes sense in that in order to get to the target, the
* condition must be true, and so to reverse the direction we also need that
* same condition to be true.
*
* However, if the condition function uses the `source`/`target` property of
* the route in some way, then we must reverse these before passing to the
* condition on the "prev" route because `source` in the condition will almost
* certainly be referring to the source of the "next" route.
*
* If `tgt` is an egress node, do not create a `prev` route for it, because
* there's no way back from that point to this Plan.
*
* @param {string} src Source waypoint.
* @param {string} tgt Target waypoint.
* @param {PlanRouteCondition} [followNext] Follow test function.
* @param {PlanRouteCondition} [followPrev] Follow test function.
* @returns {Plan} Chain
*/
setRoute(src: string, tgt: string, followNext?: PlanRouteCondition, followPrev?: PlanRouteCondition): Plan;
/**
* Create a named route between two waypoints, and give that route a function
* that determine whether it should be followed during traversal operations.
* Note that the source waypoint must be in a successful validation state to
* be considered for traversal, regardless of what the custom function
* determines.
*
* You may also define routes that take the user to any generic URL within the
* same domain by using the `url://` protocol. These are considered "exit
* nodes".
*
* SetNamedRoute("my-waypoint", "url:///some/absolute/url");
*
* @param {string} src Source waypoint.
* @param {string} tgt Target waypoint.
* @param {string} name Name of the route (must be unique for this waypoint
* pairing).
* @param {PlanRouteCondition} follow Test function to determine if route can
* be followed.
* @returns {Plan} Chain
* @throws {Error} If attempting to create a "next" route from an exit node
*/
setNamedRoute(src: string, tgt: string, name: string, follow: PlanRouteCondition): Plan;
/**
* This is a convenience method for traversing all "next" routes, and
* returning the IDs of all waypoints visited along the way.
*
* @param {JourneyContext} context Journey Context
* @param {PlanTraverseOptions} options Options
* @returns {string[]} List of traversed waypoints
*/
traverse(context: JourneyContext, options?: PlanTraverseOptions): string[];
/**
* Traverse the Plan by following all "next" routes, and returning the IDs of
* all waypoints visited along the way.
*
* @param {JourneyContext} context Journey Context
* @param {PlanTraverseOptions} options Options
* @returns {PlanRoute[]} List of traversed waypoints
*/
traverseNextRoutes(context: JourneyContext, options?: PlanTraverseOptions): PlanRoute[];
/**
* Traverse the Plan by following all "prev" routes, and returning the IDs of
* all waypoints visited along the way.
*
* @param {JourneyContext} context Journey Context
* @param {PlanTraverseOptions} options Options
* @returns {PlanRoute[]} List of traversed waypoints
*/
traversePrevRoutes(context: JourneyContext, options?: PlanTraverseOptions): PlanRoute[];
/**
* Traverse through the plan from a particular starting waypoint. This is a
* non-exhaustive Graph Exploration.
*
* The last route in the list will contain the source of the last waypoint
* that can be reached, i.e. The waypoint that has no further satisfiable
* out-edges.
*
* If a cyclical set of routes are encountered, traversal will stop after
* reaching the first repeated waypoint.
*
* @param {JourneyContext} context Journey context
* @param {PlanTraverseOptions} options Options
* @returns {PlanRoute[]} Routes that were traversed
* @throws {TypeError} When context is not a JourneyContext
*/
traverseRoutes(context: JourneyContext, options?: PlanTraverseOptions): PlanRoute[];
/**
* Get raw graph data structure. This can be used with other libraries to
* generate graph visualisations, for example.
*
* @returns {Graph} Graph data structure.
*/
getGraphStructure(): Graph;
#private;
}
export type PlanRoute = import("../casa").PlanRoute;
export type PlanRouteCondition = import("../casa").PlanRouteCondition;
export type PlanTraverseOptions = import("../casa").PlanTraverseOptions;
export type PlanArbiter = import("../casa").PlanArbiter;
export type PlanConstructorOptions = {
/**
* Check page validity
* before conditions. Default is `true`
*/
validateBeforeRouteCondition?: boolean | undefined;
/**
* Arbitration mechanism.
* Default is `undefined`
*/
arbiter?: string | import("../casa").PlanArbiter | undefined;
};
import JourneyContext from "./JourneyContext.js";
import { Graph } from "@dagrejs/graphlib";