{"id":15499227,"url":"https://github.com/zimme/meteor-collection-behaviours","last_synced_at":"2025-10-12T06:31:37.069Z","repository":{"id":20861224,"uuid":"24148048","full_name":"zimme/meteor-collection-behaviours","owner":"zimme","description":"Define and attach behaviours to collections","archived":true,"fork":false,"pushed_at":"2016-05-26T14:32:28.000Z","size":80,"stargazers_count":19,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-29T11:37:13.013Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://atmospherejs.com/zimme/collection-behaviours","language":"CoffeeScript","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/zimme.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":"2014-09-17T14:27:45.000Z","updated_at":"2024-06-23T19:12:38.000Z","dependencies_parsed_at":"2022-09-13T20:01:13.823Z","dependency_job_id":null,"html_url":"https://github.com/zimme/meteor-collection-behaviours","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/zimme/meteor-collection-behaviours","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimme%2Fmeteor-collection-behaviours","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimme%2Fmeteor-collection-behaviours/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimme%2Fmeteor-collection-behaviours/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimme%2Fmeteor-collection-behaviours/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zimme","download_url":"https://codeload.github.com/zimme/meteor-collection-behaviours/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimme%2Fmeteor-collection-behaviours/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010507,"owners_count":26084757,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-02T08:50:50.500Z","updated_at":"2025-10-12T06:31:36.766Z","avatar_url":"https://github.com/zimme.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gitter]](https://gitter.im/zimme/meteor-collection-behaviours)\n[![Code Climate]](https://codeclimate.com/github/zimme/meteor-collection-behaviours)\n[![License]](https://github.com/zimme/meteor-collection-timestampable/blob/master/LICENSE.md)\n\n# Behaviours for collections\n\nDefine and attach behaviours to collections.\n\n## Installation\n\n```sh\nmeteor add zimme:collection-behaviours\n```\n\n## Available behaviours\n\nThe behaviours are split into separate packages, which depend on this package.\n\n* `zimme:collection-softremovable`\n\n  This behaviour adds `.softRemove()` and `.restore()` to collections, which\n  make it possible to mark documents as removed. It also tracks the time and\n  user for the last soft remove and restore.\n\n  https://atmospherejs.com/zimme/collection-softremovable\n\n\n* `zimme:collection-timestampable`\n\n  This behaviour timestamps documents on insert and update. It also tracks the\n  user who made the last insert or update.\n\n  https://atmospherejs.com/zimme/collection-timestampable\n\n## Usage\n\n### Define a behaviour\n\n```js\nCollectionBehaviours.define('behaviourName', function(options) {\n  var collection = this.collection;\n\n  // Setup some default options for the behaviour\n  var defaultOptions = {\n    exampleOption: \"I'm a default value\"\n  };\n\n  // Make the behaviour configurable both globally and locally and uses the\n  // defaults if not configured.\n  options = _.defaults(options, this.options, defaultOptions);\n\n  // Behaviour logic goes here\n});\n```\n\n### Attach behaviours\n\n```js\n// Attach a behavour using the collection identifier\nMeteor.users.attachBehaviour('timestampable');\n\n// Attach a behaviour to a colleciton using CollectionBehaviours\nCollectionBehaviours.attach(Meteor.users, 'timestampable');\n\n// Attach multiple behaviours to a collection with default options\nCollectionBehaviours.attach(Meteor.users, ['timestampable', 'softremovable']);\n\n// Attach multiple behaviours to a collcetion with custom options\nCollectionBehaviours.attach(Meteor.users, {\n  timestampable: {\n    createdAt: 'insertedAt',\n  },\n  softremovable: {\n    removedBy: 'deletedBy',\n  },\n});\n\n// Attach a behaviour to multiple collections\nCollectionBehaviours.attach([Meteor.users, Posts], 'timestampable');\n\n// Attach multiple behaviours to multiple collections\nCollectionBehaviours.attach(\n  [Meteor.users, Posts],\n  ['timestampable', 'softremovable']\n);\n```\n\n### Configuration\n\n```js\n// Configure behaviour globally i.e. set you own defaults\nCollectionBehaviours.configure('behaviourName', {\n  exampleOption: \"I'm a global value\"\n});\n\n// Attach behaviour with custom options\nMeteor.users.attachBehaviour('behaviourName', {\n  exampleOption: \"I'm a local value\"\n});\n\n// Attach behaviour with custom options, using CollectionBehaviours\nCollectionBehaviours.attach(Meteor.users, 'behaviourName', {\n  exampleOption: \"I'm a local value\"\n});\n```\n\n## API\n\n### CollectionBehaviours.define\n\nUsed to defined a new behaviour or overwrite an already defined behaviour.\n\n```js\nCollectionBehaviours.define('behaviourName', behaviourFunciton, options);\n```\n\n* `'behaviourName'`: Required. The name of the behaviour.\n* `behaviourFunction`: Required. A `Function` that takes `options` as an\n  argument. This function is the behaviour.\n* `options`: Optional. `Object` with the options for the behaviour.\n\n#### Options\n\n* `replace`: Optional. Set to `true` to replace a previously defined behaviour.\n\n### CollectionBehaviours.configure\n\nUsed to confgure behaviours globally.\n\n```js\n// Configure single behaviour\nColectionBehaviours.configure('behavioursName', options);\n\n// Configure multiple behaviours\nCollectionBehaviours.configure({\n  timestampable: {\n    createdAt: 'insertedAt',\n    updatedBy: 'modifiedBy'\n  },\n  softremovable: {\n    removed: 'deleted'\n  }\n});\n```\n\n* `'behaviourName'`: Required.  \n  If set to a `String`, 'behaviourName', will configure the named behaviour.  \n  If set to an `Object`, where the keys are named behaviours and the values are  \n  the options for the behaviours, will configure those named behaviours.\n\n* `options`: Optional if `behaviourName` is an `Object`.  \n  See specific behaviour for available options.\n\n### \u0026lt;CollectionIdentifier\u0026gt;.attachBehaviour\n\nUsed to attach behaviour(s) to the collection.\n\n```js\nMeteor.users.attachBehaviour(behaviourNameOrFunction, options);\n```\n\n* `behaviourNameOrFunction`: Required.  \n  If set to a `String`, `'behaviourName'`, will attach the named behaviour.  \n  If set to a `Function`, will attach that function as an anonymous behaviour.  \n  If set to an `Array` of `String`/`Function`, will attach those named or  \n  anonymous behaviours.  \n  If set to an `Object`, where the keys are named behaviours and the values are  \n  the behaviours' options, will attach those named behaviours with the provided  \n  options.\n* `options`: Optional. See specific behaviour for available options.\n\n### CollectionBehaviours.attach\n\nUsed to attach behaviour(s) to collection(s).\n\n```js\nCollectionBehaviours.attach(ColletionIdentifier, behaviourNameOrFunction, options);\n```\n\n* `CollectionIdentifier`: Required. The collection or `Array` of collections  \n  you want to attach the behaviour(s) to.\n* `behaviourNameOrFunction`: Required.  \n  If set to a `String`, `'behaviourName'`, will attach the named behaviour.  \n  If set to a `Function`, will attach that function as an anonymous behaviour.  \n  If set to an `Array` of `String`/`Function`, will attach those named or  \n  anonymous behaviours.  \n  If set to an `Object`, where the keys are named behaviours and the values are  \n  the behaviours' options, will attach those named behaviours with the provided  \n  options.\n* `options`: Optional. See specific behaviour for available options.\n\n## Notes\n\n* `CollectionBehaviours.config` is an alias for `CollectionBehaviours.configure`\n* The inspiration for this package came from\n[`sewdn:collection-behaviours`][sewdn]\n\n[Atmosphere]: https://atmospherejs.com\n[Code Climate]: https://img.shields.io/codeclimate/github/zimme/meteor-collection-behaviours.svg\n[Gitter]: https://img.shields.io/badge/gitter-join_chat-brightgreen.svg\n[License]: https://img.shields.io/badge/license-MIT-blue.svg\n[sewdn]: https://github.com/Sewdn/meteor-collection-behaviours\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzimme%2Fmeteor-collection-behaviours","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzimme%2Fmeteor-collection-behaviours","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzimme%2Fmeteor-collection-behaviours/lists"}