AdonisJS API
    Preparing search index...

    Session store encapsulates the session data and offers a declarative API to mutate it.

    const store = new ValuesStore({ counter: 0 })
    store.set('username', 'john')
    store.increment('counter')
    const hasData = store.hasBeenModified

    Hierarchy (View Summary)

    Index
    • get isEmpty(): boolean

      Returns true if the store is empty

      Returns boolean

    • get hasBeenModified(): boolean

      Returns true if the store has been modified

      Returns boolean

    • Gets value for a given key

      Parameters

      • key: string | string[]

        The key or key path to retrieve

      • OptionaldefaultValue: any

        Default value if key doesn't exist

      Returns any

      store.get('username', 'guest')
      store.get(['user', 'preferences', 'theme'], 'light')
    • Checks if a value exists. Includes extra guards to check arrays for length.

      Parameters

      • key: string | string[]

        The key or key path to check

      • checkForArraysLength: boolean = true

        Whether to check array length (default: true)

      Returns boolean

      store.has('username')                    // Check if key exists
      store.has(['user', 'roles']) // Check nested key
      store.has('items', false) // Don't check array length
    • Sets a key/value pair in the store

      Parameters

      Returns void

      store.set('username', 'john')
      store.set(['user', 'preferences'], { theme: 'dark' })
    • Removes a key from the store

      Parameters

      • key: string | string[]

        The key or key path to remove

      Returns void

      store.unset('temp_data')
      store.unset(['user', 'cache'])
    • Pulls value from the store. Same as calling store.get then store.unset.

      Parameters

      • key: string | string[]

        The key or key path to pull

      • OptionaldefaultValue: any

        Default value if key doesn't exist

      Returns any

      const message = store.pull('notification', 'No messages')
      const data = store.pull(['temp', 'data'])
    • Increments a numeric value. Raises an error when underlying value is not a number.

      Parameters

      • key: string | string[]

        The key or key path to increment

      • steps: number = 1

        Number of steps to increment (default: 1)

      Returns void

      store.increment('page_views')     // Increments by 1
      store.increment('score', 10) // Increments by 10
    • Decrements a numeric value. Raises an error when underlying value is not a number.

      Parameters

      • key: string | string[]

        The key or key path to decrement

      • steps: number = 1

        Number of steps to decrement (default: 1)

      Returns void

      store.decrement('attempts')       // Decrements by 1
      store.decrement('credits', 5) // Decrements by 5
    • Overwrites existing store data with new values

      Parameters

      • values: { [key: string]: any }

        New values to replace existing data

      Returns void

      store.update({ username: 'jane', theme: 'light' })
      
    • Merges values with existing store data

      Parameters

      • values: { [key: string]: any }

        Values to merge with existing data

      Returns any

      store.merge({ newField: 'value', existingField: 'updated' })
      
    • Resets store by clearing all values

      Returns void

      store.clear() // Removes all data from store