{"id":19128806,"url":"https://github.com/peerlibrary/meteor-publish-context","last_synced_at":"2025-05-06T00:10:30.658Z","repository":{"id":68281853,"uuid":"85680364","full_name":"peerlibrary/meteor-publish-context","owner":"peerlibrary","description":"Provide DDP._CurrentPublish with access to current publish context","archived":false,"fork":false,"pushed_at":"2019-09-20T02:16:37.000Z","size":7,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-19T12:42:17.941Z","etag":null,"topics":["ddp","ddp-publish","meteor","meteor-package"],"latest_commit_sha":null,"homepage":"https://atmospherejs.com/peerlibrary/publish-context","language":"JavaScript","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-21T09:03:26.000Z","updated_at":"2020-03-04T16:56:40.000Z","dependencies_parsed_at":"2023-02-25T11:46:10.562Z","dependency_job_id":null,"html_url":"https://github.com/peerlibrary/meteor-publish-context","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-publish-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-publish-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-publish-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-publish-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peerlibrary","download_url":"https://codeload.github.com/peerlibrary/meteor-publish-context/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":["ddp","ddp-publish","meteor","meteor-package"],"created_at":"2024-11-09T06:05:42.019Z","updated_at":"2025-05-06T00:10:30.640Z","avatar_url":"https://github.com/peerlibrary.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"`DDP._CurrentPublish` with current publish context\n==================================================\n\nAdding this package to your [Meteor](http://www.meteor.com/) application creates a `DDP._CurrentPublish`\nenvironment variable which you can use to access current publish context (`this` inside publish function)\nfrom anywhere in the server-side code, if that server-side code was called from a publish function.\n\nIt is similar to existing undocumented `DDP._CurrentInvocation` which does the same for method calls,\ngiving you access to the current context of a method call (`this` inside a method's body).\n\n**Not needed with Meteor \u003e= 1.5.1.** There is `DDP._CurrentPublicationInvocation` now available,\nand `DDP._CurrentInvocation` has been renamed to `DDP._CurrentMethodInvocation`. This package\nprovides the same functionality for previous Meteor versions.\n\nServer side only.\n\nInstallation\n------------\n\n```\nmeteor add peerlibrary:publish-context\n```\n\nAfter adding the package, you have to depend on, or import, Meteor's core `ddp` package to\nget access to the `DDP` symbol.\n\nExamples\n--------\n\nImplementing a `userId()` function on the server-side, which works in any code\ncalled from methods or publish functions, can then be simply implemented as:\n\n```javascript\nfunction userId() {\n  const currentInvocation = DDP._CurrentInvocation.get();\n  if (currentInvocation) return currentInvocation.userId;\n\n  const currentContext = DDP._CurrentPublish.get();\n  if (currentContext) return currentContext.userId;\n\n  throw new Error(\"userId() not invoked from a method or publish function.\");\n}\n```\n\nThis is more or less what [peerlibrary:user-extra](https://github.com/peerlibrary/meteor-user-extra)\npackage does to provide `Meteor.userId()`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-publish-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeerlibrary%2Fmeteor-publish-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-publish-context/lists"}