Store

ol-ishare/store. Store

Store base class

Common interface for storing data as key-value pairs. Keys must be strings.

All instance methods are asynchronous to allow for sub-classes that make use of web services, or other back-end that introduces latency

Initially implemented to provide interchangeable storage for ol-ishare State instances, this has been made more generic so that it could also be used wherever a similar requirement exists for being able to switch between two storage mechanisms, or where a Store sub-class has already been created that adds value above working with such a mechanism directly.

Constructor

new Store(optionsopt)

Parameters:
Name Type Attributes Description
options Object <optional>

Optional settings for Store (none currently defined for base class)

Methods

(abstract) put(dict) → {Promise}

Put items in storage

Parameters:
Name Type Description
dict Object

Items to store, keys/property names must be strings. Values must be serializable to strings.

Returns:

Resolves to the keys of values that were successfully stored.

Type
Promise

(abstract) fetch(keys) → {Promise}

Fetch items from storage

Parameters:
Name Type Description
keys Array.<String>

Names of items to fetch from storage.

Returns:

Resolves to an object with properties for each valid key, and the stored item with that name as the value.

Type
Promise

(abstract) discard(keys) → {Promise}

Discard items in storage

Parameters:
Name Type Description
keys Array.<String>

Names of items to discard.

Returns:

Resolves to an array of names of items that were successfully deleted.

Type
Promise

(static) validateKeys(keys) → {Array.<String>}

Validate key names

Ensures that keys are strings and ignores those that aren't.

This method can be overridden in sub-classes if stores have different and/or additional validation requirements.

Parameters:
Name Type Description
keys Array.<String> | String

Names of properties to validate.

Returns:

Keys that were successfully validated.

Type
Array.<String>

(static) sanitizeValues(dict) → {Object}

Sanitize property values

Ensures that values are able to be transformed to JSON strings and back again (or are undefined), ignores those that aren't.

This method can be overridden in sub-classes if stores have different and/or additional validation requirements.

Parameters:
Name Type Description
dict Object

Object containing values to validate.

Returns:

Contains only those properties which have values that can be converted, and sanitized copies of the original values.

Type
Object