mingo
Version:
MongoDB query language for in-memory objects
51 lines (50 loc) • 2.37 kB
TypeScript
import { ComputeOptions } from "../../core/_internal";
import { Query } from "../../query";
import { Any, AnyObject, ArrayOrObject, Callback, Options } from "../../types";
import { WalkOptions } from "../../util/_internal";
export type SingleKeyRecord<K extends PropertyKey, V> = {
[P in K]: Record<P, V>;
}[K];
export declare const DEFAULT_OPTIONS: Options;
export declare const clone: (val: Any, opts: Options) => Any;
export type PathNode = {
selector: string;
position?: string;
next?: PathNode;
};
/**
* Applies an update function to a value to produce a new value to modify an object in-place.
* @param o The object or array to modify.
* @param n The path node of the update selector.
* @param q Map of positional identifiers to queries for filtering.
* @param f The update function which accepts containver value and key.
* @param opts The optional {@link WalkOptions} passed to the walk function.
*/
export declare const applyUpdate: (o: ArrayOrObject, n: PathNode, q: Record<string, Query>, f: Callback<boolean>, opts?: WalkOptions) => boolean;
export type Action<T> = (val: T, pathNode: PathNode, queries: Record<string, Query>) => boolean;
/**
* Walks the expression and apply the given action for each key-value pair.
*
* @param expr The expression for the update operator.
* @param arrayFilters Filter conditions passed to the operator.
* @param options The options provided by the caller.
* @param callback The action to apply for a given path and value.
* @returns {Any[]<string>}
*/
export declare function walkExpression<T>(expr: AnyObject, arrayFilters: AnyObject[], options: Options, callback: Action<T>): string[];
/**
* Builds a map of parameters for update operations, where each parameter is associated
* with its corresponding path node and query conditions. Conflicting selectors are detected.
*/
export declare function buildParams(exprList: AnyObject[], arrayFilters: AnyObject[], options: ComputeOptions): Record<string, {
node: PathNode;
queries: Record<string, Query>;
}>;
export type UpdateParams = ReturnType<typeof buildParams>;
export type UpdateOperator = (obj: AnyObject, expr: Any, arrayFilters: AnyObject[], options: Options) => string[];
/** Simple to trie for validating path conflicts */
export declare class Trie {
private root;
constructor();
add(selector: string): boolean;
}