diff --git a/lib/links/lib/attachFieldSchema.js b/lib/links/lib/attachFieldSchema.js index ebbf515..2ab5808 100644 --- a/lib/links/lib/attachFieldSchema.js +++ b/lib/links/lib/attachFieldSchema.js @@ -61,7 +61,5 @@ function constructMetadataSchema(field, isMany, metadataSchema) { schemaDefinition[field + suffix + '.' + key] = value; }); - console.log(schemaDefinition); - return schemaDefinition; } \ No newline at end of file diff --git a/lib/query/lib/prepareForDelivery.js b/lib/query/lib/prepareForDelivery.js index 50e62d8..dfa0999 100644 --- a/lib/query/lib/prepareForDelivery.js +++ b/lib/query/lib/prepareForDelivery.js @@ -116,11 +116,10 @@ function cloneMetaChildren(node, parentResults) { } export function assembleMetadata(node, parentResults) { + // assembling metadata is depth first node.collectionNodes.forEach(collectionNode => { - const linkName = collectionNode.linkName; - _.each(parentResults, result => { - assembleMetadata(collectionNode, result[linkName]) + assembleMetadata(collectionNode, result[node.linkName]) }); }); @@ -131,7 +130,8 @@ export function assembleMetadata(node, parentResults) { _.each(childResult, object => { const storage = object[node.linkStorageField]; - return storeMetadata(object, parentResult, storage, true); + + storeMetadata(object, parentResult, storage, true); }); }) } else { diff --git a/lib/query/testing/bootstrap/fixtures.js b/lib/query/testing/bootstrap/fixtures.js index ea9aee0..3b5a9ef 100644 --- a/lib/query/testing/bootstrap/fixtures.js +++ b/lib/query/testing/bootstrap/fixtures.js @@ -8,65 +8,67 @@ import Posts from './posts/collection'; import Tags from './tags/collection'; import Groups from './groups/collection'; -Authors.remove({}); -Comments.remove({}); -Posts.remove({}); -Tags.remove({}); -Groups.remove({}); +Meteor.startup(() => { + Authors.remove({}); + Comments.remove({}); + Posts.remove({}); + Tags.remove({}); + Groups.remove({}); -const AUTHORS = 6; -const POST_PER_USER = 6; -const COMMENTS_PER_POST = 6; -const TAGS = ['JavaScript', 'Meteor', 'React', 'Other']; -const GROUPS = ['JavaScript', 'Meteor', 'React', 'Other']; -const COMMENT_TEXT_SAMPLES = [ - 'Good', 'Bad', 'Neutral' -]; + const AUTHORS = 6; + const POST_PER_USER = 6; + const COMMENTS_PER_POST = 6; + const TAGS = ['JavaScript', 'Meteor', 'React', 'Other']; + const GROUPS = ['JavaScript', 'Meteor', 'React', 'Other']; + const COMMENT_TEXT_SAMPLES = [ + 'Good', 'Bad', 'Neutral' + ]; -console.log('[testing] Loading test fixtures ...'); + console.log('[testing] Loading test fixtures ...'); -let tags = TAGS.map(name => Tags.insert({name})); -let groups = GROUPS.map(name => Groups.insert({name})); -let authors = _.range(AUTHORS).map(idx => { - return Authors.insert({ - name: 'Author - ' + idx, - profile: { - firstName: 'First Name - ' + idx, - lastName: 'Last Name - ' + idx - } - }); -}); - -_.each(authors, (author) => { - const authorPostLink = Authors.getLink(author, 'posts'); - const authorGroupLink = Authors.getLink(author, 'groups'); - - authorGroupLink.add(_.sample(groups), { - isAdmin: _.sample([true, false]) + let tags = TAGS.map(name => Tags.insert({name})); + let groups = GROUPS.map(name => Groups.insert({name})); + let authors = _.range(AUTHORS).map(idx => { + return Authors.insert({ + name: 'Author - ' + idx, + profile: { + firstName: 'First Name - ' + idx, + lastName: 'Last Name - ' + idx + } + }); }); - _.each(_.range(POST_PER_USER), (idx) => { - let post = { - title: `User Post - ${idx}` - }; + _.each(authors, (author) => { + const authorPostLink = Authors.getLink(author, 'posts'); + const authorGroupLink = Authors.getLink(author, 'groups'); - authorPostLink.add(post); - const postCommentsLink = Posts.getLink(post, 'comments'); - const postTagsLink = Posts.getLink(post, 'tags'); - const postGroupLink = Posts.getLink(post, 'group'); - postGroupLink.set(_.sample(groups), {random: Random.id()}); + authorGroupLink.add(_.sample(groups), { + isAdmin: _.sample([true, false]) + }); - postTagsLink.add(_.sample(tags)); - - _.each(_.range(COMMENTS_PER_POST), (idx) => { - let comment = { - text: _.sample(COMMENT_TEXT_SAMPLES) + _.each(_.range(POST_PER_USER), (idx) => { + let post = { + title: `User Post - ${idx}` }; - postCommentsLink.add(comment); - Comments.getLink(comment, 'author').set(_.sample(authors)); - }) - }) -}); + authorPostLink.add(post); + const postCommentsLink = Posts.getLink(post, 'comments'); + const postTagsLink = Posts.getLink(post, 'tags'); + const postGroupLink = Posts.getLink(post, 'group'); + postGroupLink.set(_.sample(groups), {random: Random.id()}); -console.log('[ok] fixtures have been loaded.'); \ No newline at end of file + postTagsLink.add(_.sample(tags)); + + _.each(_.range(COMMENTS_PER_POST), (idx) => { + let comment = { + text: _.sample(COMMENT_TEXT_SAMPLES) + }; + + postCommentsLink.add(comment); + Comments.getLink(comment, 'author').set(_.sample(authors)); + }) + }) + }); + + console.log('[ok] fixtures have been loaded.'); +}) diff --git a/lib/query/testing/server.test.js b/lib/query/testing/server.test.js index 539b967..93ed70f 100644 --- a/lib/query/testing/server.test.js +++ b/lib/query/testing/server.test.js @@ -221,6 +221,28 @@ describe('Hypernova', function () { }) }); + it('Should fetch direct One Meta links with $metadata that are under a nesting level', function () { + let authors = createQuery({ + authors: { + $options: { limit: 1 }, + posts: { + $options: { limit: 1 }, + group: { + name: 1 + } + } + } + }).fetch(); + + let data = authors[0]; + + _.each(data.posts, post => { + assert.isObject(post.group.$metadata); + assert.isDefined(post.group.$metadata.random); + }); + + }); + it('Should fetch Inversed One & Many Meta links with $metadata', function () { let data = createQuery({ groups: { diff --git a/package.js b/package.js index cc30938..ffe6e94 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'cultofcoders:grapher', - version: '1.2.8', + version: '1.2.8_1', // Brief, one-line summary of the package. summary: 'Grapher makes linking collections easily. And fetching data as a graph.', // URL to the Git repository containing the source code for this package.