Class Chain<CC, IdsInContext, EndsInMultiple>

Source
Expand description

A collection of states to chain onto

A Chain has a start and zero or more chainable ends. If there are zero ends, calling next() on the Chain will fail.

Properties§

Source§

public readonly endStates: INextable[]

The chainable end state(s) of this chain

Source§

readonly id: "chain" = [object Object]

Descriptive identifier for this element

Source§

public readonly startState: State

The start state of this chain

Methods§

Source§

connect<
    Keys extends string,
    Ids extends Keys[],
    N extends IChainable<string, any>,
>(
    ids: Ids,
    _next: ChainableProvider<N, CC>,
    connectionOptions?: {
        [k in string]?: Pick<ConnectionOptions, "to">
    },
): Chain<
    {
        [K in string
        | number
        | symbol]: (
            N extends Chain<C_CC, any, false>
                ? IgnoreContext<C_CC> extends true
                    ? Omit<CC, "json">
                    : Omit<CC, "json"> & C_CC
                : N extends Group<_, G_Chain_CC, any>
                    ? IgnoreContext<G_Chain_CC> extends true
                        ? Omit<CC, "json">
                        : Omit<CC, "json"> & G_Chain_CC
                    : N extends If<any, any, any, I_Chain_CC, any>
                        ? IgnoreContext<I_Chain_CC> extends true
                            ? Omit<CC, "json">
                            : Omit<CC & I_Chain_CC, "json">
                        : N extends IChainable<Id, C>
                            ? IgnoreContext<C> extends true
                                ? Omit<CC, "json">
                                : { [k in string]: C } & Omit<CC, "json"> & {
                                    json: C;
                                }
                            : CC
        )[K]
    },
>

Connect a new state to specific states in the chain by their IDs Used to create connections from specific nodes rather than all end states

throws

Error if any specified state ID does not exist in the chain

Source§

multiple<N extends IChainable<string, any>>(
    _next: MultipleChainableProvider<N, CC>,
): Chain<
    {
        [K in string
        | number
        | symbol]: (
            N extends Chain<C_CC, any, false>
                ? IgnoreContext<C_CC> extends true
                    ? Omit<CC, "json">
                    : Omit<CC, "json"> & C_CC
                : N extends Group<_, G_Chain_CC, any>
                    ? IgnoreContext<G_Chain_CC> extends true
                        ? Omit<CC, "json">
                        : Omit<CC, "json"> & G_Chain_CC
                    : N extends If<any, any, any, I_Chain_CC, any>
                        ? IgnoreContext<I_Chain_CC> extends true
                            ? Omit<CC, "json">
                            : Omit<CC & I_Chain_CC, "json">
                        : N extends IChainable<Id, C>
                            ? IgnoreContext<C> extends true
                                ? Omit<CC, "json">
                                : { [k in string]: C } & Omit<CC, "json"> & {}
                            : CC
        )[K]
    },
    AddNodeIdToIds<N, IdsInContext>,
    true,
>

Connect multiple states in parallel to all current end states After using multiple(), you must use connect() to continue the chain

throws

Error if no states are provided

Source§

next<N extends IChainable<string, any>>(
    _next: EndsInMultiple extends true
        ? "Cannot use next() after multiple(), use connect() instead "
        : ChainableProvider<N, CC>,
    connectionOptions?: ConnectionOptions,
): Chain<
    {
        [K in string
        | number
        | symbol]: (
            N extends Chain<C_CC, any, false>
                ? IgnoreContext<C_CC> extends true
                    ? Omit<CC, "json">
                    : Omit<CC, "json"> & C_CC
                : N extends Group<_, G_Chain_CC, any>
                    ? IgnoreContext<G_Chain_CC> extends true
                        ? Omit<CC, "json">
                        : Omit<CC, "json"> & G_Chain_CC
                    : N extends If<any, any, any, I_Chain_CC, any>
                        ? IgnoreContext<I_Chain_CC> extends true
                            ? Omit<CC, "json">
                            : Omit<CC & I_Chain_CC, "json">
                        : N extends IChainable<Id, C>
                            ? IgnoreContext<C> extends true
                                ? Omit<CC, "json">
                                : { [k in string]: C } & Omit<CC, "json"> & {
                                    json: C;
                                }
                            : CC
        )[K]
    },
    AddNodeIdToIds<N, IdsInContext>,
>

Continue normal execution by adding the next state to the chain

Source§

start<N1 extends IChainable<string, any>>(
    state: N1,
): Chain<
    {
        [K in string
        | number
        | symbol]: (
            N1 extends Chain<C_CC, any, false>
                ? IgnoreContext<C_CC> extends true
                    ? Omit<{}, "json">
                    : Omit<{}, "json"> & C_CC
                : N1 extends Group<_, G_Chain_CC, any>
                    ? IgnoreContext<G_Chain_CC> extends true
                        ? Omit<{}, "json">
                        : Omit<{}, "json"> & G_Chain_CC
                    : N1 extends If<any, any, any, I_Chain_CC, any>
                        ? IgnoreContext<I_Chain_CC> extends true
                            ? Omit<{}, "json">
                            : Omit<{} & I_Chain_CC, "json">
                        : N1 extends IChainable<Id, C>
                            ? IgnoreContext<C> extends true
                                ? Omit<{}, "json">
                                : { [k in string]: C } & Omit<{}, "json"> & {
                                    json: C;
                                }
                            : {}
        )[K]
    },
    [N1["id"]],
    false,
>

Begin a new Chain from one chainable state

Source§

toList(): State<string, any>[]

Get all states that this chain traverses Performs a breadth-first traversal of the chain to collect all reachable states