@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-kv
const {LevelDbKeyValueService, LevelDbKeyValueManager} = require('@lgslabs/bits-level-kv');
Service
The Service is responsible for creating, load
ing, and unload
ing 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})
messageCenter
MessageCenter The MessageCenter to usetag
String The tag to use for requests/eventsscopes
Array The scopes to use on requests/eventsreadScopes
Array The scopes for read-type requests/eventswriteScopes
Array The scopes for write-type requestsapiExport
Symbol(API_EXPORT) How to export the API. This must be a value from API_EXPORT object in order to exportapiData
Object The data to supply for export ({name, filepath}
forGLOBAL
,{topic, value}
forRESOURCE
)location
String The file location for the DB. The location will be created if it doesn't already exist.valueEncoding
String The encoding type to use in the DB. The default isjson
...args
Any 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)
options
Object The options passed into the Service'sload
function- 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})
messageCenter
MessageCenter The MessageCenter to use- Returns Promise resolving to request or rejecting to error