From b0b4ecb45a330c86f6b4ca634bbbd747acbf0b48 Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Sat, 16 Jan 2016 10:39:58 -0800 Subject: [PATCH 1/5] Adding meteor-publish-composite defs. --- .../meteor-publish-composite-tests.ts | 60 +++++++++++++++++++ .../meteor-publish-composite.d.ts | 39 ++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 meteor-publish-composite/meteor-publish-composite-tests.ts create mode 100644 meteor-publish-composite/meteor-publish-composite.d.ts diff --git a/meteor-publish-composite/meteor-publish-composite-tests.ts b/meteor-publish-composite/meteor-publish-composite-tests.ts new file mode 100644 index 000000000..ad84c0f3a --- /dev/null +++ b/meteor-publish-composite/meteor-publish-composite-tests.ts @@ -0,0 +1,60 @@ +/// +/// + +import User = Meteor.User; +interface IPost { _id : string, authorId : string }; +interface IComment { authorId : string }; +var Posts : Mongo.Collection = new Mongo.Collection('Posts'); +var Comments : Mongo.Collection = new Mongo.Collection('Comments'); + +// Server +Meteor.publishComposite('topTenPosts', { + find: function() : Mongo.Cursor { + // Find top ten highest scoring posts + return Posts.find({}, { sort: { score: -1 }, limit: 10 }); + }, + children: [ + { + find: function(post) { + // Find post author. Even though we only want to return + // one record here, we use "find" instead of "findOne" + // since this function should return a cursor. + return Meteor.users.find( + { _id: post.authorId }, + { limit: 1, fields: { profile: 1 } }); + } + }, + { + find: function(post) { + // Find top two comments on post + return Comments.find( + { postId: post._id }, + { sort: { score: -1 }, limit: 2 }); + }, + children: [ + { + find: function(comment, post) { + // Find user that authored comment. + return Meteor.users.find( + { _id: comment.authorId }, + { limit: 1, fields: { profile: 1 } }); + } + } + ] + } + ] +}); + +// Server +Meteor.publishComposite('postsByUser', function(userId, limit) { + return { + find: function() { + // Find posts made by user. Note arguments for callback function + // being used in query. + return Posts.find({ authorId: userId }, { limit: limit }); + }, + children: [ + // This section will be similar to that of the previous example. + ] + } +}); diff --git a/meteor-publish-composite/meteor-publish-composite.d.ts b/meteor-publish-composite/meteor-publish-composite.d.ts new file mode 100644 index 000000000..6b7c0308c --- /dev/null +++ b/meteor-publish-composite/meteor-publish-composite.d.ts @@ -0,0 +1,39 @@ +// Type definitions for meteor-publish-composite +// Project: https://github.com/englue/meteor-publish-composite +// Definitions by: Robert Van Gorkom +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare interface IPublishCompositeConfigN { + children? : IPublishCompositeConfigN[]; + find(...args : any[]) : Mongo.Cursor; +} + +declare interface IPublishCompositeConfig4 { + children? : IPublishCompositeConfigN[]; + find(arg1 : InLevel1, arg2 : InLevel2, arg3 : InLevel3, arg4 : InLevel4) : Mongo.Cursor; +} + +declare interface IPublishCompositeConfig3 { + children? : IPublishCompositeConfig4[]; + find(arg1 : InLevel1, arg2 : InLevel2, arg3 : InLevel3) : Mongo.Cursor; +} + +declare interface IPublishCompositeConfig2 { + children? : IPublishCompositeConfig3[]; + find(arg1 : InLevel1, arg2 : InLevel2) : Mongo.Cursor; +} + +declare interface IPublishCompositeConfig1 { + children? : IPublishCompositeConfig2[]; + find(arg1 : InLevel1) : Mongo.Cursor; +} + +declare interface IPublishCompositeConfig { + children? : IPublishCompositeConfig1[]; + find() : Mongo.Cursor; +} + +declare module Meteor { + function publishComposite(name : string, config : IPublishCompositeConfig) : void; + function publishComposite(name : string, configFunc : (...args : any[]) => IPublishCompositeConfig) : void; +} From 1de41285d9757970847c59d284244c0243b46181 Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Sat, 16 Jan 2016 10:48:41 -0800 Subject: [PATCH 2/5] Adding missing reference. --- meteor-publish-composite/meteor-publish-composite.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meteor-publish-composite/meteor-publish-composite.d.ts b/meteor-publish-composite/meteor-publish-composite.d.ts index 6b7c0308c..d3b3aff87 100644 --- a/meteor-publish-composite/meteor-publish-composite.d.ts +++ b/meteor-publish-composite/meteor-publish-composite.d.ts @@ -3,6 +3,8 @@ // Definitions by: Robert Van Gorkom // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + declare interface IPublishCompositeConfigN { children? : IPublishCompositeConfigN[]; find(...args : any[]) : Mongo.Cursor; From 62550bd2dc274af7c228993526a83d3d8714ca03 Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Mon, 18 Jan 2016 21:11:51 -0800 Subject: [PATCH 3/5] Fixing order of args in find functions. --- meteor-publish-composite/meteor-publish-composite.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/meteor-publish-composite/meteor-publish-composite.d.ts b/meteor-publish-composite/meteor-publish-composite.d.ts index d3b3aff87..0fe64fa17 100644 --- a/meteor-publish-composite/meteor-publish-composite.d.ts +++ b/meteor-publish-composite/meteor-publish-composite.d.ts @@ -12,17 +12,17 @@ declare interface IPublishCompositeConfigN { declare interface IPublishCompositeConfig4 { children? : IPublishCompositeConfigN[]; - find(arg1 : InLevel1, arg2 : InLevel2, arg3 : InLevel3, arg4 : InLevel4) : Mongo.Cursor; + find(arg4 : InLevel4, arg3 : InLevel3, arg2 : InLevel2, arg1 : InLevel1) : Mongo.Cursor; } declare interface IPublishCompositeConfig3 { children? : IPublishCompositeConfig4[]; - find(arg1 : InLevel1, arg2 : InLevel2, arg3 : InLevel3) : Mongo.Cursor; + find(arg3 : InLevel3, arg2 : InLevel2, arg1 : InLevel1) : Mongo.Cursor; } declare interface IPublishCompositeConfig2 { children? : IPublishCompositeConfig3[]; - find(arg1 : InLevel1, arg2 : InLevel2) : Mongo.Cursor; + find(arg2 : InLevel2, arg1 : InLevel1) : Mongo.Cursor; } declare interface IPublishCompositeConfig1 { @@ -36,6 +36,6 @@ declare interface IPublishCompositeConfig { } declare module Meteor { - function publishComposite(name : string, config : IPublishCompositeConfig) : void; + function publishComposite(name : string, config : IPublishCompositeConfig|IPublishCompositeConfig[]) : void; function publishComposite(name : string, configFunc : (...args : any[]) => IPublishCompositeConfig) : void; } From fecf4a9e6c2df5f96d00b2c0c4eb0ca16276e36e Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Tue, 19 Jan 2016 08:08:04 -0800 Subject: [PATCH 4/5] Adding array return type and formating to play nice with tslint. --- .../meteor-publish-composite.d.ts | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/meteor-publish-composite/meteor-publish-composite.d.ts b/meteor-publish-composite/meteor-publish-composite.d.ts index 0fe64fa17..afc02bc55 100644 --- a/meteor-publish-composite/meteor-publish-composite.d.ts +++ b/meteor-publish-composite/meteor-publish-composite.d.ts @@ -7,27 +7,43 @@ declare interface IPublishCompositeConfigN { children? : IPublishCompositeConfigN[]; - find(...args : any[]) : Mongo.Cursor; + find( + ...args : any[] + ) : Mongo.Cursor; } declare interface IPublishCompositeConfig4 { children? : IPublishCompositeConfigN[]; - find(arg4 : InLevel4, arg3 : InLevel3, arg2 : InLevel2, arg1 : InLevel1) : Mongo.Cursor; + find( + arg4 : InLevel4, + arg3 : InLevel3, + arg2 : InLevel2, + arg1 : InLevel1 + ) : Mongo.Cursor; } declare interface IPublishCompositeConfig3 { children? : IPublishCompositeConfig4[]; - find(arg3 : InLevel3, arg2 : InLevel2, arg1 : InLevel1) : Mongo.Cursor; + find( + arg3 : InLevel3, + arg2 : InLevel2, + arg1 : InLevel1 + ) : Mongo.Cursor; } declare interface IPublishCompositeConfig2 { children? : IPublishCompositeConfig3[]; - find(arg2 : InLevel2, arg1 : InLevel1) : Mongo.Cursor; + find( + arg2 : InLevel2, + arg1 : InLevel1 + ) : Mongo.Cursor; } declare interface IPublishCompositeConfig1 { children? : IPublishCompositeConfig2[]; - find(arg1 : InLevel1) : Mongo.Cursor; + find( + arg1 : InLevel1 + ) : Mongo.Cursor; } declare interface IPublishCompositeConfig { @@ -36,6 +52,14 @@ declare interface IPublishCompositeConfig { } declare module Meteor { - function publishComposite(name : string, config : IPublishCompositeConfig|IPublishCompositeConfig[]) : void; - function publishComposite(name : string, configFunc : (...args : any[]) => IPublishCompositeConfig) : void; + function publishComposite( + name : string, + config : IPublishCompositeConfig|IPublishCompositeConfig[] + ) : void; + + function publishComposite( + name : string, + configFunc : (...args : any[]) => + IPublishCompositeConfig|IPublishCompositeConfig[] + ) : void; } From d299ef07770732e6592564eefceac3038adbd822 Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Sat, 23 Jan 2016 08:06:08 -0800 Subject: [PATCH 5/5] Changing interface name to not include I prefix. --- .../meteor-publish-composite.d.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/meteor-publish-composite/meteor-publish-composite.d.ts b/meteor-publish-composite/meteor-publish-composite.d.ts index afc02bc55..ddab6ef47 100644 --- a/meteor-publish-composite/meteor-publish-composite.d.ts +++ b/meteor-publish-composite/meteor-publish-composite.d.ts @@ -5,15 +5,15 @@ /// -declare interface IPublishCompositeConfigN { - children? : IPublishCompositeConfigN[]; +declare interface PublishCompositeConfigN { + children? : PublishCompositeConfigN[]; find( ...args : any[] ) : Mongo.Cursor; } -declare interface IPublishCompositeConfig4 { - children? : IPublishCompositeConfigN[]; +declare interface PublishCompositeConfig4 { + children? : PublishCompositeConfigN[]; find( arg4 : InLevel4, arg3 : InLevel3, @@ -22,8 +22,8 @@ declare interface IPublishCompositeConfig4; } -declare interface IPublishCompositeConfig3 { - children? : IPublishCompositeConfig4[]; +declare interface PublishCompositeConfig3 { + children? : PublishCompositeConfig4[]; find( arg3 : InLevel3, arg2 : InLevel2, @@ -31,35 +31,35 @@ declare interface IPublishCompositeConfig3; } -declare interface IPublishCompositeConfig2 { - children? : IPublishCompositeConfig3[]; +declare interface PublishCompositeConfig2 { + children? : PublishCompositeConfig3[]; find( arg2 : InLevel2, arg1 : InLevel1 ) : Mongo.Cursor; } -declare interface IPublishCompositeConfig1 { - children? : IPublishCompositeConfig2[]; +declare interface PublishCompositeConfig1 { + children? : PublishCompositeConfig2[]; find( arg1 : InLevel1 ) : Mongo.Cursor; } -declare interface IPublishCompositeConfig { - children? : IPublishCompositeConfig1[]; +declare interface PublishCompositeConfig { + children? : PublishCompositeConfig1[]; find() : Mongo.Cursor; } declare module Meteor { function publishComposite( name : string, - config : IPublishCompositeConfig|IPublishCompositeConfig[] + config : PublishCompositeConfig|PublishCompositeConfig[] ) : void; function publishComposite( name : string, configFunc : (...args : any[]) => - IPublishCompositeConfig|IPublishCompositeConfig[] + PublishCompositeConfig|PublishCompositeConfig[] ) : void; }