{"id":42218289,"url":"https://github.com/chatr/safe-update","last_synced_at":"2026-01-27T01:35:01.905Z","repository":{"id":78087653,"uuid":"362861496","full_name":"chatr/safe-update","owner":"chatr","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-24T12:04:58.000Z","size":10,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-24T13:19:52.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chatr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-04-29T15:21:55.000Z","updated_at":"2021-05-14T11:18:01.000Z","dependencies_parsed_at":"2023-03-24T22:53:39.116Z","dependency_job_id":null,"html_url":"https://github.com/chatr/safe-update","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chatr/safe-update","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chatr%2Fsafe-update","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chatr%2Fsafe-update/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chatr%2Fsafe-update/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chatr%2Fsafe-update/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chatr","download_url":"https://codeload.github.com/chatr/safe-update/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chatr%2Fsafe-update/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28795469,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T01:07:07.743Z","status":"ssl_error","status_checked_at":"2026-01-27T01:07:06.974Z","response_time":59,"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":[],"created_at":"2026-01-27T01:35:01.296Z","updated_at":"2026-01-27T01:35:01.895Z","avatar_url":"https://github.com/chatr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chatra:safe-update\n\n[![Version](https://img.shields.io/badge/meteor-2.x%20|%203.x-brightgreen?logo=meteor\u0026logoColor=white)](https://github.com/chatr/safe-update)\n[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)\n\nMake Meteor’s `collection.update`/`collection.updateAsync` safer by preventing unintended updates and enforcing best practices.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Prevent Empty Selector Updates](#prevent-empty-selector-updates)\n    - [Enforce Modifier Operators](#enforce-modifier-operators)\n    - [Configuration](#configuration)\n- [Examples](#examples)\n- [Tests](#tests)\n- [License](#license)\n\n---\n\n## Introduction\n\nThe `chatra:safe-update` package enhances the safety of MongoDB `update` operations in Meteor applications by:\n\n- Preventing updates with empty selectors unless explicitly allowed.\n- Ensuring that updates use modifier operators (e.g., `$set`, `$inc`) unless the `replace` option is specified.\n- Providing configuration options to include or exclude specific collections.\n\n---\n\n## Installation\n\n```shell\nmeteor add chatra:safe-update\n```\n\n---\n\n## Compatibility\n\n- **Meteor Version 3 and Above**: Fully compatible, using the new asynchronous Meteor collections’ methods.\n- **Meteor Version 2**: Maintains compatibility with synchronous methods.\n\n---\n\n## Usage\n\n### Prevent Empty Selector Updates\n\nBy default, the package throws an error if you attempt to perform an update with an empty selector:\n\n```javascript\n// Throws an error\nMyCollection.update({}, { $set: { field: 'value' } });\n```\n\nTo allow updates with an empty selector, pass `allowEmptySelector: true` in the options:\n\n```javascript\n// Allowed\nMyCollection.update({}, { $set: { field: 'value' } }, { allowEmptySelector: true });\n```\n\n### Enforce Modifier Operators\n\nThe package ensures that you use modifier operators (e.g., `$set`, `$inc`) in your updates:\n\n```javascript\n// Throws an error\nMyCollection.update({ _id: 'docId' }, { field: 'value' });\n```\n\nTo replace a document entirely, pass `replace: true` in the options:\n\n```javascript\n// Allowed\nMyCollection.update({ _id: 'docId' }, { field: 'value' }, { replace: true });\n```\n\n### Configuration\n\nTo configure the package behavior, use the `setSafeUpdateConfig` function provided by the package:\n\n```javascript\nimport { setSafeUpdateConfig } from 'meteor/chatra:safe-update';\n\nsetSafeUpdateConfig({\n  except: ['logs'], // Collections to exclude from safety checks\n  only: ['users', 'posts'], // Only apply safety checks to these collections\n});\n```\n\n- **`except`**: An array of collection names to exclude from the safety checks.\n- **`only`**: An array of collection names to include in the safety checks (all others are excluded).\n\n---\n\n## Examples\n\n```javascript\nimport { Mongo } from 'meteor/mongo';\n\nconst Messages = new Mongo.Collection('messages');\n\n// Safe update with modifier\nMessages.update({ _id: 'msgId' }, { $set: { text: 'Updated message' } });\nawait Messages.updateAsync({ _id: 'msgId' }, { $set: { text: 'Updated message' } });\n\n// Unsafe update without modifier (throws error)\nMessages.update({ _id: 'msgId' }, { text: 'Updated message' }); // Throws error\nawait Messages.updateAsync({ _id: 'msgId' }, { text: 'Updated message' }); // Throws error\n\n// Replacing document with replace option\nMessages.update({ _id: 'msgId' }, { text: 'Updated message' }, { replace: true });\nawait Messages.updateAsync({ _id: 'msgId' }, { text: 'Updated message' }, { replace: true });\n```\n\n---\n\n## Tests\n\nThe package includes a comprehensive test suite. To run the tests:\n\n```shell\nmeteor test-packages ./\n```\n\n---\n\n## License\n\nThis package is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchatr%2Fsafe-update","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchatr%2Fsafe-update","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchatr%2Fsafe-update/lists"}