import * as _ from "lodash" ; import { QueryBodyType , IQueryContext } from "../defs" ; import CollectionNode from "./nodes/CollectionNode" ; import hypernova from "./hypernova/hypernova" ; import { Collection } from "mongodb" ; export default class Query < T = any > { public collection : Collection < T > ; private graph : CollectionNode ; public readonly body : any ; public queryName : string ; param collection param body constructor ( collection , body , context ? ) { this . collection = collection ; this . queryName = collection . collectionName ; this . body = body ; this . graph = new CollectionNode ( { collection , body , name : "root" , } , context || { } ) ; } param context returns { * } public async fetch ( ) { this . graph . forceSingleResult = false ; return this . toArray ( ) ; } public async toArray ( ) { return hypernova ( this . graph ) ; } public async fetchOne ( ) { this . graph . forceSingleResult = true ; const results = await this . toArray ( ) ; return _ . first ( results ) ; } }