Skip to content
This repository has been archived by the owner on Jul 9, 2018. It is now read-only.
/ m8-mongoose Public archive

NOT MAINTAINED. Bad/hard idea to get right. Not worth it.

License

Notifications You must be signed in to change notification settings

clux/m8-mongoose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser Mongoose via modul8

m8-mongoose is a modul8 plugin that aims to partially port mongoose logic to the client.

A web application using mongodb on its backend and using mongoose as an ORM layer ends up defining a lot of validation logic on the server. Logic that should be reused on the client. This plugin will export sanitized versions of your explicitly exported mongoose models, along with helpers to utilize this data in a helpful way.

Pre-Requisites

m&m&m:

  • mongodb
  • mongoose
  • modul8

Willingness to perform an extra function call when defining your mongoose modules.

Usage

Install with

$ npm install m8-mongoose

then require the register function, and register a model with it

var Schema = require('mongoose').Schema;
var toBrowser = require('m8-mongoose').register;

User = new Schema(toBrowser('user', {
  name : String
  pass : {type: String, private: true}
}));

The output Schema instance is mongoose compatible (toBrowser remembers the extra attributes like private, but returns an object without these).

On deployment, the plugin will pass back the serialized version of what was passed in above to modul8

var modul8 = require('modul8')
var MongoosePlugin = require('m8-mongoose').Plugin;
modul8('./client/app.js')
  .use(new MongoosePlugin())
  .compile('./out.js');

An optional first parameter to the MongoosePlugin constructor can be set, which will specify the name of the domain and data key used when exporting. This parameter defaults to 'mongoose'.

Behavior

Calls to register() serializes the model to the plugins 'runtime' directory, whereas MongoosePlugin will read these for modul8. Code to help auto generate certain form code and validation logic is (soon) included on the mongoose domain, and will be bundled with the output source if required by the application.

Extensions

You can extend the classical mongoose object with certain unused attributes. These work as follows:

  • private - if true, it this key will not be sent to the client
  • label - if set, it will be used by formGenerator to construct standard text inputs
  • labels - if set to array, it will be used by formGenerator to construct a select input

These attributes will be removed before passing the object back to mongoose's Schema constructor.

License

MIT Licensed - See LICENSE file for details

About

NOT MAINTAINED. Bad/hard idea to get right. Not worth it.

Resources

License

Stars

Watchers

Forks

Packages

No packages published