import CollectionNode from "../nodes/CollectionNode" ; import processDirectNode from "./processDirectNode" ; import processRecursiveNode from "./processRecursiveNode" ; import processVirtualNode from "./processVirtualNode" ; import { createFilters } from "../lib/createFilters" ; import * as _ from "lodash" ; export default async function storeHypernovaResults ( childCollectionNode ) { if ( childCollectionNode . parent . results . length === 0 ) { return ; } const linker = childCollectionNode . linker ; const isVirtual = linker . isVirtual ( ) ; if ( shouldProcessRecursively ( childCollectionNode ) ) { await processRecursiveNode ( childCollectionNode ) ; return ; } const hypernovaFilters = createFilters ( childCollectionNode ) ; childCollectionNode . results = await childCollectionNode . toArray ( hypernovaFilters ) ; if ( ! isVirtual ) { processDirectNode ( childCollectionNode ) ; } else { processVirtualNode ( childCollectionNode ) ; } } export function shouldProcessRecursively ( childCollectionNode ) { if ( _ . isFunction ( childCollectionNode . props ) ) { return true ; } const { filters , options } = childCollectionNode . getPropsForQuerying ( ) ; if ( ! childCollectionNode . isOneResult ) { /**
         * In this case we perform a recursive fetch, yes, not very optimal
         */ if ( options . limit !== undefined || options . skip !== undefined ) { return true ; } } }