jkuester:remote-collections-provider
This meteor package allows to manage the registration of methods, collections and publications to be used by jkuester:remote-collections or any other remote application via DDP.
Usage
The package is a handy tool, if you want to manage which collections are available to an external app (which may use jkuester:remote-collections) or a custom DDP based implementation.
The RemoteCollectionsProvider is a singleton and can be imported and initialized via:
import {RemoteCollectionsProvider} from "meteor/jkuester:remote-collections-provider"; RemoteCollectionsProvider.init();
Your remote application requires some information, to successfully get your collections:
- What method can it call to get a list of available collections (their names)
- What method can it call to get a list of available subscriptions (their names)
Therefore you first need to add your collections to the list of available collection:
1RemoteCollectionsProvider.addCollectionNames('myMongoCollection'); //pass the name, you passed to the Mongo.Collection constructor
Then you need to add your publications (you do not need to call Meteor.publish, it does this for you, too).
1RemoteCollectionsProvider.addPublication('myCollection.public', function(){ 2 return myCollection.find({}); //your code here 3});
Finally you need to provide two methods, which allows your external app to retrieve the lists of available collections and subscriptions:
1 2//ake all collection names available 3RemoteCollectionsProvider.addMethod( 4 "ddp.getAvailableRemoteMethods", 5 function(){ 6 //returns a list of all available publications 7 return RemoteCollectionsProvider.getAllCollectionNames(); 8 }, 9 //use true to call Meteor.methods(...) on this immediatly 10 //you can also use false to bundle and the call RemoteCollectionsProvider.applyAllMethods() 11 true 12); 13 14 15//make all subscription names available 16RemoteCollectionsProvider.addMethod( 17 "ddp.getAvailableRemotePublications", 18 function(){ 19 //returns a list of all available publications 20 return RemoteCollectionsProvider.getAllPublicationNames(); 21 }, 22 true 23);
In your external application you can consume these functions via
1const remote = DDP.connect(yourProviderAppUrl); 2//... 3 4const remoteCollections = remote.call("ddp.getAvailableRemoteMethods"); 5for(let collection of remoteCollections) 6 //add collection... 7 8const remotePublications = remote.call("ddp.getAvailableRemotePublications"); 9for(let publication of remotePublications) 10 //subscribe... 11
Licence
MIT Licence, see Licence file