grapher/lib/query/hypernova/hypernova.js
2016-09-28 18:30:12 +03:00

47 lines
1.9 KiB
JavaScript

import applyProps from '../lib/applyProps.js';
import LinkResolve from '../../links/linkTypes/linkResolve.js';
import storeHypernovaResults from './storeHypernovaResults.js';
import assembler from './assembler.js';
import logger from './logger.js';
function hypernova(collectionNode, userId, debug) {
_.each(collectionNode.collectionNodes, childCollectionNode => {
let {filters, options} = applyProps(childCollectionNode);
if (childCollectionNode.linker.isResolver()) {
logger(debug, `[Resolving] ${collectionNode._name} -> ${childCollectionNode.linkName}`, () => {
_.each(collectionNode.results, result => {
const accessor = childCollectionNode.linker.createLink(result);
result[childCollectionNode.linkName] = accessor.find(filters, options);
});
logger.log(debug, `[Resolved] ${childCollectionNode.getName()}: ${collectionNode.results.length} results`)
});
} else {
logger(debug,
`[Fetch and Assembly] ${collectionNode.getName()} -> ${childCollectionNode.linkName}`, () => {
storeHypernovaResults(childCollectionNode, userId, debug);
logger.log(debug, `[Fetch and Assembly] ${childCollectionNode.getName()}: ${childCollectionNode.results.length} results`)
});
hypernova(childCollectionNode, userId, debug);
}
});
}
export default function hypernovaInit(collectionNode, userId, debug) {
let {filters, options} = applyProps(collectionNode);
const collection = collectionNode.collection;
logger(debug, `[Fetch] ${collection._name}`, () => {
collectionNode.results = collection.find(filters, options, userId).fetch();
logger.log(debug, `[Fetch] ${collectionNode.getName()}: ${collectionNode.results.length} results`)
});
hypernova(collectionNode, userId, debug);
return collectionNode.results;
}