import * as _ from "lodash" ; import applyReducers from "./computeReducers" ; import CollectionNode from "../nodes/CollectionNode" ; export default async ( node ) => { storeOneResults ( node , node . results ) ; await applyReducers ( node ) ; node . project ( ) ; } ; export function storeOneResults ( node , sameLevelResults ) { if ( ! sameLevelResults ) { return ; } node . collectionNodes . forEach ( ( childCollectionNode ) => { sameLevelResults . forEach ( ( result ) => { if ( result !== undefined ) { if ( Array . isArray ( result [ childCollectionNode . name ] ) ) { storeOneResults ( childCollectionNode , result [ childCollectionNode . name ] ) ; } } } ) ; if ( childCollectionNode . isOneResult ) { sameLevelResults . forEach ( ( result ) => { if ( result [ childCollectionNode . name ] && Array . isArray ( result [ childCollectionNode . name ] ) ) { result [ childCollectionNode . name ] = result [ childCollectionNode . name ] . length > 0 ? _ . first ( result [ childCollectionNode . name ] ) : null ; } } ) ; } } ) ; }