{"id":21534059,"url":"https://github.com/boycce/monastery","last_synced_at":"2025-04-10T01:35:01.013Z","repository":{"id":37261571,"uuid":"258901555","full_name":"boycce/monastery","owner":"boycce","description":"⛪ A simple, straightforward Mongo ODM","archived":false,"fork":false,"pushed_at":"2024-08-27T06:38:43.000Z","size":2250,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-14T03:32:15.667Z","etag":null,"topics":["database","javascript","mongo","mongodb","mongodriver","nodejs","odm","orm"],"latest_commit_sha":null,"homepage":"https://boycce.github.io/monastery/","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/boycce.png","metadata":{"files":{"readme":"docs/readme.md","changelog":"changelog.md","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":"2020-04-26T00:16:00.000Z","updated_at":"2024-08-27T06:38:46.000Z","dependencies_parsed_at":"2023-12-06T03:31:43.992Z","dependency_job_id":"3efc0348-cb89-4fec-b40f-5ce7a6384600","html_url":"https://github.com/boycce/monastery","commit_stats":{"total_commits":421,"total_committers":1,"mean_commits":421.0,"dds":0.0,"last_synced_commit":"98b95c9467dc60b1301757ec834e4cbf595101b5"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boycce%2Fmonastery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boycce%2Fmonastery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boycce%2Fmonastery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boycce%2Fmonastery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boycce","download_url":"https://codeload.github.com/boycce/monastery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248140980,"owners_count":21054374,"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":["database","javascript","mongo","mongodb","mongodriver","nodejs","odm","orm"],"created_at":"2024-11-24T03:09:00.998Z","updated_at":"2025-04-10T01:35:01.004Z","avatar_url":"https://github.com/boycce.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](./assets/imgs/monastery.jpg)\n\n[![NPM](https://img.shields.io/npm/v/monastery.svg)](https://www.npmjs.com/package/monastery) [![Build Status](https://travis-ci.com/boycce/monastery.svg?branch=master)](https://app.travis-ci.com/github/boycce/monastery)\n\n\u003e v3.0 has been released 🎉 refer to [breaking changes](#v3-breaking-changes) below when upgrading from v2.x.\n\n## Features\n\n* User friendly API design, *inspired by SailsJS*\n* Simple CRUD operations, with simple but fast model population\n* Model validation controlled by your model definitions\n* Normalized error responses objects ready for client consumption\n* Custom error messages can be defined in your model definitions\n* Blacklist sensitive fields once in your model definition, or per operation\n* Model methods can accept data in bracket (multipart/form) and dot notation, you can also mix these together\n* Automatic Mongo index creation\n* Documents validate, insert and update 7-10x faster than Mongoose\n\n#### Why Monastery over Mongoose?\n\n* User friendly API designed for busy agencies, allowing you to quickly build projects without distractions\n* Model schema and configurations are all defined within a single object (model definition)\n* You can blacklist/exclude sensitive model fields in the model definition for each CRUD operation\n* Model population uses a single aggregation call instead of multiple queries for faster responses\n* Errors throw normalized error objects that contain the model, field, error message etc, handy in the client\n\n## Install\n\nThis repository is distributed with NPM. After installing NPM, you can install Monastery via:\n\n```bash\n$ npm install --save monastery\n```\n\n## Usage\n\n```javascript\nimport db from 'monastery'\n\n// Initialize a monastery manager\ndb.manager('localhost/mydb')\n\n// Define a model\ndb.model('user', {\n  fields: {\n    name: { type: 'string' },\n    pets: [{ type: 'string' }],\n    address: { city: { type: 'string', minLength: 10 } },\n    points: [[{ type: 'number' }]]\n  }\n})\n\n// Insert some data\ntry {\n  const newUser = await db.user.insert({\n    data: {\n      name: 'Martin Luther',\n      pets: ['sparky', 'tiny'],\n      address: { city: 'Eisleben' },\n      points: [[1, 5], [3, 1]]\n    }\n  })\n} catch (errs) {\n  // [{\n  //   detail: \"Value needs to be at least 10 characters long.\",\n  //   status: \"400\",\n  //   title: \"address.city\",\n  //   meta: {\n  //     field: \"city\",\n  //     model: \"user\",\n  //     rule: \"minLength\"\n  //   }\n  // }]\n}\n```\n## Version Compatibility\n\nYou can view MongoDB's [compatibility table here](https://www.mongodb.com/docs/drivers/node/current/compatibility/), and see all of MongoDB NodeJS Driver [releases here](https://mongodb.github.io/node-mongodb-native/)\n\n| Monastery            | Mongo NodeJS Driver | MongoDB Server    | Node                |\n| :------------------- | :-----------------: | :---------------: | ------------------: |\n| `3.x` | [`5.9.x`](https://mongodb.github.io/node-mongodb-native/5.9/) | `\u003e=3.6  \u003c=7.x` | `\u003e=14.x \u003c=latest` |\n| `2.x` | [`3.7.x`](https://mongodb.github.io/node-mongodb-native/3.7/api/) | `\u003e=2.6  \u003c=6.x` | `\u003e=4.x  \u003c=14.x` |\n\n\n## v3 Breaking Changes\n\n  - Removed callback functions on all model methods, you can use the returned promise instead\n  - model.update() now returns the following res._output property: `{ acknowledged: true, matchedCount: 1, modifiedCount: 1, upsertedCount: 0, upsertedId: null }` instead of `{ n: 1, nModified: 1, ok: 1 }`\n  - model.remove() now returns `{ acknowledged: true, deletedCount: 1 }`, instead of `{ results: {n:1, ok:1} }`\n  - model._indexes() now returns collection._indexes() not collection._indexInformation()\n  - db.model.* moved to db.models.*\n  - db.models(path, waitForIndex) changed to db.models(path, { waitForIndex })\n  - db._client moved to db.client\n  - db._db moved to db.db\n  - db.catch/then() moved to db.onError/db.onOpen()\n  - next() is now redundant when returning promises from hooks, e.g. `afterFind: [async (data) =\u003e {...}]`\n  - deep paths in data, e.g. `books[].title` are now validated, and don't replace the whole object, e.g. `books`\n  - `db()` moved to `db.manager()`\n\n## v2 Breaking Changes\n\n  - changed model.messages, array paths now must include '.$'\n  - updated AWS to client v3 (requires ES6 features, NodeJs \u003e=14)\n\n## Roadmap\n\n- Add Aggregate\n- ~~Add FindOneAndUpdate~~\n- ~~Add beforeInsertUpdate / afterInsertUpdate~~\n- Bug: Setting an object literal on an ID field ('model') saves successfully\n- ~~Blacklist false removes all blacklisting~~\n- ~~Add project to insert/update/validate~~\n- ~~Whitelisting a parent will remove any previously blacklisted children~~\n- ~~Blacklist/project works the same across find/insert/update/validate~~\n- Automatic embedded document ids/createdAt/updatedAt fields\n- ~~Ability to change ACL default on the manager~~\n- ~~Public db.arrayWithSchema method~~\n- ~~Added support for array population~~\n- ~~MongoClient instances can now be reused when initializing the manager, e.g. `monastery(mongoClient)`, handy for migrate-mongo~~\n- Change population warnings into errors\n- Global after/before hooks\n- Before hooks can receive a data array, remove this\n- Docs: Make the implicit ID query conversion more apparent\n- ~~Split away from Monk so we can update the MongoDB NodeJS Driver version~~\n- Add a warning if an invalid model is referenced in jthe schema\n- Remove leading forward slashes from custom image paths (AWS adds this as a seperate folder)\n- Double check await db.model.remove({ query: idfromparam }) doesnt cause issues for null, undefined or '', but continue to allow {}\n- ~~Can't insert/update model id (maybe we can allow this and add _id to default insert/update blacklists)~~\n- timstamps are blacklisted by default (instead of the `timestamps` opt), and can be switched off via blacklisting\n- Allow rules on image types, e.g. `required`\n- Test importing of models\n- ~~Docs: model.methods~~\n- ~~Convert hooks to promises~~\n- ~~added `model.count()`~~\n- Typescript support\n- Add soft remove plugin\n- ~~Added deep path validation support for updates~~\n- ~~Added option skipHooks~~\n\n## Debugging\n\nThis package uses [debug](https://github.com/visionmedia/debug) which allows you to set the level of output via the `DEBUG` environment variable. Using `DEBUG` will override the manager's `logLevel` option, e.g. `monastery('...', { logLevel: 3 })`.\n\n```bash\n$ DEBUG=monastery:error # level 1, shows errors\n$ DEBUG=monastery:warn  # level 2, shows warnings and depreciation notices\n$ DEBUG=monastery:info  # level 3, shows operation information\n```\n\n## Contributing\n\nAll pull requests are welcome. To run isolated tests with Jest:\n\n```bash\nnpm run dev -- -t 'Model indexes'\n```\n\n## Special Thanks\n\n[Jerome Gravel-Niquet](https://github.com/jeromegn)\n\n## License\n\nCopyright 2024 Ricky Boyce. Code released under the MIT license\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboycce%2Fmonastery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboycce%2Fmonastery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboycce%2Fmonastery/lists"}