Home Reference Source Test
public interface | source

IIndex

Direct Implemented:

Indirect Implemented:

This interface represents a secondary index. A secondary index is always associated with a so called key path. The key path describes the path of the secondary key within the stored objects. Only objects for which the key path exists are part of the secondary index.

A key path is defined by a key within the object or alternatively a path through the object to a specific subkey. For example, ['a', 'b'] could be used to use 'key' as the key in the following object: { 'a': { 'b': 'key' } }

If a secondary index is a multi entry index, and the value at the key path is iterable, every item of the iterable value will be associated with the object.

All methods with the Keys suffix return a set of primary keys, while the given key ranges are evaluated on the secondary index and thus on the value at the specified key path. For simplicity, we refer to the value at the key path as the secondary key.

Member Summary

Public Members
public get abstract

keyPath: string | Array<string>

The key path associated with this index.

public get abstract

multiEntry: boolean

This value determines whether the index supports multiple secondary keys per entry.

public get abstract

unique: boolean

This value determines whether the index is a unique constraint.

Method Summary

Public Methods
public abstract

async count(query: KeyRange): Promise<number>

Returns the count of entries, whose secondary key is in the given range.

public abstract

keyStream(callback: function(key: string): boolean, ascending: boolean, query: KeyRange): Promise

Iterates over the primary keys in a given range of secondary keys and direction.

public abstract

async keys(query: KeyRange, limit: number): Promise<Set<string>>

Returns a promise of a set of primary keys, whose associated objects' secondary keys are in the given range. If the optional query is not given, it returns all primary keys in the index. If the query is of type KeyRange, it returns all primary keys for which the secondary key is within this range.

public abstract

async maxKeys(query: KeyRange): Promise<Set<*>>

Returns a promise of a set of primary keys, whose associated secondary keys are maximal for the given range.

public abstract

async maxValues(query: KeyRange): Promise<Array<*>>

Returns a promise of an array of objects whose secondary key is maximal for the given range.

public abstract

async minKeys(query: KeyRange): Promise<Set<*>>

Returns a promise of a set of primary keys, whose associated secondary keys are minimal for the given range.

public abstract

async minValues(query: KeyRange): Promise<Array<*>>

Returns a promise of an array of objects whose secondary key is minimal for the given range.

public abstract

async truncate(): Promise

Reinitialises the index.

public abstract

valueStream(callback: function(value: *, key: string): boolean, ascending: boolean, query: KeyRange): Promise

Iterates over the values of the store in a given range of secondary keys and direction.

public abstract

async values(query: KeyRange, limit: number): Promise<Array<*>>

Returns a promise of an array of objects whose secondary keys fulfill the given query.

Public Members

public get abstract keyPath: string | Array<string> source

The key path associated with this index. A key path is defined by a key within the object or alternatively a path through the object to a specific subkey. For example, ['a', 'b'] could be used to use 'key' as the key in the following object: { 'a': { 'b': 'key' } }

public get abstract multiEntry: boolean source

This value determines whether the index supports multiple secondary keys per entry. If so, the value at the key path is considered to be an iterable.

public get abstract unique: boolean source

This value determines whether the index is a unique constraint.

Public Methods

public abstract async count(query: KeyRange): Promise<number> source

Returns the count of entries, whose secondary key is in the given range. If the optional query is not given, it returns the count of entries in the index. If the query is of type KeyRange, it returns the count of entries, whose secondary key is within the given range.

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Return:

Promise<number>

public abstract keyStream(callback: function(key: string): boolean, ascending: boolean, query: KeyRange): Promise source

Iterates over the primary keys in a given range of secondary keys and direction. The order is determined by the secondary keys first and by the primary keys second. The callback is called for each primary key fulfilling the query until it returns false and stops the iteration.

Params:

NameTypeAttributeDescription
callback function(key: string): boolean

A predicate called for each key until returning false.

ascending boolean

Determines the direction of traversal.

query KeyRange

An optional KeyRange to narrow down the iteration space.

Return:

Promise

The promise resolves after all elements have been streamed.

public abstract async keys(query: KeyRange, limit: number): Promise<Set<string>> source

Returns a promise of a set of primary keys, whose associated objects' secondary keys are in the given range. If the optional query is not given, it returns all primary keys in the index. If the query is of type KeyRange, it returns all primary keys for which the secondary key is within this range.

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Optional query to check the secondary keys against.

limit number
  • optional

Limits the number of results if given.

Return:

Promise<Set<string>>

A promise of the set of primary keys relevant to the query.

public abstract async maxKeys(query: KeyRange): Promise<Set<*>> source

Returns a promise of a set of primary keys, whose associated secondary keys are maximal for the given range. If the optional query is not given, it returns the set of primary keys, whose associated secondary key is maximal within the index. If the query is of type KeyRange, it returns the set of primary keys, whose associated secondary key is maximal for the given range.

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Optional query to check keys against.

Return:

Promise<Set<*>>

A promise of the key relevant to the query.

public abstract async maxValues(query: KeyRange): Promise<Array<*>> source

Returns a promise of an array of objects whose secondary key is maximal for the given range. If the optional query is not given, it returns the objects whose secondary key is maximal within the index. If the query is of type KeyRange, it returns the objects whose secondary key is maximal for the given range.

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Optional query to check keys against.

Return:

Promise<Array<*>>

A promise of array of objects relevant to the query.

public abstract async minKeys(query: KeyRange): Promise<Set<*>> source

Returns a promise of a set of primary keys, whose associated secondary keys are minimal for the given range. If the optional query is not given, it returns the set of primary keys, whose associated secondary key is minimal within the index. If the query is of type KeyRange, it returns the set of primary keys, whose associated secondary key is minimal for the given range.

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Optional query to check keys against.

Return:

Promise<Set<*>>

A promise of the key relevant to the query.

public abstract async minValues(query: KeyRange): Promise<Array<*>> source

Returns a promise of an array of objects whose secondary key is minimal for the given range. If the optional query is not given, it returns the objects whose secondary key is minimal within the index. If the query is of type KeyRange, it returns the objects whose secondary key is minimal for the given range.

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Optional query to check keys against.

Return:

Promise<Array<*>>

A promise of array of objects relevant to the query.

public abstract async truncate(): Promise source

Reinitialises the index.

Return:

Promise

The promise resolves after emptying the index.

public abstract valueStream(callback: function(value: *, key: string): boolean, ascending: boolean, query: KeyRange): Promise source

Iterates over the values of the store in a given range of secondary keys and direction. The order is determined by the secondary keys first and by the primary keys second. The callback is called for each value and primary key fulfilling the query until it returns false and stops the iteration.

Params:

NameTypeAttributeDescription
callback function(value: *, key: string): boolean

A predicate called for each value and key until returning false.

ascending boolean

Determines the direction of traversal.

query KeyRange

An optional KeyRange to narrow down the iteration space.

Return:

Promise

The promise resolved after all elements have been streamed.

public abstract async values(query: KeyRange, limit: number): Promise<Array<*>> source

Returns a promise of an array of objects whose secondary keys fulfill the given query. If the optional query is not given, it returns all objects in the index. If the query is of type KeyRange, it returns all objects whose secondary keys are within this range.

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Optional query to check secondary keys against.

limit number
  • optional

Limits the number of results if given.

Return:

Promise<Array<*>>

A promise of the array of objects relevant to the query.