Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StateDB<T>

The default concrete implementation of a state database. A namespace for StateDB statics.

Type parameters

  • T: ReadonlyJSONValue

Hierarchy

  • StateDB

Implements

Index

Type aliases

Static Change

Change: object

A state database change.

Type declaration

Static DataTransform

DataTransform: object

A data transformation that can be applied to a state database.

Type declaration

Constructors

constructor

  • Create a new state database.

    Parameters

    • Default value options: IOptions = {}

      The instantiation options for a state database.

    Returns StateDB

Properties

Private _changed

_changed: Signal<this, object> = new Signal<this, StateDB.Change>(this)

Private _connector

_connector: IDataConnector<string>

Private _ready

_ready: Promise<void>

Accessors

changed

  • get changed(): ISignal<this, Change>
  • A signal that emits the change type any time a value changes.

    Returns ISignal<this, Change>

Methods

Private _clear

  • _clear(): Promise<void>
  • Clear the entire database.

    Returns Promise<void>

Private _fetch

  • _fetch(id: string): Promise<T | undefined>
  • Fetch a value from the database.

    Parameters

    • id: string

    Returns Promise<T | undefined>

Private _list

  • _list(query?: string): Promise<object>
  • Fetch a list from the database.

    Parameters

    • Optional query: string

    Returns Promise<object>

Private _merge

  • _merge(contents: object): Promise<void>
  • Merge data into the state database.

    Parameters

    • contents: object
      • [id: string]: T

    Returns Promise<void>

Private _overwrite

  • _overwrite(contents: object): Promise<void>
  • Overwrite the entire database with new contents.

    Parameters

    • contents: object
      • [id: string]: T

    Returns Promise<void>

Private _remove

  • _remove(id: string): Promise<void>
  • Remove a key in the database.

    Parameters

    • id: string

    Returns Promise<void>

Private _save

  • _save(id: string, value: T): Promise<void>
  • Save a key and its value in the database.

    Parameters

    • id: string
    • value: T

    Returns Promise<void>

clear

  • clear(): Promise<void>
  • Clear the entire database.

    Returns Promise<void>

fetch

  • fetch(id: string): Promise<T>
  • Retrieve a saved bundle from the database.

    Parameters

    • id: string

      The identifier used to retrieve a data bundle.

    Returns Promise<T>

    A promise that bears a data payload if available.

    Notes

    The id values of stored items in the state database are formatted: 'namespace:identifier', which is the same convention that command identifiers in JupyterLab use as well. While this is not a technical requirement for fetch(), remove(), and save(), it is necessary for using the list(namespace: string) method.

    The promise returned by this method may be rejected if an error occurs in retrieving the data. Non-existence of an id will succeed with the value undefined.

list

  • list(namespace: string): Promise<object>
  • Retrieve all the saved bundles for a namespace.

    Parameters

    • namespace: string

    Returns Promise<object>

    A promise that bears a collection of payloads for a namespace.

    Notes

    Namespaces are entirely conventional entities. The id values of stored items in the state database are formatted: 'namespace:identifier', which is the same convention that command identifiers in JupyterLab use as well.

    If there are any errors in retrieving the data, they will be logged to the console in order to optimistically return any extant data without failing. This promise will always succeed.

remove

  • remove(id: string): Promise<void>
  • Remove a value from the database.

    Parameters

    • id: string

      The identifier for the data being removed.

    Returns Promise<void>

    A promise that is rejected if remove fails and succeeds otherwise.

save

  • save(id: string, value: T): Promise<void>
  • Save a value in the database.

    Parameters

    • id: string

      The identifier for the data being saved.

    • value: T

      The data being saved.

    Returns Promise<void>

    A promise that is rejected if saving fails and succeeds otherwise.

    Notes

    The id values of stored items in the state database are formatted: 'namespace:identifier', which is the same convention that command identifiers in JupyterLab use as well. While this is not a technical requirement for fetch(), remove(), and save(), it is necessary for using the list(namespace: string) method.

toJSON

  • toJSON(): Promise<object>
  • Return a serialized copy of the state database's entire contents.

    Returns Promise<object>

    A promise that resolves with the database contents as JSON.

Generated using TypeDoc