Merge pull request #7663 from vangorra/master

Adding meteor-publish-composite defs.
This commit is contained in:
Horiuchi_H
2016-02-01 17:29:31 +09:00
2 changed files with 125 additions and 0 deletions
@@ -0,0 +1,60 @@
/// <reference path="meteor-publish-composite.d.ts" />
/// <reference path="../meteor/meteor.d.ts" />
import User = Meteor.User;
interface IPost { _id : string, authorId : string };
interface IComment { authorId : string };
var Posts : Mongo.Collection<IPost> = new Mongo.Collection<IPost>('Posts');
var Comments : Mongo.Collection<IComment> = new Mongo.Collection<IComment>('Comments');
// Server
Meteor.publishComposite('topTenPosts', {
find: function() : Mongo.Cursor<IPost> {
// 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.
]
}
});
+65
View File
@@ -0,0 +1,65 @@
// Type definitions for meteor-publish-composite
// Project: https://github.com/englue/meteor-publish-composite
// Definitions by: Robert Van Gorkom <https://github.com/vangorra>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../meteor/meteor.d.ts" />
declare interface PublishCompositeConfigN {
children? : PublishCompositeConfigN[];
find(
...args : any[]
) : Mongo.Cursor<any>;
}
declare interface PublishCompositeConfig4<InLevel1, InLevel2, InLevel3, InLevel4, OutLevel> {
children? : PublishCompositeConfigN[];
find(
arg4 : InLevel4,
arg3 : InLevel3,
arg2 : InLevel2,
arg1 : InLevel1
) : Mongo.Cursor<OutLevel>;
}
declare interface PublishCompositeConfig3<InLevel1, InLevel2, InLevel3, OutLevel> {
children? : PublishCompositeConfig4<InLevel1, InLevel2, InLevel3, OutLevel, any>[];
find(
arg3 : InLevel3,
arg2 : InLevel2,
arg1 : InLevel1
) : Mongo.Cursor<OutLevel>;
}
declare interface PublishCompositeConfig2<InLevel1, InLevel2, OutLevel> {
children? : PublishCompositeConfig3<InLevel1, InLevel2, OutLevel, any>[];
find(
arg2 : InLevel2,
arg1 : InLevel1
) : Mongo.Cursor<OutLevel>;
}
declare interface PublishCompositeConfig1<InLevel1, OutLevel> {
children? : PublishCompositeConfig2<InLevel1, OutLevel, any>[];
find(
arg1 : InLevel1
) : Mongo.Cursor<OutLevel>;
}
declare interface PublishCompositeConfig<OutLevel> {
children? : PublishCompositeConfig1<OutLevel, any>[];
find() : Mongo.Cursor<OutLevel>;
}
declare module Meteor {
function publishComposite(
name : string,
config : PublishCompositeConfig<any>|PublishCompositeConfig<any>[]
) : void;
function publishComposite(
name : string,
configFunc : (...args : any[]) =>
PublishCompositeConfig<any>|PublishCompositeConfig<any>[]
) : void;
}