2.1.2 • Published 4 years ago

@lgslabs/bits-level-kv v2.1.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

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, 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})
  • messageCenter MessageCenter The MessageCenter to use
  • tag String The tag to use for requests/events
  • scopes Array The scopes to use on requests/events
  • readScopes Array The scopes for read-type requests/events
  • writeScopes Array The scopes for write-type requests
  • apiExport Symbol(API_EXPORT) How to export the API. This must be a value from API_EXPORT object in order to export
  • apiData Object The data to supply for export ({name, filepath} for GLOBAL, {topic, value} for RESOURCE)
  • 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 is json
  • ...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's load 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
2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago