Options
All
  • Public
  • Public/Protected
  • All
Menu

A key-value store persisted by the backend layer.

Hierarchy

  • Store

Index

Constructors

  • new Store(path: string): Store

Properties

path: string

Methods

  • clear(): Promise<void>
  • Clears the store, removing all key-value pairs.

    Note: To clear the storage and reset it to it's default value, use reset instead.

    Returns Promise<void>

  • delete(key: string): Promise<boolean>
  • Removes a key-value pair from the store.

    Parameters

    • key: string

    Returns Promise<boolean>

  • entries<T>(): Promise<[key: string, value: T][]>
  • Returns a list of all entries in the store.

    Type parameters

    • T

    Returns Promise<[key: string, value: T][]>

  • get<T>(key: string): Promise<null | T>
  • Returns the value for the given key or null the key does not exist.

    Type parameters

    • T

    Parameters

    • key: string

    Returns Promise<null | T>

  • has(key: string): Promise<boolean>
  • Returns true if the given key exists in the store.

    Parameters

    • key: string

    Returns Promise<boolean>

  • keys(): Promise<string[]>
  • Returns a list of all key in the store.

    Returns Promise<string[]>

  • length(): Promise<string[]>
  • Returns the number of key-value pairs in the store.

    Returns Promise<string[]>

  • load(): Promise<void>
  • Attempts to load the on-disk state at the stores path into memory.

    This method is useful if the on-disk state was edited by the user and you want to synchronize the changes.

    Note: This method does not emit change events.

    Returns Promise<void>

  • onChange(cb: (key: string, value: unknown) => void): Promise<UnlistenFn>
  • Listen to changes on the store.

    Parameters

    • cb: (key: string, value: unknown) => void
        • (key: string, value: unknown): void
        • Parameters

          • key: string
          • value: unknown

          Returns void

    Returns Promise<UnlistenFn>

    A promise resolving to a function to unlisten to the event.

  • onKeyChange<T>(key: string, cb: (value: null | T) => void): Promise<UnlistenFn>
  • Listen to changes on a store key.

    Type parameters

    • T

    Parameters

    • key: string
    • cb: (value: null | T) => void
        • (value: null | T): void
        • Parameters

          • value: null | T

          Returns void

    Returns Promise<UnlistenFn>

    A promise resolving to a function to unlisten to the event.

  • reset(): Promise<void>
  • Resets the store to it's default value.

    If no default value has been set, this method behaves identical to clear.

    Returns Promise<void>

  • save(): Promise<void>
  • Saves the store to disk at the stores path.

    As the store is only persistet to disk before the apps exit, changes might be lost in a crash. This method let's you persist the store to disk whenever you deem necessary.

    Returns Promise<void>

  • set(key: string, value: unknown): Promise<void>
  • Inserts a key-value pair into the store.

    Parameters

    • key: string
    • value: unknown

    Returns Promise<void>

  • values(): Promise<string[]>
  • Returns a list of all values in the store.

    Returns Promise<string[]>

Generated using TypeDoc