• Method decorator that guards a method with state validation. The decorated method can only be called when the state machine is in one of the allowed states.

    IMPORTANT: This decorator gracefully handles uninitialized FSM:

    • If FSM is not yet initialized, the guard allows the method to proceed
    • Once FSM is initialized, the guard enforces state validation

    Type Parameters

    • TState extends string

    Parameters

    Returns MethodDecorator

    A method decorator

    Example

    @kosStateGuard({ allowedStates: ['ready'] })
    async pourBeverage(bevId: string): Promise<void> {
    // This method can only be called when currentState === 'ready'
    this.transition('POUR');
    await this.deviceService.dispense(bevId);
    this.transition('COMPLETE');
    }