{"id":19128847,"url":"https://github.com/peerlibrary/meteor-middleware","last_synced_at":"2025-05-06T00:09:53.643Z","repository":{"id":21257408,"uuid":"24572998","full_name":"peerlibrary/meteor-middleware","owner":"peerlibrary","description":"Middleware support for Meteor publish functions","archived":false,"fork":false,"pushed_at":"2019-09-21T05:48:01.000Z","size":14,"stargazers_count":14,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-06T00:09:44.071Z","etag":null,"topics":["meteor","meteor-middleware"],"latest_commit_sha":null,"homepage":"https://atmospherejs.com/peerlibrary/middleware","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-09-28T23:07:41.000Z","updated_at":"2019-09-21T05:48:03.000Z","dependencies_parsed_at":"2022-08-17T22:40:57.394Z","dependency_job_id":null,"html_url":"https://github.com/peerlibrary/meteor-middleware","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peerlibrary","download_url":"https://codeload.github.com/peerlibrary/meteor-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596422,"owners_count":21773845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-middleware"],"created_at":"2024-11-09T06:05:49.109Z","updated_at":"2025-05-06T00:09:53.626Z","avatar_url":"https://github.com/peerlibrary.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Meteor Middleware\n=================\n\nMeteor smart package which provides middleware support for Meteor publish functions. It creates a system of\npublish endpoints and stacked middleware which allows easy use of reusable components in the pipeline between\nMongoDB and clients, in a reactive manner.\n\nImplemented features are:\n * class-based publish endpoint\n * class-based middleware which can post-process documents send to the subscriber by the publish endpoint\n * stacking of middleware onto the publish endpoint\n\nPlanned features are:\n * auto-generation of public API documentation for publish endpoints\n * integration of automatic arguments checking\n\nAdding this package to your [Meteor](http://www.meteor.com/) application adds `PublishEndpoint` and `PublishMiddleware`\nobjects into the global scope.\n\nServer side only.\n\nInstallation\n------------\n\n```\nmeteor add peerlibrary:middleware\n```\n\nPublish endpoints\n-----------------\n\n`PublishEndpoint` provides a base connection between the database and the rest of the stack. It can be seen as\ntraditional Meteor publish function and you define it in a similar, but class-based way:\n\n```coffee\nmyEndpoint = new PublishEndpoint 'my-endpoint', (argument1, argument2) -\u003e\n  # Here you can define your base publish function in the same way as you\n  # would otherwise. For example, you can just return a cursor:\n  Posts.find()\n```\n\nPublish middleware\n------------------\n\nTo define middleware, you extend the `PublishMiddleware` class with following methods:\n\n```coffee\nclass PublishMiddleware\n  added: (publish, collection, id, fields) =\u003e\n    publish.added collection, id, fields\n\n  changed: (publish, collection, id, fields) =\u003e\n    publish.changed collection, id, fields\n\n  removed: (publish, collection, id) =\u003e\n    publish.removed collection, id\n\n  onReady: (publish) =\u003e\n    publish.ready()\n\n  onStop: (publish) =\u003e\n    publish.stop()\n\n  onError: (publish, error) =\u003e\n    publish.error error\n```\n\n`publish` argument is the publish context of the current subscription. It is passed as an argument because\nthe same middleware instance is reused among all subscriptions to the same publish endpoint. In addition to\n[all official methods available for you otherwise](http://docs.meteor.com/#meteor_publish), there are few additional:\n\n * `publish.params()` – returns the arguments passed to the subscription by the client, an array\n * `publish.set(key, value)` – sets a `value` for the `key` in the state for this subscription, you can use this to share state\n between middleware\n * `publish.get(key)` – retrieves the value for the `key` from the state\n\nDefault implementation of all `PublishMiddleware` methods is to pass it on to the client. You can modify parameters,\ndecide to send something all, or simply to ignore and not do anything. You call `publish` methods you want.\n\nExample:\n\n```coffee\nclass LogAllActionsMiddleware extends PublishMiddleware\n  added: (publish, collection, id, fields) =\u003e\n    console.log \"added\", collection, id, fields\n    super\n\n  changed: (publish, collection, id, fields) =\u003e\n    console.log \"changed\", collection, id, fields\n    super\n\n  removed: (publish, collection, id) =\u003e\n    console.log \"removed\", collection, id\n    super\n\n  onReady: (publish) =\u003e\n    console.log \"ready\"\n    super\n\n  onStop: (publish) =\u003e\n    console.log \"stop\"\n    super\n\n  onError: (publish, error) =\u003e\n    console.log \"error\", error\n    super\n```\n\nStacking middleware\n-------------------\n\nOnce you defined your middleware class, you can add in onto the publish endpoint:\n\n```coffee\nmyEndpoint.use new LogAllActionsMiddleware()\n```\n\nMiddleware is stacked in the order they were registered. Those registered earlier are called earlier. At each middleware,\nonly later middleware is processed, no matter what you call from the method. For example, if you are in `added` method\nand you call `publish.changed`, only `changed` for the rest of middleware stack will be called, and will **not** go from the\ntop again.\n\nExamples\n--------\n\nSee [tests](https://github.com/peerlibrary/meteor-middleware/blob/master/tests.coffee) for some examples. See\n[middleware definitions in PeerLibrary](https://github.com/peerlibrary/peerlibrary/tree/development/server/middlewares) for\nreal-world definitions, and [their endpoints](https://github.com/peerlibrary/peerlibrary/blob/development/server).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeerlibrary%2Fmeteor-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-middleware/lists"}