UNPKG

@thisisagile/easy-mongo

Version:
55 lines (54 loc) 2.67 kB
import { Condition, FetchOptions, Field, Id, Json, JsonValue, LogicalCondition, OneOrMore, PageList, Sort } from '@thisisagile/easy'; import { AggregationCursor, Collection as MongoCollection, CreateIndexesOptions, Document, FindCursor, FindOptions as MongoFindOptions, IndexSpecification, MongoClient, StrictFilter as MongoFilter } from 'mongodb'; import { Collection } from './Collection'; export type Projection = Record<string, 0 | 1>; export type FindOptions = FetchOptions & { projection?: Projection; }; export type Filter<T = unknown> = MongoFilter<T>; export type Query = Condition | LogicalCondition | Filter<any>; export type IndexOptions = { unique?: boolean; filter?: Query; languageOverride?: string; languageDefault?: string; }; export type Indexes = OneOrMore<string | Field | Sort | Record<string, 1 | -1>>; export type Options = { maxTimeMS?: number; }; export declare class MongoProvider { readonly coll: Collection; protected static readonly clients: { [key: string]: Promise<MongoClient>; }; constructor(coll: Collection); static destroyAll(): Promise<void>; private static connect; cluster(): Promise<MongoClient>; collection<T extends Document = Document>(): Promise<MongoCollection<T>>; toMongoJson(query: Query): Json; find(query: Query, options?: FindOptions & Options): Promise<PageList<Json>>; all(options?: FindOptions): Promise<PageList<Json>>; byId(id: Id, options?: FindOptions): Promise<Json>; by(key: string, value: JsonValue, options?: FindOptions): Promise<PageList<Json>>; group(qs: Filter<any>[], options?: Options): Promise<PageList<Json>>; aggregate(qs: Filter<any>[], options?: Options): Promise<PageList<Json>>; add(item: Json): Promise<Json>; update(item: Json): Promise<Json>; remove(id: Id): Promise<boolean>; count(query?: Query, options?: Options): Promise<number>; createIndex(indexes: Indexes, options?: IndexOptions): Promise<string>; createPartialIndex(indexes: Indexes, filter: Query, options?: Omit<IndexOptions, 'filter'>): Promise<string>; createTextIndex(indexes: OneOrMore<Field | string>, options?: IndexOptions): Promise<string>; protected toFindOptions(options?: FindOptions): MongoFindOptions & { total: boolean; }; protected toIndexSpecification(index: Indexes): IndexSpecification; protected toCreateIndexesOptions(options?: IndexOptions): CreateIndexesOptions; protected toArray(cursor: FindCursor<Document> | AggregationCursor<Document>, options?: { take?: number; skip?: number; total?: number; }): Promise<PageList<Json>>; }