{"id":19128797,"url":"https://github.com/peerlibrary/meteor-related","last_synced_at":"2026-03-07T19:33:23.598Z","repository":{"id":16766678,"uuid":"19524687","full_name":"peerlibrary/meteor-related","owner":"peerlibrary","description":"Publish with reactive dependencies on related queries","archived":false,"fork":false,"pushed_at":"2019-09-20T09:06:24.000Z","size":31,"stargazers_count":36,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-06T00:12:20.651Z","etag":null,"topics":["meteor","meteor-reactivity"],"latest_commit_sha":null,"homepage":"https://atmospherejs.com/peerlibrary/related","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peerlibrary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-07T07:10:55.000Z","updated_at":"2024-08-10T01:08:56.000Z","dependencies_parsed_at":"2022-09-19T06:41:15.465Z","dependency_job_id":null,"html_url":"https://github.com/peerlibrary/meteor-related","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/peerlibrary/meteor-related","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-related","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-related/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-related/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-related/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peerlibrary","download_url":"https://codeload.github.com/peerlibrary/meteor-related/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-related/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30227853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["meteor","meteor-reactivity"],"created_at":"2024-11-09T06:05:41.456Z","updated_at":"2026-03-07T19:33:23.574Z","avatar_url":"https://github.com/peerlibrary.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Publish with reactive dependencies\n==================================\n\nAdding this package to your [Meteor](http://www.meteor.com/) application augments\n[Meteor.publish](http://docs.meteor.com/#meteor_publish) handler object with method\n`related` which allows you to define publish endpoints with reactive dependencies on\nadditional queries. It allows easy wrapping of existing publish functions without any\nchange needed. You can use publish functions which return query cursors, or one which\nuses publish `added`/`changed`/`removed` API for custom publish functions.\n\nThis is useful in all situations where you want to publish documents which have a\nquery based on data from some other document and you want that everything behaves\nreactively, if any of those documents change, published documents should change as\nwell. Examples are any queries which limit published based documents on a list\nof IDs in another document. Or a permission system where you want to limit published\ndocuments based on flags and other properties of currently logged-in user.\n\nServer side only.\n\nSee also the follow-up package [peerlibrary:reactive-publish](https://github.com/peerlibrary/meteor-reactive-publish)\nwhich provides an alternative API through Meteor reactivity and familiar server-side `autorun`.\n\nInstallation\n------------\n\n```\nmeteor add peerlibrary:related\n```\n\n`this.related`\n--------------\n\nAlong with existing properties and methods, `this` inside `Meteor.publish` callback now\nhas `related` method available. Method accepts:\n\n * a callback – a new publish callback which will get as arguments results of your queries\n * one or more query cursors which should each return at most one document at any given moment;\n documents returned from query cursors will then be passed to the callback reactively, every\n time any of them changes callback will be rerun\n\nExample\n-------\n\nLet's say that you have a list of blog posts user is following as `follows` field in Meteor's\n`users` documents. You want to create a publish endpoint which will publish only those blog posts\nwhich current user follows. But if `follows` field changes, published blog posts should also\nchange (or if published blog posts themselves change, changes should be pushed to the client).\n\n```\nMeteor.publish('followed-blog-posts', function () {\n  if (!this.userId) return;\n\n  this.related(function (user) {\n    return Posts.find({_id: {$in: user.follows}});\n  },\n    Meteor.users.find(this.userId, {fields: {follows: 1}})\n  );\n});\n```\n\nEvery time `follows` field of currently logged-in user changes, related publish callback is\nrerun with new `user` document as an argument (as returned from `Meteor.users.find` query).\nCallback should do anything a normal publish callback should: or call `added`/`changed`/`removed`,\nor simply return a query to publish like in our example.\n\nDocuments are tracked between reruns and are not republished if they remain the same between\nreruns.\n\nKnown limitations\n-----------------\n\nCurrently each of related queries is expected to return at most one document at all times.\nIn theory returning multiple documents could be supported, but this means that related publish\ncallback would be rerun at any change of any of those multiple documents. This is probably not\na very efficient approach.\n\nNested calls to `related` should probably work, but were not yet tested.\n\nRelated projects\n----------------\n\nThere are few other similar projects trying to address a similar feature. We needed something\nproduction grade, with tests, and simple code base built upon existing Meteor features\ninstead of trying to replace them. Most of our code just wraps existing Meteor code into the\nreactive loop, and allowing existing publish functions to be reused without any change needed,\nyou can return queries or you can use `added`/`changed`/`removed`, all this is supported. Just\ninstead of having static arguments to your publish function, publish function is rerun when any\nof arguments changes. Its API is thus simple and intuitive.\n\n* [meteor-reactive-publish](https://github.com/Diggsey/meteor-reactive-publish) – uses API based on server-side dependency\n  tracking, but no tests and no support for `added`/`changed`/`removed`\n* [meteor-publish-with-relations](https://github.com/tmeasday/meteor-publish-with-relations) – complicated custom API not\n  allowing to reuse existing publish functions, which means no support for `added`/`changed`/`removed` as well\n* [meteor-smart-publish](https://github.com/yeputons/meteor-smart-publish) – complicated way of defining dependencies\nand works only with query cursors and not custom `added`/`changed`/`removed` functions\n* [reywood:publish-composite](https://github.com/englue/meteor-publish-composite) – allow you to define a nested structure\n  of cursors, which get documents from higher levels in a reactive manner, but it works only with only with query cursors\n  and not custom `added`/`changed`/`removed` functions\n* [copleyjk:simple-publish](https://github.com/copleykj/meteor-simple-publish) – seems similar to\n  `meteor-publish-with-relations`, but a more developed version covering more edge cases; on the other hand it\n  has the same limitations of no support for `added`/`changed`/`removed`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-related","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeerlibrary%2Fmeteor-related","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-related/lists"}