mingo
Version:
MongoDB query language for in-memory objects
76 lines (75 loc) • 3.08 kB
TypeScript
import { Iterator, Source } from "./lazy";
import type { Any, AnyObject, CollationSpec, Options, Predicate, Projection } from "./types";
/**
* The `Cursor` class provides a mechanism for iterating over a collection of data
* with support for filtering, projection, sorting, skipping, and limiting results.
* It is designed to be chainable and supports lazy evaluation for efficient data processing.
*
* @template T - The type of the elements in the cursor.
*/
export declare class Cursor<T> {
#private;
/**
* Creates an instance of the Cursor class.
*
* @param source - The source of data to be iterated over.
* @param predicate - A function or condition to filter the data.
* @param projection - An object specifying the fields to include or exclude in the result.
* @param options - Optional settings to customize the behavior of the cursor.
*/
constructor(source: Source, predicate: Predicate<Any>, projection: Projection<T>, options?: Options);
/** Returns the iterator from running the query */
private fetch;
/** Returns an iterator with the buffered data included */
private fetchAll;
/**
* Return remaining objects in the cursor as an array. This method exhausts the cursor
* @returns {Array}
*/
all(): T[];
/**
* Returns a cursor that begins returning results only after passing or skipping a number of documents.
* @param {Number} n the number of results to skip.
* @return {Cursor} Returns the cursor, so you can chain this call.
*/
skip(n: number): Cursor<T>;
/**
* Limits the number of items returned by the cursor.
*
* @param n - The maximum number of items to return.
* @returns The current cursor instance for chaining.
*/
limit(n: number): Cursor<T>;
/**
* Returns results ordered according to a sort specification.
* @param {AnyObject} modifier an object of key and values specifying the sort order. 1 for ascending and -1 for descending
* @return {Cursor} Returns the cursor, so you can chain this call.
*/
sort(modifier: AnyObject): Cursor<T>;
/**
* Sets the collation options for the cursor.
* Collation allows users to specify language-specific rules for string comparison,
* such as case sensitivity and accent marks.
*
* @param spec - The collation specification to apply.
* @returns The current cursor instance for chaining.
*/
collation(spec: CollationSpec): Cursor<T>;
/**
* Retrieves the next item in the cursor.
*/
next(): T;
/**
* Determines if there are more elements available in the cursor.
*
* @returns {boolean} `true` if there are more elements to iterate over, otherwise `false`.
*/
hasNext(): boolean;
/**
* Returns an iterator for the cursor, allowing it to be used in `for...of` loops.
* The iterator fetches all the results from the cursor.
*
* @returns {Iterator} An iterator over the fetched results.
*/
[Symbol.iterator](): Iterator;
}