mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Adding meteor-publish-composite defs.
This commit is contained in:
@@ -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.
|
||||
]
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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
|
||||
|
||||
declare interface IPublishCompositeConfigN {
|
||||
children? : IPublishCompositeConfigN[];
|
||||
find(...args : any[]) : Mongo.Cursor<any>;
|
||||
}
|
||||
|
||||
declare interface IPublishCompositeConfig4<InLevel1, InLevel2, InLevel3, InLevel4, OutLevel> {
|
||||
children? : IPublishCompositeConfigN[];
|
||||
find(arg1 : InLevel1, arg2 : InLevel2, arg3 : InLevel3, arg4 : InLevel4) : Mongo.Cursor<OutLevel>;
|
||||
}
|
||||
|
||||
declare interface IPublishCompositeConfig3<InLevel1, InLevel2, InLevel3, OutLevel> {
|
||||
children? : IPublishCompositeConfig4<InLevel1, InLevel2, InLevel3, OutLevel, any>[];
|
||||
find(arg1 : InLevel1, arg2 : InLevel2, arg3 : InLevel3) : Mongo.Cursor<OutLevel>;
|
||||
}
|
||||
|
||||
declare interface IPublishCompositeConfig2<InLevel1, InLevel2, OutLevel> {
|
||||
children? : IPublishCompositeConfig3<InLevel1, InLevel2, OutLevel, any>[];
|
||||
find(arg1 : InLevel1, arg2 : InLevel2) : Mongo.Cursor<OutLevel>;
|
||||
}
|
||||
|
||||
declare interface IPublishCompositeConfig1<InLevel1, OutLevel> {
|
||||
children? : IPublishCompositeConfig2<InLevel1, OutLevel, any>[];
|
||||
find(arg1 : InLevel1) : Mongo.Cursor<OutLevel>;
|
||||
}
|
||||
|
||||
declare interface IPublishCompositeConfig<OutLevel> {
|
||||
children? : IPublishCompositeConfig1<OutLevel, any>[];
|
||||
find() : Mongo.Cursor<OutLevel>;
|
||||
}
|
||||
|
||||
declare module Meteor {
|
||||
function publishComposite(name : string, config : IPublishCompositeConfig<any>) : void;
|
||||
function publishComposite(name : string, configFunc : (...args : any[]) => IPublishCompositeConfig<any>) : void;
|
||||
}
|
||||
Reference in New Issue
Block a user