{"id":13761041,"url":"https://github.com/dburles/meteor-collection-helpers","last_synced_at":"2025-04-06T08:15:55.926Z","repository":{"id":12868140,"uuid":"15544452","full_name":"dburles/meteor-collection-helpers","owner":"dburles","description":"⚙️ Meteor package that allows you to define helpers on your collections","archived":false,"fork":false,"pushed_at":"2017-09-27T20:33:28.000Z","size":69,"stargazers_count":497,"open_issues_count":12,"forks_count":33,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-10-29T20:06:13.665Z","etag":null,"topics":["meteor","meteor-package"],"latest_commit_sha":null,"homepage":"https://atmospherejs.com/dburles/collection-helpers","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dburles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-31T06:25:24.000Z","updated_at":"2024-09-17T08:10:43.000Z","dependencies_parsed_at":"2022-07-13T21:44:23.451Z","dependency_job_id":null,"html_url":"https://github.com/dburles/meteor-collection-helpers","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmeteor-collection-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmeteor-collection-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmeteor-collection-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmeteor-collection-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dburles","download_url":"https://codeload.github.com/dburles/meteor-collection-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411225,"owners_count":20934653,"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-package"],"created_at":"2024-08-03T13:01:34.558Z","updated_at":"2025-04-06T08:15:55.884Z","avatar_url":"https://github.com/dburles.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Packages"],"sub_categories":[],"readme":"# Meteor Collection Helpers\n\nCollection helpers automatically sets up a transformation on your collections using Meteor's Mongo.Collection `transform` option, allowing for simple models with an interface that's similar to template helpers.\n\n## Installation\n\n```sh\nmeteor add dburles:collection-helpers\n```\n\n## Usage\n\nWrite your helpers somewhere seen by both client and server.\n\n```javascript\nconst Books = new Mongo.Collection('books');\nconst Authors = new Mongo.Collection('authors');\n\nBooks.helpers({\n  author() {\n    return Authors.findOne(this.authorId); // Client only (Meteor 3+)\n  },\n  authorAsync() {\n    return Authors.findOneAsync(this.authorId);\n  }\n});\n\nAuthors.helpers({\n  fullName() {\n    return `${this.firstName} ${this.lastName}`;\n  },\n  books() {\n    return Books.find({ authorId: this._id });\n  }\n});\n```\n\nThis will then allow you to do:\n\n```javascript\nconst book = await Books.findOneAsync();\nconst author = await book.authorAsync();\nauthor.firstName; // Charles\nauthor.fullName(); // Charles Darwin\n```\n\nand:\n\n```javascript\nconst author = await Authors.findOneAsync();\nawait author.books().fetchAsync();\n```\n\nOur relationships are resolved by the collection helper, avoiding unnecessary template helpers. So we can simply write:\n\n```javascript\nTemplate.books.helpers({\n  books() {\n    return Books.find();\n  }\n});\n```\n\n...with the corresponding template:\n\n```html\n\u003ctemplate name=\"books\"\u003e\n  \u003cul\u003e\n    {{#each books}}\n      \u003cli\u003e{{name}} by {{author.fullName}}\u003c/li\u003e\n    {{/each}}\n  \u003c/ul\u003e\n\u003c/template\u003e\n```\n\n### Meteor.users\n\nYou can also apply helpers to the Meteor.users collection\n\n```javascript\nMeteor.users.helpers({\n  // ...\n});\n```\n\n### Applying the transformation function\n\nSometimes it may be useful to apply the transformation directly to an object.\n\n```js\nconst doc = {\n  firstName: 'Charles',\n  lastName: 'Darwin'\n};\n\nconst transformedDoc = Authors._transform(doc);\n\ntransformedDoc.fullName(); // Charles Darwin\n```\n\n### Testing\n\n```sh\nmeteor test-packages ./\n```\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdburles%2Fmeteor-collection-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdburles%2Fmeteor-collection-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdburles%2Fmeteor-collection-helpers/lists"}