Skip to content

Latest commit

 

History

History
616 lines (428 loc) · 20.1 KB

api.md

File metadata and controls

616 lines (428 loc) · 20.1 KB

Classes

BatchExecutor

Class responsible for executing a batch of operations atomically.

Batch

Class responsible for building a batch of operations.

MemoryDB

In-memory database extending SortedTree and providing eventing.

SortedTree

Nested and Sorted structure, extending functionalities from Nested and Storage mixins.

Node

Represents a Node in a doubly linked list.

Sorted

Sorted doubly linked list with Map based indexing.

BatchExecutor

Class responsible for executing a batch of operations atomically.

Kind: global class

new BatchExecutor(storage, performingUndo)

Creates a BatchExecutor instance.

Param Type Default Description
storage Storage The storage instance where operations are performed.
performingUndo boolean false Flag indicating if undo operations should be performed.

batchExecutor.execute(ops) ⇒ Promise

Executes the given operations atomically.

Kind: instance method of BatchExecutor
Returns: Promise - Resolves when all operations have been executed.

Param Type Description
ops Array Array of operations to execute.

batchExecutor.createUndoOps(ops) ⇒ Promise.<Array>

Creates undo operations for the given array of operations.

Kind: instance method of BatchExecutor
Returns: Promise.<Array> - Resolves with an array of undo operations.

Param Type Description
ops Array The operations for which to create undo operations.

batchExecutor.getDb([path]) ⇒ Storage

Gets a database instance based on a given path.

Kind: instance method of BatchExecutor
Returns: Storage - The database instance.

Param Type Description
[path] string The sub-path for the database.

batchExecutor.buildPromises(ops) ⇒ Array.<Promise>

Builds an array of promises for the given operations.

Kind: instance method of BatchExecutor
Returns: Array.<Promise> - An array of promises representing the operations.

Param Type Description
ops Array The operations for which to create promises.

batchExecutor.createUndoOp(operation) ⇒ Promise.<Object>

Creates an undo operation for a single operation.

Kind: instance method of BatchExecutor
Returns: Promise.<Object> - Resolves with the undo operation.

Param Type Description
operation Object The operation for which to create an undo operation.

BatchExecutor.execute(storage, ops) ⇒ Promise

Executes batch operations statically.

Kind: static method of BatchExecutor
Returns: Promise - Resolves when all operations have been executed.

Param Type Description
storage Storage The storage instance.
ops Array Array of operations to execute.

Batch

Class responsible for building a batch of operations.

Kind: global class

new Batch(storage)

Creates a Batch instance.

Param Type Description
storage Storage The storage instance where operations are performed.

batch.put(key, value, [sub]) ⇒ Batch

Adds a put operation to the batch.

Kind: instance method of Batch
Returns: Batch - Returns the current Batch instance.

Param Type Description
key any The key for the operation.
value any The value for the operation.
[sub] string Optional sub-path.

batch.del(key, [sub]) ⇒ Batch

Adds a delete operation to the batch.

Kind: instance method of Batch
Returns: Batch - Returns the current Batch instance.

Param Type Description
key any The key for the operation.
[sub] string Optional sub-path.

batch.build() ⇒ Array

Builds the batch operations.

Kind: instance method of Batch
Returns: Array - Array of batch operations.

batch.exec() ⇒ Promise

Executes the batch operations atomically.

Kind: instance method of Batch
Returns: Promise - Resolves when all operations have been executed.

Batch.execute(storage, arr) ⇒ Promise

Executes an array of operations atomically.

Kind: static method of Batch
Returns: Promise - Resolves when all operations have been executed.

Param Type Description
storage Storage The storage instance.
arr Array Array of operations to execute.

MemoryDB

In-memory database extending SortedTree and providing eventing.

Kind: global class

new MemoryDB(opts, ...args)

Creates a MemoryDB instance.

Param Type Description
opts object Options for the MemoryDB.
...args any Additional arguments.

memoryDB.isReady() ⇒ Promise

Checks if the database is ready.

Kind: instance method of MemoryDB
Returns: Promise - Resolves when the database is ready.

memoryDB.put(key, value) ⇒ Promise

Puts a key-value pair into the database and emits a 'put' event.

Kind: instance method of MemoryDB
Returns: Promise - Resolves when the put operation is complete.

Param Type Description
key any The key to store.
value any The value to store.

memoryDB.get(key) ⇒ Promise.<any>

Retrieves a value associated with a key from the database.

Kind: instance method of MemoryDB
Returns: Promise.<any> - The associated value.

Param Type Description
key any The key to retrieve.

memoryDB.del(key) ⇒ Promise

Deletes a key-value pair from the database and emits a 'del' event.

Kind: instance method of MemoryDB
Returns: Promise - Resolves when the delete operation is complete.

Param Type Description
key any The key to delete.

memoryDB.setOpts(opts) ⇒ MemoryDB

Sets additional options for the database.

Kind: instance method of MemoryDB
Returns: MemoryDB - The updated MemoryDB instance.

Param Type Description
opts object Additional options.

