import type { RxQueryBase } from '../rx-query.d.ts'; import type { Paths, StringKeys } from './util.d.ts'; /** * Typed Mango Query Selector * @link https://github.com/mongodb/node-mongodb-native/blob/26bce4a8debb65df5a42dc8599e886c9c83de10d/src/mongo_types.ts * @link https://stackoverflow.com/a/58436959/3443137 */ export type PropertyType = string extends Property ? unknown : Property extends keyof Type ? Type[Property] : Property extends `${number}` ? Type extends ReadonlyArray ? ArrayType : unknown : Property extends `${infer Key}.${infer Rest}` ? Key extends `${number}` ? Type extends ReadonlyArray ? PropertyType : unknown : Key extends keyof Type ? Type[Key] extends Map ? MapType : PropertyType : unknown : unknown; export type MangoQueryRegexOptions = 'i' | 'g' | 'm' | 'gi' | 'ig' | 'igm' | string; /* * The MongoDB query library is huge and we do not need all the operators. * If you add an operator here, make sure that you properly add a test in * the file /test/unit/rx-storage-query-correctness.test.ts * * @link https://github.com/kofrasa/mingo#es6 */ export interface MangoQueryOperators { $eq?: PathValueType; $gt?: PathValueType; $gte?: PathValueType; $lt?: PathValueType; $lte?: PathValueType; $ne?: PathValueType; $in?: PathValueType[]; $nin?: PathValueType[]; $regex?: string; $options?: MangoQueryRegexOptions; $exists?: boolean; $type?: 'null' | 'boolean' | 'number' | 'string' | 'array' | 'object'; $mod?: [number, number]; $not?: PathValueType; $size?: number; $elemMatch?: MangoQuerySelector; } export type MangoQuerySelector = Partial<{ [Property in Paths]: MangoQueryOperators | PropertyType; }> & { $and?: MangoQuerySelector[]; $or?: MangoQuerySelector[]; $nor?: MangoQuerySelector[]; }; /** * Discussion was at: * @link https://github.com/pubkey/rxdb/issues/1972 */ export type MangoQuerySortDirection = 'asc' | 'desc'; export type MangoQuerySortPart = { [k in StringKeys | string]: MangoQuerySortDirection; }; export type MangoQuerySelectorAndIndex = { /** * Selector is optional, * if not given, the query matches all documents * that are not _deleted=true. */ selector?: MangoQuerySelector; /** * By default, the RxStorage implementation * decides which index to use when running the query. * * For better performance, a different index might be defined * by setting it in the query. * How this improves performance and if the defined index is used, * depends on the RxStorage implementation. */ index?: string | string[]; }; export type MangoQueryNoLimit = MangoQuerySelectorAndIndex & { /** * Sorting of the results. * If no sort is set, RxDB will sort by the primary key. * Also if sort is set, RxDB will add primaryKey sorting * if the primaryKey was not in the sort parameters before. * This ensures that there is a deterministic sorting of the * results, not mather at which order the documents have been * inserted into the storage. */ sort?: MangoQuerySortPart[]; }; export type MangoQuery = MangoQueryNoLimit & { skip?: number; limit?: number; }; export type RxQueryOP = 'find' | 'findOne' | 'count' | 'findByIds'; export declare class RxQuery< RxDocumentType = any, RxQueryResult = any, OrmMethods = {}, Reactivity = unknown > extends RxQueryBase { equals(queryObj: any): RxQuery; eq(queryObj: any): RxQuery; or(queryObj: keyof RxDocumentType | string | any[]): RxQuery; nor(queryObj: keyof RxDocumentType | string | any[]): RxQuery; and(queryObj: keyof RxDocumentType | string | any[]): RxQuery; gt(queryObj: any): RxQuery; gte(queryObj: any): RxQuery; lt(queryObj: any): RxQuery; lte(queryObj: any): RxQuery; ne(queryObj: any): RxQuery; in(queryObj: any[]): RxQuery; nin(queryObj: any[]): RxQuery; all(queryObj: any): RxQuery; regex(queryObj: string | { $regex: string; $options: MangoQueryRegexOptions; }): RxQuery; exists(queryObj: any): RxQuery; elemMatch(queryObj: any): RxQuery; mod(p1: any, p2: any, p3: any): RxQuery; }