Socket
Socket
Sign inDemoInstall

modm

Package Overview
Dependencies
19
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.0 to 0.4.0

38

example/array.js

@@ -1,23 +0,25 @@

var modm = require('../index');
var modm = require("../index");
var Schema = new modm.Schema({array: {
var Schema = new modm.Schema({
array: {
type: Array,
required: true,
default: ["a", "b"],
//validate: function () {},
//manipulate: function () {},
//live: true,
type: Array,
required: true,
default: ['a', 'b'],
//validate: function () {},
//manipulate: function () {},
//live: true,
// INFO only the input gets validated, not the result of an atomic operation
maxLength: 5,
minLength: 1
}
});
// INFO only the input gets validated, not the result of an atomic operation
maxLength: 5,
minLength: 1
var test1 = {
array: ["1", "2", "3"]
};
}});
var test1 = {array: ['1', '2', '3']};
module.exports = function (model, callback) {
var document = model('array', Schema);
module.exports = function(model, callback) {
var document = model("array", Schema);
document.insert(test1, callback);
}
};

@@ -1,19 +0,21 @@

var modm = require('../index');
var modm = require("../index");
var Schema = new modm.Schema({boolean: {
var Schema = new modm.Schema({
boolean: {
type: Boolean,
required: true,
default: false
//validate: function () {},
//manipulate: function () {},
//live: true
}
});
type: Boolean,
required: true,
default: false
//validate: function () {},
//manipulate: function () {},
//live: true
var test1 = {
boolean: true
};
}});
var test1 = {boolean: true};
module.exports = function (model, callback) {
var document = model('boolean', Schema);
module.exports = function(model, callback) {
var document = model("boolean", Schema);
document.insert(test1, callback);
}
};

@@ -1,23 +0,25 @@

var modm = require('../index');
var modm = require("../index");
var Schema = new modm.Schema({buffer: {
var Schema = new modm.Schema({
buffer: {
type: Buffer,
required: true,
default: new Buffer("buffer data"),
maxLength: 512,
minLength: 128
//validate: function () {},
//manipulate: function () {},
//live: true
}
});
type: Buffer,
required: true,
default: new Buffer('buffer data'),
maxLength: 512,
minLength: 128
//validate: function () {},
//manipulate: function () {},
//live: true
}});
var buffer = new Buffer(256);
var test1 = {buffer: new Buffer(256)};
var test1 = {
buffer: new Buffer(256)
};
module.exports = function (model, callback) {
var document = model('buffer', Schema);
module.exports = function(model, callback) {
var document = model("buffer", Schema);
document.insert(test1, callback);
}
};

@@ -1,19 +0,21 @@

var modm = require('../index');
var modm = require("../index");
var Schema = new modm.Schema({date: {
var Schema = new modm.Schema({
date: {
type: Date,
required: true,
default: new Date()
//validate: function () {},
//manipulate: function () {},
//live: true
}
});
type: Date,
required: true,
default: new Date()
//validate: function () {},
//manipulate: function () {},
//live: true
var test1 = {
date: new Date()
};
}});
var test1 = {date: new Date()};
module.exports = function (model, callback) {
var document = model('date', Schema);
module.exports = function(model, callback) {
var document = model("date", Schema);
document.insert(test1, callback);
}
};

@@ -1,32 +0,37 @@

