Skip to content

Provides functionality to manage methods, collections and publications for the jokester:remote-collections package.

License

Notifications You must be signed in to change notification settings

jankapunkt/meteor-remote-collections-provider

Repository files navigation

Build Status Code Climate Test Coverage Issue Count

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:

RemoteCollectionsProvider.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).

RemoteCollectionsProvider.addPublication('myCollection.public', function(){
    return myCollection.find({}); //your code here
});

Finally you need to provide two methods, which allows your external app to retrieve the lists of available collections and subscriptions:

//ake all collection names available
RemoteCollectionsProvider.addMethod(
    "ddp.getAvailableRemoteMethods",
    function(){
        //returns a list of all available publications
        return RemoteCollectionsProvider.getAllCollectionNames();
    },
    //use true to call Meteor.methods(...) on this immediatly
    //you can also use false to bundle and the call RemoteCollectionsProvider.applyAllMethods()
    true
);


//make all subscription names available
RemoteCollectionsProvider.addMethod(
    "ddp.getAvailableRemotePublications",
    function(){
        //returns a list of all available publications
        return RemoteCollectionsProvider.getAllPublicationNames();
    },
    true
);

In your external application you can consume these functions via

const remote = DDP.connect(yourProviderAppUrl);
//...

const remoteCollections = remote.call("ddp.getAvailableRemoteMethods");
for(let collection of remoteCollections)
    //add collection...

const remotePublications = remote.call("ddp.getAvailableRemotePublications");
for(let publication of remotePublications)
    //subscribe...

Licence

MIT Licence, see Licence file

About

Provides functionality to manage methods, collections and publications for the jokester:remote-collections package.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published