Documentation - v0.27.1
    Preparing search index...

    Class UpdateState<State>

    State of the current update.

    Possible scene names

    Type Parameters

    • State extends object

      Type that represents the state

    Index

    Constructors

    • Type Parameters

      • State extends object

      Parameters

      • storage: StateService
      • key: string
      • scene: string | null
      • Optionalscoped: boolean
      • OptionalcustomStorage: StateService
      • OptionalcustomKey: string

      Returns UpdateState<State>

    Accessors

    Methods

    • Enter some scene

      Type Parameters

      Parameters

      • scene: Scene
      • Optionalparams: { reset?: boolean; ttl?: number; with?: SceneState }
        • Optionalreset?: boolean

          If currently in a scoped scene, whether to reset the state

          true
          
        • Optionalttl?: number

          TTL for the scene (in seconds)

        • Optionalwith?: SceneState

          Initial state for the scene

          Note that this will only work if the scene uses the same key delegate as this state.

      Returns Promise<void>

    • Exit from current scene to the root

      Parameters

      • reset: boolean = true

        Whether to reset scene state (only applicable in case this is a scoped scene)

      Returns Promise<void>

    • Merge the given object to the current state.

      Note: If the storage currently has no state, then fallback must be provided.

      Basically a shorthand to calling .get(), modifying and then calling .set()

      Parameters

      • state: Partial<State>

        State to be merged

      • params: { fallback?: State | (() => State); forceLoad?: boolean; ttl?: number } = {}

      Returns Promise<State>

    • Rate limit some handler.

      When the rate limit exceeds, RateLimitError is thrown.

      This is a simple rate-limiting solution that uses the same key as the state. If you need something more sophisticated and/or customizable, you'll have to implement your own rate-limiter.

      Note: key is used to prefix the local key derived using the given key delegate.

      Parameters

      • key: string

        Key of the rate limit

      • limit: number

        Maximum number of requests in window

      • window: number

        Window size in seconds

      Returns Promise<[number, number]>

      Tuple containing the number of remaining and unix time in ms when the user can try again

    • Throttle some handler.

      When the rate limit exceeds, this function waits for it to reset.

      This is a simple wrapper over rateLimit, and follows the same logic.

      Note: key is used to prefix the local key derived using the given key delegate.

      Parameters

      • key: string

        Key of the rate limit

      • limit: number

        Maximum number of requests in window

      • window: number

        Window size in seconds

      Returns Promise<[number, number]>

      Tuple containing the number of remaining and unix time in ms when the user can try again