UNPKG

tripetto-runner-foundation

Version:

Foundation library for building form/survey runners for Tripetto.

1,037 lines (1,020 loc) 542 kB
/*! Tripetto Runner Foundation 6.3.0 - Copyright (C) 2022 Tripetto B.V. - All Rights Reserved */ declare module "tripetto-runner-foundation" { import * as TripettoRunner from "tripetto-runner-foundation/module"; export * from "tripetto-runner-foundation/module"; export { TripettoRunner }; export default TripettoRunner; } declare module "tripetto-runner-foundation/module" { /** Contains the package name. */ export const NAME: string; /** Contains the version number. */ export const VERSION: string; /** Explicit exports */ export { Context, Data, Errors, IDataValues, IMoment, Instance, ISnapshot, IVariable, Value, IOntologyResumeEvent as IRunnerFoundationResumeEvent, } from "tripetto-runner-foundation/module/vfsm"; export { ICondition, IConditionBlock, IDefinition, INode, INodeBlock, IPrologue } from "tripetto-runner-foundation/module/map"; export { Kinds, Slot } from "tripetto-runner-foundation/module/slots"; export { TSerializeTypes } from "tripetto-runner-foundation/module/serializer"; export { Condition } from "tripetto-runner-foundation/lib/conditions/condition"; export { ConditionBlock } from "tripetto-runner-foundation/lib/conditions/blocks/block"; export { ConditionBlocksNamespace } from "tripetto-runner-foundation/lib/conditions/blocks/blocks"; export { IConditionBlockType, TConditionBlock } from "tripetto-runner-foundation/lib/conditions/blocks/type"; export { Branch } from "tripetto-runner-foundation/lib/branches/branch"; export { Cluster } from "tripetto-runner-foundation/lib/clusters/cluster"; export { RunnerFoundation } from "tripetto-runner-foundation/lib/runner"; export { IRunnerFoundationChangeEvent, IRunnerFoundationRestartEvent } from "tripetto-runner-foundation/lib/events"; export { Node } from "tripetto-runner-foundation/lib/nodes/node"; export { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; export { HeadlessBlock } from "tripetto-runner-foundation/lib/nodes/blocks/headless"; export { NodeBlocksNamespace } from "tripetto-runner-foundation/lib/nodes/blocks/blocks"; export { INodeBlockType, TNodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/type"; export { IObservableNode } from "tripetto-runner-foundation/lib/storyline/observable"; export { TChanges } from "tripetto-runner-foundation/lib/changes"; export { TModes } from "tripetto-runner-foundation/lib/modes"; export { TStatus } from "tripetto-runner-foundation/lib/status"; export { markdownify, markdownifyTo, markdownifyToString, markdownifyToPlainText, markdownifyToURL, } from "tripetto-runner-foundation/lib/markdown"; export { MarkdownFeatures, MarkdownTypes } from "tripetto-runner-foundation/module/markdown"; export { isVariable } from "tripetto-runner-foundation/lib/variables"; export { Storyline } from "tripetto-runner-foundation/lib/storyline/storyline"; export { IStoryline } from "tripetto-runner-foundation/lib/storyline/interface"; export { Moment } from "tripetto-runner-foundation/lib/storyline/moment"; export { IPage } from "tripetto-runner-foundation/lib/storyline/page"; export { Import } from "tripetto-runner-foundation/lib/data/import"; export { Export } from "tripetto-runner-foundation/lib/data/export"; export { IEpilogueContext as IEpilogue } from "tripetto-runner-foundation/lib/epilogue"; export { Namespaces, mountNamespace, unmountNamespace } from "tripetto-runner-foundation/lib/namespaces"; /** Decorators */ export { tripetto, tripetto as block } from "tripetto-runner-foundation/lib/decorators/block"; export { condition, IConditionHandler, ConditionResult } from "tripetto-runner-foundation/lib/decorators/condition"; export { validator, IValidatorHandler, ValidatorResult } from "tripetto-runner-foundation/lib/decorators/validate"; export { destroy, IDestroyHandler } from "tripetto-runner-foundation/lib/decorators/destroy"; export { fingerprint, calculateFingerprintAndStencil } from "tripetto-runner-foundation/lib/fingerprint"; export { stencil } from "tripetto-runner-foundation/lib/data/stencil"; export { checksum } from "tripetto-runner-foundation/lib/data/checksum"; export { powSolve, powVerify, powHashRate, powSpentTime, powDuration } from "tripetto-runner-foundation/lib/data/pow"; /** Implicit exports */ export * from "tripetto-runner-foundation/module/callback"; export * from "tripetto-runner-foundation/module/functional"; export * from "tripetto-runner-foundation/module/contracts"; /** Namespace exports */ export * as Slots from "tripetto-runner-foundation/module/slots"; export * as SHA2 from "tripetto-runner-foundation/module/sha2"; export * as AES from "tripetto-runner-foundation/module/aes"; export * as L10n from "tripetto-runner-foundation/module/l10n"; } declare module "tripetto-runner-foundation/lib/conditions/condition" { /** Dependencies */ import { Condition as ConditionFactory, Conditions, Context } from "tripetto-runner-foundation/module/vfsm"; import { Callback } from "tripetto-runner-foundation/module/callback"; import { RunnerFoundation } from "tripetto-runner-foundation/lib/runner"; import { ConditionResult } from "tripetto-runner-foundation/lib/decorators/condition"; import { ICondition } from "tripetto-runner-foundation/module/map"; export class Condition extends ConditionFactory<ICondition> { /** * Creates a new condition instance. * @param pConditions Reference to the conditions dispatcher. * @param pCondition Reference to the condition properties. */ constructor(pConditions: Conditions, pCondition: ICondition); /** Retrieves the identifier of the condition. */ get id(): string; /** Reference to the runner. */ get runner(): RunnerFoundation | undefined; /** * Invoked when the runner wants to verify the condition. * @param pContext Reference to the context. * @param pCallback Reference to the callback pointer. Pass this pointer as * return value to enable the asynchronous condition callback. * @return Returns the result of the condition or the callback reference if * the condition should be handled asynchronously. Returns `false` when no * block is available. * @event */ onCondition(pContext: Context, pCallback: Callback<boolean>): ConditionResult; /** * Invoked when the condition is approved. * @param pContext Reference to the context. * @event */ onApproved(pContext: Context): void; } } declare module "tripetto-runner-foundation/lib/conditions/blocks/block" { /** Dependencies */ import { IBranch, ICluster, ICondition, IConditionBlock, INode } from "tripetto-runner-foundation/module/map"; import { Condition } from "tripetto-runner-foundation/lib/conditions/condition"; import { Context, IVariable, ImmutableValue } from "tripetto-runner-foundation/module/vfsm"; import { IConditionBlockType } from "tripetto-runner-foundation/lib/conditions/blocks/type"; import { Kinds, Slot, Slots } from "tripetto-runner-foundation/module/slots"; import { TSerializeTypes } from "tripetto-runner-foundation/module/serializer"; export abstract class ConditionBlock<Properties extends {} = {}> { /** Contains the type identifier of the block. */ static readonly identifier: string; /** Retrieves the block type. */ readonly type: IConditionBlockType<ConditionBlock<Properties>>; /** Reference to the context. */ readonly context: Context; /** * Creates a new condition block instance. * @param pCondition Reference to the condition. * @param pContext Reference to the context. */ constructor(pCondition: Condition, pContext: Context); /** Retrieves the current view of the runner. */ get view(): "live" | "test" | "preview"; /** Retreieves the condition props. */ get condition(): Readonly<ICondition>; /** Retrieves the block props. */ get props(): Readonly<Properties & IConditionBlock>; /** Retrieves the node props. */ get node(): Readonly<INode> | undefined; /** Retrieves the cluster props. */ get cluster(): Readonly<ICluster> | undefined; /** Retrieves the branch props. */ get branch(): Readonly<IBranch> | undefined; /** Retrieves a reference to the slots (if the condition is connected to a node). */ get slots(): Slots | undefined; /** * Retrieves a slot. * @param sId Specifies the slot identifier. If omitted the function * tries to find the slot that is attached to the condition block. * @return Returns the slot or `undefined` if the slot was not found. */ protected slotOf<S extends Slot = Slot>(sId?: string): S | undefined; /** * Retrieves an immutable value. You can only retrieve values for the * slots of an attached node. If you want to retrieve values from other nodes * or for conditions without an attached node, use `immutableValueOf`. * @param pReference Optional parameter with a slot reference. If * omitted the function tries to find the slot that is attached to the * condition block. * @param sKind Specifies the slot kind. * @return Returns the mutable value or `undefined` if the value was not found. */ protected valueOf<T extends TSerializeTypes, S extends Slot<T> = Slot<T>>( pReference?: Slot | string, sKind?: Kinds ): ImmutableValue<T, S> | undefined; /** * Retrieves an immutable value. You can retrieve immutable values for any node. * @param pReference Optional parameter with a slot instance or identifier. If * omitted the function tries to find the slot that is attached to the * condition block. * @return Returns the immutable value or `undefined` if the value was not found. */ protected immutableValueOf<T extends TSerializeTypes, S extends Slot<T> = Slot<T>>( pReference?: Slot | string ): ImmutableValue<T, S> | undefined; /** * Retrieves a variable. * @param pReference Specifies the slot reference, value or variable identifier. * @return Returns the variable or `undefined` if the variable was not found. */ protected variableFor( pReference: | Slot | { slot: Slot; } | string ): IVariable | undefined; /** * Parses the supplied string, replacing all variables with their current values. * @param sString Specifies the string to parse. * @param sPlaceholder Specifies a string for empty variables (disabled by default). * @param bLineBreaks Specifies if line breaks are supported (disabled by default). * @return Returns the parsed string. */ protected parseVariables(sString: string, sPlaceholder?: string, bLineBreaks?: boolean): string; } } declare module "tripetto-runner-foundation/lib/conditions/blocks/blocks" { /** Dependencies */ import { Condition } from "tripetto-runner-foundation/lib/conditions/condition"; import { ConditionBlock } from "tripetto-runner-foundation/lib/conditions/blocks/block"; import { Context } from "tripetto-runner-foundation/module/vfsm"; import { TConditionBlock } from "tripetto-runner-foundation/lib/conditions/blocks/type"; export class ConditionBlocksNamespace { /** Creates a new namespace instance. */ constructor(sIdentifier: string); /** Retrieves the identifier for the namespace. */ get identifier(): string; /** * Registers a block. * @param pBlock Specifies the block. * @param sIdentifier Specifies the block type identifier. * @param pAliases Specifies type aliases for the block. */ register(pBlock: TConditionBlock, sIdentifier: string, pAliases: string[]): void; /** * Provides a new instance of a condition block for the supplied condition. * @param pCondition Reference to the condition. * @param pContext Reference to the context. * @return Returns a condition block instance. */ create<T extends ConditionBlock>(pCondition: Condition, pContext: Context): T | undefined; } } declare module "tripetto-runner-foundation/lib/conditions/blocks/type" { /** Dependencies */ import { Condition } from "tripetto-runner-foundation/lib/conditions/condition"; import { ConditionBlock } from "tripetto-runner-foundation/lib/conditions/blocks/block"; import { Context } from "tripetto-runner-foundation/module/vfsm"; export interface IConditionBlockType<T extends ConditionBlock> { /** Contains the block type identifier. */ readonly identifier: string; /** * Creates a new block instance. * @param pCondition Reference to the condition. * @param pContext Reference to the context. */ new (pCondition: Condition, pContext: Context): T; } export type TConditionBlock = IConditionBlockType<ConditionBlock>; } declare module "tripetto-runner-foundation/lib/branches/branch" { /** Dependencies */ import { Branch as BranchFactory, Context } from "tripetto-runner-foundation/module/vfsm"; import { IBranch } from "tripetto-runner-foundation/module/map"; import { RunnerFoundation } from "tripetto-runner-foundation/lib/runner"; import { Cluster } from "tripetto-runner-foundation/lib/clusters/cluster"; export class Branch extends BranchFactory<IBranch> { /** Retrieves the identifier of the branch. */ get id(): string; /** Reference to the runner. */ get runner(): RunnerFoundation | undefined; /** Reference to the cluster. */ get cluster(): Cluster; /** * Invoked when the branch condition is requested. * @return For now, the branch condition is always true. * @event */ onCondition(): boolean; /** * Invoked when the branch is left. * @param pContext Reference to the context. * @event */ onLeave(pContext: Context): void; } } declare module "tripetto-runner-foundation/lib/clusters/cluster" { /** Dependencies */ import { Await } from "tripetto-runner-foundation/module/callback"; import { RunnerFoundation } from "tripetto-runner-foundation/lib/runner"; import { Context, State } from "tripetto-runner-foundation/module/vfsm"; import { ICluster } from "tripetto-runner-foundation/module/map"; export class Cluster extends State<ICluster> { /** Retrieves the identifier of the cluster. */ get id(): string; /** Reference to the runner. */ get runner(): RunnerFoundation; /** Specifies the position of the cluster in the runner as a percentage. */ get percentageInRunner(): number; /** * Retrieves the validation result for the supplied context. * @param pContext Reference to the context. */ getValidation(pContext: Context): "unknown" | "pass" | "fail"; /** * Invoked when the enter condition for the cluster is requested. * @event */ onEnterCondition(): boolean; /** * Invoked when the cluster is entered. * @param pContext Reference to the context. * @param pAwait Reference to the await pointer * @return Returns the await reference. * @event */ onEnter(pContext: Context, pAwait: Await): Await; /** * Invoked when the cluster leave condition is requested. * @event */ onLeaveCondition(): boolean; /** * Invoked when the cluster is left (only for paginated runners). * @param pContext Reference to the context. * @event */ onLeave(pContext: Context): void; /** * Invoked when the cluster is canceled (only for paginated runners). * @param pContext Reference to the context. * @event */ onCancel(pContext: Context): void; /** * Invoked when the cluster needs to be validated. * @event */ onValidate(pContext: Context): boolean; /** * Invoked when the cluster is validated. * @param pContext Reference to the context. * @param sResult Specifies the validation state. * @param sType Specifies if the validation type. * @event */ onValidated(pContext: Context, sResult: "fail" | "pass", sType: "initial" | "revalidate"): void; /** * Invoked when the cluster starts or stops evaluating. * @param pContext Reference to the context. * @param bEvaluating Specifies if the cluster is evaluating. * @event */ onEvaluate(pContext: Context, bEvaluating: boolean): void; } } declare module "tripetto-runner-foundation/lib/runner" { /** Dependencies */ import { Branch } from "tripetto-runner-foundation/lib/branches/branch"; import { IDefinition, IPrologue } from "tripetto-runner-foundation/module/map"; import { Namespace as L10nNamespace } from "tripetto-runner-foundation/module/l10n"; import { Cluster } from "tripetto-runner-foundation/lib/clusters/cluster"; import { Condition } from "tripetto-runner-foundation/lib/conditions/condition"; import { Context, IDataChangeEvent, ISnapshot, Instance, Ontology } from "tripetto-runner-foundation/module/vfsm"; import { IRunnerFoundationChangeEvent, TRunnerFoundationEvents } from "tripetto-runner-foundation/lib/events"; import { Await } from "tripetto-runner-foundation/module/callback"; import { IStoryline } from "tripetto-runner-foundation/lib/storyline/interface"; import { Node } from "tripetto-runner-foundation/lib/nodes/node"; import { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; import { Storyline } from "tripetto-runner-foundation/lib/storyline/storyline"; import { TChanges } from "tripetto-runner-foundation/lib/changes"; import { TModes } from "tripetto-runner-foundation/lib/modes"; import { TStatus } from "tripetto-runner-foundation/lib/status"; import { IEpilogueContext } from "tripetto-runner-foundation/lib/epilogue"; import { INamespace } from "tripetto-runner-foundation/lib/namespaces"; export class RunnerFoundation<T extends NodeBlock = NodeBlock, Data = undefined> extends Ontology< Cluster, Node<T>, Branch, Condition, IDefinition, TRunnerFoundationEvents > { /** * Invoked when the runner instance is changed. * @event */ onChange?: (pEvent: IRunnerFoundationChangeEvent<T>) => void; /** * Invoked when the collected data of an instance is changed. * @event */ onData?: (pInstance: Instance, pDataChangeEvent: IDataChangeEvent) => void; /** * Invoked when the runner instance finishes. * @event */ onFinish?: (pInstance: Instance) => Promise<string | undefined> | boolean; /** * Invoked when the runner is restarted. * @event */ onRestart?: (pInstance: Instance) => void; /** Retrieves an initial storyline. */ static getInitialStoryline<T extends NodeBlock = NodeBlock>(sMode: TModes): IStoryline<T>; /** * Creates a new runner instance. * @param pProps Specifies the properties for the runner instance. */ constructor(pProps: { /** Specifies the definition to load. */ readonly definition: IDefinition | string; /** * Specifies the mode of operation. Can be one of the following values: * - `paginated`: Render each cluster on a separate page (this is the default behavior); * - `continuous`: Render all completed clusters and the current cluster on a page; * - `progressive`: Render all completed, current and future clusters on a page. */ readonly mode: TModes; /** Specifies a namespace identifier for the runner. */ readonly namespace?: string; /** Specifies the l10n namespace to use. */ readonly l10n?: L10nNamespace; /** Specifies if the runner should be started. */ readonly start?: boolean; /** Specifies if the runner should run in preview mode (this will start the runner when the `start`-prop is omitted). */ readonly preview?: boolean; /** Specifies if the runner runs in test mode. */ readonly test?: boolean; /** Specifies the snapshot to restore (this will start the runner when the `start`-prop is omitted). */ readonly snapshot?: ISnapshot<Data>; /** Specifies data for instances. */ readonly data?: (pInstance: Instance) => void; }); /** Retrieves the namespace for the runner. */ get namespace(): INamespace; /** Retrieves the definition. */ get definition(): Readonly<IDefinition> | undefined; /** Sets the definition. */ set definition(pDefinition: IDefinition | undefined); /** Retrieves a reference to the active instance. */ get instance(): Instance | undefined; /** Retrieves the storyline of the running instance. */ get storyline(): Storyline<T> | undefined; /** Retrieves the name of the definition. */ get name(): string; /** Retrieves the mode of operation. */ get mode(): TModes; /** Sets the operation mode. */ set mode(sMode: TModes); /** Retrieves if the preview mode is enabled. */ get isPreview(): boolean; /** Sets the preview mode. */ set isPreview(bPreview: boolean); /** Retrieves the test flag. */ get isTest(): boolean; /** Sets the test flag. */ set isTest(bTest: boolean); /** Retrieves the status of the runner. */ get status(): TStatus; /** Retrieves if the runner is empty. */ get isEmpty(): boolean; /** Retrieves the prologue of the loaded definition. */ get prologue(): IPrologue | undefined; /** Retrieves the epilogue of the loaded definition. */ get epilogue(): IEpilogueContext; /** * Invoked when the runner is updated. * @param pInstance Reference to the instance. * @param sChange Specifies the type of change. * @param pStoryline Contains the storyline (if the instance is running). * @event */ protected onInstanceChange(pInstance: Instance, sChange: TChanges, pStoryline: Storyline<T> | undefined): void; /** * Invoked when an instance is started. * @param pInstance Reference to the instance. * @event */ protected onInstanceStart(pInstance: Instance): void; /** * Invoked when the collected data of an instance is changed. * @param pInstance Reference to the instance. * @param pDataChangeEvent Reference to a value change event. * @event */ protected onInstanceData(pInstance: Instance, pDataChangeEvent: IDataChangeEvent): void; /** * Invoked when an instance is processing. * @param pInstance Reference to the instance. * @param bProcessing Specifies if the instance is processing. * @event */ protected onInstanceProcessing(pInstance: Instance, bProcessing: boolean): void; /** * Invoked when an instance wants to check if it can step forward. * @param pInstance Reference to the instance. * @param pCluster Reference to the current cluster. * @return Returns `true` if step forward is allowed. * @event */ protected onInstanceStepForward(pInstance: Instance, pCluster: Cluster): boolean; /** * Invoked when the instance is updated. * @param pInstance Reference to the instance. * @event */ protected onInstanceUpdate(pInstance: Instance): void; /** * Invoked when an instance is about to finish. * @param pInstance Reference to the instance. * @param fnFinish A callback function that can be used to control the finish process when you override this event and return `false`. * @return Return `true` if the instance finish is allowed or `false` if the instance finish should wait till the callback function is invoked. * @event */ protected onInstanceFinishing(pInstance: Instance, fnFinish: (bFinish: boolean, sReference?: string) => void): boolean; /** * Invoked when an instance ends. This event is always invoked * when an instance is finished, stopped or paused. * @param pInstance Reference to the instance. * @param sType Specifies why the instance has ended. Can be one of the * following values: * - `finished`: The instance has finished; * - `stopped`: The instance was forced to stop; * - `paused`: The instance was paused. * @event */ protected onInstanceEnd(pInstance: Instance, sType: "finished" | "stopped" | "paused"): void; /** * Invoked when a cluster is entered. * @param pContext Reference to the context. * @param pCluster Reference to the cluster to render. * @param pObserver Reference to the await pointer that signals the * runner to validate the cluster and make a step forward. If the * mode is set to `progressive` this is done automatically. * @event */ onInstanceCluster(pContext: Context, pCluster: Cluster, pObserver: Await): void; /** * Invoked when a cluster starts or stops evaluating. * @param pInstance Reference to the instance. * @param pCluster Reference to the cluster that is evaluating. * @param bEvaluating Specifies if the cluster is evaluating. * @event */ onInstanceClusterEvaluating(pInstance: Instance, pCluster: Cluster, bEvaluating: boolean): void; /** * Invoked when a cluster is left. * @param pInstance Reference to the instance. * @param sDirection Specifies the step direction. * @param pCluster Reference to the cluster that is left. * @event */ onInstanceClusterLeave(pInstance: Instance, sDirection: "forward" | "backward", pCluster: Cluster): void; /** * Invoked when a branch is left. * @param pContext Reference to the context. * @param pBranch Reference to the branch that is left. * @event */ onInstanceBranchLeave(pContext: Context, pBranch: Branch): void; /** * Invoked when a node is entered. * @param pContext Reference to the context. * @param pNode Reference to the node to render. * @param pObserver Reference to the await pointer that signals the * runner to validate the node. If the mode is set to `progressive` this * is done automatically. * @event */ onInstanceNode(pContext: Context, pNode: Node<T>, pObserver: Await): void; /** * Invoked when the progress changes. * @param pInstance Reference to the instance. * @param nPercentage Contains the progress percentage. * @event */ onInstanceProgress(pInstance: Instance, nPercentage: number): void; /** * Invoked when the instance makes a step. * @param pInstance Reference to the instance. * @param sDirection Specifies the step direction. * @event */ onInstanceStep(pInstance: Instance, sDirection: "forward" | "backward"): void; /** * Invoked when the cluster is validated. * @param pInstance Reference to the instance. * @param sResult Specifies the validation state. * @param sType Specifies if the validation type. * @event */ onInstanceValidated(pInstance: Instance, sResult: "fail" | "pass", sType: "initial" | "revalidate"): void; /** * Restores a runner snapshot. * @param pSnapshot Specifies the snapshot data. * @return Returns a reference to the instance. */ restore(pSnapshot: ISnapshot<Data>): Instance | undefined; /** * Reloads the runner with the specified definition. During a reload * the runner tries to maintain any collected data. * @param pDefinition Specifies the definition. * @param bOnlyRestartWhenRunning Specifies to only restart the runner * if it was running before the reload was requested (defaults to `false`). * @return Returns the new instance or `undefined` if no new instance was started. */ reload(pDefinition: IDefinition, bOnlyRestartWhenRunning?: boolean): Instance | undefined; /** * Restarts the runner. * @param bPreserveData Specifies if the data of an existing running * instance should be preserved (defaults to `false`). * @return Returns a reference to the instance. */ restart(bPreserveData?: boolean): Instance; /** * Rerenders the runner for the specified instance. * @param pInstance Reference to the instance. */ rerender(pInstance: Instance): void; /** * Step forward in the instance. * @return Returns `true` if the step succeeded. */ stepForward(): boolean; /** * Step backward in the active instance. * @return Returns `true` if the step succeeded. */ stepBackward(): boolean; /** * Step to the start of the active instance. * @return Returns `true` if the step succeeded. */ stepToStart(): boolean; /** * Step to the head in the history of the active instance. * @return Returns `true` if the step succeeded. */ stepToHead(): boolean; /** * Finish the active instance when it is finishable. * @return Returns a promise that resolves when the instance was finished. */ finish(): Promise<void> | false; } } declare module "tripetto-runner-foundation/lib/events" { /** Dependencies */ import { RunnerFoundation } from "tripetto-runner-foundation/lib/runner"; import { IHookPayload, THooks } from "tripetto-runner-foundation/module/hookup"; import { Instance } from "tripetto-runner-foundation/module/vfsm"; import { IStoryline } from "tripetto-runner-foundation/lib/storyline/interface"; import { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; import { TChanges } from "tripetto-runner-foundation/lib/changes"; export type TRunnerFoundationEvents = "OnChange" | "OnRestart" | "OnReload"; interface IRunnerFoundationEvent<H extends THooks, T extends NodeBlock, Data> extends IHookPayload<H> { /** Reference to the runner. */ readonly runner: RunnerFoundation<T, Data>; } export interface IRunnerFoundationChangeEvent<T extends NodeBlock = NodeBlock, Data = undefined> extends IRunnerFoundationEvent<"OnChange", T, Data> { /** Specifies the type of change. */ readonly change: TChanges; /** Reference to the instance. */ readonly instance: Instance | undefined; /** Reference to the storyline. */ readonly storyline: IStoryline<T>; } export interface IRunnerFoundationRestartEvent<T extends NodeBlock = NodeBlock, Data = undefined> extends IRunnerFoundationEvent<"OnRestart", T, Data> { /** Reference to the instance. */ readonly instance: Instance; } export {}; } declare module "tripetto-runner-foundation/lib/nodes/node" { /** Dependencies */ import { Await, Callback } from "tripetto-runner-foundation/module/callback"; import { Cluster } from "tripetto-runner-foundation/lib/clusters/cluster"; import { INode } from "tripetto-runner-foundation/module/map"; import { RunnerFoundation } from "tripetto-runner-foundation/lib/runner"; import { ConditionResult } from "tripetto-runner-foundation/lib/decorators/condition"; import { Context, Transducer, Transducers } from "tripetto-runner-foundation/module/vfsm"; import { ValidatorResult } from "tripetto-runner-foundation/lib/decorators/validate"; import { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; import { HeadlessBlock } from "tripetto-runner-foundation/lib/nodes/blocks/headless"; export class Node<T extends NodeBlock | HeadlessBlock = NodeBlock> extends Transducer<INode> { /** * Creates a new node instance. * @param pNodes Reference to the nodes dispatcher. * @param pNode Reference to the node properties. */ constructor(pNodes: Transducers, pNode: INode); /** Retrieves the identifier of the node. */ get id(): string; /** Reference to the runner. */ get runner(): RunnerFoundation; /** Reference to the cluster. */ get cluster(): Cluster; /** Retrieves if the node is a visible block. */ get isVisible(): boolean; /** * Retrieves the block instance. * @param pContext Reference to the context. * @return Returns the block instance or `undefined` if the block was not found. */ block(pContext: Context): T | undefined; /** * Invoked when the runner wants to verify the condition for the node. * This event is invoked just before the node is entered. * @param pContext Reference to the context. * @param pCallback Reference to the callback pointer. Pass this pointer as * return value to enable the asynchronous condition callback. * @return Returns the result of the condition or the callback reference if * the condition should be handled asynchronously. * @event */ onEnterCondition(pContext: Context, pCallback: Callback<boolean>): ConditionResult; /** * Invoked when the node is entered. * @param pContext Reference to the context. * @param pAwait Reference to the await pointer. * @event */ onEnter(pContext: Context, pAwait: Await): Await | void; /** * Invoked when the node is left. * @param pContext Reference to the context. * @event */ onLeave(pContext: Context): void; /** * Invoked when the transducer is canceled. * @param pContext Reference to the context. * @event */ onCancel(pContext: Context): void; /** * Invoked when the node needs to be validated. * @param pContext Reference to the context. * @param sCurrent Specifies the current node validation state. * @param pCallback Reference to the callback pointer. Pass this pointer as * return value to enable the asynchronous validation callback. * @return Returns the result of the validation or the callback reference if * the validation should be handled asynchronously. * @event */ onValidate(pContext: Context, sCurrent: "unknown" | "fail" | "pass", pCallback: Callback<boolean>): ValidatorResult; /** * Invoked when the node is validated. * @param pContext Reference to the context. * @param sResult Specifies the validation result. * @param sType Specifies the validation type. * @event */ onValidated(pContext: Context, sResult: "fail" | "pass", sType: "initial" | "revalidate"): void; /** * Invoked when a side effect is generated. * @param pContext Reference to the context. * @event */ onSideEffect(pContext: Context): void; } } declare module "tripetto-runner-foundation/lib/nodes/blocks/block" { import { Context, IVariable, ImmutableValue, Value } from "tripetto-runner-foundation/module/vfsm"; import { INode, INodeBlock } from "tripetto-runner-foundation/module/map"; import { INodeBlockType } from "tripetto-runner-foundation/lib/nodes/blocks/type"; import { Kinds, Slot } from "tripetto-runner-foundation/module/slots"; import { Node } from "tripetto-runner-foundation/lib/nodes/node"; import { TSerializeTypes } from "tripetto-runner-foundation/module/serializer"; export abstract class NodeBlock<Properties extends {} = {}> { /** Contains the type name of the block. */ static readonly identifier: string; /** Contains an optional ref. */ static readonly ref?: {}; /** Specifies if the block needs an automatic render upon value store. */ static readonly autoRender: boolean; /** Specifies if the block needs automatic validation. */ static readonly autoValidate: boolean; /** Retrieves the block type. */ readonly type: INodeBlockType<NodeBlock<Properties>>; /** Reference to the context. */ readonly context: Context; /** * Creates a new node block instance. * @param pNode Reference to the node. * @param pContext Reference to the context. */ constructor(pNode: Node, pContext: Context); /** Retrieves the current view of the runner. */ get view(): "live" | "test" | "preview"; /** Retrieves the validation state of the block. */ get validation(): "unknown" | "pass" | "fail"; /** Reference to the node props. */ get node(): Readonly<INode>; /** Contains the block props. */ get props(): Readonly<Properties & INodeBlock>; /** Specifies if an automatic render is needed upon value store. */ get shouldAutoRender(): boolean; /** Specifies if automatic validation is applied. */ get shouldAutoValidate(): boolean; /** Retrieves if the validation of the block failed. */ get isFailed(): boolean; /** Retrieves if the validation of the block passed. */ get isPassed(): boolean; /** * Retrieves a slot. * @param sReference Specifies the slot reference. * @param sKind Specifies the slot kind. * @return Returns the slot or `undefined` if the slot was not found. */ protected slotOf<S extends Slot = Slot>(sReference: string, sKind?: Kinds): S | undefined; /** * Retrieves a mutable value. You can only retrieve mutable values for the * slots managed by the block. If you want values from other nodes, use the * `immutableValueOf` method. * @param pReference Specifies the slot reference. * @param sKind Specifies the slot kind. * @param pOptions Specifies optional options. * @return Returns the mutable value or `undefined` if the value was not found. */ protected valueOf<T extends TSerializeTypes, S extends Slot<T> = Slot<T>>( pReference: Slot | string, sKind?: Kinds, pOptions?: { /** Specifies if the slot always has a confirmed value. */ readonly confirm?: boolean; /** Specifies a prefill value. */ readonly prefill?: { readonly value: TSerializeTypes; readonly reference?: string; }; /** Specifies a modifier function that is invoked when the data is about to change. */ readonly modifier?: (pValue: Value<T, S>) => | { readonly value: TSerializeTypes; readonly reference?: string; } | undefined; /** Invoked when a value is changed. */ readonly onChange?: (pValue: Value<T, S>) => void; /** Invoked when a value is used within another context. */ readonly onContext?: (pValue: Value<T, S>, pContext: Context) => void; } ): Value<T, S> | undefined; /** * Retrieves an immutable value. You can retrieve immutable values for any node. * @param pReference Specifies the slot instance or identifier. * @return Returns the immutable value or `undefined` if the value was not found. */ protected immutableValueOf<T extends TSerializeTypes, S extends Slot<T> = Slot<T>>( pReference: Slot | string ): ImmutableValue<T, S> | undefined; /** * Retrieves a variable. * @param pReference Specifies the slot reference, value or variable identifier. * @return Returns the variable or `undefined` if the variable was not found. */ protected variableFor( pReference: | Slot | { slot: Slot; } | string ): IVariable | undefined; /** * Parses the supplied string, replacing all variables with their current values. * @param sString Specifies the string to parse. * @param sPlaceholder Specifies a string for empty variables (disabled by default). * @param bLineBreaks Specifies if line breaks are supported (disabled by default). * @return Returns the parsed string. */ protected parseVariables(sString: string, sPlaceholder?: string, bLineBreaks?: boolean): string; /** * Retrieves a unique key for the block within the current context for the * specified label (the key is prefixed with an underscore). Use this function * if you need stable unique keys (for example for use as element identifiers). * @param sLabel Optional label for the key (if omitted the default key will * be returned). * @return Returns the key. */ key(sLabel?: string): string; /** Invokes a block rerendering. */ rerender(): void; /** Locks the data values of a block. */ lock(): void; /** Unlocks the data values of a block. */ unlock(): void; /** Clears the data values of a block. */ clear(): void; } } declare module "tripetto-runner-foundation/lib/nodes/blocks/headless" { /** Dependencies */ import { Await } from "tripetto-runner-foundation/module/callback"; import { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; import { Value } from "tripetto-runner-foundation/module/vfsm"; import { Slot } from "tripetto-runner-foundation/module/slots"; import { TSerializeTypes } from "tripetto-runner-foundation/module/serializer"; export abstract class HeadlessBlock<Properties extends {} = {}> extends NodeBlock<Properties> { /** * Retrieves the mutable value for the supplied slot instance or identifier. * @param pReference Specifies the slot instance or identifier. * @return Returns the value or `undefined` if no value was found. */ protected mutableValueOf<T extends TSerializeTypes, S extends Slot<T> = Slot<T>>( pReference: Slot | string ): Value<T, S> | undefined; /** * Implements the operation for the block. * @param pDone Reference to an await pointer that can be used for asynchronous operations. */ abstract do(pDone?: Await): Await | void; } } declare module "tripetto-runner-foundation/lib/nodes/blocks/blocks" { /** Dependencies */ import { Context } from "tripetto-runner-foundation/module/vfsm"; import { Node } from "tripetto-runner-foundation/lib/nodes/node"; import { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; import { HeadlessBlock } from "tripetto-runner-foundation/lib/nodes/blocks/headless"; import { TNodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/type"; export class NodeBlocksNamespace { /** Creates a new namespace instance. */ constructor(sIdentifier: string); /** Retrieves the identifier for the namespace. */ get identifier(): string; /** * Registers the supplied block. * @param pBlock Specifies the block. * @param sIdentifier Specifies the block type identifier. * @param pAliases Specifies type aliases for the block. * @param pRef Specifies an optional ref to something. * @param bAutoRender Specifies if the block needs to be rerendered upon * value store (disabled by default). * @param bAutoValidate Specifies if the block checks if all required * slots contain a value (enabled by default). */ register( pBlock: TNodeBlock, sIdentifier: string, pAliases: string[], pRef?: {}, bAutoRender?: boolean, bAutoValidate?: boolean ): void; /** * Creates a new instance of a node block for the supplied node. * @param pNode Reference to the node. * @param pContext Reference to the context. * @return Returns a node block instance. */ create<T extends NodeBlock | HeadlessBlock>(pNode: Node<T>, pContext: Context): T | undefined; } } declare module "tripetto-runner-foundation/lib/nodes/blocks/type" { /** Dependencies */ import { Context } from "tripetto-runner-foundation/module/vfsm"; import { Node } from "tripetto-runner-foundation/lib/nodes/node"; import { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; export interface INodeBlockType<T extends NodeBlock> { /** Contains the block type identifier. */ readonly identifier: string; /** Optional reference to something. */ readonly ref?: {}; /** Specifies if the block needs an automatic render upon value store. */ readonly autoRender?: boolean; /** Specifies if the block needs automatic validation. */ readonly autoValidate?: boolean; /** * Creates a new block instance. * @param pNode Reference to the node. * @param pContext Reference to the context. */ new (pNode: Node, pContext: Context): T; } export type TNodeBlock = INodeBlockType<NodeBlock>; } declare module "tripetto-runner-foundation/lib/storyline/observable" { /** Dependencies */ import { Await } from "tripetto-runner-foundation/module/callback"; import { Context } from "tripetto-runner-foundation/module/vfsm"; import { INode } from "tripetto-runner-foundation/module/map"; import { Node } from "tripetto-runner-foundation/lib/nodes/node"; import { NodeBlock } from "tripetto-runner-foundation/lib/nodes/blocks/block"; export interface IObservableNode<T extends NodeBlock> { /** Contains a unique identifier for the node. */ readonly id: string; /** Contains a unique key for the node within the current context (the key is prefixed with an underscore). */ readonly key: string; /** Reference to the node. */ readonly node: Node; /** Reference to the node properties. */ readonly props: INode; /** Reference to the node block. */ readonly block: T | undefined; /** Reference to the context. */ readonly context: Context; /** Specifies if the node collects data. */ readonly collectsData: boolean; /** Specifies if the node has collected data. */ readonly hasDataCollected: boolean; /** * Specifies if the node has changed and needs to be rerendered. * @param bReset Specifies if the change flag needs to reset to `false` * after this function is invoked (defaults to `true`). * @return Returns `true` if the node has changed. */ readonly hasChanged: (bReset?: boolean) => boolean; /** * Contains the enumerator for the node. Enumerators are only granted to nodes * that have a block that collects data. */ readonly enumerator: number | undefined; /** Contains the validation state of the node. */ readonly validation: "unknown" | "pass" | "fail"; /** Retrieves if the validation of the node failed. */ readonly isFailed: boolean; /** Retrieves if the validation of the node passed. */ readonly isPassed: boolean; /** Reference to the node observer. */ readonly observer: Await | undefined; } } declare module "tripetto-runner-fou