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

Bring schema validation to Mongorito thanks to tcomb

  • 0.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by1000%
Maintainers
1
Weekly downloads
 
Created
Source

mongorito-tcomb Build Status Dependency Status devDependency Status Coverage Status

Bring schema validation to Mongorito thanks to tcomb

Install

npm i -S mongorito-tcomb

Usage (ES6)

// 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

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.

TODOS

  • Add t.ID for validating ID
  • Add t.unique for unique index creation
  • Add tests for t.unique
  • More efficient indexing
  • More efficient ID validation
  • Add tests for t.ID
  • Add example for t.unique
  • Add example for t.ID
  • Add docs for t.ID/t.unique
  • Find recursively t.ID/t.unique

Keywords

FAQs

Package last updated on 21 Feb 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc