### State Machine Initialization and Start Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/-building-state-machine/index Functions related to initializing and starting the state machine, including setting the initial state and starting with or without arguments. ```APIDOC ## setInitialState ### Description Sets the initial child state. This is required if the child mode is `ChildMode.EXCLUSIVE` and a state has children. ### Method `abstract fun setInitialState(state: IState)` ### Endpoint N/A (Kotlin function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```kotlin // Example usage within a State definition state("myState") { initialChild = setInitialState(childState) } ``` ### Response N/A --- ## start ### Description Starts the state machine. This is a suspendable function. ### Method `abstract suspend fun start(argument: Any? = null)` ### Endpoint N/A (Kotlin function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```kotlin stateMachine.start(initialArgument) ``` ### Response N/A --- ## startBlocking ### Description Starts the state machine in a blocking manner. ### Method `fun StateMachine.startBlocking(argument: Any? = null)` ### Endpoint N/A (Kotlin extension function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```kotlin stateMachine.startBlocking(initialArgument) ``` ### Response N/A ``` -------------------------------- ### Start State Machine (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/-state-machine/index Starts the state machine, optionally with an initial argument. This is the primary function to initiate the state machine's execution. ```kotlin abstract suspend fun start(argument: Any? = null) ``` -------------------------------- ### Starting from Specific States Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/-building-state-machine/index Functions to start the state machine from a specific state or a set of states, both in suspendable and blocking modes. ```APIDOC ## startFrom ### Description Starts the state machine from a specific state or a set of states. This is a suspendable function. ### Method `suspend fun StateMachine.startFrom(stateName: String, argument: Any? = null)` `suspend fun StateMachine.startFrom(state: DataState, data: D, argument: Any? = null)` `suspend fun StateMachine.startFrom(states: Set, argument: Any? = null)` `suspend fun StateMachine.startFrom(state: IState, argument: Any? = null)` `suspend fun StateMachine.startFrom(state1: IState, state2: IState, vararg states: IState, argument: Any? = null)` ### Endpoint N/A (Kotlin extension functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```kotlin // Start from a state by name stateMachine.startFrom("MyStateName") // Start from a specific IState object val targetState: IState = ... stateMachine.startFrom(targetState) // Start from multiple parallel states val parallelStates: Set = setOf(state1, state2) stateMachine.startFrom(parallelStates) // Start from multiple states using vararg stateMachine.startFrom(state1, state2, state3) ``` ### Response N/A --- ## startFromBlocking ### Description Starts the state machine from a specific state or a set of states in a blocking manner. ### Method `fun StateMachine.startFromBlocking(stateName: String, argument: Any? = null)` `fun StateMachine.startFromBlocking(states: Set, argument: Any? = null)` `fun StateMachine.startFromBlocking(state: IState, argument: Any? = null)` `fun StateMachine.startFromBlocking(state: DataState, data: D, argument: Any? = null)` `fun StateMachine.startFromBlocking(state1: IState, state2: IState, vararg states: IState, argument: Any? = null)` ### Endpoint N/A (Kotlin extension functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```kotlin // Start blocking from a state by name stateMachine.startFromBlocking("MyStateName") // Start blocking from a specific IState object val targetState: IState = ... stateMachine.startFromBlocking(targetState) // Start blocking from multiple parallel states val parallelStates: Set = setOf(state1, state2) stateMachine.startFromBlocking(parallelStates) // Start blocking from multiple states using vararg stateMachine.startFromBlocking(state1, state2, state3) ``` ### Response N/A ``` -------------------------------- ### Start State Machine From State (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/-state-machine/index Starts the state machine from a specific state, identified by its name or object. Overloads exist for single states, multiple states (including parallel states), and data states. ```kotlin suspend fun StateMachine.startFrom(stateName: String, argument: Any? = null) ``` ```kotlin suspend fun StateMachine.startFrom(state: DataState, data: D, argument: Any? = null) ``` ```kotlin suspend fun StateMachine.startFrom(states: Set, argument: Any? = null) ``` ```kotlin suspend fun StateMachine.startFrom(state: IState, argument: Any? = null) ``` ```kotlin suspend fun StateMachine.startFrom(state1: IState, state2: IState, vararg states: IState, argument: Any? = null) ``` -------------------------------- ### StateMachine.startFrom(state: IState, argument: Any?) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Starts the state machine from a particular state. This is the primary method for initiating the machine's execution from a defined starting point. ```APIDOC ## StateMachine.startFrom(state: IState, argument: Any?) ### Description Starts the state machine from a particular state. ### Method `suspend` ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **state** (IState) - Required - The initial state to start the machine from. - **argument** (Any?) - Optional - An argument to pass to the initial state. ### Request Example ```json { "state": "InitialStateObject", "argument": "someData" } ``` ### Response #### Success Response (200) N/A (This is a suspend function, its success is indicated by completion without exceptions). #### Response Example N/A ``` -------------------------------- ### StateMachine.startFrom(state: DataState, data: D, argument: Any?) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Starts the state machine from a DataState, providing associated data. ```APIDOC ## StateMachine.startFrom(state: DataState, data: D, argument: Any?) ### Description Starts the state machine from a DataState, providing associated data. ### Method `suspend` ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **state** (DataState) - Required - The initial DataState. - **data** (D) - Required - The data associated with the DataState. - **argument** (Any?) - Optional - An argument to pass to the initial state. ### Request Example ```json { "state": "MyDataState", "data": {"key": "value"}, "argument": "dataDrivenStart" } ``` ### Response #### Success Response (200) N/A (This is a suspend function, its success is indicated by completion without exceptions). #### Response Example N/A ``` -------------------------------- ### Start State Machine from DataState with Data (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Starts the state machine from a specific DataState, providing associated data of type D. The data is passed to the target state. ```kotlin suspend fun StateMachine.startFrom(state: DataState, data: D, argument: Any? = null) ``` -------------------------------- ### Start State Machine From State Blocking (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/-state-machine/index Starts the state machine from a specific state in a blocking manner. Overloads are available for various state targeting scenarios. ```kotlin fun StateMachine.startFromBlocking(stateName: String, argument: Any? = null) ``` ```kotlin fun StateMachine.startFromBlocking(states: Set, argument: Any? = null) ``` ```kotlin fun StateMachine.startFromBlocking(state: IState, argument: Any? = null) ``` ```kotlin fun StateMachine.startFromBlocking(state: DataState, data: D, argument: Any? = null) ``` ```kotlin fun StateMachine.startFromBlocking(state1: IState, state2: IState, vararg states: IState, argument: Any? = null) ``` -------------------------------- ### Start State Machine from State (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/index Initiates the state machine from a specified state. Supports starting from a single state, multiple parallel states, or a state defined by its name. An optional argument can be passed to the initial state. ```kotlin suspend fun StateMachine.startFrom(stateName: String, argument: Any? = null) suspend fun StateMachine.startFrom( state: DataState, data: D, argument: Any? = null) suspend fun StateMachine.startFrom(states: Set, argument: Any? = null) suspend fun StateMachine.startFrom(state: IState, argument: Any? = null) suspend fun StateMachine.startFrom( state1: IState, state2: IState, vararg states: IState, argument: Any? = null) ``` -------------------------------- ### Start State Machine from a Set of Parallel States (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Starts the state machine by targeting a set of states that must be parallel state sub-children. This functionality is implemented by the targetParallelStates method. ```kotlin suspend fun StateMachine.startFrom(states: Set, argument: Any? = null) ``` -------------------------------- ### Start State Machine (Blocking) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/index Synchronously starts the state machine, initiating its operation. An optional argument can be passed during the start sequence. ```kotlin fun StateMachine.startBlocking(argument: Any? = null) ``` -------------------------------- ### Start State Machine from Single State (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Initiates the state machine from a specified initial state. Accepts an optional argument that can be passed to the target state. ```kotlin suspend fun StateMachine.startFrom(state: IState, argument: Any? = null) ``` -------------------------------- ### Start State Machine from State Name (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Initiates the state machine by providing the name of the target state as a string. An optional argument can be passed. ```kotlin suspend fun StateMachine.startFrom(stateName: String, argument: Any? = null) ``` -------------------------------- ### Start State Machine from Specific State for Testing Source: https://kstatemachine.github.io/kstatemachine/pages/testing Allows starting a state machine from a specific state for testing purposes. It utilizes overloaded Testing.startFrom() functions. This is useful for verifying reactions to events from a particular state. ```kotlin lateinit var state2: State val machine = createStateMachine(scope, start = false) { initialState("state1") state2 = state("state2") // ... } machine.startFrom(state2) ``` -------------------------------- ### Start State Machine from Multiple States (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Allows initiating the state machine by targeting multiple states simultaneously. This overload accepts a variable number of IState arguments. ```kotlin suspend fun StateMachine.startFrom( state1: IState, state2: IState, vararg states: IState, argument: Any? = null) ``` -------------------------------- ### StateMachine.startFrom(stateName: String, argument: Any?) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Starts the state machine from a particular state identified by its name. ```APIDOC ## StateMachine.startFrom(stateName: String, argument: Any?) ### Description Starts the state machine from a particular state identified by its name. ### Method `suspend` ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **stateName** (String) - Required - The name of the initial state to start the machine from. - **argument** (Any?) - Optional - An argument to pass to the initial state. ### Request Example ```json { "stateName": "MyState", "argument": "nameBasedStart" } ``` ### Response #### Success Response (200) N/A (This is a suspend function, its success is indicated by completion without exceptions). #### Response Example N/A ``` -------------------------------- ### Start State Machine from Specific State (Blocking) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/index Synchronously starts the state machine from a designated state, optionally with an argument. ```APIDOC ## POST /state-machine/startFromBlocking ### Description Synchronously starts the state machine from a particular state. This function blocks until the initial state transition is complete. ### Method POST ### Endpoint /state-machine/startFromBlocking ### Parameters #### Request Body - **stateName** (String) - Optional - The name of the state to start from. - **state** (IState) - Optional - The specific state object to start from. - **states** (Set) - Optional - A set of parallel states to start from. - **state1** (IState) - Optional - The first state in a vararg list for targeting multiple states. - **state2** (IState) - Optional - The second state in a vararg list for targeting multiple states. - **vararg states** (IState...) - Optional - Additional states for targeting multiple states. - **dataState** (DataState) - Optional - For starting with data. - **data** (D) - Optional - The data to associate with the starting state. - **argument** (Any?) - Optional - An optional argument to pass to the starting state. ### Request Example ```json { "stateName": "InitialState", "argument": null } ``` ### Response #### Success Response (200) Indicates the state machine has successfully transitioned to the specified starting state. #### Response Example ```json { "status": "success", "currentState": "InitialState" } ``` ``` -------------------------------- ### Start State Machine from Specific State Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/index Allows starting the state machine from a designated state, optionally with an argument. ```APIDOC ## POST /state-machine/startFrom ### Description Starts the state machine from a particular state. This can be a single named state, a specific `IState` object, or multiple parallel states. ### Method POST ### Endpoint /state-machine/startFrom ### Parameters #### Request Body - **stateName** (String) - Optional - The name of the state to start from. - **state** (IState) - Optional - The specific state object to start from. - **states** (Set) - Optional - A set of parallel states to start from. - **state1** (IState) - Optional - The first state in a vararg list for targeting multiple states. - **state2** (IState) - Optional - The second state in a vararg list for targeting multiple states. - **vararg states** (IState...) - Optional - Additional states for targeting multiple states. - **dataState** (DataState) - Optional - For starting with data. - **data** (D) - Optional - The data to associate with the starting state. - **argument** (Any?) - Optional - An optional argument to pass to the starting state. ### Request Example ```json { "stateName": "InitialState", "argument": { "userId": 123 } } ``` ### Response #### Success Response (200) Indicates the state machine has successfully transitioned to the specified starting state. #### Response Example ```json { "status": "success", "currentState": "InitialState" } ``` ``` -------------------------------- ### Creating a State Machine with a Finished Listener Source: https://kstatemachine.github.io/kstatemachine/pages/states/states This example shows how to create a state machine that includes an `onFinished` callback. This callback is triggered when the state machine enters its final state and stops processing further events. ```kotlin val machine = createStateMachine(scope) { initialFinalState("final") onFinished { println("State machine is finished") } } machine.isFinished // is true ``` -------------------------------- ### Create and Process Events with KStateMachine in Kotlin Source: https://kstatemachine.github.io/kstatemachine/index Demonstrates how to create a state machine using the KStateMachine DSL and process events to trigger transitions. This involves defining the state machine's initial setup within a scope and then using the `processEvent` method to send events to the machine. ```kotlin val machine = createStateMachine(scope) { // Setup is made in this block ... } // After setup and start, it is ready to process events machine.processEvent(FirstEvent) // ... machine.processEvent(OtherEvent) ``` -------------------------------- ### Listen to All Transitions Globally in Kotlin Source: https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions Enables listening to all transition events within the entire state machine from the setup block. Dependencies: kstatemachine library. Input: Any triggered transition. Output: Global callback execution for all transitions. ```Kotlin createStateMachine(scope) { // ... onTransitionTriggered { // Listen to all triggered transitions here println(it.event) } } ``` -------------------------------- ### Start State Machine from State (Blocking) (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/index Similar to `startFrom`, but executes in a blocking manner. This is useful for synchronous testing scenarios where the program flow should halt until the state machine reaches a stable state. Supports various overloads for targeting different state configurations. ```kotlin fun StateMachine.startFromBlocking(stateName: String, argument: Any? = null) fun StateMachine.startFromBlocking(states: Set, argument: Any? = null) fun StateMachine.startFromBlocking(state: IState, argument: Any? = null) fun StateMachine.startFromBlocking( state: DataState, data: D, argument: Any? = null) fun StateMachine.startFromBlocking( state1: IState, state2: IState, vararg states: IState, argument: Any? = null) ``` -------------------------------- ### Create Initial State (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state/-default-final-state/index Initializes the starting state of a state machine or a sub-state machine. This is a fundamental function for defining the entry point of a state. Supports synchronous and asynchronous initialization, and child mode configuration. ```kotlin fun IState.initialState(name: String? = null, childMode: ChildMode = ChildMode.EXCLUSIVE): State inline suspend fun IState.initialState(name: String? = null, childMode: ChildMode = ChildMode.EXCLUSIVE, init: StateBlock): State ``` -------------------------------- ### Initial State Management Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state/-final-state/index Provides a shortcut for adding an initial state and setting it as the machine's entry point. ```APIDOC ## Initial State Management ### Description A convenience function that combines adding a state and setting it as the initial state of the machine. ### Methods - `addInitialState(state: S): S` - `addInitialState(state: S, init: StateBlock): S` (suspend) ### Parameters - **state** (S) - The initial state to add. - **init** (StateBlock) - An optional initialization block for configuring the initial state. ### Request Example ```kotlin // Direct addition val initialState = stateMachine.addInitialState(MyInitialState()) // Using initialization block stateMachine.addInitialState(MyInitialState()) { // configuration for the state } ``` ### Response - **S** - The added initial state. ``` -------------------------------- ### Started Notification Class Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine-coroutines/ru.nsk.kstatemachine.statemachine/-state-machine-notification/index The Started class, inheriting from StateMachineNotification, signals the beginning of a state machine's operation or a significant transition. It carries TransitionParams and a reference to the StateMachine. This notification is useful for logging or triggering actions when the machine starts or resumes. ```kotlin class Started( val transitionParams: TransitionParams<*>, val machine: StateMachine) : StateMachineNotification ``` -------------------------------- ### StateMachine.startFrom(state1: IState, state2: IState, vararg states: IState, argument: Any?) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Vararg overload for targeting multiple states. This allows initiating the state machine from several states simultaneously. ```APIDOC ## StateMachine.startFrom(state1: IState, state2: IState, vararg states: IState, argument: Any?) ### Description Vararg overload for targeting multiple states. Allows initiating the state machine from several states simultaneously. ### Method `suspend` ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **state1** (IState) - Required - The first initial state. - **state2** (IState) - Required - The second initial state. - **states** (Array) - Optional - Additional initial states. - **argument** (Any?) - Optional - An argument to pass to the initial states. ### Request Example ```json { "state1": "StateA", "state2": "StateB", "states": ["StateC", "StateD"], "argument": "initialData" } ``` ### Response #### Success Response (200) N/A (This is a suspend function, its success is indicated by completion without exceptions). #### Response Example N/A ``` -------------------------------- ### StateMachine.startFrom(states: Set, argument: Any?) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.testing/-testing/start-from Allows targeting multiple states which must be parallel state sub-children. Implemented by targetParallelStates. ```APIDOC ## StateMachine.startFrom(states: Set, argument: Any?) ### Description Allows targeting multiple states which must be parallel state sub-children. Implemented by targetParallelStates. ### Method `suspend` ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **states** (Set) - Required - A set of initial states, which must be parallel state sub-children. - **argument** (Any?) - Optional - An argument to pass to the initial states. ### Request Example ```json { "states": ["ParallelState1", "ParallelState2"], "argument": "parallelData" } ``` ### Response #### Success Response (200) N/A (This is a suspend function, its success is indicated by completion without exceptions). #### Response Example N/A ``` -------------------------------- ### Register On Started Listener Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/index Registers a listener to be invoked when the state machine starts. The listener receives transition parameters and executes suspendable code. ```kotlin inline fun StateMachine.onStarted(crossinline block: suspend StateMachine.(TransitionParams<*>) -> Unit): StateMachine.Listener ``` -------------------------------- ### TransitionBuilder Constructor Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.transition/-transition-builder/index Initializes a new instance of the TransitionBuilder class. ```APIDOC ## TransitionBuilder Constructor ### Description Initializes a new instance of the TransitionBuilder class with an optional name and a source state. ### Method CONSTRUCTOR ### Endpoint N/A (Class Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```kotlin // Example of creating a TransitionBuilder instance val builder = TransitionBuilder("MyTransition", mySourceState) ``` ### Response #### Success Response (200) N/A (Constructor) #### Response Example N/A (Constructor) ``` -------------------------------- ### Get State Machine Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state/-state/index Retrieves the state machine associated with the current state, if any. ```APIDOC ## GET /states/machine ### Description Retrieves the state machine to which this state belongs. Returns null if the state is not part of any machine. ### Method GET ### Endpoint /states/machine ### Response #### Success Response (200) - **stateMachine** (StateMachine?) - The state machine instance, or null. #### Response Example ```json { "stateMachine": { "id": "machine1" } } ``` ``` -------------------------------- ### State Creation and Configuration Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state/-i-state/index Functions for initializing various types of states within the state machine. ```APIDOC ## historyState ### Description Creates a history state. This allows the state machine to remember and return to a previous state. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/history` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the history state. - **defaultState** (IState) - Optional - The state to transition to if no history is available. - **historyType** (HistoryType) - Optional - The type of history (e.g., SHALLOW, DEEP). ### Response #### Success Response (201) - **historyState** (HistoryState) - The created history state. #### Response Example ```json { "historyState": { "type": "SHALLOW" } } ``` ``` ```APIDOC ## initialChoiceDataState ### Description Initializes a choice data state. This state type allows for conditional transitions based on data. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial-choice-data` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the choice data state. - **choiceAction** (suspend EventAndArgument<*>.() -> DataState) - Required - A suspend function defining the logic for determining the next data state. ### Response #### Success Response (201) - **choiceDataState** (DefaultChoiceDataState) - The created choice data state. #### Response Example ```json { "choiceDataState": { "name": "ConditionalDataTransition" } } ``` ``` ```APIDOC ## initialChoiceState ### Description Initializes a choice state. This state type enables conditional transitions based on events or arguments. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial-choice` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the choice state. - **choiceAction** (suspend EventAndArgument<*>.() -> State) - Required - A suspend function defining the logic for determining the next state. ### Response #### Success Response (201) - **choiceState** (DefaultChoiceState) - The created choice state. #### Response Example ```json { "choiceState": { "name": "ConditionalTransition" } } ``` ``` ```APIDOC ## initialDataState ### Description Initializes a data state. This state holds and manages data within the state machine. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial-data` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the data state. - **defaultData** (D) - Required - The initial data for this state. - **childMode** (ChildMode) - Optional - The child mode for nested states (default: EXCLUSIVE). - **dataExtractor** (DataExtractor) - Optional - A function to extract data (default: defaultDataExtractor). - **init** (StateBlock>) - Optional - Initialization block for the data state. ### Response #### Success Response (201) - **dataState** (DataState) - The created data state. #### Response Example ```json { "dataState": { "name": "UserData", "data": { "userId": 123 } } } ``` ``` ```APIDOC ## initialFinalDataState ### Description Initializes a final data state. This state represents a terminal point in the state machine that also holds data. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial-final-data` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the final data state. - **defaultData** (D?) - Optional - The initial data for this state. - **dataExtractor** (DataExtractor) - Optional - A function to extract data (default: defaultDataExtractor). - **init** (StateBlock>) - Optional - Initialization block for the final data state. ### Response #### Success Response (201) - **finalDataState** (FinalDataState) - The created final data state. #### Response Example ```json { "finalDataState": { "name": "CompletedOrderData" } } ``` ``` ```APIDOC ## initialFinalMutableDataState ### Description Initializes a mutable final data state. This terminal state allows for modification of its data. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial-final-mutable-data` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the mutable final data state. - **defaultData** (D?) - Optional - The initial data for this state. - **dataExtractor** (DataExtractor) - Optional - A function to extract data (default: defaultDataExtractor). - **init** (StateBlock>) - Optional - Initialization block for the mutable final data state. ### Response #### Success Response (201) - **finalMutableDataState** (FinalMutableDataState) - The created mutable final data state. #### Response Example ```json { "finalMutableDataState": { "name": "EditableResultData" } } ``` ``` ```APIDOC ## initialFinalState ### Description Initializes a final state. This represents an end point in the state machine. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial-final` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the final state. - **init** (StateBlock) - Optional - Initialization block for the final state. ### Response #### Success Response (201) - **finalState** (DefaultFinalState or FinalState) - The created final state. #### Response Example ```json { "finalState": { "name": "Finished" } } ``` ``` ```APIDOC ## initialMutableDataState ### Description Initializes a mutable data state. This state allows for modification of its associated data. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial-mutable-data` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the mutable data state. - **defaultData** (D) - Required - The initial data for this state. - **childMode** (ChildMode) - Optional - The child mode for nested states (default: EXCLUSIVE). - **dataExtractor** (DataExtractor) - Optional - A function to extract data (default: defaultDataExtractor). - **init** (StateBlock>) - Optional - Initialization block for the mutable data state. ### Response #### Success Response (201) - **mutableDataState** (MutableDataState) - The created mutable data state. #### Response Example ```json { "mutableDataState": { "name": "EditableSettings", "data": { "theme": "dark" } } } ``` ``` ```APIDOC ## initialState ### Description Initializes a regular state. This is the fundamental building block of a state machine. ### Method POST (assumed, as it's state creation) ### Endpoint `/websites/kstatemachine_github_io_kstatemachine/states/initial` ### Parameters #### Query Parameters - **name** (string) - Optional - The name of the state. - **childMode** (ChildMode) - Optional - The child mode for nested states (default: EXCLUSIVE). - **init** (StateBlock) - Optional - Initialization block for the state. ### Response #### Success Response (201) - **state** (State) - The created state. #### Response Example ```json { "state": { "name": "Idle" } } ``` ``` -------------------------------- ### State Machine Control Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/-state-machine/index Functions for controlling the state machine, such as starting, stopping, and restarting. ```APIDOC ## State Machine Control ### Description Provides core functionalities to manage the lifecycle and behavior of the state machine. ### Functions - **machineOrNull** - **Description:** Returns the `StateMachine` instance associated with the current state, or `null` if not part of a machine. - **Signature:** `fun IState.machineOrNull(): StateMachine?` - **removeListener** (IState.Listener) - **Description:** Removes a listener associated with a specific state. - **Signature:** `abstract fun removeListener(listener: IState.Listener)` - **removeListener** (StateMachine.Listener) - **Description:** Removes a listener associated with the state machine. - **Signature:** `abstract fun removeListener(listener: StateMachine.Listener)` - **requireTransition** (by type) - **Description:** Requires and returns a transition by its event type. Throws an exception if not found. - **Signature:** `inline fun TransitionStateApi.requireTransition(): Transition` - **requireTransition** (by name) - **Description:** Requires and returns a transition by its name. Throws an exception if not found. - **Signature:** `fun TransitionStateApi.requireTransition(name: String): Transition<*>` - **restart** - **Description:** Asynchronously restarts the state machine by stopping and then starting it again. - **Signature:** `suspend fun StateMachine.restart(argument: Any? = null)` - **restartBlocking** - **Description:** Synchronously restarts the state machine. - **Signature:** `fun StateMachine.restartBlocking(argument: Any? = null)` - **restoreByRecordedEvents** - **Description:** Restores the state machine to a previous configuration based on recorded events. This is a suspendable operation. - **Signature:** `suspend fun StateMachine.restoreByRecordedEvents(recordedEvents: RecordedEvents, muteListeners: Boolean = true, disableStructureHashCodeCheck: Boolean = false, validator: RestorationResultValidator = StrictValidator): RestorationResult` - **restoreByRecordedEventsBlocking** - **Description:** A blocking version of `restoreByRecordedEvents`. - **Signature:** `fun StateMachine.restoreByRecordedEventsBlocking(recordedEvents: RecordedEvents, muteListeners: Boolean = true, disableStructureHashCodeCheck: Boolean = false)` - **queuePendingEventHandler** - **Description:** Retrieves an object that allows queuing pending event handlers. - **Signature:** `fun StateMachine.queuePendingEventHandler(): QueuePendingEventHandler` - **setInitialState** - **Description:** Sets the initial state for the state machine. (Note: The actual signature and return type are not fully specified in the input, this is a placeholder.) - **Signature:** `fun StateMachine.setInitialState(...)` ``` -------------------------------- ### Coroutine Abstraction Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.coroutines/index Provides methods to start coroutines in both blocking and non-blocking ways. Primarily for internal library use. ```APIDOC ## Interface CoroutineAbstraction ### Description Starts coroutines in blocking and non-blocking way. Mostly for internal use, there should be no reason to use it directly in client code. ### Methods This interface does not expose public methods directly for client interaction. Its functionality is utilized by other components of the library. ``` -------------------------------- ### State Creation and Configuration Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.statemachine/-state-machine/index Functions for creating initial states, data states, mutable states, and final states with various configurations. ```APIDOC ## State Creation and Configuration This section details functions for initializing and configuring different types of states within the kstatemachine library. ### `finalDataState` Creates a final data state. Can be defined with an optional name, default data, a data extractor, and an initialization block. - **Method**: `inline suspend fun ` - **Parameters**: - `name` (String?): Optional name for the state. - `defaultData` (D?): Optional default data for the state. - `dataExtractor` (DataExtractor): Function to extract data. - `init` (StateBlock>): Initialization block for the state. ### `finalMutableDataState` Creates a mutable data state that can be modified. Supports both synchronous and asynchronous initialization. - **Method**: `inline fun ` or `inline suspend fun ` - **Parameters**: - `name` (String?): Optional name for the state. - `defaultData` (D?): Optional default data for the state. - `dataExtractor` (DataExtractor): Function to extract data. - `init` (StateBlock>): Optional initialization block for the state. ### `finalState` Creates a final state. Can be defined with an optional name and an optional initialization block for asynchronous operations. - **Method**: `fun IState.finalState(name: String? = null): DefaultFinalState` or `inline suspend fun IState.finalState(name: String? = null, init: StateBlock): FinalState` - **Parameters**: - `name` (String?): Optional name for the state. - `init` (StateBlock): Optional initialization block for the state. ### `initialChoiceDataState` Creates an initial choice data state where the next state is determined by a choice action. - **Method**: `inline fun ` - **Parameters**: - `name` (String?): Optional name for the state. - `choiceAction` (suspend EventAndArgument<*>.() -> DataState): Action to determine the data state. ### `initialChoiceState` Creates an initial choice state where the next state is determined by a choice action. - **Method**: `fun IState.initialChoiceState(name: String? = null, choiceAction: suspend EventAndArgument<*>.() -> State): DefaultChoiceState` - **Parameters**: - `name` (String?): Optional name for the state. - `choiceAction` (suspend EventAndArgument<*>.() -> State): Action to determine the next state. ### `initialDataState` Creates an initial data state with default data and optional child mode and data extractor. Supports synchronous and asynchronous initialization. - **Method**: `inline fun ` or `inline suspend fun ` - **Parameters**: - `name` (String?): Optional name for the state. - `defaultData` (D): Default data for the state. - `childMode` (ChildMode): Mode for child states (default: EXCLUSIVE). - `dataExtractor` (DataExtractor): Function to extract data. - `init` (StateBlock>): Optional initialization block for the state. ### `initialFinalDataState` Creates an initial final data state. Supports synchronous and asynchronous initialization with optional name, default data, and data extractor. - **Method**: `inline fun ` or `inline suspend fun ` - **Parameters**: - `name` (String?): Optional name for the state. - `defaultData` (D?): Optional default data for the state. - `dataExtractor` (DataExtractor): Function to extract data. - `init` (StateBlock>): Optional initialization block for the state. ### `initialFinalMutableDataState` Creates an initial mutable final data state. Supports synchronous and asynchronous initialization with optional name, default data, and data extractor. - **Method**: `inline fun ` or `inline suspend fun ` - **Parameters**: - `name` (String?): Optional name for the state. - `defaultData` (D?): Optional default data for the state. - `dataExtractor` (DataExtractor): Function to extract data. - `init` (StateBlock>): Optional initialization block for the state. ### `initialFinalState` Creates an initial final state. Supports synchronous and asynchronous initialization with an optional name and initialization block. - **Method**: `fun IState.initialFinalState(name: String? = null): DefaultFinalState` or `inline suspend fun IState.initialFinalState(name: String? = null, init: StateBlock): FinalState` - **Parameters**: - `name` (String?): Optional name for the state. - `init` (StateBlock): Optional initialization block for the state. ### `initialMutableDataState` Creates an initial mutable data state. Supports synchronous and asynchronous initialization with optional name, default data, child mode, and data extractor. - **Method**: `inline fun ` or `inline suspend fun ` - **Parameters**: - `name` (String?): Optional name for the state. - `defaultData` (D): Default data for the state. - `childMode` (ChildMode): Mode for child states (default: EXCLUSIVE). - `dataExtractor` (DataExtractor): Function to extract data. - `init` (StateBlock>): Optional initialization block for the state. ### `initialState` Creates an initial state with an optional name and child mode. Supports synchronous and asynchronous initialization, with a shortcut for setting the initial state. - **Method**: `fun IState.initialState(name: String? = null, childMode: ChildMode = ChildMode.EXCLUSIVE): State` or `inline suspend fun IState.initialState(name: String? = null, childMode: ChildMode = ChildMode.EXCLUSIVE, init: StateBlock): State` - **Parameters**: - `name` (String?): Optional name for the state. - `childMode` (ChildMode): Mode for child states (default: EXCLUSIVE). - `init` (StateBlock): Optional initialization block for the state. ``` -------------------------------- ### BasePseudoState Class Documentation Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state.pseudo/-base-pseudo-state/index Details about the BasePseudoState class, its constructor, and properties. ```APIDOC ## BasePseudoState Class ### Description Represents a pseudo-state in a state machine, which does not have a corresponding active state. It can be used to represent choices or history within the state machine. ### Constructors #### `BasePseudoState(name: String?)` - **name** (String?) - Optional - The name of the pseudo-state. ### Properties - **childMode** (ChildMode) - The child mode of the pseudo-state. - **initialState** (InternalState?) - The initial state within this pseudo-state, if any. - **internalParent** (InternalState?) - The internal parent state. - **isActive** (Boolean) - Indicates if the pseudo-state is currently active. - **isFinished** (Boolean) - Indicates if the pseudo-state has finished its execution. - **listeners** (Collection) - A collection of listeners attached to the pseudo-state. - **machine** (StateMachine) - The state machine this pseudo-state belongs to. - **metaInfo** (MetaInfo?) - Optional - Metadata associated with the pseudo-state. This might be changed only during machine setup. - **name** (String?) - Optional - The name of the pseudo-state. - **parent** (IState?) - The parent state of this pseudo-state. - **payload** (Any?) - Optional - Arbitrary user-defined data. This property allows storing data in a state without subclassing it. - **states** (Set) - A set of child states within this pseudo-state. - **transitions** (Set>) - A set of transitions originating from this pseudo-state. ``` -------------------------------- ### Find Transition by Name Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state/-default-final-mutable-data-state/index Finds a transition based on its name. This can be used to start listening to a transition after the state machine is set up. ```APIDOC ## GET /findTransition/name ### Description Finds a transition based on its name. This can be used to start listening to a transition after the state machine is set up. ### Method GET ### Endpoint `/findTransition/name` ### Parameters #### Query Parameters - **name** (String) - Required - The name of the transition to find. ### Response #### Success Response (200) - **Transition<*>?** - The found transition or null if not found. ### Response Example ```json { "transition": "com.example.MyTransition" } ``` ``` -------------------------------- ### Create Initial Choice Data State (Kotlin) Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state/-data-state/index Initializes a choice data state, which allows for dynamic selection of the next state based on provided data. It takes an optional name and a suspendable choice action. This function is inline. ```kotlin inline fun IState.initialChoiceDataState(name: String? = null, noinline choiceAction: suspend EventAndArgument<*>.() -> DataState): DefaultChoiceDataState ``` -------------------------------- ### Find State by Name Source: https://kstatemachine.github.io/kstatemachine/kdoc/kstatemachine/ru.nsk.kstatemachine.state/-default-final-mutable-data-state/index Retrieves a state by its class name. This is useful for starting to listen to a state after the state machine has been set up. ```APIDOC ## GET /findState ### Description Retrieves a state by its class name. This is useful for starting to listen to a state after the state machine has been set up. ### Method GET ### Endpoint `/findState` ### Parameters #### Query Parameters - **class** (KClass) - Required - The class of the state to find. - **recursive** (Boolean) - Optional - Defaults to `true`. Whether to search recursively. ### Response #### Success Response (200) - **S?** - The found state or null if not found. ### Response Example ```json { "state": "com.example.MyState" } ``` ```