Socket
Socket
Sign inDemoInstall

monastery

Package Overview
Dependencies
191
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    monastery

⛪ A straight forward MongoDB ODM built around Monk


Version published
Weekly downloads
8
decreased by-83.67%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

NPM Build Status

Features

  • User friendly API design, built around the awesome Monk
  • Simple CRUD operations with model population
  • Model validation deriving from your model definitions
  • Custom error messages can be defined in your model definition
  • Normalised error responses ready for client consumption
  • Automatic mongodb index setup
  • CRUD operations can accept bracket (multipart/form-data) and dot notation data formats, you can also mix these together

Install

This repository is distributed with NPM. After installing NPM, you can install Monastery via:

$ npm install --save monastery

Usage

import monastery from 'monastery'

// Initialise a monastery manager
const db = monastery('localhost/mydb')
// const db = monastery('user:pass@localhost:port/mydb')

// Define a model
db.model('user', {
  fields: {
    name: { type: 'string' },
    pets: [{ type: 'string' }],
    address: { city: { type: 'string', minLength: 10 } },
    points: [[{ type: 'number' }]]
  }
})

// Insert some data
db.user.insert({
  data: {
    name: 'Martin Luther',
    pets: ['sparky', 'tiny'],
    address: { city: 'Eisleben' },
    points: [[1, 5], [3, 1]]
  }

}).then(data => {
  // valid data..

}).catch(errs => {
  // [{
  //   detail: "Value needs to be at least 10 characters long.",
  //   status: "400",
  //   title: "address.city",
  //   meta: {
  //     field: "city",
  //     model: "user",
  //     rule: "minLength"
  //   }
  // }]
})

Debugging

This package uses debug which allows you to set different levels of output via the DEBUG environment variable. Due to known limations monastery:warning and monastery:error are forced on, you can however disable these via manager settings.

$ DEBUG=monastery:info # shows operation information

To run isolated tests with Jest:

npm run dev -- -t 'Model indexes'

Contributing

Coming soon...

Roadmap

  • Add Aggregate
  • Add FindOneAndUpdate
  • Add beforeInsertUpdate / afterInsertUpdate
  • Bug: Setting an object literal on an ID field ('model') saves successfully
  • Blacklist false removes all blacklisting
  • Add project to insert/update/validate
  • Whitelisting a parent will remove any previously blacklisted children
  • Blacklist/project works the same across find/insert/update/validate
  • Automatic embedded document ids/createdAt/updatedAt fields
  • Ability to change ACL default on the manager
  • Public db.arrayWithSchema method
  • Added support for array population
  • Change population warnings into errors
  • Global after/before hooks
  • before hooks can receive a data array, remove this
  • docs: Make the implicit ID query conversion more apparent
  • Split away from Monk (unless updated)
  • Add a warning if an invalid model is referenced in jthe schema
  • Remove leading forward slashes from custom image paths (AWS adds this as a seperate folder)
  • double check await db.model.remove({ query: idfromparam }) doesnt cause issues for null, undefined or '', but continue to allow {}
  • can't insert/update model id (maybe we can allow this and add _id to default insert/update blacklists)
  • timstamps are blacklisted by default (instead of the timestamps opt), and can be switched off via blacklisting
  • Allow rules on image types, e.g. required
  • test importing of models
  • Docs: model.methods

Versions

Special Thanks

Jerome Gravel-Niquet

License

Copyright 2020 Ricky Boyce. Code released under the MIT license.

Keywords

FAQs

Last updated on 07 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc