1.1.0 • Published 8 years ago

common-storage v1.1.0

Weekly downloads
9
License
-
Repository
github
Last release
8 years ago

Common Storage

Storage abstraction and utilities for the Common Framework.

Installation

Install it from NPM:

npm install common-storage

Usage

This package does not expose any functionality on its own. Instead, it can be used to create storage drivers that conform to a standardized interface for implementation-agnostic consumption.

Previously, it contained update types. Those are now a part of Common Updates.

Storage abstraction

An asynchronous key-value storage should extend the Storage class. For convenience, keys in the storage can be passed as instances which implement the IReferenceable interface from Common Collections.

The methods create(target), acquire(target [, properties]), update(target, property, update), and remove(target) are already defined and handle the resolution of referenceable targets. Storage drivers should implement the corresponding abstract _create(key), _acquire(key [, properties]), _update(key, property, update), and _remove(key) methods, which take a string key as the first argument.

Multiplexer storage

In some instances, the data associated with a logical unit is not contained in a single storage. Special logic is necessary to account for the delegation of different properties to different storages. The StorageMultiplexer : Storage class can be used to package these into one opaque object.

Instantiation

To instantiate one, call new commonStorage.StorageMultiplexer([storageDefault, storageProperties]). The first argument defines a default storage to which the multiplexer will revert to in the case that no property-specific storage is known. The second is a map of property strings to storages to which each should be delegated.

Dynamic property-storage delegation

To associate a storage with a property, call the associateStorageProperty(property, storage) method. Changing these associations over the lifetime of a program is not recommended and may leave your data in undesired places.

Drivers

Helpers:

Drivers: