Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongorito-tcomb

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongorito-tcomb - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0

2

package.json
{
"name": "mongorito-tcomb",
"version": "0.6.1",
"version": "0.7.0",
"description": "Bring schema validation to Mongorito thanks to tcomb",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

# mongorito-tcomb [![Build Status](https://travis-ci.org/xouabita/mongorito-tcomb.svg?branch=master)](https://travis-ci.org/xouabita/mongorito-tcomb) [![Dependency Status](https://david-dm.org/xouabita/mongorito-tcomb.svg)](https://david-dm.org/xouabita/mongorito-tcomb) [![devDependency Status](https://david-dm.org/alanshaw/david/dev-status.svg)](https://david-dm.org/alanshaw/david#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/github/xouabita/mongorito-tcomb/badge.svg?branch=master)](https://coveralls.io/github/xouabita/mongorito-tcomb?branch=master)
Bring schema validation to Mongorito thanks to tcomb
## Example
Install
-------
See `example.coffee`
`npm i -S mongorito-tcomb`
## TODO
Usage (ES6)
-----------
- [x] Do more tests
- [x] Add code coverage
- [ ] Add documentation
~~~js
// 1. Import the dependencies
import co from 'co'
import t from 'tcomb'
import Mongorito, {Model} from 'mongorito-tcomb'
// 2. We define the model user
class User extends Model {
// We add the optional Schema
get Schema() {
return t.struct({
name: t.String, // name is a required String
surname: t.maybe(t.String) // surname is an optional String
});
}
}
co(function *(val) {
// 3. Connect the database
yield Mongorito.connect('localhost/mongo-tcomb-playground');
// 4. Save a valid Model
var valid = new User({name: "Valid"});
yield valid.save();
// 5. Try to save an invalid Model
var invalid = new User({name: 'Invalid', surname: 88});
try {
yield invalid.save();
} catch (e) {
console.log(e); // An exception is throw here
}
// 6. Don't forget to disconnect Mongorito
yield Mongorito.disconnect();
});
~~~
For **coffeescript**, you can see [`example.coffee`](https://github.com/xouabita/mongorito-tcomb/blob/master/example.coffee)
API
---
### `patch: (Model) -> PatchedModel`
The patch function can be useful to combine different Mongorito plugins. It take a class,
extend it then return the extended class.
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc