@lgslabs/bits-level-kv v2.1.2
BITS Level Key/Value
The level-backed implementation of key/value store for BITS. This package extends the functionality provided in bits-memory-kv, only changing the underlying implementations for KeyValueService and KeyValueManager. Keys and values can be of any type.
Use
Importing
npm install @lgslabs/bits-level-kvconst {LevelDbKeyValueService, LevelDbKeyValueManager} = require('@lgslabs/bits-level-kv');Service
The Service is responsible for creating, loading, and unloading the manager, messenger, a public API (if desired), and any resources the subsystem may need.
load
Loads the Service, thereby creating and loading the other subsystem components with the provided options. In addition to the options documented below, any options that level accepts can be passed to this function.
load({messageCenter, tag, scopes, readScopes, writeScopes, filter, apiExport, apiData, ...args})messageCenterMessageCenter The MessageCenter to usetagString The tag to use for requests/eventsscopesArray The scopes to use on requests/eventsreadScopesArray The scopes for read-type requests/eventswriteScopesArray The scopes for write-type requestsapiExportSymbol(API_EXPORT) How to export the API. This must be a value from API_EXPORT object in order to exportapiDataObject The data to supply for export ({name, filepath}forGLOBAL,{topic, value}forRESOURCE)locationString The file location for the DB. The location will be created if it doesn't already exist.valueEncodingString The encoding type to use in the DB. The default isjson...argsAny number of additional key/value pairs- Returns Promise resolving to request or rejecting to error
createManager
Called in the Service's load function to create the manager. By default, it creates an instance of the base implementation of the Level DB Key/Value manager. If the subsystem needs additional functionality, it is recommended to override this function.
createManager()- Returns Promise resolving to request or rejecting to error
Manager
The Manager is responsible for performing any operations related to the subsystem. It has default implementations for all Key/Value operations. The manager is an EventEmitter to allow communication with the Messenger. To change the Manager class being used, override the createManager function in the Service to create and return the desired Manager implementation. The loadManager and unloadManager functions can be overridden in the event more customization is required.
load
Loads the Manager. This is where all initialization should be done, and how the Manager should receive any additional parameters. During this function, the Manager will also open a connection to the DB instance.
load(options)optionsObject The options passed into the Service'sloadfunction- Returns Promise resolving to request or rejecting to error
`unload
Unloads the Manager. This is where all teardown should be done. During this function, the Manager will also close the connection to the DB instance, if one exists.
unload({messageCenter})messageCenterMessageCenter The MessageCenter to use- Returns Promise resolving to request or rejecting to error