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'
const db = monastery('localhost/mydb')
db.model('user', {
fields: {
name: { type: 'string' },
pets: [{ type: 'string' }],
address: { city: { type: 'string', minLength: 10 } },
points: [[{ type: 'number' }]]
}
})
db.user.insert({
data: {
name: 'Martin Luther',
pets: ['sparky', 'tiny'],
address: { city: 'Eisleben' },
points: [[1, 5], [3, 1]]
}
}).then(data => {
}).catch(errs => {
})
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
To run isolated tests with Jest:
npm run dev -- -t 'Model indexes'
Contributing
Coming soon...
Roadmap
- Add Aggregate
Add FindOneAndUpdateAdd beforeInsertUpdate / afterInsertUpdate- Bug: Setting an object literal on an ID field ('model') saves successfully
Blacklist false removes all blacklistingAdd project to insert/update/validateWhitelisting a parent will remove any previously blacklisted childrenBlacklist/project works the same across find/insert/update/validate- Automatic embedded document ids/createdAt/updatedAt fields
Ability to change ACL default on the managerPublic db.arrayWithSchema methodAdded 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.