mirror of
https://github.com/vale981/grapher
synced 2025-03-05 09:31:42 -05:00
added , and refactored stuff a bit
This commit is contained in:
parent
44ea8627c4
commit
81837044e6
3 changed files with 48 additions and 31 deletions
|
@ -9,11 +9,12 @@ const specialFields = [
|
|||
'$options',
|
||||
'$postFilters',
|
||||
'$postOptions',
|
||||
'$postProcessing'
|
||||
'$postFilter'
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates node objects from the body
|
||||
* Creates node objects from the body. The root is always a collection node.
|
||||
*
|
||||
* @param root
|
||||
*/
|
||||
export function createNodes(root) {
|
||||
|
@ -29,9 +30,7 @@ export function createNodes(root) {
|
|||
|
||||
// if it's a prop
|
||||
if (_.contains(specialFields, fieldName)) {
|
||||
_.extend(root.props, {
|
||||
[fieldName]: body
|
||||
});
|
||||
root.addProp(fieldName, body);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -102,6 +101,14 @@ export default function (collection, body) {
|
|||
return root;
|
||||
};
|
||||
|
||||
/**
|
||||
* Ads denormalization config properly, including _id
|
||||
*
|
||||
* @param root
|
||||
* @param linker
|
||||
* @param body
|
||||
* @param fieldName
|
||||
*/
|
||||
function handleDenormalized(root, linker, body, fieldName) {
|
||||
Object.assign(body, {_id: 1});
|
||||
|
||||
|
|
|
@ -23,8 +23,9 @@ export default (node) => {
|
|||
});
|
||||
|
||||
removeLinkStorages(node, node.results);
|
||||
|
||||
storeOneResults(node, node.results);
|
||||
|
||||
node.postFilter();
|
||||
}
|
||||
|
||||
export function applyPostFilters(node) {
|
||||
|
@ -206,28 +207,3 @@ function snapBackCaches(node) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param elements
|
||||
// * @param storage
|
||||
// * @returns {Array}
|
||||
// */
|
||||
// function assembleMetadata(elements, storage) {
|
||||
// if (_.isArray(storage)) {
|
||||
// return _.map(elements, element => {
|
||||
// element.$metadata = _.find(storage, (storageMetadata) => {
|
||||
// return element._id == storageMetadata._id
|
||||
// });
|
||||
//
|
||||
// return _.extend({}, element, {
|
||||
// $metadata: _.omit(element.$metadata, '_id')
|
||||
// });
|
||||
// })
|
||||
// } else {
|
||||
// return _.map(elements, element => {
|
||||
// return _.extend({}, element, {
|
||||
// $metadata: _.omit(storage, '_id')
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import FieldNode from './fieldNode.js';
|
||||
import ReducerNode from './reducerNode.js';
|
||||
import deepClone from 'lodash.clonedeep';
|
||||
import {check, Match} from 'meteor/check';
|
||||
|
||||
export default class CollectionNode {
|
||||
constructor(collection, body = {}, linkName = null) {
|
||||
|
@ -37,6 +38,8 @@ export default class CollectionNode {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds children to itself
|
||||
*
|
||||
* @param node
|
||||
* @param linker
|
||||
*/
|
||||
|
@ -55,6 +58,20 @@ export default class CollectionNode {
|
|||
this.nodes.push(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param prop
|
||||
* @param value
|
||||
*/
|
||||
addProp(prop, value) {
|
||||
if (prop === '$postFilter') {
|
||||
check(value, Match.OneOf(Function, [Function]))
|
||||
}
|
||||
|
||||
_.extend(this.props, {
|
||||
[prop]: value
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _node
|
||||
*/
|
||||
|
@ -184,6 +201,23 @@ export default class CollectionNode {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally applies a post filtering option
|
||||
*/
|
||||
postFilter() {
|
||||
if (this.props.$postFilter) {
|
||||
const filter = this.props.$postFilter;
|
||||
|
||||
if (_.isArray(filter)) {
|
||||
filter.forEach(f => {
|
||||
this.results = f(this.results);
|
||||
})
|
||||
} else {
|
||||
this.results = filter(this.results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method verifies whether to remove the linkStorageField form the results
|
||||
* unless you specify it in your query.
|
||||
|
|
Loading…
Add table
Reference in a new issue