var modm = require('../index');
var modm = require("../index");
var string = require('./string');
var number = require('./number');
var array = require('./array');
var object = require('./object');
var boolean = require('./boolean');
var buffer = require('./buffer');
var objectid = require('./objectid');
var date = require('./date');
var string = require("./string");
var number = require("./number");
var array = require("./array");
var object = require("./object");
var boolean = require("./boolean");
var buffer = require("./buffer");
var objectid = require("./objectid");
var date = require("./date");
var model = modm('crm2', {
var model = modm("crm2", {
autoIndex: true,
server: {poolSize: 2},
db: {w: 1}
server: { poolSize: 2 },
db: { w: 1 }
});
model.connect(function () {
model.connect(function() {
// string
string(model, function (err, result) {
console.log('------------------------------------------------');
console.log('string');
string(model, function(err, result) {
console.log("------------------------------------------------");
console.log("string");
console.log(err || result);
});
var model1 = modm("crm3", {
autoIndex: true,
server: { poolSize: 2 },
db: { w: 1 }
});
});
// number
number(model, function (err, result) {
console.log('------------------------------------------------');
console.log('number');
number(model, function(err, result) {
console.log("------------------------------------------------");
console.log("number");
console.log(err || result);

@@ -36,5 +41,5 @@ });

// array
array(model, function (err, result) {
console.log('------------------------------------------------');
console.log('array');
array(model, function(err, result) {
console.log("------------------------------------------------");
console.log("array");
console.log(err || result);

@@ -44,5 +49,5 @@ });

// object
object(model, function (err, result) {
console.log('------------------------------------------------');
console.log('object');
object(model, function(err, result) {
console.log("------------------------------------------------");
console.log("object");
console.log(err || result);

@@ -52,5 +57,5 @@ });

// boolean
boolean(model, function (err, result) {
console.log('------------------------------------------------');
console.log('boolean');
boolean(model, function(err, result) {
console.log("------------------------------------------------");
console.log("boolean");
console.log(err || result);

@@ -60,5 +65,5 @@ });

// buffer
buffer(model, function (err, result) {
console.log('------------------------------------------------');
console.log('buffer');
buffer(model, function(err, result) {
console.log("------------------------------------------------");
console.log("buffer");
console.log(err || result);

@@ -68,5 +73,5 @@ });

// objectid
objectid(model, function (err, result) {
console.log('------------------------------------------------');
console.log('objectid');
objectid(model, function(err, result) {
console.log("------------------------------------------------");
console.log("objectid");
console.log(err || result);

@@ -76,6 +81,6 @@ });

// date
date(model, function (err, result) {
console.log('------------------------------------------------');
console.log('date');
date(model, function(err, result) {
console.log("------------------------------------------------");
console.log("date");
console.log(err || result);
});

@@ -1,21 +0,23 @@

var modm = require('../index');
var modm = require("../index");
var Schema = new modm.Schema({number: {
var Schema = new modm.Schema({
number: {
type: Number,
required: true,
max: 5,
min: 0,
default: 0
//validate: function () {},
//manipulate: function () {},
//live: true
}
});
type: Number,
required: true,
max: 5,
min: 0,
default: 0
//validate: function () {},
//manipulate: function () {},
//live: true
var test1 = {
number: 5
};
}});
var test1 = {number: 5};
module.exports = function (model, callback) {
var document = model('number', Schema);
module.exports = function(model, callback) {
var document = model("number", Schema);
document.insert(test1, callback);
}
};

@@ -1,19 +0,23 @@

var modm = require('../index');
var modm = require("../index");
var Schema = new modm.Schema({object: {
var Schema = new modm.Schema({
object: {
type: Object,
required: true,
default: {
a: "b"
}
//validate: function () {},
//manipulate: function () {},
//live: true
}
});
type: Object,
required: true,
default: {a: 'b'}
//validate: function () {},
//manipulate: function () {},
//live: true
var test1 = {
object: {}
};
}});
var test1 = {object: {}};
module.exports = function (model, callback) {
var document = model('object', Schema);
module.exports = function(model, callback) {
var document = model("object", Schema);
document.insert(test1, callback);
}
};
// TODO define objectid options
var modm = require('../index');
var ObjectID = require('../node_modules/pongo/node_modules/mongodb').ObjectID;
var modm = require("../index");
var ObjectID = require("mongodb").ObjectID;
var Schema = new modm.Schema({objectid: {
var Schema = new modm.Schema({
objectid: {
type: ObjectID,
required: true,
default: new ObjectID()
//validate: function () {},
//manipulate: function () {},
//live: true
}
});
type: ObjectID,
required: true,
default: new ObjectID()
//validate: function () {},
//manipulate: function () {},
//live: true
var test1 = {
objectid: new ObjectID()
};
}});
var test1 = {objectid: new ObjectID()};
module.exports = function (model, callback) {
var document = model('objectid', Schema);
module.exports = function(model, callback) {
var document = model("objectid", Schema);
document.insert(test1, callback);
}
};

@@ -1,32 +0,35 @@

var modm = require('../index');
var modm = require("../index");
var Schema = new modm.Schema({string: {
type: String,
required: true,
pre: ' tru',
post: 'cken ',
charStyle: 'uppercase', // normal | uppercase | lowercase
trim: true,
default: 'default',
validate: function (value) {
return true;
},
manipulate: function (value) {
return value;//'this is a manipulated value. and this is the original value: ' + value;
var Schema = new modm.Schema({
string: {
type: String,
required: true,
pre: " tru",
post: "cken ",
charStyle: "uppercase", // normal | uppercase | lowercase
trim: true,
default: "default",
validate: function(value) {
return true;
},
manipulate: function(value) {
//"this is a manipulated value. and this is the original value: " + value;
return value;
}
//live: true
}
//live: true
}}, [{
fields: ['string']
}, [{
fields: ["string"]
}]);
var test1 = {string: ''};
var test1 = {
string: ""
};
module.exports = function (model, callback) {
module.exports = function(model, callback) {
var document = model('string', Schema);
var document = model("string", Schema);
document.insert(test1, callback);
console.log('STRING FIND: ' + typeof document.find());
}
console.log("STRING FIND: " + typeof document.find());
};

@@ -1,8 +0,75 @@

var Pongo = require('pongo');
var Schema = require('./lib/schema');
var Model = require('./lib/model');
// Dependencies
var Mongo = require("mongodb");
var MongoClient = Mongo.MongoClient;
var Server = Mongo.Server;
var Schema = require("./lib/schema");
var Model = require("./lib/model");
function modm (dbName, options) {
// Constants
const DEFAULT_HOST = "127.0.0.1";
const DEFAULT_PORT = 27017;
const DEFAULT_BUFFERSIZE = 100;
var db = function (collection, schema) {
// Client cache
var _clientCache = {};
/**
* callbacks
* Fires all buffered callbacks
*
* @name callbacks
* @function
* @param {Error} err Error that is sent to all callbacks
* @param {Object} db Database instance
* @return {undefined}
*/
function callbacks(err, db) {
var self = this;
var buffer = self.buffer;
var args = arguments;
buffer.forEach(function(cBuff) {
cBuff.apply(self, args);
});
self.buffer = [];
}
/**
* bufferCallback
* Buffers a callback during connecting
*
* @name bufferCallback
* @function
* @param {Function} callback The callback that should be buffered
* @return {undefined}
*/
function bufferCallback(callback) {
var self = this;
var buffer = self.buffer;
if (buffer.length < self.MAX_CALLBACKS_IN_BUFFER) {
buffer.push(callback);
} else {
callback(new Error("Number of callbacks in buffer exceeded."));
}
}
/**
* modm
* Creates a new instance of modm
*
* @name modm
* @function
* @param {String} dbName Database name
* @param {Object} options An object containing the following fields:
* - buffersize (default: 100)
* - port (default: 27017)
* - host (default: "127.0.0.1")
* - server: the object passed when creating a server instance (default: {native_parser: true, poolSize: 1})
* - db: the object passed when creating a Mongo Client instance (default: {w: 1})
* @return {Function} Model function
*/
function modm(dbName, options) {
var db = function(collection, schema) {
return Model(db, collection, schema);

@@ -12,16 +79,61 @@ };

db.options = options;
db.driver = new Pongo(options);
db.MAX_CALLBACKS_IN_BUFFER = options.bufferSize || DEFAULT_BUFFERSIZE;
db.buffer = [];
db._dbName = dbName;
var host = options.host || DEFAULT_HOST;
var port = options.port || DEFAULT_PORT;
var serverPath = [host, port].join(":");
options.server = options.server || {
native_parser: true,
poolSize: 1
};
options.db = options.db || {
w: 1
};
var server = new Server(host, port, options.server);
db.driver = new MongoClient(server, options.db);
db.connection = null;
db.connect = function (callback) {
/**
* connect
* Connects to database
*
* @name connect
* @function
* @param {Function} callback The callback function
* @return {undefined}
*/
db.connect = function(callback) {
var self = this;
// db is connected
if (this.connection) {
return callback(null, this.connection);
if (self.connection) {
return callback(null, self.connection);
}
var self = this;
this.driver.connect(dbName, function (err, db) {
if (self._connecting) {
return bufferCallback.call(self, callback);
}
self.connection = err ? null : db;
callback(err, db);
if (_clientCache[serverPath]) {
return callback.call(self, null, self.connection = _clientCache[serverPath].db(dbName));
}
self._connecting = true;
bufferCallback.call(self, callback);
self.driver.open(function(err, client) {
if (err) {
self.connection = null;
return callbacks.call(self, err);
}
self._connecting = false;
_clientCache[serverPath] = client;
callbacks.call(self, null, self.connection = client.db(dbName));
});

@@ -34,4 +146,3 @@ };

modm.Schema = Schema;
modm.ObjectId = Pongo.ObjectId;
modm.ObjectId = Mongo.ObjectID;
module.exports = modm;

@@ -1,8 +0,8 @@

var valify = require('./manipulator');
var defaultValue = require('./default');
var jxUtils = require ('jxutils');
var valify = require("./manipulator");
var defaultValue = require("./default");
var jxUtils = require("jxutils");
function validateValue (value, path, type, paths) {
function validateValue(value, path, type, paths) {
if (value && value.constructor.name === 'Object' && type !== 'object') {
if (value && value.constructor.name === "Object" && type !== "object") {
return handleValidation.call(this, value, path, paths);

@@ -12,7 +12,7 @@ } else if (type) {

} else {
return ['Path not in schema PATH: ' + path];
return ["Path not in schema PATH: " + path];
}
}
function handleValidation (document, prefix, paths) {
function handleValidation(document, prefix, paths) {

@@ -25,3 +25,3 @@ var result;

for (var i = 0; i < document.length; ++i) {
var result = handleValidation.call(self, document[i], prefix, paths);
result = handleValidation.call(self, document[i], prefix, paths);

@@ -43,6 +43,6 @@ if (result[0]) {

// get field without operators
var _field = field[0] === '$' ? '' : field.replace(/\.\$|\[[0-9]+\]/, '');
var _field = field[0] === "$" ? "" : field.replace(/\.\$|\[[0-9]+\]/, "");
// get current path with prefix
var path = prefix ? prefix + (_field ? '.' + _field : '') : _field;
var path = prefix ? prefix + (_field ? "." + _field : "") : _field;

@@ -52,7 +52,7 @@ // get schema type

if (path !== '' && type) {
if (path !== "" && type) {
paths[path] = type;
}
if (document[field] && document[field].constructor.name === 'Array' && type !== 'array') {
if (document[field] && document[field].constructor.name === "Array" && type !== "array") {

@@ -84,3 +84,3 @@ for (var i in document[field]) {

function adapter (method, args, docIndex) {
function adapter(method, args, docIndex) {

@@ -92,3 +92,3 @@ if (!this._schema || !this._schema.paths) {

var self = this;
var args = Array.prototype.slice.call(args);
args = Array.prototype.slice.call(args);

@@ -99,3 +99,3 @@ // connect to db

var caller = adapter.caller;
return self.db.connect(function (err, db) {
return self.db.connect(function(err, db) {

@@ -109,6 +109,6 @@ caller.apply(self, args);

// get callback ref
var callback = args[args.length-1];
var callback = args[args.length - 1];
// create collection instance
if (typeof this.collection === 'string') {
if (typeof this.collection === "string") {
self.collection = self.db.connection.collection(self.collection);

@@ -124,3 +124,3 @@ }

var result = handleValidation.call(self, args[docIndex], '', {});
var result = handleValidation.call(self, args[docIndex], "", {});

@@ -134,6 +134,6 @@ if (result[0]) {

// set default value if field doesn't exists
// set default value if field doesn"t exists
if (self._schema.default) {
for (var field in self._schema.default) {
if (typeof result[2][field] === 'undefined' && self._schema.paths[field]) {
if (typeof result[2][field] === "undefined" && self._schema.paths[field]) {

@@ -143,3 +143,3 @@ var value = defaultValue(self._schema.paths[field], self._schema.default[field]);

// handle default value errors
if (value.constructor.name === 'Error') {
if (value.constructor.name === "Error") {
return callback(value);

@@ -149,3 +149,3 @@ }

// add default value to document
if (method !== 'insert') {
if (method !== "insert") {
result[1].$set[field] = value;

@@ -162,10 +162,10 @@ } else {

if (
self._schema.required &&
method === 'insert' ||
(method === 'update' &&
(args[2] && args[2].upsert ||
(Object.keys(args[docIndex])[0] || "")[0] !== '$'
)
self._schema.required &&
method === "insert" ||
(method === "update" &&
(args[2] && args[2].upsert ||
(Object.keys(args[docIndex])[0] || "")[0] !== "$"
)
) {
)
) {

@@ -180,9 +180,9 @@ // iterate the required fields

// found an invalid value
if (cRequiredField !== '_id' && !requiredFieldValue && [0, false].indexOf(requiredFieldValue) === -1) {
if (cRequiredField !== "_id" && !requiredFieldValue && [0, false].indexOf(requiredFieldValue) === -1) {
// is the result an object? then just callback an error
// if it's an array, iterate it
if (result[1] && result[1].constructor.name === 'Object') {
return callback(new Error('Missing required field: ' + self._schema.required[i]));
} else if (result[1] && result[1].constructor.name === 'Array') {
// if it"s an array, iterate it
if (result[1] && result[1].constructor.name === "Object") {
return callback(new Error("Missing required field: " + self._schema.required[i]));
} else if (result[1] && result[1].constructor.name === "Array") {

@@ -197,4 +197,4 @@ // each result object

// found an invalid value, callback an error
if (cRequiredField !== '_id' && !requiredFieldValue && requiredFieldValue !== 0) {
return callback(new Error('Missing required field: ' + cRequiredField));
if (cRequiredField !== "_id" && !requiredFieldValue && requiredFieldValue !== 0) {
return callback(new Error("Missing required field: " + cRequiredField));
}

@@ -205,4 +205,4 @@ }

}
// check if required fields are trying to be deleted
} else if (method === 'update' && (!args[2] || !args[2].upsert)) {
// check if required fields are trying to be deleted
} else if (method === "update" && (!args[2] || !args[2].upsert)) {

@@ -214,5 +214,5 @@ // iterate the required fields

var resultArr = [];
if (result[1] && result[1].constructor.name === 'Object') {
if (result[1] && result[1].constructor.name === "Object") {
resultArr.push(result[1]);
} else if (result[1] && result[1].constructor.name === 'Array') {
} else if (result[1] && result[1].constructor.name === "Array") {
resultArr = result[1];

@@ -235,3 +235,3 @@ }

if (cResObj.$unset.hasOwnProperty(cRequiredField)) {
return callback(new Error('Missing required field: ' + self._schema.required[i]));
return callback(new Error("Missing required field: " + self._schema.required[i]));
}

@@ -242,3 +242,3 @@ } else if (operator === "$set") {

if (cResObj.$set.hasOwnProperty(cRequiredField) && cResObj.$set[cRequiredField] === "") {
return callback(new Error('Missing required field: ' + self._schema.required[i]));
return callback(new Error("Missing required field: " + self._schema.required[i]));
}

@@ -245,0 +245,0 @@ }

@@ -1,2 +0,2 @@

var adapter = require('../adapter');
var adapter = require("../adapter");

@@ -8,111 +8,111 @@ // MongoDB Collection Methods

// insert(docs[, options][, callback])
insert:function(){return adapter.call(this,"insert",arguments,0)},
insert:function(){return adapter.call(this,"insert",arguments,0);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#remove
// remove([selector][, options], [callback])
remove:function(){return adapter.call(this,"remove",arguments)},
remove:function(){return adapter.call(this,"remove",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#rename
// rename(newName, callback)
rename:function(){return adapter.call(this,"rename",arguments)},
rename:function(){return adapter.call(this,"rename",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#save
// save([doc][, options], [callback])
save:function(){return adapter.call(this,"save",arguments,0)},
save:function(){return adapter.call(this,"save",arguments,0);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#update
// update(selector, document[, options][, callback])
update:function(){return adapter.call(this,"update",arguments,1)},
update:function(){return adapter.call(this,"update",arguments,1);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#distinct
// distinct(key[, query][, options], callback)
distinct:function(){return adapter.call(this,"distinct",arguments)},
distinct:function(){return adapter.call(this,"distinct",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#count
// count([query][, options], callback)
count:function(){return adapter.call(this,"count",arguments)},
count:function(){return adapter.call(this,"count",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#drop
// drop(callback)
drop:function(){return adapter.call(this,"drop",arguments)},
drop:function(){return adapter.call(this,"drop",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#findandmodify
// findAndModify(query, sort, doc[, options], callback)
findAndModify:function(){return adapter.call(this,"findAndModify",arguments,2)},
findAndModify:function(){return adapter.call(this,"findAndModify",arguments,2);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#findandremove
// findAndRemove(query, sort[, options], callback)
findAndRemove:function(){return adapter.call(this,"findAndRemove",arguments)},
findAndRemove:function(){return adapter.call(this,"findAndRemove",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#find
// find(query[, options], callback)
find:function(){return adapter.call(this,"find",arguments)},
find:function(){return adapter.call(this,"find",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#findone
// findOne(query[, options], callback)
findOne:function(){return adapter.call(this,"findOne",arguments)},
findOne:function(){return adapter.call(this,"findOne",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#createindex
// createIndex(fieldOrSpec[, options], callback)
createIndex:function(){return adapter.call(this,"createIndex",arguments)},
createIndex:function(){return adapter.call(this,"createIndex",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#ensureindex
// ensureIndex(fieldOrSpec[, options], callback)
ensureIndex:function(){return adapter.call(this,"ensureIndex",arguments)},
ensureIndex:function(){return adapter.call(this,"ensureIndex",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#indexinformation
// indexInformation([options], callback)
indexInformation:function(){return adapter.call(this,"indexInformation",arguments)},
indexInformation:function(){return adapter.call(this,"indexInformation",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#dropindex
// dropIndex(name, callback)
dropIndex:function(){return adapter.call(this,"dropIndex",arguments)},
dropIndex:function(){return adapter.call(this,"dropIndex",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#dropallindexes
// dropAllIndexes(callback)
dropAllIndexes:function(){return adapter.call(this,"dropAllIndexes",arguments)},
dropAllIndexes:function(){return adapter.call(this,"dropAllIndexes",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#reindex
// reIndex(callback)
reIndex:function(){return adapter.call(this,"reIndex",arguments)},
reIndex:function(){return adapter.call(this,"reIndex",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#mapreduce
// mapReduce(map, reduce[, options], callback)
mapReduce:function(){return adapter.call(this,"mapReduce",arguments)},
mapReduce:function(){return adapter.call(this,"mapReduce",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#group
// group(keys, condition, initial, reduce, finalize, command[, options], callback)
group:function(){return adapter.call(this,"group",arguments)},
group:function(){return adapter.call(this,"group",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#options
// options(callback)
options:function(){return adapter.call(this,"options",arguments)},
options:function(){return adapter.call(this,"options",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#iscapped
// isCapped(callback)
isCapped:function(){return adapter.call(this,"isCapped",arguments)},
isCapped:function(){return adapter.call(this,"isCapped",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#indexexists
// indexExists(indexNames, callback)
indexExists:function(){return adapter.call(this,"indexExists",arguments)},
indexExists:function(){return adapter.call(this,"indexExists",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#geonear
// geoNear(x, y[, options], callback)
geoNear:function(){return adapter.call(this,"geoNear",arguments)},
geoNear:function(){return adapter.call(this,"geoNear",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#geohaystacksearch
// geoHaystackSearch(x, y[, options], callback)
geoHaystackSearch:function(){return adapter.call(this,"geoHaystackSearch",arguments)},
geoHaystackSearch:function(){return adapter.call(this,"geoHaystackSearch",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#indexes
// indexes(callback)
indexes:function(){return adapter.call(this,"indexes",arguments)},
indexes:function(){return adapter.call(this,"indexes",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#aggregate
// aggregate(array[, options], callback)
aggregate:function(){return adapter.call(this,"aggregate",arguments)},
aggregate:function(){return adapter.call(this,"aggregate",arguments);},
// http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#stats
// stats([options], callback)
stats:function(){return adapter.call(this,"stats",arguments)}
stats:function(){return adapter.call(this,"stats",arguments);}
};

@@ -1,13 +0,13 @@

var ObjectId = require('pongo').ObjectId;
var moment = require('moment');
var ObjectId = require("mongodb").ObjectID;
var moment = require("moment");
function convert (options, value) {
function convert(options, value) {
var type = options.type;
if (typeof value === 'string') {
if (typeof value === "string") {
// convert to number
if (type === 'number') {
if (value.indexOf('.') > -1) {
if (type === "number") {
if (value.indexOf(".") > -1) {
value = parseFloat(value, 10);

@@ -18,25 +18,25 @@ } else {

return isNaN(value) ? new Error('Number conversion failed.') : value;
return isNaN(value) ? new Error("Number conversion failed.") : value;
}
// convert to boolean
if (type === 'boolean') {
if (type === "boolean") {
if (value === 'false' || value === '0') {
if (value === "false" || value === "0") {
return false;
}
if (value === 'true' || value === '1') {
if (value === "true" || value === "1") {
return true;
}
return new Error('Boolean conversion failed.');
return new Error("Boolean conversion failed.");
}
// convert to objectid
if (type === 'objectid') {
if (type === "objectid") {
try {
value = ObjectId(value);
} catch (err) {
value = new Error('ObjectId conversion failed: ' + value);
value = new Error("ObjectId conversion failed: " + value);
}

@@ -48,3 +48,3 @@

if (value && value.constructor.name !== 'Date' && type === 'date') {
if (value && value.constructor.name !== "Date" && type === "date") {

@@ -54,3 +54,3 @@ value = moment(value, options.parse || undefined).toDate();

if (isNaN(value.valueOf())) {
return new Error('Date conversion failed: ' + value);
return new Error("Date conversion failed: " + value);
}

@@ -65,2 +65,1 @@

module.exports = convert;

@@ -1,7 +0,7 @@

var convert = require('./convert');
var convert = require("./convert");
// handle special default values
var types = {
date: function (value) {
if (value === 'now') {
date: function(value) {
if (value === "now") {
return new Date();

@@ -15,3 +15,3 @@ }

// TODO handle validation
function handleValue (options, value) {
function handleValue(options, value) {

@@ -26,2 +26,1 @@ if (types[options.type]) {

module.exports = handleValue;
// INFO: results of atomic operations are not validated.
var convert = require('./convert');
var Validator = require('./validator');
var convert = require("./convert");
var Validator = require("./validator");
var manipulators = {
pre: function (optValue, value) {
pre: function(optValue, value) {
return [null, (optValue + value)];
},
post: function (optValue, value) {
post: function(optValue, value) {
return [null, (value + optValue)];
},
charStyle: function (style, value) {
charStyle: function(style, value) {
return [null, (style && value[style] ? value[style]() : value)];
},
trim: function (optValue, value) {
trim: function(optValue, value) {
return [null, (optValue ? value.trim() : value)];
},
maxLength: function (length, value) {
maxLength: function(length, value) {

@@ -29,6 +29,6 @@ if (value.length && value.length <= length) {

return ['Validation maxLength failed'];
return ["Validation maxLength failed"];
},
minLength: function (length, value) {
minLength: function(length, value) {

@@ -39,25 +39,25 @@ if (value.length && value.length >= length) {

return ['Validation minLength failed'];
return ["Validation minLength failed"];
},
max: function (optValue, value) {
max: function(optValue, value) {
if (typeof value === 'number' && value <= optValue) {
if (typeof value === "number" && value <= optValue) {
return [null, value];
}
return ['Validation max failed'];
return ["Validation max failed"];
},
min: function (optValue, value) {
min: function(optValue, value) {
if (typeof value === 'number' && value >= optValue) {
if (typeof value === "number" && value >= optValue) {
return [null, value];
}
return ['Validation min failed'];
return ["Validation min failed"];
}
}
};
// adapter (return document)
module.exports = function (options, value, path) {
module.exports = function(options, value, path) {

@@ -68,3 +68,3 @@ var result;

value = convert(options, value);
if (value && value.constructor.name === 'Error') {
if (value && value.constructor.name === "Error") {
return [value.toString()];

@@ -89,3 +89,3 @@ }

// custom manipulator
if (typeof options.manipulate === 'function') {
if (typeof options.manipulate === "function") {
value = options.manipulate(value);

@@ -97,5 +97,5 @@ }

if (typeof options[validator] !== 'undefined') {
if (typeof options[validator] !== "undefined") {
if (!Validator[validator](options[validator], value)) {
return ['Validation failed: ' + options[validator] + ' | value: ' + (value ? value.toString() : value)];
return ["Validation failed: " + options[validator] + " | value: " + (value ? value.toString() : value)];
}

@@ -106,6 +106,6 @@ }

// schema or custom validation function
if (typeof options.validate === 'function') {
if (typeof options.validate === "function") {
if (!options.validate(value)) {
return ['Schema validation failed: ' + path + ' expected ' + options.type + " but got " + (value ? value.toString() : value)];
return ["Schema validation failed: " + path + " expected " + options.type + " but got " + (value ? value.toString() : value)];
}

@@ -116,3 +116,3 @@

if (!Validator[options.validate](value)) {
return ['Validation failed: ' + options.validate + ' | value: ' + (value ? value.toString() : value)];
return ["Validation failed: " + options.validate + " | value: " + (value ? value.toString() : value)];
}

@@ -119,0 +119,0 @@ }

@@ -1,5 +0,5 @@

var Events = require('events').EventEmitter;
var interFace = require('./apis/mongodb');
var Events = require("events").EventEmitter;
var interFace = require("./apis/mongodb");
function extend (object, inherit) {
function extend(object, inherit) {

@@ -20,5 +20,5 @@ var Model = function(properties) {

return object;
};
}
function ensureIndexes () {
function ensureIndexes() {

@@ -28,6 +28,6 @@ var self = this;

// get index informations
this.indexInformation(function (err, indexInfo) {
this.indexInformation(function(err, indexInfo) {
if (err) {
return self.emit('modmError', err);
return self.emit("modmError", err);
}

@@ -41,9 +41,9 @@

// create indexes
self.createIndex(self._schema.indexes[i][0], self._schema.indexes[i][1], function (err, result) {
self.createIndex(self._schema.indexes[i][0], self._schema.indexes[i][1], function(err, result) {
if (err) {
return self.emit('modmError', err);
return self.emit("modmError", err);
}
self.emit('modmIndexCreated', result);
self.emit("modmIndexCreated", result);
});

@@ -55,3 +55,3 @@ }

function Model (db, collectionName, schema) {
function Model(db, collectionName, schema) {

@@ -58,0 +58,0 @@ var model = extend(interFace, new Events());

@@ -1,6 +0,6 @@

var Validator = require('./validator');
var Validator = require("./validator");
function checkString (string) {
function checkString(string) {
if (typeof string === 'string') {
if (typeof string === "string") {
return string;

@@ -12,9 +12,9 @@ }

function toNumber (number) {
function toNumber(number) {
if (typeof number === 'number') {
if (typeof number === "number") {
return number;
}
if (typeof number === 'string' && number.match(/\./)) {
if (typeof number === "string" && number.match(/\./)) {
return parseFloat(number, 10) || 0;

@@ -26,3 +26,3 @@ }

function checkLength (integer) {
function checkLength(integer) {

@@ -33,14 +33,13 @@ integer = parseInt(integer, 10) || 0;

function validate (type, validate) {
function validate(type, validateMethod) {
// validation info
if (typeof validate === 'function') {
return validate;
if (typeof validateMethod === "function") {
return validateMethod;
}
// find a validation method in Validator
if (typeof validate === "string") {
if (Validator[validate]) {
return Validator[validate];
if (typeof validateMethod === "string") {
if (Validator[validateMethod]) {
return Validator[validateMethod];
}

@@ -57,7 +56,7 @@ }

function validateDefault (validate, value) {
function validateDefault(validate, value) {
// validate default value
if (validate && !validate(value)) {
return console.error("Invalid default value.");
return console.error("Invalid default value.");
}

@@ -68,3 +67,3 @@

function toBoolean (value) {
function toBoolean(value) {
return value ? true : false;

@@ -79,16 +78,16 @@ }

manipulate: function (value) {
return typeof value === 'function' ? value : null;
manipulate: function(value) {
return typeof value === "function" ? value : null;
},
charStyle: function (value) {
charStyle: function(value) {
value = value.toLowerCase();
if (value === 'lowercase') {
return 'toLowerCase';
if (value === "lowercase") {
return "toLowerCase";
}
if (value === 'uppercase') {
return 'toUpperCase';
if (value === "uppercase") {
return "toUpperCase";
}

@@ -109,3 +108,3 @@

// schema (return options)
exports.prepare = function (opts) {
exports.prepare = function(opts) {

@@ -117,3 +116,3 @@ // define default item

for (var fn in options) {
if (typeof opts[fn] !== 'undefined') {
if (typeof opts[fn] !== "undefined") {
_options[fn] = options[fn](opts[fn]);

@@ -120,0 +119,0 @@ }

@@ -1,8 +0,8 @@

var prepare = require('./options').prepare;
var prepare = require("./options").prepare;
// class Schema
function Schema (obj, indexes) {
function Schema(obj, indexes) {
if (!obj || obj.constructor.name !== 'Object') {
throw new Error('First argument must be an object.');
if (!obj || obj.constructor.name !== "Object") {
throw new Error("First argument must be an object.");
}

@@ -17,8 +17,8 @@

}
};
}
// add paths to schema
Schema.prototype.add = function (obj, prefix) {
Schema.prototype.add = function(obj, prefix) {
prefix = prefix || '';
prefix = prefix || "";

@@ -28,3 +28,3 @@ for (var key in obj) {

if (obj[key] === null) {
throw new TypeError('Invalid value for schema path `' + prefix + key + '`');
throw new TypeError("Invalid value for schema path `" + prefix + key + "`");
}

@@ -37,3 +37,3 @@

// handle array structures
if (type === 'Array' && obj[key].length > 0) {
if (type === "Array" && obj[key].length > 0) {
type = obj[key][0].constructor.name;

@@ -44,3 +44,3 @@ object = obj[key][0];

// check if obj[key] is an object and not a type with options
if (type === 'Object' && typeof object.type === "undefined") {
if (type === "Object" && typeof object.type === "undefined") {

@@ -51,3 +51,3 @@ // handle nested objects

//this.nested[prefix + key] = true;
this.add(object, prefix + key + '.');
this.add(object, prefix + key + ".");

@@ -58,7 +58,7 @@ } else {

// handle nested schemas
} else if (type === 'Schema' && object.paths) {
this.add(object.paths, prefix + key + '.');
// handle nested schemas
} else if (type === "Schema" && object.paths) {
this.add(object.paths, prefix + key + ".");
// create path
// create path
} else {

@@ -70,4 +70,4 @@ path.call(this, prefix + key, object);

function getType (value) {
if (typeof value === 'string') {
function getType(value) {
if (typeof value === "string") {
return value.toLowerCase();

@@ -80,3 +80,3 @@ }

// prepare schema path options
function path (path, options) {
function path(opt_path, options) {

@@ -86,9 +86,8 @@ // convert type to string

if (typeof options.type === 'undefined') {
if (typeof options.type === "undefined") {
type = getType(options);
options = {type: type}
options = {
type: type
};
} else {
type = getType(options.type);

@@ -99,26 +98,26 @@ options.type = type;

// add to required
if (options.required){
if (options.required) {
if(!this.required) {
if (!this.required) {
this.required = [];
}
this.required.push(path);
this.required.push(opt_path);
}
// add to default
if (options.default){
if (options.default) {
if(!this.default) {
if (!this.default) {
this.default = {};
}
this.default[path] = options.default;
this.default[opt_path] = options.default;
}
// prepare options
this.paths[path] = prepare(options);
};
this.paths[opt_path] = prepare(options);
}
function prepareIndexes (indexes) {
function prepareIndexes(indexes) {

@@ -135,4 +134,4 @@ var _indexes = [];

var name;
if (indexes[i].fields.constructor.name === 'Array') {
name = indexes[i].fields.join('');
if (indexes[i].fields.constructor.name === "Array") {
name = indexes[i].fields.join("");
} else {

@@ -143,3 +142,3 @@ name = indexes[i].fields.toString();

// handle options
if (typeof indexes[i].options === 'object') {
if (typeof indexes[i].options === "object") {

@@ -150,3 +149,3 @@ var sorted = [];

if (!indexes[i].options && option !== 'w' && option !== 'v') {
if (!indexes[i].options && option !== "w" && option !== "v") {
continue;

@@ -165,3 +164,3 @@ }

// convert boolean to number
if (typeof indexes[i].options[sorted[ii]] === 'boolean') {
if (typeof indexes[i].options[sorted[ii]] === "boolean") {
indexes[i].options[sorted[ii]] = 1;

@@ -168,0 +167,0 @@ }

// validate a data types
exports.string = function (data) {
exports.string = function(data) {
return typeof data === "string" ? true : false;
};
exports.number = function (data) {
exports.number = function(data) {
if (typeof data === 'number' && (data <= 0 || data >= 0)) {
if (typeof data === "number" && (data <= 0 || data >= 0)) {
return true;

@@ -13,21 +13,21 @@ }

};
exports.array = function (data) {
return data && data.constructor.name === 'Array' ? true : false;
exports.array = function(data) {
return data && data.constructor.name === "Array" ? true : false;
};
exports.object = function (data) {
return data && data.constructor.name === 'Object' ? true : false;
exports.object = function(data) {
return data && data.constructor.name === "Object" ? true : false;
};
exports.boolean = function (data) {
exports.boolean = function(data) {
return [true, false].indexOf(data) !== -1 ? true : false;
};
exports.buffer = function (data) {
exports.buffer = function(data) {
return data && data.constructor.name === "Buffer" ? true : false;
};
exports.objectid = function (data) {
exports.objectid = function(data) {
return data && data.constructor.name === "ObjectID" ? true : false;
};
exports.date = function (data) {
exports.date = function(data) {
// handle special "now" default value
if (data === 'now') {
if (data === "now") {
return true;

@@ -40,9 +40,9 @@ }

// validate email
var special = "!#$%&'*+/=?^`{|}~";
var special = "!#$%&\"*+/=?^`{|}~";
var ascii = "a-z0-9._\\-";
var umlaut = "àáâãäåæāăąçćĉċčďđèéêëēĕėęěĝğġģĥħìíîïĩīĭįıðĵķĸĺļľŀłñńņňʼnŋòóôõöøō" +
"ŏőœŕŗřśŝšșßťŧțùúûüũūŭůűųŵýÿŷźżžþΐάέήίΰαβγδεζηθ" +
"ικλμνξοπρςστυφχψωϊϋόύώабвгдежзийклмнопрстуфхцчшщъыьэюяἀἁἂἃἄἅἆἇ" +
"ἐἑἒἓἔἕἠἡἢἣἤἥἦἧἰἱἲἳἴἵἶἷὀὁὂὃὄὅὐὑὒὓὔὕὖὗὠὡὢὣὤὥὦὧὰάὲέὴήὶίὸόὺύὼώᾀᾁᾂᾃᾄᾅᾆ" +
"ᾇᾐᾑᾒᾓᾔᾕᾖᾗᾠᾡᾢᾣᾤᾥᾦᾧᾰᾱᾲᾳᾴᾶᾷῂῃῄῆῇῐῑῒΐῖῗῠῡῢΰῤῥῦῧῲῳῴῶῷ";
"ŏőœŕŗřśŝšșßťŧțùúûüũūŭůűųŵýÿŷźżžþΐάέήίΰαβγδεζηθ" +
"ικλμνξοπρςστυφχψωϊϋόύώабвгдежзийклмнопрстуфхцчшщъыьэюяἀἁἂἃἄἅἆἇ" +
"ἐἑἒἓἔἕἠἡἢἣἤἥἦἧἰἱἲἳἴἵἶἷὀὁὂὃὄὅὐὑὒὓὔὕὖὗὠὡὢὣὤὥὦὧὰάὲέὴήὶίὸόὺύὼώᾀᾁᾂᾃᾄᾅᾆ" +
"ᾇᾐᾑᾒᾓᾔᾕᾖᾗᾠᾡᾢᾣᾤᾥᾦᾧᾰᾱᾲᾳᾴᾶᾷῂῃῄῆῇῐῑῒΐῖῗῠῡῢΰῤῥῦῧῲῳῴῶῷ";

@@ -63,3 +63,3 @@ var IEA = {};

//return new RegExp("^[" + ascii + special + umlaut + "]+@[" + ascii + umlaut + "]+\.[a-z]+$").test(string);
var pattern = new RegExp("^[" + ascii + special + umlaut + "]+@[" + ascii + umlaut + "]+\.[a-z]+$");//.test(string);
var pattern = new RegExp("^[" + ascii + special + umlaut + "]+@[" + ascii + umlaut + "]+\.[a-z]+$"); //.test(string);

@@ -77,6 +77,6 @@ if (pattern.test(string2)) {

return false;
};
}
exports.email = email;
exports.getIEA = function () {
exports.getIEA = function() {
return IEA;

@@ -83,0 +83,0 @@ };

{
"name": "modm",
"version": "0.3.0",
"author": "Adrian Ottiker <adrian@ottiker.com>",
"description": "A MongoDB Object Document Mapper (ODM)",
"contributors": [
{
"name": "Adrian Ottiker",
"email": "adrian@ottiker.com"
},
{
"name": "Ionică Bizău",
"email": "bizauionica@gmail.com"
},
{
"name": "Gabriel Petrovay",
"email": "gabipetrovay@gmail.com"
},
{
"name": "Andrei Dan",
"email": "andrei_dani_96@yahoo.com"
}
],
"repository": {
"type": "git",
"url": "https://github.com/adioo/modm.git"
},
"keywords": [
"mongodb",
"orm",
"object",
"document",
"mapper"
],
"dependencies" : {
"jxutils": "*",
"moment": "2.6.0",
"pongo": "*"
},
"engine": {
"node": ">=0.8"
}
"name": "modm",
"version": "0.4.0",
"author": "Adrian Ottiker <adrian@ottiker.com>",
"description": "A MongoDB Object Document Mapper (ODM)",
"contributors": [
"Adrian Ottiker <adrian@ottiker.com>",
"Ionică Bizău <bizauionica@gmail.com>",
"Gabriel Petrovay <gabipetrovay@gmail.com>",
"Andrei Dan <andrei_dani_96@yahoo.com>"
],
"repository": {
"type": "git",
"url": "https://github.com/adioo/modm.git"
},
"keywords": [
"mongodb",
"orm",
"object",
"document",
"mapper"
],
"dependencies": {
"jxutils": "0.1.5",
"moment": "2.6.0",
"mongodb": "1.4.14"
},
"engine": {
"node": ">=0.8"
},
"bugs": {
"url": "https://github.com/adioo/modm/issues"
},
"homepage": "https://github.com/adioo/modm",
"main": "index.js",
"directories": {
"example": "example"
},
"devDependencies": {},
"scripts": {
"test": "node example/example.js"
},
"license": "THE BEER-WARE LICENSE"
}

@@ -9,10 +9,10 @@ MODM

```js
var modm = require('modm');
var modm = require("modm");
// define a schema
schema = new modm.Schema({field: String});
var schema = new modm.Schema({field: String});
// create db connection
model = modm('myDb', {
host: '127.0.0.1',
var model = modm("myDb", {
host: "127.0.0.1",
port: 27017,

@@ -24,3 +24,3 @@ server: {pooSize: 5},

// get a collection
myCollection = model('myCollection', schema);
var myCollection = model("myCollection", schema);

@@ -27,0 +27,0 @@ // db operations

Sorry, the diff of this file is not supported yet

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