memoryDB.collect(type, opts) ⇒ Promise.<Array>

Collects key-value pairs based on the provided type and options.

Kind: instance method of MemoryDB
Returns: Promise.<Array> - An array of collected data.

Param Type Description
type string | boolean | object The type of data to collect ('key', 'value', or 'read').
opts object Options for collecting data.

memoryDB.batch(ops) ⇒ Promise | Batch

Creates or executes a batch operation.

Kind: instance method of MemoryDB
Returns: Promise | Batch - Returns a Promise if operations are provided, otherwise returns a new Batch instance.

Param Type Description
ops Array An array of batch operations.

MemoryDB.parseOptions(opts, defaultOpts) ⇒ object

Parses the given options.

Kind: static method of MemoryDB
Returns: object - Parsed options.

Param Type Description
opts object The options to parse.
defaultOpts object Default options.

SortedTree

Nested and Sorted structure, extending functionalities from Nested and Storage mixins.

Kind: global class

new SortedTree(opts, ...args)

Creates a SortedTree instance.

Param Type Description
opts object Options for the SortedTree.
...args any Additional arguments.

sortedTree._keyEncode(key) ⇒ any

Encodes the key.

Kind: instance method of SortedTree
Returns: any - - The encoded key.

Param Type Description
key any The key to be encoded.

sortedTree._valueEncode(value) ⇒ any

Encodes the value.

Kind: instance method of SortedTree
Returns: any - - The encoded value.

Param Type Description
value any The value to be encoded.

sortedTree._keyDecode(key) ⇒ any

Decodes the key.

Kind: instance method of SortedTree
Returns: any - - The decoded key.

Param Type Description
key any The key to be decoded.

sortedTree._valueDecode(value) ⇒ any

Decodes the value.

Kind: instance method of SortedTree
Returns: any - - The decoded value.

Param Type Description
value any The value to be decoded.

sortedTree.put(key, value)

Inserts or updates a key-value pair.

Kind: instance method of SortedTree

Param Type Description
key any The key to insert or update.
value any The value to insert or update.

sortedTree.get(key) ⇒ any

Retrieves a value by its key.

Kind: instance method of SortedTree
Returns: any - - The retrieved value, or null if the key doesn't exist.

Param Type Description
key any The key for which to retrieve the value.

sortedTree.del(key)

Deletes a key-value pair by its key.

Kind: instance method of SortedTree

Param Type Description
key any The key to delete.

sortedTree.sub(path, opts) ⇒ SortedTree

Creates a sub SortedTree.

Kind: instance method of SortedTree
Returns: SortedTree - - The sub SortedTree.

Param Type Description
path string | array The path for the sub SortedTree.
opts object Additional options.

sortedTree.iterator(opts)

An iterator over the SortedTree.

Kind: instance method of SortedTree

Param Type Description
opts object Iterator options.

sortedTree.listAll(opts)

Lists all key-value pairs.

Kind: instance method of SortedTree

Param Type Description
opts object Additional options for listing.

Node

Represents a Node in a doubly linked list.

Kind: global class

new Node(key, value)

Creates a new Node instance.

Param Type Description
key any The key associated with the node.
value any The value associated with the node.

Sorted

Sorted doubly linked list with Map based indexing.

Kind: global class

new Sorted(opts)

Creates a Sorted instance.

Param Type Description
opts object Options for the Sorted list.
opts.comparator function The comparator function to sort the keys.

sorted.put(key, value)

Inserts or updates a key-value pair in the list.

Kind: instance method of Sorted

Param Type Description
key any The key to insert or update.
value any The value associated with the key.

sorted.get(key) ⇒ any | null

Retrieves a value from the list based on the key.

Kind: instance method of Sorted
Returns: any | null - Returns the value if the key exists, otherwise returns null.

Param Type Description
key any The key to search for.

sorted.del(key)

Deletes a key-value pair from the list based on the key.

Kind: instance method of Sorted

Param Type Description
key any The key to delete.

sorted.iterator(opts)

Iterator function for the list based on the given options.

Kind: instance method of Sorted

Param Type Description
opts object Options for the iterator.
opts.reverse boolean Whether to reverse the order of iteration.

sorted.createReadStream(opts, mode) ⇒ Readable

Creates a readable stream based on the iterator.

Kind: instance method of Sorted
Returns: Readable - Returns a readable stream.

Param Type Default Description
opts object Options for the readable stream.
mode string "kv" Mode specifying the type of data to stream ('k', 'v', 'kv').

sorted.createKeyStream(opts) ⇒ Readable

Creates a key-only readable stream.

Kind: instance method of Sorted
Returns: Readable - Returns a readable stream.

Param Type Description
opts object Options for the readable stream.

sorted.createValueStream(opts) ⇒ Readable

Creates a value-only readable stream.

Kind: instance method of Sorted
Returns: Readable - Returns a readable stream.

Param Type Description
opts object Options for the readable stream.

sorted.listAll()

Logs all key-value pairs in the list.

Kind: instance method of Sorted