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

mongoose

Package Overview
Dependencies
Maintainers
0
Versions
892
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

test/model.querying.test.js

6

History.md
1.0.11 / 2011-02-14
===================
* Query refactor and $ne, $slice, $or, $size, $elemMatch, $nin, $exists support [brian]
* Named scopes sugar [brian]
1.0.10 / 2011-02-11

@@ -3,0 +9,0 @@ ===================

12

lib-cov/mongoose/collection.js

@@ -52,10 +52,10 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/collection.js'][13]++;
this.buffer = true;
_$jscoverage['mongoose/collection.js'][14]++;
this.queue = [];
_$jscoverage['mongoose/collection.js'][15]++;
if (this.conn.readyState == 1) {
_$jscoverage['mongoose/collection.js'][13]++;
_$jscoverage['mongoose/collection.js'][15]++;
this.onOpen();
}
_$jscoverage['mongoose/collection.js'][14]++;
this.queue = [];
_$jscoverage['mongoose/collection.js'][15]++;
this.buffer = true;
}

@@ -141,2 +141,2 @@ _$jscoverage['mongoose/collection.js'][16]++;

module.exports = Collection;
_$jscoverage['mongoose/collection.js'].source = ["","/**"," * Collection constructor"," *"," * @param {String} collection name"," * @param {Collection} connection object"," * @api public"," */","","function Collection (name, conn) {"," this.name = name;"," this.conn = conn;"," if (this.conn.readyState == 1) this.onOpen();"," this.queue = [];"," this.buffer = true;","};","","/**"," * The collection name"," *"," * @api public"," */","","Collection.prototype.name;","","/**"," * The Connection instance"," *"," * @api public"," */","","Collection.prototype.conn;","","/**"," * Called when the database connects"," *"," * @api private"," */","","Collection.prototype.onOpen = function () {"," var self = this;"," this.buffer = false;"," self.doQueue();","};","","/**"," * Called when the database disconnects"," *"," * @api private"," */","","Collection.prototype.onClose = function () {"," this.buffer = true;","};","","/**"," * Adds a callback to the queue"," *"," * @param {String} method name"," * @param {Array} arguments"," * @api private"," */","","Collection.prototype.addQueue = function (name, args) {"," this.queue.push([name, args]);"," return this;","};","","/**"," * Executes the current queue"," *"," * @api private"," */","","Collection.prototype.doQueue = function () {"," for (var i = 0, l = this.queue.length; i < l; i++){"," this[this.queue[i][0]].apply(this, this.queue[i][1]);"," }"," return this;","};","","/**"," * Ensure index function"," *"," * @api private"," */","","Collection.prototype.ensureIndex = function(){"," throw new Error('Collection#ensureIndex unimplemented by driver');","};","","/**"," * FindAndModify command"," *"," * @api private"," */","","Collection.prototype.findAndModify = function(){"," throw new Error('Collection#findAndModify unimplemented by driver');","};","","/**"," * FindOne command"," *"," * @api private"," */","","Collection.prototype.findOne = function(){"," throw new Error('Collection#findOne unimplemented by driver');","};","","/**"," * Find command"," *"," * @api private"," */","","Collection.prototype.find = function(){"," throw new Error('Collection#find unimplemented by driver');","};","","/**"," * Insert command"," *"," * @api private"," */","","Collection.prototype.insert = function(){"," throw new Error('Collection#insert unimplemented by driver');","};","","/**"," * Update command"," *"," * @api private"," */","","Collection.prototype.save = function(){"," throw new Error('Collection#save unimplemented by driver');","};","","/**"," * Insert command"," *"," * @api private"," */","","Collection.prototype.update = function(){"," throw new Error('Collection#update unimplemented by driver');","};","","/**"," * getIndexes command"," *"," * @api private"," */","","Collection.prototype.getIndexes = function(){"," throw new Error('Collection#getIndexes unimplemented by driver');","};","","/**"," * Module exports."," */","","module.exports = Collection;"];
_$jscoverage['mongoose/collection.js'].source = ["","/**"," * Collection constructor"," *"," * @param {String} collection name"," * @param {Collection} connection object"," * @api public"," */","","function Collection (name, conn) {"," this.name = name;"," this.conn = conn;"," this.buffer = true;"," this.queue = [];"," if (this.conn.readyState == 1) this.onOpen();","};","","/**"," * The collection name"," *"," * @api public"," */","","Collection.prototype.name;","","/**"," * The Connection instance"," *"," * @api public"," */","","Collection.prototype.conn;","","/**"," * Called when the database connects"," *"," * @api private"," */","","Collection.prototype.onOpen = function () {"," var self = this;"," this.buffer = false;"," self.doQueue();","};","","/**"," * Called when the database disconnects"," *"," * @api private"," */","","Collection.prototype.onClose = function () {"," this.buffer = true;","};","","/**"," * Adds a callback to the queue"," *"," * @param {String} method name"," * @param {Array} arguments"," * @api private"," */","","Collection.prototype.addQueue = function (name, args) {"," this.queue.push([name, args]);"," return this;","};","","/**"," * Executes the current queue"," *"," * @api private"," */","","Collection.prototype.doQueue = function () {"," for (var i = 0, l = this.queue.length; i < l; i++){"," this[this.queue[i][0]].apply(this, this.queue[i][1]);"," }"," return this;","};","","/**"," * Ensure index function"," *"," * @api private"," */","","Collection.prototype.ensureIndex = function(){"," throw new Error('Collection#ensureIndex unimplemented by driver');","};","","/**"," * FindAndModify command"," *"," * @api private"," */","","Collection.prototype.findAndModify = function(){"," throw new Error('Collection#findAndModify unimplemented by driver');","};","","/**"," * FindOne command"," *"," * @api private"," */","","Collection.prototype.findOne = function(){"," throw new Error('Collection#findOne unimplemented by driver');","};","","/**"," * Find command"," *"," * @api private"," */","","Collection.prototype.find = function(){"," throw new Error('Collection#find unimplemented by driver');","};","","/**"," * Insert command"," *"," * @api private"," */","","Collection.prototype.insert = function(){"," throw new Error('Collection#insert unimplemented by driver');","};","","/**"," * Update command"," *"," * @api private"," */","","Collection.prototype.save = function(){"," throw new Error('Collection#save unimplemented by driver');","};","","/**"," * Insert command"," *"," * @api private"," */","","Collection.prototype.update = function(){"," throw new Error('Collection#update unimplemented by driver');","};","","/**"," * getIndexes command"," *"," * @api private"," */","","Collection.prototype.getIndexes = function(){"," throw new Error('Collection#getIndexes unimplemented by driver');","};","","/**"," * Module exports."," */","","module.exports = Collection;"];

@@ -55,13 +55,12 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/connection.js'][140] = 0;
_$jscoverage['mongoose/connection.js'][144] = 0;
_$jscoverage['mongoose/connection.js'][145] = 0;
_$jscoverage['mongoose/connection.js'][142] = 0;
_$jscoverage['mongoose/connection.js'][143] = 0;
_$jscoverage['mongoose/connection.js'][146] = 0;
_$jscoverage['mongoose/connection.js'][147] = 0;
_$jscoverage['mongoose/connection.js'][158] = 0;
_$jscoverage['mongoose/connection.js'][159] = 0;
_$jscoverage['mongoose/connection.js'][161] = 0;
_$jscoverage['mongoose/connection.js'][163] = 0;
_$jscoverage['mongoose/connection.js'][164] = 0;
_$jscoverage['mongoose/connection.js'][149] = 0;
_$jscoverage['mongoose/connection.js'][153] = 0;
_$jscoverage['mongoose/connection.js'][154] = 0;
_$jscoverage['mongoose/connection.js'][156] = 0;
_$jscoverage['mongoose/connection.js'][167] = 0;
_$jscoverage['mongoose/connection.js'][168] = 0;
_$jscoverage['mongoose/connection.js'][169] = 0;
_$jscoverage['mongoose/connection.js'][170] = 0;

@@ -71,26 +70,26 @@ _$jscoverage['mongoose/connection.js'][172] = 0;

_$jscoverage['mongoose/connection.js'][176] = 0;
_$jscoverage['mongoose/connection.js'][177] = 0;
_$jscoverage['mongoose/connection.js'][178] = 0;
_$jscoverage['mongoose/connection.js'][179] = 0;
_$jscoverage['mongoose/connection.js'][180] = 0;
_$jscoverage['mongoose/connection.js'][181] = 0;
_$jscoverage['mongoose/connection.js'][182] = 0;
_$jscoverage['mongoose/connection.js'][185] = 0;
_$jscoverage['mongoose/connection.js'][186] = 0;
_$jscoverage['mongoose/connection.js'][188] = 0;
_$jscoverage['mongoose/connection.js'][189] = 0;
_$jscoverage['mongoose/connection.js'][191] = 0;
_$jscoverage['mongoose/connection.js'][194] = 0;
_$jscoverage['mongoose/connection.js'][195] = 0;
_$jscoverage['mongoose/connection.js'][197] = 0;
_$jscoverage['mongoose/connection.js'][200] = 0;
_$jscoverage['mongoose/connection.js'][201] = 0;
_$jscoverage['mongoose/connection.js'][205] = 0;
_$jscoverage['mongoose/connection.js'][206] = 0;
_$jscoverage['mongoose/connection.js'][208] = 0;
_$jscoverage['mongoose/connection.js'][219] = 0;
_$jscoverage['mongoose/connection.js'][220] = 0;
_$jscoverage['mongoose/connection.js'][221] = 0;
_$jscoverage['mongoose/connection.js'][222] = 0;
_$jscoverage['mongoose/connection.js'][234] = 0;
_$jscoverage['mongoose/connection.js'][235] = 0;
_$jscoverage['mongoose/connection.js'][237] = 0;
_$jscoverage['mongoose/connection.js'][238] = 0;
_$jscoverage['mongoose/connection.js'][240] = 0;
_$jscoverage['mongoose/connection.js'][241] = 0;
_$jscoverage['mongoose/connection.js'][209] = 0;
_$jscoverage['mongoose/connection.js'][210] = 0;
_$jscoverage['mongoose/connection.js'][214] = 0;
_$jscoverage['mongoose/connection.js'][215] = 0;
_$jscoverage['mongoose/connection.js'][217] = 0;
_$jscoverage['mongoose/connection.js'][228] = 0;
_$jscoverage['mongoose/connection.js'][229] = 0;
_$jscoverage['mongoose/connection.js'][230] = 0;
_$jscoverage['mongoose/connection.js'][231] = 0;
_$jscoverage['mongoose/connection.js'][243] = 0;
_$jscoverage['mongoose/connection.js'][244] = 0;
_$jscoverage['mongoose/connection.js'][245] = 0;
_$jscoverage['mongoose/connection.js'][246] = 0;

@@ -100,8 +99,14 @@ _$jscoverage['mongoose/connection.js'][247] = 0;

_$jscoverage['mongoose/connection.js'][250] = 0;
_$jscoverage['mongoose/connection.js'][251] = 0;
_$jscoverage['mongoose/connection.js'][252] = 0;
_$jscoverage['mongoose/connection.js'][253] = 0;
_$jscoverage['mongoose/connection.js'][254] = 0;
_$jscoverage['mongoose/connection.js'][255] = 0;
_$jscoverage['mongoose/connection.js'][256] = 0;
_$jscoverage['mongoose/connection.js'][258] = 0;
_$jscoverage['mongoose/connection.js'][259] = 0;
_$jscoverage['mongoose/connection.js'][266] = 0;
_$jscoverage['mongoose/connection.js'][260] = 0;
_$jscoverage['mongoose/connection.js'][261] = 0;
_$jscoverage['mongoose/connection.js'][262] = 0;
_$jscoverage['mongoose/connection.js'][265] = 0;
_$jscoverage['mongoose/connection.js'][268] = 0;
_$jscoverage['mongoose/connection.js'][275] = 0;
}

@@ -231,32 +236,46 @@ _$jscoverage['mongoose/connection.js'][6]++;

_$jscoverage['mongoose/connection.js'][140]++;
this.readyState = 1;
_$jscoverage['mongoose/connection.js'][144]++;
for (var i in this.collections) {
_$jscoverage['mongoose/connection.js'][145]++;
this.collections[i].onOpen();
var self = this;
_$jscoverage['mongoose/connection.js'][142]++;
var continuation = (function () {
_$jscoverage['mongoose/connection.js'][143]++;
self.readyState = 1;
_$jscoverage['mongoose/connection.js'][146]++;
for (var i in self.collections) {
_$jscoverage['mongoose/connection.js'][147]++;
self.collections[i].onOpen();
}
_$jscoverage['mongoose/connection.js'][147]++;
this.emit("open");
_$jscoverage['mongoose/connection.js'][149]++;
self.emit("open");
});
_$jscoverage['mongoose/connection.js'][158]++;
_$jscoverage['mongoose/connection.js'][153]++;
if (self.user && self.pass) {
_$jscoverage['mongoose/connection.js'][154]++;
self.db.authenticate(self.user, self.pass, continuation);
}
else {
_$jscoverage['mongoose/connection.js'][156]++;
continuation();
}
});
_$jscoverage['mongoose/connection.js'][167]++;
Connection.prototype.close = (function (callback) {
_$jscoverage['mongoose/connection.js'][159]++;
_$jscoverage['mongoose/connection.js'][168]++;
var self = this;
_$jscoverage['mongoose/connection.js'][161]++;
_$jscoverage['mongoose/connection.js'][170]++;
switch (this.readyState) {
case 0:
_$jscoverage['mongoose/connection.js'][163]++;
_$jscoverage['mongoose/connection.js'][172]++;
callback(null);
_$jscoverage['mongoose/connection.js'][164]++;
_$jscoverage['mongoose/connection.js'][173]++;
break;
case 1:
_$jscoverage['mongoose/connection.js'][167]++;
_$jscoverage['mongoose/connection.js'][176]++;
this.readyState = 3;
_$jscoverage['mongoose/connection.js'][168]++;
_$jscoverage['mongoose/connection.js'][177]++;
this.doClose((function (err) {
_$jscoverage['mongoose/connection.js'][169]++;
_$jscoverage['mongoose/connection.js'][178]++;
if (err) {
_$jscoverage['mongoose/connection.js'][170]++;
_$jscoverage['mongoose/connection.js'][179]++;
if (callback) {
_$jscoverage['mongoose/connection.js'][170]++;
_$jscoverage['mongoose/connection.js'][179]++;
callback(err);

@@ -266,7 +285,7 @@ }

else {
_$jscoverage['mongoose/connection.js'][172]++;
_$jscoverage['mongoose/connection.js'][181]++;
self.onClose();
_$jscoverage['mongoose/connection.js'][173]++;
_$jscoverage['mongoose/connection.js'][182]++;
if (callback) {
_$jscoverage['mongoose/connection.js'][173]++;
_$jscoverage['mongoose/connection.js'][182]++;
callback(null);

@@ -276,87 +295,87 @@ }

}));
_$jscoverage['mongoose/connection.js'][176]++;
_$jscoverage['mongoose/connection.js'][185]++;
break;
case 2:
_$jscoverage['mongoose/connection.js'][179]++;
_$jscoverage['mongoose/connection.js'][188]++;
this.once("open", (function () {
_$jscoverage['mongoose/connection.js'][180]++;
_$jscoverage['mongoose/connection.js'][189]++;
self.close(callback);
}));
_$jscoverage['mongoose/connection.js'][182]++;
_$jscoverage['mongoose/connection.js'][191]++;
break;
case 3:
_$jscoverage['mongoose/connection.js'][185]++;
_$jscoverage['mongoose/connection.js'][194]++;
this.once("close", (function () {
_$jscoverage['mongoose/connection.js'][186]++;
_$jscoverage['mongoose/connection.js'][195]++;
callback(null);
}));
_$jscoverage['mongoose/connection.js'][188]++;
_$jscoverage['mongoose/connection.js'][197]++;
break;
}
_$jscoverage['mongoose/connection.js'][191]++;
_$jscoverage['mongoose/connection.js'][200]++;
return this;
});
_$jscoverage['mongoose/connection.js'][200]++;
_$jscoverage['mongoose/connection.js'][209]++;
Connection.prototype.onClose = (function () {
_$jscoverage['mongoose/connection.js'][201]++;
_$jscoverage['mongoose/connection.js'][210]++;
this.readyState = 0;
_$jscoverage['mongoose/connection.js'][205]++;
_$jscoverage['mongoose/connection.js'][214]++;
for (var i in this.collections) {
_$jscoverage['mongoose/connection.js'][206]++;
_$jscoverage['mongoose/connection.js'][215]++;
this.collections[i].onClose();
}
_$jscoverage['mongoose/connection.js'][208]++;
_$jscoverage['mongoose/connection.js'][217]++;
this.emit("close");
});
_$jscoverage['mongoose/connection.js'][219]++;
_$jscoverage['mongoose/connection.js'][228]++;
Connection.prototype.collection = (function (name) {
_$jscoverage['mongoose/connection.js'][220]++;
_$jscoverage['mongoose/connection.js'][229]++;
if (! (name in this.collections)) {
_$jscoverage['mongoose/connection.js'][221]++;
_$jscoverage['mongoose/connection.js'][230]++;
this.collections[name] = new Collection(name, this);
}
_$jscoverage['mongoose/connection.js'][222]++;
_$jscoverage['mongoose/connection.js'][231]++;
return this.collections[name];
});
_$jscoverage['mongoose/connection.js'][234]++;
_$jscoverage['mongoose/connection.js'][243]++;
Connection.prototype.model = (function (name, collection) {
_$jscoverage['mongoose/connection.js'][235]++;
_$jscoverage['mongoose/connection.js'][244]++;
collection || (collection = utils.toCollectionName(name));
_$jscoverage['mongoose/connection.js'][237]++;
_$jscoverage['mongoose/connection.js'][246]++;
if (! this.models[collection]) {
_$jscoverage['mongoose/connection.js'][238]++;
_$jscoverage['mongoose/connection.js'][247]++;
this.models[collection] = {};
}
_$jscoverage['mongoose/connection.js'][240]++;
_$jscoverage['mongoose/connection.js'][249]++;
if (! this.models[collection][name]) {
_$jscoverage['mongoose/connection.js'][241]++;
_$jscoverage['mongoose/connection.js'][250]++;
var model = this.base.model(name, null, collection, true), Model;
_$jscoverage['mongoose/connection.js'][244]++;
_$jscoverage['mongoose/connection.js'][253]++;
if (model.prototype.connection != this) {
_$jscoverage['mongoose/connection.js'][245]++;
_$jscoverage['mongoose/connection.js'][254]++;
function Model() {
_$jscoverage['mongoose/connection.js'][246]++;
_$jscoverage['mongoose/connection.js'][255]++;
model.apply(this, arguments);
}
_$jscoverage['mongoose/connection.js'][247]++;
_$jscoverage['mongoose/connection.js'][256]++;
;
_$jscoverage['mongoose/connection.js'][249]++;
_$jscoverage['mongoose/connection.js'][258]++;
Model.__proto__ = model;
_$jscoverage['mongoose/connection.js'][250]++;
_$jscoverage['mongoose/connection.js'][259]++;
Model.prototype.__proto__ = model.prototype;
_$jscoverage['mongoose/connection.js'][251]++;
_$jscoverage['mongoose/connection.js'][260]++;
Model.prototype.db = this;
_$jscoverage['mongoose/connection.js'][252]++;
_$jscoverage['mongoose/connection.js'][261]++;
Model.prototype.collection = this.collection(collection);
_$jscoverage['mongoose/connection.js'][253]++;
_$jscoverage['mongoose/connection.js'][262]++;
Model.init();
}
_$jscoverage['mongoose/connection.js'][256]++;
_$jscoverage['mongoose/connection.js'][265]++;
this.models[collection][name] = Model || model;
}
_$jscoverage['mongoose/connection.js'][259]++;
_$jscoverage['mongoose/connection.js'][268]++;
return this.models[collection][name];
});
_$jscoverage['mongoose/connection.js'][266]++;
_$jscoverage['mongoose/connection.js'][275]++;
module.exports = Connection;
_$jscoverage['mongoose/connection.js'].source = ["","/**"," * Module dependencies."," */","","var url = require('url')"," , utils = require('./utils')"," , EventEmitter = utils.EventEmitter"," , driver = global.MONGOOSE_DRIVER_PATH || './drivers/node-mongodb-native'"," , Model = require('./model')"," , Collection = require(driver + '/collection');","","/**"," * Connection constructor. For practical reasons, a Connection equals a Db"," *"," * @param {Mongoose} mongoose base"," * @api public"," */","","function Connection (base) {"," this.base = base;"," this.collections = {};"," this.models = {};","};","","/**"," * Inherit from EventEmitter."," *"," */","","Connection.prototype.__proto__ = EventEmitter.prototype;","","/**"," * Connection ready state:"," * 0 = Disconnected"," * 1 = Connected"," * 2 = Connecting"," * 3 = Disconnecting"," *"," * @api public"," */","","Connection.prototype.readyState = 0;","","/**"," * A hash of the collections associated with this connection"," *"," * @param text"," */","","Connection.prototype.collections;","","/**"," * The mongodb.Db instance, set when the connection is opened"," *"," * @api public"," */","","Connection.prototype.db;","","/**"," * Establishes the connection"," *"," * @param {String} mongodb://uri"," * @return {Connection} self"," * @api public"," */","","Connection.prototype.open = function (host, database, port, callback) {"," var self = this"," , uri;",""," // if we've been supplied an uri"," if (typeof database != 'string'){"," uri = url.parse(host);"," host = uri.hostname;"," port = uri.port || 27017;"," callback = database;"," database = uri.pathname.replace(/\\//g, '');"," } else {"," callback = callback || port;"," port = typeof port == 'number' ? port : 27017;"," }"," "," // make sure we can open"," if (this.readyState != 0){"," if ('function' == typeof callback)"," callback(new Error('Trying to open unclosed connection'));"," return this;"," }",""," // handle authentication"," if (uri && uri.auth){"," var auth = uri.auth.split(':');"," this.user = auth[0];"," this.pass = auth[1];"," } else "," this.user = this.pass = undefined;"," "," if (!host) {"," if ('function' == typeof callback)"," callback(new Error('Please provide a valid hostname.'));"," return this;"," }",""," if (!database) {"," if ('function' == typeof callback)"," callback(new Error('Please provide a database to connect to.'));"," return this;"," }",""," this.name = database;"," this.host = host;"," this.port = port;",""," // signal connecting"," this.readyState = 2;"," this.emit('opening');",""," // open connection"," this.doOpen(function(err){"," if (err) {"," if (typeof callback == 'function') callback(err);"," } else {"," self.onOpen();"," if (typeof callback == 'function') callback(null);"," }"," });",""," return this;","};","","/**"," * Called when the connection is opened"," *"," * @api private"," */","","Connection.prototype.onOpen = function () {"," this.readyState = 1;",""," // avoid having the collection subscribe to our event emitter"," // to prevent 0.3 warning"," for (var i in this.collections)"," this.collections[i].onOpen();",""," this.emit('open');","};","","/**"," * Closes the connection"," *"," * @param {Function} optional callback"," * @return {Connection} self"," * @api public"," */","","Connection.prototype.close = function (callback) {"," var self = this;",""," switch (this.readyState){"," case 0: // disconnected"," callback(null);"," break;",""," case 1: // connected "," this.readyState = 3;"," this.doClose(function(err){"," if (err){"," if (callback) callback(err);"," } else {"," self.onClose();"," if (callback) callback(null);"," }"," });"," break;",""," case 2: // connecting"," this.once('open', function(){"," self.close(callback);"," });"," break;",""," case 3: // disconnecting"," this.once('close', function () {"," callback(null);"," });"," break;"," }",""," return this;","};","","/**"," * Called when the connection closes"," *"," * @api private"," */","","Connection.prototype.onClose = function () {"," this.readyState = 0;"," "," // avoid having the collection subscribe to our event emitter"," // to prevent 0.3 warning"," for (var i in this.collections)"," this.collections[i].onClose();",""," this.emit('close');","};","","/**"," * Retrieves a collection, creating it if not cached."," *"," * @param {String} collection name"," * @return {Collection} collection instance"," * @api public"," */","","Connection.prototype.collection = function (name) {"," if (!(name in this.collections))"," this.collections[name] = new Collection(name, this);"," return this.collections[name];","};","","/**"," * Defines a model or retrieves it"," *"," * @param {String} model name"," * @param {Schema} schema object"," * @param {String} collection name (optional, induced from model name)"," * @api public"," */","","Connection.prototype.model = function (name, collection) {"," collection || (collection = utils.toCollectionName(name));"," // look up models for the collection"," if (!this.models[collection])"," this.models[collection] = {};",""," if (!this.models[collection][name]){"," var model = this.base.model(name, null, collection, true)"," , Model;"," "," if (model.prototype.connection != this){"," function Model (){"," model.apply(this, arguments);"," };",""," Model.__proto__ = model;"," Model.prototype.__proto__ = model.prototype;"," Model.prototype.db = this;"," Model.prototype.collection = this.collection(collection);"," Model.init();"," }",""," this.models[collection][name] = Model || model;"," }"," "," return this.models[collection][name];","};","","/**"," * Module exports."," */","","module.exports = Connection;"];
_$jscoverage['mongoose/connection.js'].source = ["","/**"," * Module dependencies."," */","","var url = require('url')"," , utils = require('./utils')"," , EventEmitter = utils.EventEmitter"," , driver = global.MONGOOSE_DRIVER_PATH || './drivers/node-mongodb-native'"," , Model = require('./model')"," , Collection = require(driver + '/collection');","","/**"," * Connection constructor. For practical reasons, a Connection equals a Db"," *"," * @param {Mongoose} mongoose base"," * @api public"," */","","function Connection (base) {"," this.base = base;"," this.collections = {};"," this.models = {};","};","","/**"," * Inherit from EventEmitter."," *"," */","","Connection.prototype.__proto__ = EventEmitter.prototype;","","/**"," * Connection ready state:"," * 0 = Disconnected"," * 1 = Connected"," * 2 = Connecting"," * 3 = Disconnecting"," *"," * @api public"," */","","Connection.prototype.readyState = 0;","","/**"," * A hash of the collections associated with this connection"," *"," * @param text"," */","","Connection.prototype.collections;","","/**"," * The mongodb.Db instance, set when the connection is opened"," *"," * @api public"," */","","Connection.prototype.db;","","/**"," * Establishes the connection"," *"," * @param {String} mongodb://uri"," * @return {Connection} self"," * @api public"," */","","Connection.prototype.open = function (host, database, port, callback) {"," var self = this"," , uri;",""," // if we've been supplied an uri"," if (typeof database != 'string'){"," uri = url.parse(host);"," host = uri.hostname;"," port = uri.port || 27017;"," callback = database;"," database = uri.pathname.replace(/\\//g, '');"," } else {"," callback = callback || port;"," port = typeof port == 'number' ? port : 27017;"," }"," "," // make sure we can open"," if (this.readyState != 0){"," if ('function' == typeof callback)"," callback(new Error('Trying to open unclosed connection'));"," return this;"," }",""," // handle authentication"," if (uri && uri.auth){"," var auth = uri.auth.split(':');"," this.user = auth[0];"," this.pass = auth[1];"," } else "," this.user = this.pass = undefined;"," "," if (!host) {"," if ('function' == typeof callback)"," callback(new Error('Please provide a valid hostname.'));"," return this;"," }",""," if (!database) {"," if ('function' == typeof callback)"," callback(new Error('Please provide a database to connect to.'));"," return this;"," }",""," this.name = database;"," this.host = host;"," this.port = port;",""," // signal connecting"," this.readyState = 2;"," this.emit('opening');",""," // open connection"," this.doOpen(function(err){"," if (err) {"," if (typeof callback == 'function') callback(err);"," } else {"," self.onOpen();"," if (typeof callback == 'function') callback(null);"," }"," });",""," return this;","};","","/**"," * Called when the connection is opened"," *"," * @api private"," */","","Connection.prototype.onOpen = function () {"," var self = this;"," "," var continuation = function(){"," self.readyState = 1;"," // avoid having the collection subscribe to our event emitter"," // to prevent 0.3 warning"," for (var i in self.collections)"," self.collections[i].onOpen();"," "," self.emit('open');"," };"," "," //do authentication before we continue if a database username and password exist"," if(self.user && self.pass)"," self.db.authenticate(self.user,self.pass,continuation);"," else "," continuation();","};","","/**"," * Closes the connection"," *"," * @param {Function} optional callback"," * @return {Connection} self"," * @api public"," */","","Connection.prototype.close = function (callback) {"," var self = this;",""," switch (this.readyState){"," case 0: // disconnected"," callback(null);"," break;",""," case 1: // connected "," this.readyState = 3;"," this.doClose(function(err){"," if (err){"," if (callback) callback(err);"," } else {"," self.onClose();"," if (callback) callback(null);"," }"," });"," break;",""," case 2: // connecting"," this.once('open', function(){"," self.close(callback);"," });"," break;",""," case 3: // disconnecting"," this.once('close', function () {"," callback(null);"," });"," break;"," }",""," return this;","};","","/**"," * Called when the connection closes"," *"," * @api private"," */","","Connection.prototype.onClose = function () {"," this.readyState = 0;"," "," // avoid having the collection subscribe to our event emitter"," // to prevent 0.3 warning"," for (var i in this.collections)"," this.collections[i].onClose();",""," this.emit('close');","};","","/**"," * Retrieves a collection, creating it if not cached."," *"," * @param {String} collection name"," * @return {Collection} collection instance"," * @api public"," */","","Connection.prototype.collection = function (name) {"," if (!(name in this.collections))"," this.collections[name] = new Collection(name, this);"," return this.collections[name];","};","","/**"," * Defines a model or retrieves it"," *"," * @param {String} model name"," * @param {Schema} schema object"," * @param {String} collection name (optional, induced from model name)"," * @api public"," */","","Connection.prototype.model = function (name, collection) {"," collection || (collection = utils.toCollectionName(name));"," // look up models for the collection"," if (!this.models[collection])"," this.models[collection] = {};",""," if (!this.models[collection][name]){"," var model = this.base.model(name, null, collection, true)"," , Model;"," "," if (model.prototype.connection != this){"," function Model (){"," model.apply(this, arguments);"," };",""," Model.__proto__ = model;"," Model.prototype.__proto__ = model.prototype;"," Model.prototype.db = this;"," Model.prototype.collection = this.collection(collection);"," Model.init();"," }",""," this.models[collection][name] = Model || model;"," }"," "," return this.models[collection][name];","};","","/**"," * Module exports."," */","","module.exports = Connection;"];

@@ -12,12 +12,13 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/document.js'][30] = 0;
_$jscoverage['mongoose/document.js'][31] = 0;
_$jscoverage['mongoose/document.js'][32] = 0;
_$jscoverage['mongoose/document.js'][33] = 0;
_$jscoverage['mongoose/document.js'][34] = 0;
_$jscoverage['mongoose/document.js'][40] = 0;
_$jscoverage['mongoose/document.js'][49] = 0;
_$jscoverage['mongoose/document.js'][57] = 0;
_$jscoverage['mongoose/document.js'][65] = 0;
_$jscoverage['mongoose/document.js'][73] = 0;
_$jscoverage['mongoose/document.js'][74] = 0;
_$jscoverage['mongoose/document.js'][35] = 0;
_$jscoverage['mongoose/document.js'][36] = 0;
_$jscoverage['mongoose/document.js'][37] = 0;
_$jscoverage['mongoose/document.js'][38] = 0;
_$jscoverage['mongoose/document.js'][44] = 0;
_$jscoverage['mongoose/document.js'][53] = 0;
_$jscoverage['mongoose/document.js'][61] = 0;
_$jscoverage['mongoose/document.js'][69] = 0;
_$jscoverage['mongoose/document.js'][77] = 0;

@@ -27,174 +28,174 @@ _$jscoverage['mongoose/document.js'][78] = 0;

_$jscoverage['mongoose/document.js'][82] = 0;
_$jscoverage['mongoose/document.js'][83] = 0;
_$jscoverage['mongoose/document.js'][85] = 0;
_$jscoverage['mongoose/document.js'][86] = 0;
_$jscoverage['mongoose/document.js'][87] = 0;
_$jscoverage['mongoose/document.js'][88] = 0;
_$jscoverage['mongoose/document.js'][89] = 0;
_$jscoverage['mongoose/document.js'][99] = 0;
_$jscoverage['mongoose/document.js'][100] = 0;
_$jscoverage['mongoose/document.js'][101] = 0;
_$jscoverage['mongoose/document.js'][103] = 0;
_$jscoverage['mongoose/document.js'][104] = 0;
_$jscoverage['mongoose/document.js'][90] = 0;
_$jscoverage['mongoose/document.js'][92] = 0;
_$jscoverage['mongoose/document.js'][96] = 0;
_$jscoverage['mongoose/document.js'][106] = 0;
_$jscoverage['mongoose/document.js'][107] = 0;
_$jscoverage['mongoose/document.js'][108] = 0;
_$jscoverage['mongoose/document.js'][110] = 0;
_$jscoverage['mongoose/document.js'][111] = 0;
_$jscoverage['mongoose/document.js'][112] = 0;
_$jscoverage['mongoose/document.js'][113] = 0;
_$jscoverage['mongoose/document.js'][114] = 0;
_$jscoverage['mongoose/document.js'][115] = 0;
_$jscoverage['mongoose/document.js'][117] = 0;
_$jscoverage['mongoose/document.js'][118] = 0;
_$jscoverage['mongoose/document.js'][119] = 0;
_$jscoverage['mongoose/document.js'][121] = 0;
_$jscoverage['mongoose/document.js'][122] = 0;
_$jscoverage['mongoose/document.js'][124] = 0;
_$jscoverage['mongoose/document.js'][125] = 0;
_$jscoverage['mongoose/document.js'][126] = 0;
_$jscoverage['mongoose/document.js'][129] = 0;
_$jscoverage['mongoose/document.js'][131] = 0;
_$jscoverage['mongoose/document.js'][133] = 0;
_$jscoverage['mongoose/document.js'][134] = 0;
_$jscoverage['mongoose/document.js'][136] = 0;
_$jscoverage['mongoose/document.js'][138] = 0;
_$jscoverage['mongoose/document.js'][149] = 0;
_$jscoverage['mongoose/document.js'][150] = 0;
_$jscoverage['mongoose/document.js'][151] = 0;
_$jscoverage['mongoose/document.js'][155] = 0;
_$jscoverage['mongoose/document.js'][140] = 0;
_$jscoverage['mongoose/document.js'][141] = 0;
_$jscoverage['mongoose/document.js'][143] = 0;
_$jscoverage['mongoose/document.js'][145] = 0;
_$jscoverage['mongoose/document.js'][156] = 0;
_$jscoverage['mongoose/document.js'][182] = 0;
_$jscoverage['mongoose/document.js'][183] = 0;
_$jscoverage['mongoose/document.js'][184] = 0;
_$jscoverage['mongoose/document.js'][185] = 0;
_$jscoverage['mongoose/document.js'][186] = 0;
_$jscoverage['mongoose/document.js'][157] = 0;
_$jscoverage['mongoose/document.js'][158] = 0;
_$jscoverage['mongoose/document.js'][162] = 0;
_$jscoverage['mongoose/document.js'][163] = 0;
_$jscoverage['mongoose/document.js'][189] = 0;
_$jscoverage['mongoose/document.js'][190] = 0;
_$jscoverage['mongoose/document.js'][191] = 0;
_$jscoverage['mongoose/document.js'][192] = 0;
_$jscoverage['mongoose/document.js'][193] = 0;
_$jscoverage['mongoose/document.js'][197] = 0;
_$jscoverage['mongoose/document.js'][202] = 0;
_$jscoverage['mongoose/document.js'][203] = 0;
_$jscoverage['mongoose/document.js'][198] = 0;
_$jscoverage['mongoose/document.js'][199] = 0;
_$jscoverage['mongoose/document.js'][204] = 0;
_$jscoverage['mongoose/document.js'][205] = 0;
_$jscoverage['mongoose/document.js'][208] = 0;
_$jscoverage['mongoose/document.js'][209] = 0;
_$jscoverage['mongoose/document.js'][210] = 0;
_$jscoverage['mongoose/document.js'][211] = 0;
_$jscoverage['mongoose/document.js'][212] = 0;
_$jscoverage['mongoose/document.js'][215] = 0;
_$jscoverage['mongoose/document.js'][216] = 0;
_$jscoverage['mongoose/document.js'][217] = 0;
_$jscoverage['mongoose/document.js'][219] = 0;
_$jscoverage['mongoose/document.js'][225] = 0;
_$jscoverage['mongoose/document.js'][228] = 0;
_$jscoverage['mongoose/document.js'][229] = 0;
_$jscoverage['mongoose/document.js'][239] = 0;
_$jscoverage['mongoose/document.js'][240] = 0;
_$jscoverage['mongoose/document.js'][243] = 0;
_$jscoverage['mongoose/document.js'][244] = 0;
_$jscoverage['mongoose/document.js'][245] = 0;
_$jscoverage['mongoose/document.js'][222] = 0;
_$jscoverage['mongoose/document.js'][223] = 0;
_$jscoverage['mongoose/document.js'][224] = 0;
_$jscoverage['mongoose/document.js'][226] = 0;
_$jscoverage['mongoose/document.js'][232] = 0;
_$jscoverage['mongoose/document.js'][235] = 0;
_$jscoverage['mongoose/document.js'][236] = 0;
_$jscoverage['mongoose/document.js'][246] = 0;
_$jscoverage['mongoose/document.js'][247] = 0;
_$jscoverage['mongoose/document.js'][258] = 0;
_$jscoverage['mongoose/document.js'][259] = 0;
_$jscoverage['mongoose/document.js'][262] = 0;
_$jscoverage['mongoose/document.js'][263] = 0;
_$jscoverage['mongoose/document.js'][250] = 0;
_$jscoverage['mongoose/document.js'][251] = 0;
_$jscoverage['mongoose/document.js'][252] = 0;
_$jscoverage['mongoose/document.js'][254] = 0;
_$jscoverage['mongoose/document.js'][265] = 0;
_$jscoverage['mongoose/document.js'][275] = 0;
_$jscoverage['mongoose/document.js'][276] = 0;
_$jscoverage['mongoose/document.js'][277] = 0;
_$jscoverage['mongoose/document.js'][278] = 0;
_$jscoverage['mongoose/document.js'][288] = 0;
_$jscoverage['mongoose/document.js'][289] = 0;
_$jscoverage['mongoose/document.js'][293] = 0;
_$jscoverage['mongoose/document.js'][294] = 0;
_$jscoverage['mongoose/document.js'][266] = 0;
_$jscoverage['mongoose/document.js'][269] = 0;
_$jscoverage['mongoose/document.js'][270] = 0;
_$jscoverage['mongoose/document.js'][272] = 0;
_$jscoverage['mongoose/document.js'][282] = 0;
_$jscoverage['mongoose/document.js'][283] = 0;
_$jscoverage['mongoose/document.js'][284] = 0;
_$jscoverage['mongoose/document.js'][285] = 0;
_$jscoverage['mongoose/document.js'][295] = 0;
_$jscoverage['mongoose/document.js'][297] = 0;
_$jscoverage['mongoose/document.js'][298] = 0;
_$jscoverage['mongoose/document.js'][296] = 0;
_$jscoverage['mongoose/document.js'][300] = 0;
_$jscoverage['mongoose/document.js'][301] = 0;
_$jscoverage['mongoose/document.js'][310] = 0;
_$jscoverage['mongoose/document.js'][312] = 0;
_$jscoverage['mongoose/document.js'][322] = 0;
_$jscoverage['mongoose/document.js'][323] = 0;
_$jscoverage['mongoose/document.js'][324] = 0;
_$jscoverage['mongoose/document.js'][325] = 0;
_$jscoverage['mongoose/document.js'][326] = 0;
_$jscoverage['mongoose/document.js'][328] = 0;
_$jscoverage['mongoose/document.js'][302] = 0;
_$jscoverage['mongoose/document.js'][304] = 0;
_$jscoverage['mongoose/document.js'][305] = 0;
_$jscoverage['mongoose/document.js'][308] = 0;
_$jscoverage['mongoose/document.js'][317] = 0;
_$jscoverage['mongoose/document.js'][319] = 0;
_$jscoverage['mongoose/document.js'][329] = 0;
_$jscoverage['mongoose/document.js'][330] = 0;
_$jscoverage['mongoose/document.js'][331] = 0;
_$jscoverage['mongoose/document.js'][340] = 0;
_$jscoverage['mongoose/document.js'][341] = 0;
_$jscoverage['mongoose/document.js'][350] = 0;
_$jscoverage['mongoose/document.js'][351] = 0;
_$jscoverage['mongoose/document.js'][361] = 0;
_$jscoverage['mongoose/document.js'][362] = 0;
_$jscoverage['mongoose/document.js'][367] = 0;
_$jscoverage['mongoose/document.js'][332] = 0;
_$jscoverage['mongoose/document.js'][333] = 0;
_$jscoverage['mongoose/document.js'][335] = 0;
_$jscoverage['mongoose/document.js'][336] = 0;
_$jscoverage['mongoose/document.js'][337] = 0;
_$jscoverage['mongoose/document.js'][338] = 0;
_$jscoverage['mongoose/document.js'][347] = 0;
_$jscoverage['mongoose/document.js'][348] = 0;
_$jscoverage['mongoose/document.js'][357] = 0;
_$jscoverage['mongoose/document.js'][358] = 0;
_$jscoverage['mongoose/document.js'][368] = 0;
_$jscoverage['mongoose/document.js'][369] = 0;
_$jscoverage['mongoose/document.js'][370] = 0;
_$jscoverage['mongoose/document.js'][371] = 0;
_$jscoverage['mongoose/document.js'][372] = 0;
_$jscoverage['mongoose/document.js'][373] = 0;
_$jscoverage['mongoose/document.js'][374] = 0;
_$jscoverage['mongoose/document.js'][375] = 0;
_$jscoverage['mongoose/document.js'][376] = 0;
_$jscoverage['mongoose/document.js'][377] = 0;
_$jscoverage['mongoose/document.js'][378] = 0;
_$jscoverage['mongoose/document.js'][379] = 0;
_$jscoverage['mongoose/document.js'][380] = 0;
_$jscoverage['mongoose/document.js'][381] = 0;
_$jscoverage['mongoose/document.js'][384] = 0;
_$jscoverage['mongoose/document.js'][382] = 0;
_$jscoverage['mongoose/document.js'][383] = 0;
_$jscoverage['mongoose/document.js'][385] = 0;
_$jscoverage['mongoose/document.js'][388] = 0;
_$jscoverage['mongoose/document.js'][398] = 0;
_$jscoverage['mongoose/document.js'][399] = 0;
_$jscoverage['mongoose/document.js'][408] = 0;
_$jscoverage['mongoose/document.js'][409] = 0;
_$jscoverage['mongoose/document.js'][410] = 0;
_$jscoverage['mongoose/document.js'][391] = 0;
_$jscoverage['mongoose/document.js'][392] = 0;
_$jscoverage['mongoose/document.js'][395] = 0;
_$jscoverage['mongoose/document.js'][405] = 0;
_$jscoverage['mongoose/document.js'][406] = 0;
_$jscoverage['mongoose/document.js'][415] = 0;
_$jscoverage['mongoose/document.js'][416] = 0;
_$jscoverage['mongoose/document.js'][417] = 0;
_$jscoverage['mongoose/document.js'][419] = 0;
_$jscoverage['mongoose/document.js'][420] = 0;
_$jscoverage['mongoose/document.js'][423] = 0;
_$jscoverage['mongoose/document.js'][425] = 0;
_$jscoverage['mongoose/document.js'][424] = 0;
_$jscoverage['mongoose/document.js'][426] = 0;
_$jscoverage['mongoose/document.js'][427] = 0;
_$jscoverage['mongoose/document.js'][429] = 0;
_$jscoverage['mongoose/document.js'][430] = 0;
_$jscoverage['mongoose/document.js'][431] = 0;
_$jscoverage['mongoose/document.js'][432] = 0;
_$jscoverage['mongoose/document.js'][433] = 0;
_$jscoverage['mongoose/document.js'][434] = 0;
_$jscoverage['mongoose/document.js'][436] = 0;
_$jscoverage['mongoose/document.js'][437] = 0;
_$jscoverage['mongoose/document.js'][438] = 0;
_$jscoverage['mongoose/document.js'][439] = 0;
_$jscoverage['mongoose/document.js'][440] = 0;
_$jscoverage['mongoose/document.js'][443] = 0;
_$jscoverage['mongoose/document.js'][444] = 0;
_$jscoverage['mongoose/document.js'][446] = 0;
_$jscoverage['mongoose/document.js'][447] = 0;
_$jscoverage['mongoose/document.js'][449] = 0;
_$jscoverage['mongoose/document.js'][450] = 0;
_$jscoverage['mongoose/document.js'][451] = 0;
_$jscoverage['mongoose/document.js'][460] = 0;
_$jscoverage['mongoose/document.js'][461] = 0;
_$jscoverage['mongoose/document.js'][470] = 0;
_$jscoverage['mongoose/document.js'][471] = 0;
_$jscoverage['mongoose/document.js'][473] = 0;
_$jscoverage['mongoose/document.js'][474] = 0;
_$jscoverage['mongoose/document.js'][475] = 0;
_$jscoverage['mongoose/document.js'][476] = 0;
_$jscoverage['mongoose/document.js'][454] = 0;
_$jscoverage['mongoose/document.js'][456] = 0;
_$jscoverage['mongoose/document.js'][457] = 0;
_$jscoverage['mongoose/document.js'][458] = 0;
_$jscoverage['mongoose/document.js'][467] = 0;
_$jscoverage['mongoose/document.js'][468] = 0;
_$jscoverage['mongoose/document.js'][477] = 0;
_$jscoverage['mongoose/document.js'][478] = 0;
_$jscoverage['mongoose/document.js'][480] = 0;
_$jscoverage['mongoose/document.js'][481] = 0;
_$jscoverage['mongoose/document.js'][482] = 0;
_$jscoverage['mongoose/document.js'][483] = 0;
_$jscoverage['mongoose/document.js'][495] = 0;
_$jscoverage['mongoose/document.js'][496] = 0;
_$jscoverage['mongoose/document.js'][497] = 0;
_$jscoverage['mongoose/document.js'][506] = 0;
_$jscoverage['mongoose/document.js'][507] = 0;
_$jscoverage['mongoose/document.js'][508] = 0;
_$jscoverage['mongoose/document.js'][509] = 0;
_$jscoverage['mongoose/document.js'][510] = 0;
_$jscoverage['mongoose/document.js'][521] = 0;
_$jscoverage['mongoose/document.js'][522] = 0;
_$jscoverage['mongoose/document.js'][532] = 0;
_$jscoverage['mongoose/document.js'][533] = 0;
_$jscoverage['mongoose/document.js'][542] = 0;
_$jscoverage['mongoose/document.js'][543] = 0;
_$jscoverage['mongoose/document.js'][553] = 0;
_$jscoverage['mongoose/document.js'][555] = 0;
_$jscoverage['mongoose/document.js'][556] = 0;
_$jscoverage['mongoose/document.js'][557] = 0;
_$jscoverage['mongoose/document.js'][558] = 0;
_$jscoverage['mongoose/document.js'][559] = 0;
_$jscoverage['mongoose/document.js'][562] = 0;
_$jscoverage['mongoose/document.js'][485] = 0;
_$jscoverage['mongoose/document.js'][489] = 0;
_$jscoverage['mongoose/document.js'][490] = 0;
_$jscoverage['mongoose/document.js'][502] = 0;
_$jscoverage['mongoose/document.js'][503] = 0;
_$jscoverage['mongoose/document.js'][504] = 0;
_$jscoverage['mongoose/document.js'][513] = 0;
_$jscoverage['mongoose/document.js'][514] = 0;
_$jscoverage['mongoose/document.js'][515] = 0;
_$jscoverage['mongoose/document.js'][516] = 0;
_$jscoverage['mongoose/document.js'][517] = 0;
_$jscoverage['mongoose/document.js'][529] = 0;
_$jscoverage['mongoose/document.js'][530] = 0;
_$jscoverage['mongoose/document.js'][540] = 0;
_$jscoverage['mongoose/document.js'][541] = 0;
_$jscoverage['mongoose/document.js'][550] = 0;
_$jscoverage['mongoose/document.js'][551] = 0;
_$jscoverage['mongoose/document.js'][561] = 0;
_$jscoverage['mongoose/document.js'][563] = 0;
_$jscoverage['mongoose/document.js'][564] = 0;
_$jscoverage['mongoose/document.js'][565] = 0;
_$jscoverage['mongoose/document.js'][566] = 0;
_$jscoverage['mongoose/document.js'][567] = 0;
_$jscoverage['mongoose/document.js'][568] = 0;
_$jscoverage['mongoose/document.js'][570] = 0;
_$jscoverage['mongoose/document.js'][571] = 0;
_$jscoverage['mongoose/document.js'][572] = 0;

@@ -206,7 +207,7 @@ _$jscoverage['mongoose/document.js'][573] = 0;

_$jscoverage['mongoose/document.js'][580] = 0;
_$jscoverage['mongoose/document.js'][581] = 0;
_$jscoverage['mongoose/document.js'][583] = 0;
_$jscoverage['mongoose/document.js'][584] = 0;
_$jscoverage['mongoose/document.js'][586] = 0;
_$jscoverage['mongoose/document.js'][587] = 0;
_$jscoverage['mongoose/document.js'][588] = 0;
_$jscoverage['mongoose/document.js'][591] = 0;
_$jscoverage['mongoose/document.js'][592] = 0;

@@ -216,5 +217,4 @@ _$jscoverage['mongoose/document.js'][594] = 0;

_$jscoverage['mongoose/document.js'][596] = 0;
_$jscoverage['mongoose/document.js'][597] = 0;
_$jscoverage['mongoose/document.js'][599] = 0;
_$jscoverage['mongoose/document.js'][600] = 0;
_$jscoverage['mongoose/document.js'][601] = 0;
_$jscoverage['mongoose/document.js'][602] = 0;

@@ -224,14 +224,20 @@ _$jscoverage['mongoose/document.js'][603] = 0;

_$jscoverage['mongoose/document.js'][605] = 0;
_$jscoverage['mongoose/document.js'][606] = 0;
_$jscoverage['mongoose/document.js'][607] = 0;
_$jscoverage['mongoose/document.js'][608] = 0;
_$jscoverage['mongoose/document.js'][609] = 0;
_$jscoverage['mongoose/document.js'][610] = 0;
_$jscoverage['mongoose/document.js'][611] = 0;
_$jscoverage['mongoose/document.js'][612] = 0;
_$jscoverage['mongoose/document.js'][613] = 0;
_$jscoverage['mongoose/document.js'][624] = 0;
_$jscoverage['mongoose/document.js'][614] = 0;
_$jscoverage['mongoose/document.js'][615] = 0;
_$jscoverage['mongoose/document.js'][617] = 0;
_$jscoverage['mongoose/document.js'][621] = 0;
_$jscoverage['mongoose/document.js'][632] = 0;
_$jscoverage['mongoose/document.js'][633] = 0;
_$jscoverage['mongoose/document.js'][634] = 0;
_$jscoverage['mongoose/document.js'][635] = 0;
_$jscoverage['mongoose/document.js'][636] = 0;
_$jscoverage['mongoose/document.js'][640] = 0;
_$jscoverage['mongoose/document.js'][641] = 0;
_$jscoverage['mongoose/document.js'][642] = 0;
_$jscoverage['mongoose/document.js'][643] = 0;
_$jscoverage['mongoose/document.js'][644] = 0;
_$jscoverage['mongoose/document.js'][650] = 0;
_$jscoverage['mongoose/document.js'][652] = 0;
}

@@ -247,44 +253,58 @@ _$jscoverage['mongoose/document.js'][6]++;

_$jscoverage['mongoose/document.js'][28]++;
var self = this;
_$jscoverage['mongoose/document.js'][29]++;
this.schema.requiredPaths.forEach((function (path) {
_$jscoverage['mongoose/document.js'][30]++;
self.activePaths.require(path);
}));
_$jscoverage['mongoose/document.js'][32]++;
this.saveError = null;
_$jscoverage['mongoose/document.js'][29]++;
_$jscoverage['mongoose/document.js'][33]++;
if (obj) {
_$jscoverage['mongoose/document.js'][29]++;
_$jscoverage['mongoose/document.js'][33]++;
this.set(obj);
}
_$jscoverage['mongoose/document.js'][30]++;
_$jscoverage['mongoose/document.js'][34]++;
this.pres = {};
_$jscoverage['mongoose/document.js'][31]++;
_$jscoverage['mongoose/document.js'][35]++;
this.registerHooks();
_$jscoverage['mongoose/document.js'][32]++;
_$jscoverage['mongoose/document.js'][36]++;
this.doQueue();
_$jscoverage['mongoose/document.js'][33]++;
_$jscoverage['mongoose/document.js'][37]++;
this.isNew = true;
}
_$jscoverage['mongoose/document.js'][34]++;
_$jscoverage['mongoose/document.js'][38]++;
;
_$jscoverage['mongoose/document.js'][40]++;
_$jscoverage['mongoose/document.js'][44]++;
Document.prototype.__proto__ = EventEmitter.prototype;
_$jscoverage['mongoose/document.js'][49]++;
_$jscoverage['mongoose/document.js'][53]++;
Document.prototype.base;
_$jscoverage['mongoose/document.js'][57]++;
_$jscoverage['mongoose/document.js'][61]++;
Document.prototype.schema;
_$jscoverage['mongoose/document.js'][65]++;
_$jscoverage['mongoose/document.js'][69]++;
Document.prototype.isNew;
_$jscoverage['mongoose/document.js'][73]++;
_$jscoverage['mongoose/document.js'][77]++;
Document.prototype.buildDoc = (function () {
_$jscoverage['mongoose/document.js'][74]++;
_$jscoverage['mongoose/document.js'][78]++;
var doc = {}, self = this;
_$jscoverage['mongoose/document.js'][77]++;
_$jscoverage['mongoose/document.js'][81]++;
this.schema.eachPath((function (i, type) {
_$jscoverage['mongoose/document.js'][78]++;
_$jscoverage['mongoose/document.js'][82]++;
var path = i.split("."), len = path.length;
_$jscoverage['mongoose/document.js'][81]++;
_$jscoverage['mongoose/document.js'][85]++;
path.reduce((function (ref, piece, i) {
_$jscoverage['mongoose/document.js'][82]++;
_$jscoverage['mongoose/document.js'][86]++;
var _default;
_$jscoverage['mongoose/document.js'][87]++;
if (i === len - 1) {
_$jscoverage['mongoose/document.js'][83]++;
ref[piece] = type.getDefault(self);
_$jscoverage['mongoose/document.js'][88]++;
_default = type.getDefault(self);
_$jscoverage['mongoose/document.js'][89]++;
if ("undefined" !== typeof _default) {
_$jscoverage['mongoose/document.js'][90]++;
ref[piece] = _default;
}
}
else {
_$jscoverage['mongoose/document.js'][85]++;
_$jscoverage['mongoose/document.js'][92]++;
return ref[piece] || (ref[piece] = {});

@@ -294,36 +314,36 @@ }

}));
_$jscoverage['mongoose/document.js'][89]++;
_$jscoverage['mongoose/document.js'][96]++;
return doc;
});
_$jscoverage['mongoose/document.js'][99]++;
_$jscoverage['mongoose/document.js'][106]++;
Document.prototype.init = (function (doc, fn) {
_$jscoverage['mongoose/document.js'][100]++;
_$jscoverage['mongoose/document.js'][107]++;
var self = this;
_$jscoverage['mongoose/document.js'][101]++;
_$jscoverage['mongoose/document.js'][108]++;
this.isNew = false;
_$jscoverage['mongoose/document.js'][103]++;
_$jscoverage['mongoose/document.js'][110]++;
function init(obj, doc, prefix) {
_$jscoverage['mongoose/document.js'][104]++;
_$jscoverage['mongoose/document.js'][111]++;
prefix = prefix || "";
_$jscoverage['mongoose/document.js'][106]++;
_$jscoverage['mongoose/document.js'][113]++;
for (var i in obj) {
_$jscoverage['mongoose/document.js'][107]++;
_$jscoverage['mongoose/document.js'][114]++;
var path = prefix + i, schema = self.schema.path(path);
_$jscoverage['mongoose/document.js'][110]++;
_$jscoverage['mongoose/document.js'][117]++;
if (! schema && obj[i].constructor == Object) {
_$jscoverage['mongoose/document.js'][111]++;
_$jscoverage['mongoose/document.js'][118]++;
doc[i] = {};
_$jscoverage['mongoose/document.js'][112]++;
_$jscoverage['mongoose/document.js'][119]++;
init(obj[i], doc[i], path + ".");
}
else {
_$jscoverage['mongoose/document.js'][114]++;
_$jscoverage['mongoose/document.js'][121]++;
if (obj[i] !== null && obj[i] !== undefined) {
_$jscoverage['mongoose/document.js'][115]++;
_$jscoverage['mongoose/document.js'][122]++;
var schema = self.schema.path(path);
_$jscoverage['mongoose/document.js'][117]++;
_$jscoverage['mongoose/document.js'][124]++;
if (schema) {
_$jscoverage['mongoose/document.js'][118]++;
_$jscoverage['mongoose/document.js'][125]++;
self["try"]((function () {
_$jscoverage['mongoose/document.js'][119]++;
_$jscoverage['mongoose/document.js'][126]++;
doc[i] = schema.cast(obj[i], self);

@@ -333,7 +353,7 @@ }));

else {
_$jscoverage['mongoose/document.js'][122]++;
_$jscoverage['mongoose/document.js'][129]++;
doc[i] = obj[i];
}
}
_$jscoverage['mongoose/document.js'][126]++;
_$jscoverage['mongoose/document.js'][133]++;
self.activePaths.init(path);

@@ -343,45 +363,45 @@ }

}
_$jscoverage['mongoose/document.js'][129]++;
_$jscoverage['mongoose/document.js'][136]++;
;
_$jscoverage['mongoose/document.js'][131]++;
_$jscoverage['mongoose/document.js'][138]++;
init(doc, self.doc);
_$jscoverage['mongoose/document.js'][133]++;
_$jscoverage['mongoose/document.js'][140]++;
if (fn) {
_$jscoverage['mongoose/document.js'][134]++;
_$jscoverage['mongoose/document.js'][141]++;
fn(null);
}
_$jscoverage['mongoose/document.js'][136]++;
_$jscoverage['mongoose/document.js'][143]++;
this.emit("init");
_$jscoverage['mongoose/document.js'][138]++;
_$jscoverage['mongoose/document.js'][145]++;
return this;
});
_$jscoverage['mongoose/document.js'][149]++;
_$jscoverage['mongoose/document.js'][156]++;
Document.prototype.pre = (function (method, fn) {
_$jscoverage['mongoose/document.js'][150]++;
_$jscoverage['mongoose/document.js'][157]++;
if (! (method in this.pres)) {
_$jscoverage['mongoose/document.js'][151]++;
_$jscoverage['mongoose/document.js'][158]++;
this.pres[method] = {serial: [], parallel: []};
}
_$jscoverage['mongoose/document.js'][155]++;
_$jscoverage['mongoose/document.js'][162]++;
this.pres[method][fn.length == 1? "serial": "parallel"].push(fn);
_$jscoverage['mongoose/document.js'][156]++;
_$jscoverage['mongoose/document.js'][163]++;
return this;
});
_$jscoverage['mongoose/document.js'][182]++;
_$jscoverage['mongoose/document.js'][189]++;
Document.prototype.set = (function (path, val) {
_$jscoverage['mongoose/document.js'][183]++;
_$jscoverage['mongoose/document.js'][190]++;
if (typeof path != "string") {
_$jscoverage['mongoose/document.js'][184]++;
_$jscoverage['mongoose/document.js'][191]++;
var prefix = val? val + ".": "";
_$jscoverage['mongoose/document.js'][185]++;
_$jscoverage['mongoose/document.js'][192]++;
for (var i in path) {
_$jscoverage['mongoose/document.js'][186]++;
_$jscoverage['mongoose/document.js'][193]++;
if (! (this.schema.path(prefix + i) instanceof MixedSchema) && "undefined" !== typeof path[i] && path[i] !== null && path[i].constructor == Object) {
_$jscoverage['mongoose/document.js'][190]++;
_$jscoverage['mongoose/document.js'][197]++;
this.set(path[i], prefix + i);
}
else {
_$jscoverage['mongoose/document.js'][191]++;
_$jscoverage['mongoose/document.js'][198]++;
if ("undefined" !== typeof path[i]) {
_$jscoverage['mongoose/document.js'][192]++;
_$jscoverage['mongoose/document.js'][199]++;
this.set(prefix + i, path[i]);

@@ -393,29 +413,29 @@ }

else {
_$jscoverage['mongoose/document.js'][197]++;
_$jscoverage['mongoose/document.js'][204]++;
var schema = this.schema.path(path), parts = path.split("."), obj = this.doc, self = this;
_$jscoverage['mongoose/document.js'][202]++;
_$jscoverage['mongoose/document.js'][209]++;
if (this.schema.pathType(path) === "virtual") {
_$jscoverage['mongoose/document.js'][203]++;
_$jscoverage['mongoose/document.js'][210]++;
schema = this.schema.virtualpath(path);
_$jscoverage['mongoose/document.js'][204]++;
_$jscoverage['mongoose/document.js'][211]++;
schema.applySetters(val, this);
_$jscoverage['mongoose/document.js'][205]++;
_$jscoverage['mongoose/document.js'][212]++;
return this;
}
_$jscoverage['mongoose/document.js'][208]++;
_$jscoverage['mongoose/document.js'][215]++;
this.activePaths.modify(path);
_$jscoverage['mongoose/document.js'][210]++;
_$jscoverage['mongoose/document.js'][217]++;
if ((! schema || val === null || val === undefined) || this["try"]((function () {
_$jscoverage['mongoose/document.js'][212]++;
_$jscoverage['mongoose/document.js'][219]++;
val = schema.applySetters(schema.cast(val, self), self);
}))) {
_$jscoverage['mongoose/document.js'][215]++;
_$jscoverage['mongoose/document.js'][222]++;
for (var i = 0, l = parts.length; i < l; i++) {
_$jscoverage['mongoose/document.js'][216]++;
_$jscoverage['mongoose/document.js'][223]++;
if (i + 1 == l) {
_$jscoverage['mongoose/document.js'][217]++;
_$jscoverage['mongoose/document.js'][224]++;
obj[parts[i]] = val;
}
else {
_$jscoverage['mongoose/document.js'][219]++;
_$jscoverage['mongoose/document.js'][226]++;
obj = obj[parts[i]];

@@ -426,195 +446,195 @@ }

}
_$jscoverage['mongoose/document.js'][225]++;
_$jscoverage['mongoose/document.js'][232]++;
return this;
});
_$jscoverage['mongoose/document.js'][228]++;
_$jscoverage['mongoose/document.js'][235]++;
Document.prototype._markModified = (function (path) {
_$jscoverage['mongoose/document.js'][229]++;
_$jscoverage['mongoose/document.js'][236]++;
this.activePaths.modify(path);
});
_$jscoverage['mongoose/document.js'][239]++;
_$jscoverage['mongoose/document.js'][246]++;
Document.prototype.getValue = (function (path) {
_$jscoverage['mongoose/document.js'][240]++;
_$jscoverage['mongoose/document.js'][247]++;
var parts = path.split("."), obj = this.doc;
_$jscoverage['mongoose/document.js'][243]++;
_$jscoverage['mongoose/document.js'][250]++;
for (var i = 0, l = parts.length; i < l - 1; i++) {
_$jscoverage['mongoose/document.js'][244]++;
_$jscoverage['mongoose/document.js'][251]++;
obj = obj[parts[i]];
_$jscoverage['mongoose/document.js'][245]++;
_$jscoverage['mongoose/document.js'][252]++;
if (! obj) {
_$jscoverage['mongoose/document.js'][245]++;
_$jscoverage['mongoose/document.js'][252]++;
return obj;
}
}
_$jscoverage['mongoose/document.js'][247]++;
_$jscoverage['mongoose/document.js'][254]++;
return obj[parts[l - 1]];
});
_$jscoverage['mongoose/document.js'][258]++;
_$jscoverage['mongoose/document.js'][265]++;
Document.prototype.setValue = (function (path, val) {
_$jscoverage['mongoose/document.js'][259]++;
_$jscoverage['mongoose/document.js'][266]++;
var parts = path.split("."), obj = this.doc;
_$jscoverage['mongoose/document.js'][262]++;
_$jscoverage['mongoose/document.js'][269]++;
for (var i = 0, l = parts.length; i < l - 1; i++) {
_$jscoverage['mongoose/document.js'][262]++;
_$jscoverage['mongoose/document.js'][269]++;
obj = obj[parts[i]];
}
_$jscoverage['mongoose/document.js'][263]++;
_$jscoverage['mongoose/document.js'][270]++;
obj[parts[l - 1]] = val;
_$jscoverage['mongoose/document.js'][265]++;
_$jscoverage['mongoose/document.js'][272]++;
return this;
});
_$jscoverage['mongoose/document.js'][275]++;
_$jscoverage['mongoose/document.js'][282]++;
Document.prototype.doCast = (function (path) {
_$jscoverage['mongoose/document.js'][276]++;
_$jscoverage['mongoose/document.js'][283]++;
var schema = this.schema.path(path);
_$jscoverage['mongoose/document.js'][277]++;
_$jscoverage['mongoose/document.js'][284]++;
if (schema) {
_$jscoverage['mongoose/document.js'][278]++;
_$jscoverage['mongoose/document.js'][285]++;
this.setValue(path, this.getValue(path));
}
});
_$jscoverage['mongoose/document.js'][288]++;
_$jscoverage['mongoose/document.js'][295]++;
Document.prototype.get = (function (path) {
_$jscoverage['mongoose/document.js'][289]++;
_$jscoverage['mongoose/document.js'][296]++;
var obj, schema = this.schema.path(path) || this.schema.virtualpath(path), pieces = path.split(".");
_$jscoverage['mongoose/document.js'][293]++;
_$jscoverage['mongoose/document.js'][300]++;
obj = this.doc;
_$jscoverage['mongoose/document.js'][294]++;
_$jscoverage['mongoose/document.js'][301]++;
for (var i = 0, l = pieces.length; i < l; i++) {
_$jscoverage['mongoose/document.js'][295]++;
_$jscoverage['mongoose/document.js'][302]++;
obj = obj[pieces[i]];
}
_$jscoverage['mongoose/document.js'][297]++;
_$jscoverage['mongoose/document.js'][304]++;
if (schema) {
_$jscoverage['mongoose/document.js'][298]++;
_$jscoverage['mongoose/document.js'][305]++;
obj = schema.applyGetters(obj, this);
}
_$jscoverage['mongoose/document.js'][301]++;
_$jscoverage['mongoose/document.js'][308]++;
return obj;
});
_$jscoverage['mongoose/document.js'][310]++;
_$jscoverage['mongoose/document.js'][317]++;
Document.prototype.commit = (function (path) {
_$jscoverage['mongoose/document.js'][312]++;
_$jscoverage['mongoose/document.js'][319]++;
this.activePaths.modify(path);
});
_$jscoverage['mongoose/document.js'][322]++;
_$jscoverage['mongoose/document.js'][329]++;
Document.prototype["try"] = (function (fn, scope) {
_$jscoverage['mongoose/document.js'][323]++;
_$jscoverage['mongoose/document.js'][330]++;
var res;
_$jscoverage['mongoose/document.js'][324]++;
_$jscoverage['mongoose/document.js'][331]++;
try {
_$jscoverage['mongoose/document.js'][325]++;
_$jscoverage['mongoose/document.js'][332]++;
fn.call(scope);
_$jscoverage['mongoose/document.js'][326]++;
_$jscoverage['mongoose/document.js'][333]++;
res = true;
}
catch (e) {
_$jscoverage['mongoose/document.js'][328]++;
_$jscoverage['mongoose/document.js'][335]++;
this.error(e);
_$jscoverage['mongoose/document.js'][329]++;
_$jscoverage['mongoose/document.js'][336]++;
res = false;
}
_$jscoverage['mongoose/document.js'][330]++;
_$jscoverage['mongoose/document.js'][337]++;
;
_$jscoverage['mongoose/document.js'][331]++;
_$jscoverage['mongoose/document.js'][338]++;
return res;
});
_$jscoverage['mongoose/document.js'][340]++;
_$jscoverage['mongoose/document.js'][347]++;
Document.prototype.isModified = (function (path) {
_$jscoverage['mongoose/document.js'][341]++;
_$jscoverage['mongoose/document.js'][348]++;
return (path in this.activePaths.states.modify);
});
_$jscoverage['mongoose/document.js'][350]++;
_$jscoverage['mongoose/document.js'][357]++;
Document.prototype.isInit = (function (path) {
_$jscoverage['mongoose/document.js'][351]++;
_$jscoverage['mongoose/document.js'][358]++;
return (path in this.activePaths.states.init);
});
_$jscoverage['mongoose/document.js'][361]++;
_$jscoverage['mongoose/document.js'][368]++;
Document.prototype.validate = (function (next) {
_$jscoverage['mongoose/document.js'][362]++;
_$jscoverage['mongoose/document.js'][369]++;
var total = 0, self = this, validating = {}, didErr = false;
_$jscoverage['mongoose/document.js'][367]++;
if (! this.activePaths.some("init", "modify")) {
_$jscoverage['mongoose/document.js'][367]++;
_$jscoverage['mongoose/document.js'][374]++;
if (! this.activePaths.some("require", "init", "modify")) {
_$jscoverage['mongoose/document.js'][374]++;
return next();
}
_$jscoverage['mongoose/document.js'][369]++;
_$jscoverage['mongoose/document.js'][376]++;
function validatePath(path) {
_$jscoverage['mongoose/document.js'][370]++;
_$jscoverage['mongoose/document.js'][377]++;
if (validating[path]) {
_$jscoverage['mongoose/document.js'][370]++;
_$jscoverage['mongoose/document.js'][377]++;
return;
}
_$jscoverage['mongoose/document.js'][371]++;
_$jscoverage['mongoose/document.js'][378]++;
total++;
_$jscoverage['mongoose/document.js'][372]++;
_$jscoverage['mongoose/document.js'][379]++;
process.nextTick((function () {
_$jscoverage['mongoose/document.js'][373]++;
_$jscoverage['mongoose/document.js'][380]++;
self.schema.path(path).doValidate(self.getValue(path), (function (err) {
_$jscoverage['mongoose/document.js'][374]++;
_$jscoverage['mongoose/document.js'][381]++;
if (err) {
_$jscoverage['mongoose/document.js'][375]++;
_$jscoverage['mongoose/document.js'][382]++;
didErr = true;
_$jscoverage['mongoose/document.js'][376]++;
_$jscoverage['mongoose/document.js'][383]++;
return next(err);
}
_$jscoverage['mongoose/document.js'][378]++;
_$jscoverage['mongoose/document.js'][385]++;
--total || next();
}), self);
}));
_$jscoverage['mongoose/document.js'][381]++;
_$jscoverage['mongoose/document.js'][388]++;
validating[path] = true;
}
_$jscoverage['mongoose/document.js'][384]++;
this.activePaths.forEach("init", "modify", (function (path) {
_$jscoverage['mongoose/document.js'][385]++;
_$jscoverage['mongoose/document.js'][391]++;
this.activePaths.forEach("require", "init", "modify", (function (path) {
_$jscoverage['mongoose/document.js'][392]++;
if (! didErr) {
_$jscoverage['mongoose/document.js'][385]++;
_$jscoverage['mongoose/document.js'][392]++;
validatePath(path);
}
}));
_$jscoverage['mongoose/document.js'][388]++;
_$jscoverage['mongoose/document.js'][395]++;
return this;
});
_$jscoverage['mongoose/document.js'][398]++;
_$jscoverage['mongoose/document.js'][405]++;
Document.prototype.__defineGetter__("modified", (function () {
_$jscoverage['mongoose/document.js'][399]++;
_$jscoverage['mongoose/document.js'][406]++;
return this.activePaths.some("modified");
}));
_$jscoverage['mongoose/document.js'][408]++;
_$jscoverage['mongoose/document.js'][415]++;
function compile(tree, proto, prefix) {
_$jscoverage['mongoose/document.js'][409]++;
_$jscoverage['mongoose/document.js'][416]++;
for (var i in tree) {
_$jscoverage['mongoose/document.js'][410]++;
_$jscoverage['mongoose/document.js'][417]++;
define(i, ((tree[i].constructor == Object && Object.keys(tree[i]).length) && (! tree[i].type || tree[i].__nested)? tree[i]: null), proto, prefix);
}
}
_$jscoverage['mongoose/document.js'][417]++;
_$jscoverage['mongoose/document.js'][424]++;
;
_$jscoverage['mongoose/document.js'][419]++;
_$jscoverage['mongoose/document.js'][426]++;
function define(prop, subprops, prototype, prefix) {
_$jscoverage['mongoose/document.js'][420]++;
_$jscoverage['mongoose/document.js'][427]++;
var prefix = prefix || "", path = (prefix? prefix + ".": "") + prop;
_$jscoverage['mongoose/document.js'][423]++;
_$jscoverage['mongoose/document.js'][430]++;
if (subprops) {
_$jscoverage['mongoose/document.js'][425]++;
_$jscoverage['mongoose/document.js'][432]++;
prototype.__defineGetter__(prop, (function () {
_$jscoverage['mongoose/document.js'][426]++;
_$jscoverage['mongoose/document.js'][433]++;
if (! this.__getters) {
_$jscoverage['mongoose/document.js'][427]++;
_$jscoverage['mongoose/document.js'][434]++;
this.__getters = {};
}
_$jscoverage['mongoose/document.js'][429]++;
_$jscoverage['mongoose/document.js'][436]++;
if (! this.__getters[path]) {
_$jscoverage['mongoose/document.js'][430]++;
_$jscoverage['mongoose/document.js'][437]++;
var nested = (function () {
});
_$jscoverage['mongoose/document.js'][431]++;
nested.prototype = this;
_$jscoverage['mongoose/document.js'][432]++;
_$jscoverage['mongoose/document.js'][438]++;
nested.prototype.__proto__ = this;
_$jscoverage['mongoose/document.js'][439]++;
compile(subprops, nested.prototype, path);
_$jscoverage['mongoose/document.js'][433]++;
_$jscoverage['mongoose/document.js'][440]++;
this.__getters[path] = new nested();
}
_$jscoverage['mongoose/document.js'][436]++;
_$jscoverage['mongoose/document.js'][443]++;
return this.__getters[path];

@@ -624,10 +644,10 @@ }));

else {
_$jscoverage['mongoose/document.js'][439]++;
_$jscoverage['mongoose/document.js'][446]++;
prototype.__defineGetter__(prop, (function () {
_$jscoverage['mongoose/document.js'][440]++;
_$jscoverage['mongoose/document.js'][447]++;
return this.get(path);
}));
_$jscoverage['mongoose/document.js'][443]++;
_$jscoverage['mongoose/document.js'][450]++;
prototype.__defineSetter__(prop, (function (v) {
_$jscoverage['mongoose/document.js'][444]++;
_$jscoverage['mongoose/document.js'][451]++;
return this.set(path, v);

@@ -637,186 +657,186 @@ }));

}
_$jscoverage['mongoose/document.js'][447]++;
_$jscoverage['mongoose/document.js'][454]++;
;
_$jscoverage['mongoose/document.js'][449]++;
_$jscoverage['mongoose/document.js'][456]++;
Document.prototype.__defineSetter__("schema", (function (schema) {
_$jscoverage['mongoose/document.js'][450]++;
_$jscoverage['mongoose/document.js'][457]++;
compile(schema.tree, this);
_$jscoverage['mongoose/document.js'][451]++;
_$jscoverage['mongoose/document.js'][458]++;
this._schema = schema;
}));
_$jscoverage['mongoose/document.js'][460]++;
_$jscoverage['mongoose/document.js'][467]++;
Document.prototype.__defineGetter__("schema", (function () {
_$jscoverage['mongoose/document.js'][461]++;
_$jscoverage['mongoose/document.js'][468]++;
return this._schema;
}));
_$jscoverage['mongoose/document.js'][470]++;
_$jscoverage['mongoose/document.js'][477]++;
Document.prototype.registerHooks = (function () {
_$jscoverage['mongoose/document.js'][471]++;
_$jscoverage['mongoose/document.js'][478]++;
var self = this;
_$jscoverage['mongoose/document.js'][473]++;
_$jscoverage['mongoose/document.js'][480]++;
this.pre("save", (function checkForExistingErrors(next) {
_$jscoverage['mongoose/document.js'][474]++;
_$jscoverage['mongoose/document.js'][481]++;
if (self.saveError) {
_$jscoverage['mongoose/document.js'][475]++;
_$jscoverage['mongoose/document.js'][482]++;
next(self.saveError);
_$jscoverage['mongoose/document.js'][476]++;
_$jscoverage['mongoose/document.js'][483]++;
self.saveError = null;
}
else {
_$jscoverage['mongoose/document.js'][478]++;
_$jscoverage['mongoose/document.js'][485]++;
next();
}
}));
_$jscoverage['mongoose/document.js'][482]++;
_$jscoverage['mongoose/document.js'][489]++;
this.pre("save", (function validation(next) {
_$jscoverage['mongoose/document.js'][483]++;
_$jscoverage['mongoose/document.js'][490]++;
return self.validate.call(self, next);
}));
});
_$jscoverage['mongoose/document.js'][495]++;
_$jscoverage['mongoose/document.js'][502]++;
Document.prototype.error = (function (err) {
_$jscoverage['mongoose/document.js'][496]++;
_$jscoverage['mongoose/document.js'][503]++;
this.saveError = err;
_$jscoverage['mongoose/document.js'][497]++;
_$jscoverage['mongoose/document.js'][504]++;
return this;
});
_$jscoverage['mongoose/document.js'][506]++;
_$jscoverage['mongoose/document.js'][513]++;
Document.prototype.doQueue = (function () {
_$jscoverage['mongoose/document.js'][507]++;
_$jscoverage['mongoose/document.js'][514]++;
if (this.schema && this.schema.callQueue) {
_$jscoverage['mongoose/document.js'][508]++;
_$jscoverage['mongoose/document.js'][515]++;
for (var i = 0, l = this.schema.callQueue.length; i < l; i++) {
_$jscoverage['mongoose/document.js'][509]++;
_$jscoverage['mongoose/document.js'][516]++;
this[this.schema.callQueue[i][0]].apply(this, this.schema.callQueue[i][1]);
}
}
_$jscoverage['mongoose/document.js'][510]++;
_$jscoverage['mongoose/document.js'][517]++;
return this;
});
_$jscoverage['mongoose/document.js'][521]++;
_$jscoverage['mongoose/document.js'][529]++;
Document.prototype.toObject = (function () {
_$jscoverage['mongoose/document.js'][522]++;
return clone(this.doc);
_$jscoverage['mongoose/document.js'][530]++;
return clone(this.doc, true);
});
_$jscoverage['mongoose/document.js'][532]++;
_$jscoverage['mongoose/document.js'][540]++;
Document.prototype.toJSON = (function () {
_$jscoverage['mongoose/document.js'][533]++;
return JSON.stringify(this.toObject());
_$jscoverage['mongoose/document.js'][541]++;
return this.toObject();
});
_$jscoverage['mongoose/document.js'][542]++;
_$jscoverage['mongoose/document.js'][550]++;
Document.prototype.equals = (function (doc) {
_$jscoverage['mongoose/document.js'][543]++;
_$jscoverage['mongoose/document.js'][551]++;
return this.get("_id") === doc.get("_id");
});
_$jscoverage['mongoose/document.js'][553]++;
_$jscoverage['mongoose/document.js'][561]++;
function noop() {
}
_$jscoverage['mongoose/document.js'][553]++;
_$jscoverage['mongoose/document.js'][561]++;
;
_$jscoverage['mongoose/document.js'][555]++;
_$jscoverage['mongoose/document.js'][563]++;
Document.registerHooks = (function () {
_$jscoverage['mongoose/document.js'][556]++;
_$jscoverage['mongoose/document.js'][564]++;
for (var i = 0, l = arguments.length; i < l; i++) {
_$jscoverage['mongoose/document.js'][557]++;
_$jscoverage['mongoose/document.js'][565]++;
this.prototype[arguments[i]] = (function (methodName, oldFn) {
_$jscoverage['mongoose/document.js'][558]++;
_$jscoverage['mongoose/document.js'][566]++;
return (function () {
_$jscoverage['mongoose/document.js'][559]++;
_$jscoverage['mongoose/document.js'][567]++;
var self = this, args = arguments;
_$jscoverage['mongoose/document.js'][562]++;
_$jscoverage['mongoose/document.js'][570]++;
function error(err) {
_$jscoverage['mongoose/document.js'][563]++;
_$jscoverage['mongoose/document.js'][571]++;
var lastArg = args[args.length - 1];
_$jscoverage['mongoose/document.js'][564]++;
_$jscoverage['mongoose/document.js'][572]++;
if (typeof lastArg == "function") {
_$jscoverage['mongoose/document.js'][565]++;
_$jscoverage['mongoose/document.js'][573]++;
lastArg.call(self, err);
}
}
_$jscoverage['mongoose/document.js'][567]++;
_$jscoverage['mongoose/document.js'][575]++;
var pres = this.pres[methodName];
_$jscoverage['mongoose/document.js'][568]++;
_$jscoverage['mongoose/document.js'][576]++;
if (! pres) {
_$jscoverage['mongoose/document.js'][568]++;
_$jscoverage['mongoose/document.js'][576]++;
return oldFn.apply(this, args);
}
_$jscoverage['mongoose/document.js'][570]++;
_$jscoverage['mongoose/document.js'][578]++;
var pres = this.pres[methodName], chain = pres.serial.map((function (fn, i) {
_$jscoverage['mongoose/document.js'][572]++;
_$jscoverage['mongoose/document.js'][580]++;
return (function (err) {
_$jscoverage['mongoose/document.js'][573]++;
_$jscoverage['mongoose/document.js'][581]++;
if (arguments.callee._hookCalled) {
_$jscoverage['mongoose/document.js'][573]++;
_$jscoverage['mongoose/document.js'][581]++;
return;
}
_$jscoverage['mongoose/document.js'][575]++;
_$jscoverage['mongoose/document.js'][583]++;
if (err instanceof Error) {
_$jscoverage['mongoose/document.js'][576]++;
_$jscoverage['mongoose/document.js'][584]++;
error(err);
}
else {
_$jscoverage['mongoose/document.js'][578]++;
_$jscoverage['mongoose/document.js'][586]++;
fn.call(self, chain[i + 1] || parallel);
}
_$jscoverage['mongoose/document.js'][580]++;
_$jscoverage['mongoose/document.js'][588]++;
arguments.callee._hookCalled = true;
});
}));
_$jscoverage['mongoose/document.js'][584]++;
_$jscoverage['mongoose/document.js'][592]++;
chain.length? chain[0](): parallel();
_$jscoverage['mongoose/document.js'][586]++;
_$jscoverage['mongoose/document.js'][594]++;
function parallel(err) {
_$jscoverage['mongoose/document.js'][587]++;
_$jscoverage['mongoose/document.js'][595]++;
if (err instanceof Error) {
_$jscoverage['mongoose/document.js'][588]++;
_$jscoverage['mongoose/document.js'][596]++;
return error(err);
}
_$jscoverage['mongoose/document.js'][591]++;
_$jscoverage['mongoose/document.js'][599]++;
var complete = pres.parallel.length;
_$jscoverage['mongoose/document.js'][592]++;
_$jscoverage['mongoose/document.js'][600]++;
if (! complete) {
_$jscoverage['mongoose/document.js'][592]++;
_$jscoverage['mongoose/document.js'][600]++;
return oldFn.apply(self, args);
}
_$jscoverage['mongoose/document.js'][594]++;
_$jscoverage['mongoose/document.js'][602]++;
function done(err) {
_$jscoverage['mongoose/document.js'][595]++;
_$jscoverage['mongoose/document.js'][603]++;
if (err instanceof Error) {
_$jscoverage['mongoose/document.js'][596]++;
_$jscoverage['mongoose/document.js'][604]++;
return error(err);
}
_$jscoverage['mongoose/document.js'][597]++;
_$jscoverage['mongoose/document.js'][605]++;
--complete || oldFn.apply(self, args);
}
_$jscoverage['mongoose/document.js'][600]++;
_$jscoverage['mongoose/document.js'][608]++;
var chain = pres.parallel.map((function (fn, i) {
_$jscoverage['mongoose/document.js'][601]++;
_$jscoverage['mongoose/document.js'][609]++;
return (function (err) {
_$jscoverage['mongoose/document.js'][602]++;
_$jscoverage['mongoose/document.js'][610]++;
if (arguments.callee._hookCalled) {
_$jscoverage['mongoose/document.js'][602]++;
_$jscoverage['mongoose/document.js'][610]++;
return;
}
_$jscoverage['mongoose/document.js'][603]++;
_$jscoverage['mongoose/document.js'][611]++;
if (err) {
_$jscoverage['mongoose/document.js'][603]++;
_$jscoverage['mongoose/document.js'][611]++;
return error(err);
}
_$jscoverage['mongoose/document.js'][604]++;
_$jscoverage['mongoose/document.js'][612]++;
fn.call(self, chain[i + 1] || noop, (function (err) {
_$jscoverage['mongoose/document.js'][605]++;
_$jscoverage['mongoose/document.js'][613]++;
if (arguments.callee._hookCalled) {
_$jscoverage['mongoose/document.js'][605]++;
_$jscoverage['mongoose/document.js'][613]++;
return;
}
_$jscoverage['mongoose/document.js'][606]++;
_$jscoverage['mongoose/document.js'][614]++;
done(err);
_$jscoverage['mongoose/document.js'][607]++;
_$jscoverage['mongoose/document.js'][615]++;
arguments.callee._hookCalled = true;
}));
_$jscoverage['mongoose/document.js'][609]++;
_$jscoverage['mongoose/document.js'][617]++;
arguments.callee._hookCalled = true;
});
}));
_$jscoverage['mongoose/document.js'][613]++;
_$jscoverage['mongoose/document.js'][621]++;
chain[0]();

@@ -828,19 +848,19 @@ }

});
_$jscoverage['mongoose/document.js'][624]++;
_$jscoverage['mongoose/document.js'][632]++;
module.exports = Document;
_$jscoverage['mongoose/document.js'][632]++;
_$jscoverage['mongoose/document.js'][640]++;
function DocumentError() {
_$jscoverage['mongoose/document.js'][633]++;
_$jscoverage['mongoose/document.js'][641]++;
MongooseError.call(this, msg);
_$jscoverage['mongoose/document.js'][634]++;
_$jscoverage['mongoose/document.js'][642]++;
MongooseError.captureStackTrace(this, arguments.callee);
_$jscoverage['mongoose/document.js'][635]++;
_$jscoverage['mongoose/document.js'][643]++;
this.name = "DocumentError";
}
_$jscoverage['mongoose/document.js'][636]++;
_$jscoverage['mongoose/document.js'][644]++;
;
_$jscoverage['mongoose/document.js'][642]++;
_$jscoverage['mongoose/document.js'][650]++;
DocumentError.prototype.__proto__ = MongooseError.prototype;
_$jscoverage['mongoose/document.js'][644]++;
_$jscoverage['mongoose/document.js'][652]++;
exports.Error = DocumentError;
_$jscoverage['mongoose/document.js'].source = ["","/**"," * Module dependencies."," */","","var EventEmitter = require('events').EventEmitter"," , MongooseError = require('./error')"," , Schema = require('./schema')"," , SchemaType = require('./schematype')"," , VirtualType = require('./virtualtype')"," , ArrayType = require('./types/array')"," , MixedSchema = require('./schema/mixed')"," , DocumentArraySchema = require('./schema/documentarray')"," , utils = require('./utils')"," , clone = utils.clone"," , ActiveRoster = utils.StateMachine.ctor('require', 'modify', 'init');","","/**"," * Document constructor."," *"," * @param {Object} values to set"," * @api private"," */","","function Document (obj) {"," this.doc = this.buildDoc();"," this.activePaths = new ActiveRoster();"," this.saveError = null;"," if (obj) this.set(obj);"," this.pres = {};"," this.registerHooks();"," this.doQueue();"," this.isNew = true;","};","","/**"," * Inherit from EventEmitter."," */","","Document.prototype.__proto__ = EventEmitter.prototype;","","/**"," * Base Mongoose instance for the model. Set by the Mongoose instance upon"," * pre-compilation."," *"," * @api public"," */","","Document.prototype.base;","","/**"," * Document schema as a nested structure."," *"," * @api public"," */","","Document.prototype.schema;","","/**"," * Whether the document is new."," *"," * @api public"," */","","Document.prototype.isNew;","","/**"," * Builds the default doc structure"," *"," * @api private"," */","","Document.prototype.buildDoc = function () {"," var doc = {}"," , self = this;",""," this.schema.eachPath( function (i, type) {"," var path = i.split('.')"," , len = path.length;",""," path.reduce( function (ref, piece, i) {"," if (i === len-1)"," ref[piece] = type.getDefault(self);"," else"," return ref[piece] || (ref[piece] = {});"," }, doc);"," });",""," return doc;","};","","/**"," * Inits (hydrates) the document."," *"," * @param {Object} document returned by mongo"," * @api private"," */","","Document.prototype.init = function (doc, fn) {"," var self = this;"," this.isNew = false;",""," function init (obj, doc, prefix) {"," prefix = prefix || '';",""," for (var i in obj){"," var path = prefix + i"," , schema = self.schema.path(path);",""," if (!schema &amp;&amp; obj[i].constructor == Object){ // assume nested object"," doc[i] = {};"," init(obj[i], doc[i], path + '.');"," } else {"," if (obj[i] !== null &amp;&amp; obj[i] !== undefined) {"," var schema = self.schema.path(path);",""," if (schema)"," self.try(function(){"," doc[i] = schema.cast(obj[i], self);"," });"," else"," doc[i] = obj[i];"," }",""," // mark as hydrated"," self.activePaths.init(path);"," }"," }"," };",""," init(doc, self.doc);",""," if (fn)"," fn(null);",""," this.emit('init');",""," return this;","};","","/**"," * Registers a middleware that is executed before a method."," *"," * @param {String} method name"," * @param {Function} callback"," * @api public"," */","","Document.prototype.pre = function (method, fn) {"," if (!(method in this.pres))"," this.pres[method] = {"," serial: []"," , parallel: []"," };"," this.pres[method][fn.length == 1 ? 'serial' : 'parallel'].push(fn);"," return this;","};","","/**"," * Sets a path, or many paths"," *"," * Examples:"," * // path, value"," * doc.set(path, value)"," *"," * // object"," * doc.set({"," * path : value"," * , path2 : {"," * path : value"," * }"," * }"," *"," * @param {String/Object} key path, or object"," * @param {Object} value, or undefined if first parameter is an object"," * @param {Boolean} whether to apply transformations: cast, setters (true) "," * @param {Boolean} whether to mark dirty (true)"," * @param {Boolean} whether this is an initialization"," * @api public"," */","","Document.prototype.set = function (path, val) {"," if (typeof path != 'string'){"," var prefix = val ? val + '.' : '';"," for (var i in path){"," if (!(this.schema.path(prefix + i) instanceof MixedSchema)"," &amp;&amp; 'undefined' !== typeof path[i]"," &amp;&amp; path[i] !== null"," &amp;&amp; path[i].constructor == Object) {"," this.set(path[i], prefix + i);"," } else if ('undefined' !== typeof path[i]) {"," this.set(prefix + i, path[i]);"," }"," }"," } else {"," // TODO: do actual checking to see if the value changed"," var schema = this.schema.path(path)"," , parts = path.split('.')"," , obj = this.doc"," , self = this;",""," if (this.schema.pathType(path) === 'virtual') {"," schema = this.schema.virtualpath(path);"," schema.applySetters(val, this);"," return this;"," }",""," this.activePaths.modify(path);",""," if ( (!schema || val === null || val === undefined) || "," this.try(function(){"," val = schema.applySetters(schema.cast(val, self), self);"," })"," ){"," for (var i = 0, l = parts.length; i &lt; l; i++){"," if (i + 1 == l)"," obj[parts[i]] = val;"," else {"," obj = obj[parts[i]];"," }"," }"," }"," }",""," return this;","};","","Document.prototype._markModified = function (path) {"," this.activePaths.modify(path);","};","","/**"," * Gets a raw value from a path (no getters)"," *"," * @param {String} path"," * @api private"," */","","Document.prototype.getValue = function (path) {"," var parts = path.split('.')"," , obj = this.doc;",""," for (var i = 0, l = parts.length; i &lt; l-1; i++) {"," obj = obj[parts[i]];"," if (!obj) return obj;"," }"," return obj[parts[l-1]];","};","","/**"," * Sets a raw value for a path (no casting, setters, transformations)"," *"," * @param {String} path"," * @param {Object} value"," * @api private"," */","","Document.prototype.setValue = function (path, val) {"," var parts = path.split('.')"," , obj = this.doc;",""," for (var i = 0, l = parts.length; i &lt; l-1; i++) obj = obj[parts[i]];"," obj[parts[l-1]] = val;",""," return this;","};","","/**"," * Triggers casting on a specific path"," *"," * @param {String} path"," * @api public"," */","","Document.prototype.doCast = function (path) {"," var schema = this.schema.path(path);"," if (schema)"," this.setValue(path, this.getValue(path));","};","","/**"," * Gets a path"," *"," * @param {String} key path"," * @api public"," */","","Document.prototype.get = function (path) {"," var obj"," , schema = this.schema.path(path) || this.schema.virtualpath(path)"," , pieces = path.split('.');",""," obj = this.doc;"," for (var i = 0, l = pieces.length; i &lt; l; i++)"," obj = obj[pieces[i]];"," "," if (schema)"," obj = schema.applyGetters(obj, this);"," // TODO Cache obj",""," return obj;","};","","/**"," * Commits a path, marking as modified if needed. Useful for mixed keys"," *"," * @api public"," */","","Document.prototype.commit = function (path) {"," // TODO: do actual checking to see if the value changed"," this.activePaths.modify(path);","};","","/**"," * Captures an exception that will be bubbled to `save`"," *"," * @param {Function} function to execute"," * @param {Object} scope"," */","","Document.prototype.try = function (fn, scope) {"," var res;"," try {"," fn.call(scope);"," res = true;"," } catch(e){"," this.error(e);"," res = false;"," };"," return res;","};","","/**"," * Checks if a path is modified"," *"," * @param {String} path"," */","","Document.prototype.isModified = function (path) {"," return (path in this.activePaths.states.modify);","};","","/**"," * Checks if a certain path was initialized"," *"," * @param {String} path"," */","","Document.prototype.isInit = function (path) {"," return (path in this.activePaths.states.init);","};","","/**"," * Validation middleware"," *"," * @param {Function} next"," * @api private"," */","","Document.prototype.validate = function (next) {"," var total = 0"," , self = this"," , validating = {}"," , didErr = false;",""," if (!this.activePaths.some('init', 'modify')) return next();",""," function validatePath (path) {"," if (validating[path]) return;"," total++;"," process.nextTick(function(){"," self.schema.path(path).doValidate(self.getValue(path), function(err){"," if (err) {"," didErr = true;"," return next(err);"," }"," --total || next();"," }, self);"," });"," validating[path] = true;"," }",""," this.activePaths.forEach('init', 'modify', function (path) {"," if (!didErr) validatePath(path);"," });",""," return this;","};","","/**"," * Returns if the document has been modified"," *"," * @return {Boolean}"," * @api public"," */","","Document.prototype.__defineGetter__('modified', function () {"," return this.activePaths.some('modified');","});","","/**"," * We override the schema setter to compile accessors"," *"," * @api private"," */","","function compile (tree, proto, prefix) {"," for (var i in tree)"," define(i, ((tree[i].constructor == Object"," &amp;&amp; Object.keys(tree[i]).length)"," &amp;&amp; (!tree[i].type || tree[i].__nested)"," ? tree[i]"," : null)"," , proto"," , prefix);","};","","function define (prop, subprops, prototype, prefix) {"," var prefix = prefix || ''"," , path = (prefix ? prefix + '.' : '') + prop;",""," if (subprops) {"," // if prop hasn't been defined"," prototype.__defineGetter__(prop, function () {"," if (!this.__getters)"," this.__getters = {};",""," if (!this.__getters[path]){"," var nested = function(){};"," nested.prototype = this;"," compile(subprops, nested.prototype, path);"," this.__getters[path] = new nested();"," }",""," return this.__getters[path];"," });"," } else {"," prototype.__defineGetter__(prop, function () {"," return this.get(path);"," });",""," prototype.__defineSetter__(prop, function (v) {"," return this.set(path, v);"," });"," }","};","","Document.prototype.__defineSetter__('schema', function (schema) {"," compile(schema.tree, this);"," this._schema = schema;","});","","/**"," * We override the schema getter to return the internal reference"," *"," * @api private"," */","","Document.prototype.__defineGetter__('schema', function () {"," return this._schema;","});","","/**"," * Register default hooks"," *"," * @api private"," */","","Document.prototype.registerHooks = function () {"," var self = this;",""," this.pre('save', function checkForExistingErrors (next) {"," if (self.saveError){"," next(self.saveError);"," self.saveError = null;"," } else {"," next();"," }"," });",""," this.pre('save', function validation (next) {"," return self.validate.call(self, next);"," });","};","","/**"," * Registers an error"," * TODO: handle multiple"," *"," * @param {Error} error"," * @api private"," */","","Document.prototype.error = function (err) {"," this.saveError = err;"," return this;","};","","/**"," * Executes methods queued from the Schema definition"," *"," * @api private"," */","","Document.prototype.doQueue = function () {"," if (this.schema &amp;&amp; this.schema.callQueue)"," for (var i = 0, l = this.schema.callQueue.length; i &lt; l; i++)"," this[this.schema.callQueue[i][0]].apply(this, this.schema.callQueue[i][1]);"," return this;","};","","/**"," * Gets the document"," *"," * @todo Should we apply getters?"," * @return {Object} plain object"," * @api public"," */","","Document.prototype.toObject = function () {"," return clone(this.doc);","};","","/**"," * Returns a JSON string for the document"," *"," * @return {String} JSON representation"," * @api public"," */","","Document.prototype.toJSON = function () {"," return JSON.stringify(this.toObject());","};","","/**"," * Returns true if the Document stores the same data as doc."," * @param {Document} doc to compare to"," * @return {Boolean}"," * @api public"," */","Document.prototype.equals = function (doc) {"," return this.get('_id') === doc.get('_id');","};","","/**"," * Wrap methods for hooks. Should be called on implemented classes (eg: Model)"," * Takes multiple method names as arguments."," *"," * @api private"," */","","function noop () {};","","Document.registerHooks = function () {"," for (var i = 0, l = arguments.length; i &lt; l; i++){"," this.prototype[arguments[i]] = (function(methodName, oldFn){"," return function () {"," var self = this"," , args = arguments;",""," function error (err){"," var lastArg = args[args.length-1];"," if (typeof lastArg == 'function')"," lastArg.call(self, err);"," }"," var pres = this.pres[methodName];"," if (!pres) return oldFn.apply(this, args);",""," var pres = this.pres[methodName]"," , chain = pres.serial.map(function (fn, i) {"," return function (err) {"," if (arguments.callee._hookCalled) return;",""," if (err instanceof Error)"," error(err);"," else"," fn.call(self, chain[i+1] || parallel);",""," arguments.callee._hookCalled = true;"," };"," });",""," chain.length ? chain[0]() : parallel();",""," function parallel (err) {"," if (err instanceof Error)"," return error(err);",""," // chain determines execution, callbacks completeness"," var complete = pres.parallel.length;"," if (!complete) return oldFn.apply(self, args);"," "," function done (err) {"," if (err instanceof Error)"," return error(err);"," --complete || oldFn.apply(self, args);"," }",""," var chain = pres.parallel.map(function (fn, i) {"," return function (err) {"," if (arguments.callee._hookCalled) return;"," if (err) return error(err);"," fn.call(self, chain[i+1] || noop, function (err) {"," if (arguments.callee._hookCalled) return;"," done(err);"," arguments.callee._hookCalled = true;"," });"," arguments.callee._hookCalled = true;"," };"," });"," "," chain[0]();"," }"," };"," })(arguments[i], this.prototype[arguments[i]]);"," }","};","","/**"," * Module exports."," */","","module.exports = Document;","","/**"," * Document Error"," *"," * @param text"," */","","function DocumentError () {"," MongooseError.call(this, msg);"," MongooseError.captureStackTrace(this, arguments.callee);"," this.name = 'DocumentError';","};","","/**"," * Inherits from MongooseError."," */","","DocumentError.prototype.__proto__ = MongooseError.prototype;","","exports.Error = DocumentError;"];
_$jscoverage['mongoose/document.js'].source = ["","/**"," * Module dependencies."," */","","var EventEmitter = require('events').EventEmitter"," , MongooseError = require('./error')"," , Schema = require('./schema')"," , SchemaType = require('./schematype')"," , VirtualType = require('./virtualtype')"," , ArrayType = require('./types/array')"," , MixedSchema = require('./schema/mixed')"," , DocumentArraySchema = require('./schema/documentarray')"," , utils = require('./utils')"," , clone = utils.clone"," , ActiveRoster = utils.StateMachine.ctor('require', 'modify', 'init');","","/**"," * Document constructor."," *"," * @param {Object} values to set"," * @api private"," */","","function Document (obj) {"," this.doc = this.buildDoc();"," this.activePaths = new ActiveRoster();"," var self = this;"," this.schema.requiredPaths.forEach( function (path) {"," self.activePaths.require(path);"," });"," this.saveError = null;"," if (obj) this.set(obj);"," this.pres = {};"," this.registerHooks();"," this.doQueue();"," this.isNew = true;","};","","/**"," * Inherit from EventEmitter."," */","","Document.prototype.__proto__ = EventEmitter.prototype;","","/**"," * Base Mongoose instance for the model. Set by the Mongoose instance upon"," * pre-compilation."," *"," * @api public"," */","","Document.prototype.base;","","/**"," * Document schema as a nested structure."," *"," * @api public"," */","","Document.prototype.schema;","","/**"," * Whether the document is new."," *"," * @api public"," */","","Document.prototype.isNew;","","/**"," * Builds the default doc structure"," *"," * @api private"," */","","Document.prototype.buildDoc = function () {"," var doc = {}"," , self = this;",""," this.schema.eachPath( function (i, type) {"," var path = i.split('.')"," , len = path.length;",""," path.reduce( function (ref, piece, i) {"," var _default;"," if (i === len-1) {"," _default = type.getDefault(self);"," if ('undefined' !== typeof _default)"," ref[piece] = _default;"," } else"," return ref[piece] || (ref[piece] = {});"," }, doc);"," });",""," return doc;","};","","/**"," * Inits (hydrates) the document."," *"," * @param {Object} document returned by mongo"," * @api private"," */","","Document.prototype.init = function (doc, fn) {"," var self = this;"," this.isNew = false;",""," function init (obj, doc, prefix) {"," prefix = prefix || '';",""," for (var i in obj){"," var path = prefix + i"," , schema = self.schema.path(path);",""," if (!schema &amp;&amp; obj[i].constructor == Object){ // assume nested object"," doc[i] = {};"," init(obj[i], doc[i], path + '.');"," } else {"," if (obj[i] !== null &amp;&amp; obj[i] !== undefined) {"," var schema = self.schema.path(path);",""," if (schema)"," self.try(function(){"," doc[i] = schema.cast(obj[i], self);"," });"," else"," doc[i] = obj[i];"," }",""," // mark as hydrated"," self.activePaths.init(path);"," }"," }"," };",""," init(doc, self.doc);",""," if (fn)"," fn(null);",""," this.emit('init');",""," return this;","};","","/**"," * Registers a middleware that is executed before a method."," *"," * @param {String} method name"," * @param {Function} callback"," * @api public"," */","","Document.prototype.pre = function (method, fn) {"," if (!(method in this.pres))"," this.pres[method] = {"," serial: []"," , parallel: []"," };"," this.pres[method][fn.length == 1 ? 'serial' : 'parallel'].push(fn);"," return this;","};","","/**"," * Sets a path, or many paths"," *"," * Examples:"," * // path, value"," * doc.set(path, value)"," *"," * // object"," * doc.set({"," * path : value"," * , path2 : {"," * path : value"," * }"," * }"," *"," * @param {String/Object} key path, or object"," * @param {Object} value, or undefined if first parameter is an object"," * @param {Boolean} whether to apply transformations: cast, setters (true) "," * @param {Boolean} whether to mark dirty (true)"," * @param {Boolean} whether this is an initialization"," * @api public"," */","","Document.prototype.set = function (path, val) {"," if (typeof path != 'string'){"," var prefix = val ? val + '.' : '';"," for (var i in path){"," if (!(this.schema.path(prefix + i) instanceof MixedSchema)"," &amp;&amp; 'undefined' !== typeof path[i]"," &amp;&amp; path[i] !== null"," &amp;&amp; path[i].constructor == Object) {"," this.set(path[i], prefix + i);"," } else if ('undefined' !== typeof path[i]) {"," this.set(prefix + i, path[i]);"," }"," }"," } else {"," // TODO: do actual checking to see if the value changed"," var schema = this.schema.path(path)"," , parts = path.split('.')"," , obj = this.doc"," , self = this;",""," if (this.schema.pathType(path) === 'virtual') {"," schema = this.schema.virtualpath(path);"," schema.applySetters(val, this);"," return this;"," }",""," this.activePaths.modify(path);",""," if ( (!schema || val === null || val === undefined) || "," this.try(function(){"," val = schema.applySetters(schema.cast(val, self), self);"," })"," ){"," for (var i = 0, l = parts.length; i &lt; l; i++){"," if (i + 1 == l)"," obj[parts[i]] = val;"," else {"," obj = obj[parts[i]];"," }"," }"," }"," }",""," return this;","};","","Document.prototype._markModified = function (path) {"," this.activePaths.modify(path);","};","","/**"," * Gets a raw value from a path (no getters)"," *"," * @param {String} path"," * @api private"," */","","Document.prototype.getValue = function (path) {"," var parts = path.split('.')"," , obj = this.doc;",""," for (var i = 0, l = parts.length; i &lt; l-1; i++) {"," obj = obj[parts[i]];"," if (!obj) return obj;"," }"," return obj[parts[l-1]];","};","","/**"," * Sets a raw value for a path (no casting, setters, transformations)"," *"," * @param {String} path"," * @param {Object} value"," * @api private"," */","","Document.prototype.setValue = function (path, val) {"," var parts = path.split('.')"," , obj = this.doc;",""," for (var i = 0, l = parts.length; i &lt; l-1; i++) obj = obj[parts[i]];"," obj[parts[l-1]] = val;",""," return this;","};","","/**"," * Triggers casting on a specific path"," *"," * @param {String} path"," * @api public"," */","","Document.prototype.doCast = function (path) {"," var schema = this.schema.path(path);"," if (schema)"," this.setValue(path, this.getValue(path));","};","","/**"," * Gets a path"," *"," * @param {String} key path"," * @api public"," */","","Document.prototype.get = function (path) {"," var obj"," , schema = this.schema.path(path) || this.schema.virtualpath(path)"," , pieces = path.split('.');",""," obj = this.doc;"," for (var i = 0, l = pieces.length; i &lt; l; i++)"," obj = obj[pieces[i]];"," "," if (schema)"," obj = schema.applyGetters(obj, this);"," // TODO Cache obj",""," return obj;","};","","/**"," * Commits a path, marking as modified if needed. Useful for mixed keys"," *"," * @api public"," */","","Document.prototype.commit = function (path) {"," // TODO: do actual checking to see if the value changed"," this.activePaths.modify(path);","};","","/**"," * Captures an exception that will be bubbled to `save`"," *"," * @param {Function} function to execute"," * @param {Object} scope"," */","","Document.prototype.try = function (fn, scope) {"," var res;"," try {"," fn.call(scope);"," res = true;"," } catch(e){"," this.error(e);"," res = false;"," };"," return res;","};","","/**"," * Checks if a path is modified"," *"," * @param {String} path"," */","","Document.prototype.isModified = function (path) {"," return (path in this.activePaths.states.modify);","};","","/**"," * Checks if a certain path was initialized"," *"," * @param {String} path"," */","","Document.prototype.isInit = function (path) {"," return (path in this.activePaths.states.init);","};","","/**"," * Validation middleware"," *"," * @param {Function} next"," * @api private"," */","","Document.prototype.validate = function (next) {"," var total = 0"," , self = this"," , validating = {}"," , didErr = false;",""," if (!this.activePaths.some('require', 'init', 'modify')) return next();",""," function validatePath (path) {"," if (validating[path]) return;"," total++;"," process.nextTick(function(){"," self.schema.path(path).doValidate(self.getValue(path), function(err){"," if (err) {"," didErr = true;"," return next(err);"," }"," --total || next();"," }, self);"," });"," validating[path] = true;"," }",""," this.activePaths.forEach('require', 'init', 'modify', function (path) {"," if (!didErr) validatePath(path);"," });",""," return this;","};","","/**"," * Returns if the document has been modified"," *"," * @return {Boolean}"," * @api public"," */","","Document.prototype.__defineGetter__('modified', function () {"," return this.activePaths.some('modified');","});","","/**"," * We override the schema setter to compile accessors"," *"," * @api private"," */","","function compile (tree, proto, prefix) {"," for (var i in tree)"," define(i, ((tree[i].constructor == Object"," &amp;&amp; Object.keys(tree[i]).length)"," &amp;&amp; (!tree[i].type || tree[i].__nested)"," ? tree[i]"," : null)"," , proto"," , prefix);","};","","function define (prop, subprops, prototype, prefix) {"," var prefix = prefix || ''"," , path = (prefix ? prefix + '.' : '') + prop;",""," if (subprops) {"," // if prop hasn't been defined"," prototype.__defineGetter__(prop, function () {"," if (!this.__getters)"," this.__getters = {};",""," if (!this.__getters[path]){"," var nested = function(){};"," nested.prototype.__proto__ = this;"," compile(subprops, nested.prototype, path);"," this.__getters[path] = new nested();"," }",""," return this.__getters[path];"," });"," } else {"," prototype.__defineGetter__(prop, function () {"," return this.get(path);"," });",""," prototype.__defineSetter__(prop, function (v) {"," return this.set(path, v);"," });"," }","};","","Document.prototype.__defineSetter__('schema', function (schema) {"," compile(schema.tree, this);"," this._schema = schema;","});","","/**"," * We override the schema getter to return the internal reference"," *"," * @api private"," */","","Document.prototype.__defineGetter__('schema', function () {"," return this._schema;","});","","/**"," * Register default hooks"," *"," * @api private"," */","","Document.prototype.registerHooks = function () {"," var self = this;",""," this.pre('save', function checkForExistingErrors (next) {"," if (self.saveError){"," next(self.saveError);"," self.saveError = null;"," } else {"," next();"," }"," });",""," this.pre('save', function validation (next) {"," return self.validate.call(self, next);"," });","};","","/**"," * Registers an error"," * TODO: handle multiple"," *"," * @param {Error} error"," * @api private"," */","","Document.prototype.error = function (err) {"," this.saveError = err;"," return this;","};","","/**"," * Executes methods queued from the Schema definition"," *"," * @api private"," */","","Document.prototype.doQueue = function () {"," if (this.schema &amp;&amp; this.schema.callQueue)"," for (var i = 0, l = this.schema.callQueue.length; i &lt; l; i++)"," this[this.schema.callQueue[i][0]].apply(this, this.schema.callQueue[i][1]);"," return this;","};","","/**"," * Gets the document"," *"," * @todo Should we apply getters?"," * @return {Object} plain object"," * @api public"," */","","","Document.prototype.toObject = function () {"," return clone(this.doc, true);","};","","/**"," * Returns a JSON string for the document"," *"," * @return {String} JSON representation"," * @api public"," */","","Document.prototype.toJSON = function () {"," return this.toObject();","};","","/**"," * Returns true if the Document stores the same data as doc."," * @param {Document} doc to compare to"," * @return {Boolean}"," * @api public"," */","Document.prototype.equals = function (doc) {"," return this.get('_id') === doc.get('_id');","};","","/**"," * Wrap methods for hooks. Should be called on implemented classes (eg: Model)"," * Takes multiple method names as arguments."," *"," * @api private"," */","","function noop () {};","","Document.registerHooks = function () {"," for (var i = 0, l = arguments.length; i &lt; l; i++){"," this.prototype[arguments[i]] = (function(methodName, oldFn){"," return function () {"," var self = this"," , args = arguments;",""," function error (err){"," var lastArg = args[args.length-1];"," if (typeof lastArg == 'function')"," lastArg.call(self, err);"," }"," var pres = this.pres[methodName];"," if (!pres) return oldFn.apply(this, args);",""," var pres = this.pres[methodName]"," , chain = pres.serial.map(function (fn, i) {"," return function (err) {"," if (arguments.callee._hookCalled) return;",""," if (err instanceof Error)"," error(err);"," else"," fn.call(self, chain[i+1] || parallel);",""," arguments.callee._hookCalled = true;"," };"," });",""," chain.length ? chain[0]() : parallel();",""," function parallel (err) {"," if (err instanceof Error)"," return error(err);",""," // chain determines execution, callbacks completeness"," var complete = pres.parallel.length;"," if (!complete) return oldFn.apply(self, args);"," "," function done (err) {"," if (err instanceof Error)"," return error(err);"," --complete || oldFn.apply(self, args);"," }",""," var chain = pres.parallel.map(function (fn, i) {"," return function (err) {"," if (arguments.callee._hookCalled) return;"," if (err) return error(err);"," fn.call(self, chain[i+1] || noop, function (err) {"," if (arguments.callee._hookCalled) return;"," done(err);"," arguments.callee._hookCalled = true;"," });"," arguments.callee._hookCalled = true;"," };"," });"," "," chain[0]();"," }"," };"," })(arguments[i], this.prototype[arguments[i]]);"," }","};","","/**"," * Module exports."," */","","module.exports = Document;","","/**"," * Document Error"," *"," * @param text"," */","","function DocumentError () {"," MongooseError.call(this, msg);"," MongooseError.captureStackTrace(this, arguments.callee);"," this.name = 'DocumentError';","};","","/**"," * Inherits from MongooseError."," */","","DocumentError.prototype.__proto__ = MongooseError.prototype;","","exports.Error = DocumentError;"];

@@ -259,3 +259,3 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/index.js'][256]++;
exports.version = "1.0.7";
exports.version = "1.0.10";
_$jscoverage['mongoose/index.js'][264]++;

@@ -281,2 +281,2 @@ exports.Mongoose = Mongoose;

exports.mongo = require("../../support/node-mongodb-native/lib/mongodb");
_$jscoverage['mongoose/index.js'].source = ["","/**"," * Module dependencies."," */","","var Schema = require('./schema')"," , SchemaType = require('./schematype')"," , VirtualType = require('./virtualtype')"," , SchemaTypes = Schema.Types"," , Types = require('./types')"," , Query = require('./query')"," , Promise = require('./promise')"," , Model = require('./model')"," , utils = require('./utils');","","/**"," * Mongoose constructor. Most apps will only use one instance."," *"," * @api public"," */","","function Mongoose () {"," this.connections = [];"," this.plugins = [];"," this.models = {};"," this.modelSchemas = {};"," this.options = {};"," this.createConnection(); // default connection","};","","/**"," * Sets/gets mongoose options"," *"," * Examples:"," * mongoose.set('test') // returns the 'test' value"," * mongoose.set('test', value) // sets the 'test' value"," *"," * @param {String} key"," * @param {String} value"," * @api public"," */","","Mongoose.prototype.set =","Mongoose.prototype.get = function (key, value) {"," if (arguments.length == 1)"," return this.options[key];"," this.options[key] = value;"," return this;","};","","/**"," * Creates a Connection instance."," *"," * Examples:"," *"," * // with mongodb:// URI"," * db = mongoose.createConnection('mongodb://localhost:port/database');"," *"," * // with [host, database_name[, port] signature "," * db = mongoose.createConnection('localhost', 'database', port)"," *"," * // initialize now, connect later"," * db = mongoose.createConnection();"," * db.open('localhost', 'database', port);"," *"," * @param {String} mongodb:// URI"," * @return {Connection} the created Connection object"," * @api public"," */","","Mongoose.prototype.createConnection = function () {"," var conn = new Connection(this);"," this.connections.push(conn);"," if (arguments.length)"," conn.open.apply(conn, arguments);"," return conn;","};","","/**"," * Connects the default mongoose connection"," *"," * @see {Mongoose#createConnection}"," * @api public"," */","","Mongoose.prototype.connect = function (){"," this.connection.open.apply(this.connection, arguments);"," return this;","};","","/**"," * Disconnects from all connections."," *"," * @param {Function} optional callback"," * @api public"," */","","Mongoose.prototype.disconnect = function (fn) {"," var count = this.connections.length;"," this.connections.forEach(function(conn){"," conn.close(function(err){"," if (err) return fn(err);"," if (fn)"," --count || fn();"," });"," });"," return this;","};","","/**"," * Defines a model or retrieves it"," *"," * @param {String} model name"," * @param {Schema} schema object"," * @param {String} collection name (optional, induced from model name)"," * @param {Boolean} whether to skip initialization (defaults to false)"," * @api public"," */","","Mongoose.prototype.model = function (name, schema, collection, skipInit) {"," // normalize collection"," if (!(schema instanceof Schema)){"," collection = schema;"," schema = false;"," }",""," collection = collection || utils.toCollectionName(name);"," "," // look up models for the collection"," if (schema){"," if (!this.modelSchemas[name]) {"," this.modelSchemas[name] = schema;"," for (var i = 0, l = this.plugins.length; i &lt; l; i++)"," schema.plugin(this.plugins[i][0], this.plugins[i][1]);"," }"," } else {"," if (!this.modelSchemas[name])"," throw new Error('Schema hasn\\'t been registered for model \"' + name + '\".\\n'"," + 'Use Mongoose.define(name, schema)');",""," var conn = this.connection"," , model;",""," if (!this.models[collection])"," this.models[collection] = {};",""," if (!this.models[collection][name]){"," model = Model.compile(name"," , this.modelSchemas[name]"," , collection"," , conn"," , this);",""," if (!skipInit)"," model.init();",""," this.models[collection][name] = model;"," };",""," return this.models[collection][name];"," }","};","","/**"," * Declares a plugin executed on Schemas. Equivalent to calling `.plugin(fn)`"," * on each Schema you create."," *"," * @param {Function} plugin callback"," * @api public"," */","","Mongoose.prototype.plugin = function (fn, opts) {"," this.plugins.push([fn, opts]);"," return this;","};","","/**"," * Default connection"," *"," * @api public"," */","","Mongoose.prototype.__defineGetter__('connection', function(){"," return this.connections[0];","});","","/**"," * Compat flag."," *"," * @api public"," */","","var compat = false;","","exports.__defineGetter__('compat', function(){"," return compat;","});","","exports.__defineSetter__('compat', function(v){"," compat = v;"," if (v) require('./compat');","});","","/**"," * Driver depentend APIs"," */","","var driver = global.MONGOOSE_DRIVER_PATH || './drivers/node-mongodb-native';","","/**"," * Connection"," *"," * @api public"," */","","var Connection = require(driver + '/connection');","","/**"," * Collection"," *"," * @api public"," */","","var Collection = require(driver + '/collection');","","/**"," * Export default singleton."," * "," * @api public"," */","","module.exports = exports = new Mongoose();","","/**"," * Collection"," *"," * @api public"," */","","exports.Collection = Collection;","","/**"," * Connection"," *"," * @api public"," */","","exports.Connection = Connection;","","/**"," * Exports Mongoose version"," *"," * @param version"," */","","exports.version = '1.0.7';","","/**"," * Export Mongoose constructor"," *"," * @api public"," */","","exports.Mongoose = Mongoose;","","/**"," * Export Schema constructor"," *"," * @api public"," */","","exports.Schema = Schema;","","/**"," * Export SchemaType constructor."," *"," * @api public"," */","","exports.SchemaType = SchemaType;","","/**"," * Export VirtualType constructor."," *"," * @api public"," */","","exports.VirtualType = VirtualType;","","/**"," * Export Schema types"," *"," * @api public"," */","","exports.SchemaTypes = SchemaTypes;","","/**"," * Export types"," *"," * @api public"," */","","exports.Types = Types;","","/**"," * Export Query"," *"," * @api public"," */","","exports.Query = Query;","","/**"," * Export Promise"," *"," * @api public"," */","","exports.Promise = Promise;","","/**"," * Export MongooseError"," *"," * @api public"," */","","exports.Error = require('./error');","","exports.mongo = require('../../support/node-mongodb-native/lib/mongodb');"];
_$jscoverage['mongoose/index.js'].source = ["","/**"," * Module dependencies."," */","","var Schema = require('./schema')"," , SchemaType = require('./schematype')"," , VirtualType = require('./virtualtype')"," , SchemaTypes = Schema.Types"," , Types = require('./types')"," , Query = require('./query')"," , Promise = require('./promise')"," , Model = require('./model')"," , utils = require('./utils');","","/**"," * Mongoose constructor. Most apps will only use one instance."," *"," * @api public"," */","","function Mongoose () {"," this.connections = [];"," this.plugins = [];"," this.models = {};"," this.modelSchemas = {};"," this.options = {};"," this.createConnection(); // default connection","};","","/**"," * Sets/gets mongoose options"," *"," * Examples:"," * mongoose.set('test') // returns the 'test' value"," * mongoose.set('test', value) // sets the 'test' value"," *"," * @param {String} key"," * @param {String} value"," * @api public"," */","","Mongoose.prototype.set =","Mongoose.prototype.get = function (key, value) {"," if (arguments.length == 1)"," return this.options[key];"," this.options[key] = value;"," return this;","};","","/**"," * Creates a Connection instance."," *"," * Examples:"," *"," * // with mongodb:// URI"," * db = mongoose.createConnection('mongodb://localhost:port/database');"," *"," * // with [host, database_name[, port] signature "," * db = mongoose.createConnection('localhost', 'database', port)"," *"," * // initialize now, connect later"," * db = mongoose.createConnection();"," * db.open('localhost', 'database', port);"," *"," * @param {String} mongodb:// URI"," * @return {Connection} the created Connection object"," * @api public"," */","","Mongoose.prototype.createConnection = function () {"," var conn = new Connection(this);"," this.connections.push(conn);"," if (arguments.length)"," conn.open.apply(conn, arguments);"," return conn;","};","","/**"," * Connects the default mongoose connection"," *"," * @see {Mongoose#createConnection}"," * @api public"," */","","Mongoose.prototype.connect = function (){"," this.connection.open.apply(this.connection, arguments);"," return this;","};","","/**"," * Disconnects from all connections."," *"," * @param {Function} optional callback"," * @api public"," */","","Mongoose.prototype.disconnect = function (fn) {"," var count = this.connections.length;"," this.connections.forEach(function(conn){"," conn.close(function(err){"," if (err) return fn(err);"," if (fn)"," --count || fn();"," });"," });"," return this;","};","","/**"," * Defines a model or retrieves it"," *"," * @param {String} model name"," * @param {Schema} schema object"," * @param {String} collection name (optional, induced from model name)"," * @param {Boolean} whether to skip initialization (defaults to false)"," * @api public"," */","","Mongoose.prototype.model = function (name, schema, collection, skipInit) {"," // normalize collection"," if (!(schema instanceof Schema)){"," collection = schema;"," schema = false;"," }",""," collection = collection || utils.toCollectionName(name);"," "," // look up models for the collection"," if (schema){"," if (!this.modelSchemas[name]) {"," this.modelSchemas[name] = schema;"," for (var i = 0, l = this.plugins.length; i &lt; l; i++)"," schema.plugin(this.plugins[i][0], this.plugins[i][1]);"," }"," } else {"," if (!this.modelSchemas[name])"," throw new Error('Schema hasn\\'t been registered for model \"' + name + '\".\\n'"," + 'Use Mongoose.define(name, schema)');",""," var conn = this.connection"," , model;",""," if (!this.models[collection])"," this.models[collection] = {};",""," if (!this.models[collection][name]){"," model = Model.compile(name"," , this.modelSchemas[name]"," , collection"," , conn"," , this);",""," if (!skipInit)"," model.init();",""," this.models[collection][name] = model;"," };",""," return this.models[collection][name];"," }","};","","/**"," * Declares a plugin executed on Schemas. Equivalent to calling `.plugin(fn)`"," * on each Schema you create."," *"," * @param {Function} plugin callback"," * @api public"," */","","Mongoose.prototype.plugin = function (fn, opts) {"," this.plugins.push([fn, opts]);"," return this;","};","","/**"," * Default connection"," *"," * @api public"," */","","Mongoose.prototype.__defineGetter__('connection', function(){"," return this.connections[0];","});","","/**"," * Compat flag."," *"," * @api public"," */","","var compat = false;","","exports.__defineGetter__('compat', function(){"," return compat;","});","","exports.__defineSetter__('compat', function(v){"," compat = v;"," if (v) require('./compat');","});","","/**"," * Driver depentend APIs"," */","","var driver = global.MONGOOSE_DRIVER_PATH || './drivers/node-mongodb-native';","","/**"," * Connection"," *"," * @api public"," */","","var Connection = require(driver + '/connection');","","/**"," * Collection"," *"," * @api public"," */","","var Collection = require(driver + '/collection');","","/**"," * Export default singleton."," * "," * @api public"," */","","module.exports = exports = new Mongoose();","","/**"," * Collection"," *"," * @api public"," */","","exports.Collection = Collection;","","/**"," * Connection"," *"," * @api public"," */","","exports.Connection = Connection;","","/**"," * Exports Mongoose version"," *"," * @param version"," */","","exports.version = '1.0.10';","","/**"," * Export Mongoose constructor"," *"," * @api public"," */","","exports.Mongoose = Mongoose;","","/**"," * Export Schema constructor"," *"," * @api public"," */","","exports.Schema = Schema;","","/**"," * Export SchemaType constructor."," *"," * @api public"," */","","exports.SchemaType = SchemaType;","","/**"," * Export VirtualType constructor."," *"," * @api public"," */","","exports.VirtualType = VirtualType;","","/**"," * Export Schema types"," *"," * @api public"," */","","exports.SchemaTypes = SchemaTypes;","","/**"," * Export types"," *"," * @api public"," */","","exports.Types = Types;","","/**"," * Export Query"," *"," * @api public"," */","","exports.Query = Query;","","/**"," * Export Promise"," *"," * @api public"," */","","exports.Promise = Promise;","","/**"," * Export MongooseError"," *"," * @api public"," */","","exports.Error = require('./error');","","exports.mongo = require('../../support/node-mongodb-native/lib/mongodb');"];

@@ -6,113 +6,109 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/model.js'][6] = 0;
_$jscoverage['mongoose/model.js'][22] = 0;
_$jscoverage['mongoose/model.js'][23] = 0;
_$jscoverage['mongoose/model.js'][24] = 0;
_$jscoverage['mongoose/model.js'][28] = 0;
_$jscoverage['mongoose/model.js'][29] = 0;
_$jscoverage['mongoose/model.js'][30] = 0;
_$jscoverage['mongoose/model.js'][39] = 0;
_$jscoverage['mongoose/model.js'][47] = 0;
_$jscoverage['mongoose/model.js'][55] = 0;
_$jscoverage['mongoose/model.js'][65] = 0;
_$jscoverage['mongoose/model.js'][66] = 0;
_$jscoverage['mongoose/model.js'][70] = 0;
_$jscoverage['mongoose/model.js'][36] = 0;
_$jscoverage['mongoose/model.js'][45] = 0;
_$jscoverage['mongoose/model.js'][53] = 0;
_$jscoverage['mongoose/model.js'][61] = 0;
_$jscoverage['mongoose/model.js'][71] = 0;
_$jscoverage['mongoose/model.js'][72] = 0;
_$jscoverage['mongoose/model.js'][73] = 0;
_$jscoverage['mongoose/model.js'][74] = 0;
_$jscoverage['mongoose/model.js'][76] = 0;
_$jscoverage['mongoose/model.js'][77] = 0;
_$jscoverage['mongoose/model.js'][78] = 0;
_$jscoverage['mongoose/model.js'][79] = 0;
_$jscoverage['mongoose/model.js'][80] = 0;
_$jscoverage['mongoose/model.js'][82] = 0;
_$jscoverage['mongoose/model.js'][83] = 0;
_$jscoverage['mongoose/model.js'][84] = 0;
_$jscoverage['mongoose/model.js'][86] = 0;
_$jscoverage['mongoose/model.js'][90] = 0;
_$jscoverage['mongoose/model.js'][91] = 0;
_$jscoverage['mongoose/model.js'][93] = 0;
_$jscoverage['mongoose/model.js'][88] = 0;
_$jscoverage['mongoose/model.js'][89] = 0;
_$jscoverage['mongoose/model.js'][92] = 0;
_$jscoverage['mongoose/model.js'][96] = 0;
_$jscoverage['mongoose/model.js'][97] = 0;
_$jscoverage['mongoose/model.js'][98] = 0;
_$jscoverage['mongoose/model.js'][99] = 0;
_$jscoverage['mongoose/model.js'][100] = 0;
_$jscoverage['mongoose/model.js'][103] = 0;
_$jscoverage['mongoose/model.js'][104] = 0;
_$jscoverage['mongoose/model.js'][105] = 0;
_$jscoverage['mongoose/model.js'][112] = 0;
_$jscoverage['mongoose/model.js'][113] = 0;
_$jscoverage['mongoose/model.js'][115] = 0;
_$jscoverage['mongoose/model.js'][116] = 0;
_$jscoverage['mongoose/model.js'][117] = 0;
_$jscoverage['mongoose/model.js'][120] = 0;
_$jscoverage['mongoose/model.js'][106] = 0;
_$jscoverage['mongoose/model.js'][109] = 0;
_$jscoverage['mongoose/model.js'][111] = 0;
_$jscoverage['mongoose/model.js'][118] = 0;
_$jscoverage['mongoose/model.js'][119] = 0;
_$jscoverage['mongoose/model.js'][121] = 0;
_$jscoverage['mongoose/model.js'][122] = 0;
_$jscoverage['mongoose/model.js'][124] = 0;
_$jscoverage['mongoose/model.js'][125] = 0;
_$jscoverage['mongoose/model.js'][123] = 0;
_$jscoverage['mongoose/model.js'][126] = 0;
_$jscoverage['mongoose/model.js'][127] = 0;
_$jscoverage['mongoose/model.js'][128] = 0;
_$jscoverage['mongoose/model.js'][130] = 0;
_$jscoverage['mongoose/model.js'][131] = 0;
_$jscoverage['mongoose/model.js'][132] = 0;
_$jscoverage['mongoose/model.js'][133] = 0;
_$jscoverage['mongoose/model.js'][134] = 0;
_$jscoverage['mongoose/model.js'][136] = 0;
_$jscoverage['mongoose/model.js'][137] = 0;
_$jscoverage['mongoose/model.js'][141] = 0;
_$jscoverage['mongoose/model.js'][153] = 0;
_$jscoverage['mongoose/model.js'][154] = 0;
_$jscoverage['mongoose/model.js'][156] = 0;
_$jscoverage['mongoose/model.js'][157] = 0;
_$jscoverage['mongoose/model.js'][158] = 0;
_$jscoverage['mongoose/model.js'][138] = 0;
_$jscoverage['mongoose/model.js'][139] = 0;
_$jscoverage['mongoose/model.js'][140] = 0;
_$jscoverage['mongoose/model.js'][143] = 0;
_$jscoverage['mongoose/model.js'][147] = 0;
_$jscoverage['mongoose/model.js'][159] = 0;
_$jscoverage['mongoose/model.js'][160] = 0;
_$jscoverage['mongoose/model.js'][162] = 0;
_$jscoverage['mongoose/model.js'][165] = 0;
_$jscoverage['mongoose/model.js'][163] = 0;
_$jscoverage['mongoose/model.js'][164] = 0;
_$jscoverage['mongoose/model.js'][166] = 0;
_$jscoverage['mongoose/model.js'][168] = 0;
_$jscoverage['mongoose/model.js'][169] = 0;
_$jscoverage['mongoose/model.js'][171] = 0;
_$jscoverage['mongoose/model.js'][182] = 0;
_$jscoverage['mongoose/model.js'][183] = 0;
_$jscoverage['mongoose/model.js'][185] = 0;
_$jscoverage['mongoose/model.js'][186] = 0;
_$jscoverage['mongoose/model.js'][174] = 0;
_$jscoverage['mongoose/model.js'][175] = 0;
_$jscoverage['mongoose/model.js'][177] = 0;
_$jscoverage['mongoose/model.js'][188] = 0;
_$jscoverage['mongoose/model.js'][189] = 0;
_$jscoverage['mongoose/model.js'][190] = 0;
_$jscoverage['mongoose/model.js'][191] = 0;
_$jscoverage['mongoose/model.js'][192] = 0;
_$jscoverage['mongoose/model.js'][195] = 0;
_$jscoverage['mongoose/model.js'][196] = 0;
_$jscoverage['mongoose/model.js'][205] = 0;
_$jscoverage['mongoose/model.js'][207] = 0;
_$jscoverage['mongoose/model.js'][210] = 0;
_$jscoverage['mongoose/model.js'][214] = 0;
_$jscoverage['mongoose/model.js'][197] = 0;
_$jscoverage['mongoose/model.js'][198] = 0;
_$jscoverage['mongoose/model.js'][202] = 0;
_$jscoverage['mongoose/model.js'][211] = 0;
_$jscoverage['mongoose/model.js'][213] = 0;
_$jscoverage['mongoose/model.js'][216] = 0;
_$jscoverage['mongoose/model.js'][219] = 0;
_$jscoverage['mongoose/model.js'][220] = 0;
_$jscoverage['mongoose/model.js'][222] = 0;
_$jscoverage['mongoose/model.js'][224] = 0;
_$jscoverage['mongoose/model.js'][225] = 0;
_$jscoverage['mongoose/model.js'][226] = 0;
_$jscoverage['mongoose/model.js'][227] = 0;
_$jscoverage['mongoose/model.js'][228] = 0;
_$jscoverage['mongoose/model.js'][229] = 0;
_$jscoverage['mongoose/model.js'][230] = 0;
_$jscoverage['mongoose/model.js'][231] = 0;
_$jscoverage['mongoose/model.js'][232] = 0;
_$jscoverage['mongoose/model.js'][233] = 0;
_$jscoverage['mongoose/model.js'][234] = 0;
_$jscoverage['mongoose/model.js'][241] = 0;
_$jscoverage['mongoose/model.js'][250] = 0;
_$jscoverage['mongoose/model.js'][251] = 0;
_$jscoverage['mongoose/model.js'][258] = 0;
_$jscoverage['mongoose/model.js'][259] = 0;
_$jscoverage['mongoose/model.js'][267] = 0;
_$jscoverage['mongoose/model.js'][269] = 0;
_$jscoverage['mongoose/model.js'][235] = 0;
_$jscoverage['mongoose/model.js'][236] = 0;
_$jscoverage['mongoose/model.js'][237] = 0;
_$jscoverage['mongoose/model.js'][238] = 0;
_$jscoverage['mongoose/model.js'][240] = 0;
_$jscoverage['mongoose/model.js'][247] = 0;
_$jscoverage['mongoose/model.js'][256] = 0;
_$jscoverage['mongoose/model.js'][257] = 0;
_$jscoverage['mongoose/model.js'][264] = 0;
_$jscoverage['mongoose/model.js'][265] = 0;
_$jscoverage['mongoose/model.js'][273] = 0;
_$jscoverage['mongoose/model.js'][274] = 0;
_$jscoverage['mongoose/model.js'][275] = 0;
_$jscoverage['mongoose/model.js'][286] = 0;
_$jscoverage['mongoose/model.js'][294] = 0;
_$jscoverage['mongoose/model.js'][302] = 0;
_$jscoverage['mongoose/model.js'][279] = 0;
_$jscoverage['mongoose/model.js'][280] = 0;
_$jscoverage['mongoose/model.js'][281] = 0;
_$jscoverage['mongoose/model.js'][292] = 0;
_$jscoverage['mongoose/model.js'][300] = 0;
_$jscoverage['mongoose/model.js'][308] = 0;
_$jscoverage['mongoose/model.js'][309] = 0;
_$jscoverage['mongoose/model.js'][310] = 0;
_$jscoverage['mongoose/model.js'][318] = 0;
_$jscoverage['mongoose/model.js'][314] = 0;
_$jscoverage['mongoose/model.js'][315] = 0;
_$jscoverage['mongoose/model.js'][316] = 0;
_$jscoverage['mongoose/model.js'][324] = 0;
_$jscoverage['mongoose/model.js'][326] = 0;
_$jscoverage['mongoose/model.js'][327] = 0;
_$jscoverage['mongoose/model.js'][328] = 0;
_$jscoverage['mongoose/model.js'][329] = 0;
_$jscoverage['mongoose/model.js'][331] = 0;
_$jscoverage['mongoose/model.js'][345] = 0;
_$jscoverage['mongoose/model.js'][347] = 0;
_$jscoverage['mongoose/model.js'][348] = 0;
_$jscoverage['mongoose/model.js'][349] = 0;
_$jscoverage['mongoose/model.js'][330] = 0;
_$jscoverage['mongoose/model.js'][332] = 0;
_$jscoverage['mongoose/model.js'][333] = 0;
_$jscoverage['mongoose/model.js'][334] = 0;
_$jscoverage['mongoose/model.js'][335] = 0;
_$jscoverage['mongoose/model.js'][337] = 0;
_$jscoverage['mongoose/model.js'][352] = 0;

@@ -122,10 +118,16 @@ _$jscoverage['mongoose/model.js'][353] = 0;

_$jscoverage['mongoose/model.js'][357] = 0;
_$jscoverage['mongoose/model.js'][358] = 0;
_$jscoverage['mongoose/model.js'][359] = 0;
_$jscoverage['mongoose/model.js'][360] = 0;
_$jscoverage['mongoose/model.js'][361] = 0;
_$jscoverage['mongoose/model.js'][362] = 0;
_$jscoverage['mongoose/model.js'][363] = 0;
_$jscoverage['mongoose/model.js'][364] = 0;
_$jscoverage['mongoose/model.js'][366] = 0;
_$jscoverage['mongoose/model.js'][380] = 0;
_$jscoverage['mongoose/model.js'][368] = 0;
_$jscoverage['mongoose/model.js'][370] = 0;
_$jscoverage['mongoose/model.js'][374] = 0;
_$jscoverage['mongoose/model.js'][375] = 0;
_$jscoverage['mongoose/model.js'][378] = 0;
_$jscoverage['mongoose/model.js'][379] = 0;
_$jscoverage['mongoose/model.js'][381] = 0;
_$jscoverage['mongoose/model.js'][382] = 0;
_$jscoverage['mongoose/model.js'][383] = 0;

@@ -135,9 +137,6 @@ _$jscoverage['mongoose/model.js'][384] = 0;

_$jscoverage['mongoose/model.js'][386] = 0;
_$jscoverage['mongoose/model.js'][387] = 0;
_$jscoverage['mongoose/model.js'][390] = 0;
_$jscoverage['mongoose/model.js'][392] = 0;
_$jscoverage['mongoose/model.js'][393] = 0;
_$jscoverage['mongoose/model.js'][396] = 0;
_$jscoverage['mongoose/model.js'][411] = 0;
_$jscoverage['mongoose/model.js'][412] = 0;
_$jscoverage['mongoose/model.js'][413] = 0;
_$jscoverage['mongoose/model.js'][414] = 0;
_$jscoverage['mongoose/model.js'][415] = 0;

@@ -150,54 +149,53 @@ _$jscoverage['mongoose/model.js'][416] = 0;

_$jscoverage['mongoose/model.js'][421] = 0;
_$jscoverage['mongoose/model.js'][422] = 0;
_$jscoverage['mongoose/model.js'][423] = 0;
_$jscoverage['mongoose/model.js'][425] = 0;
_$jscoverage['mongoose/model.js'][424] = 0;
_$jscoverage['mongoose/model.js'][426] = 0;
_$jscoverage['mongoose/model.js'][427] = 0;
_$jscoverage['mongoose/model.js'][429] = 0;
_$jscoverage['mongoose/model.js'][430] = 0;
_$jscoverage['mongoose/model.js'][431] = 0;
_$jscoverage['mongoose/model.js'][432] = 0;
_$jscoverage['mongoose/model.js'][433] = 0;
_$jscoverage['mongoose/model.js'][434] = 0;
_$jscoverage['mongoose/model.js'][437] = 0;
_$jscoverage['mongoose/model.js'][438] = 0;
_$jscoverage['mongoose/model.js'][440] = 0;
_$jscoverage['mongoose/model.js'][442] = 0;
_$jscoverage['mongoose/model.js'][443] = 0;
_$jscoverage['mongoose/model.js'][444] = 0;
_$jscoverage['mongoose/model.js'][445] = 0;
_$jscoverage['mongoose/model.js'][452] = 0;
_$jscoverage['mongoose/model.js'][457] = 0;
_$jscoverage['mongoose/model.js'][458] = 0;
_$jscoverage['mongoose/model.js'][459] = 0;
_$jscoverage['mongoose/model.js'][460] = 0;
_$jscoverage['mongoose/model.js'][461] = 0;
_$jscoverage['mongoose/model.js'][462] = 0;
_$jscoverage['mongoose/model.js'][463] = 0;
_$jscoverage['mongoose/model.js'][464] = 0;
_$jscoverage['mongoose/model.js'][465] = 0;
_$jscoverage['mongoose/model.js'][466] = 0;
_$jscoverage['mongoose/model.js'][467] = 0;
_$jscoverage['mongoose/model.js'][468] = 0;
_$jscoverage['mongoose/model.js'][469] = 0;
_$jscoverage['mongoose/model.js'][471] = 0;
_$jscoverage['mongoose/model.js'][472] = 0;
_$jscoverage['mongoose/model.js'][474] = 0;
_$jscoverage['mongoose/model.js'][475] = 0;
_$jscoverage['mongoose/model.js'][478] = 0;
_$jscoverage['mongoose/model.js'][479] = 0;
_$jscoverage['mongoose/model.js'][481] = 0;
_$jscoverage['mongoose/model.js'][482] = 0;
_$jscoverage['mongoose/model.js'][473] = 0;
_$jscoverage['mongoose/model.js'][484] = 0;
_$jscoverage['mongoose/model.js'][485] = 0;
_$jscoverage['mongoose/model.js'][486] = 0;
_$jscoverage['mongoose/model.js'][487] = 0;
_$jscoverage['mongoose/model.js'][490] = 0;
_$jscoverage['mongoose/model.js'][492] = 0;
_$jscoverage['mongoose/model.js'][493] = 0;
_$jscoverage['mongoose/model.js'][494] = 0;
_$jscoverage['mongoose/model.js'][495] = 0;
_$jscoverage['mongoose/model.js'][496] = 0;
_$jscoverage['mongoose/model.js'][511] = 0;
_$jscoverage['mongoose/model.js'][512] = 0;
_$jscoverage['mongoose/model.js'][507] = 0;
_$jscoverage['mongoose/model.js'][508] = 0;
_$jscoverage['mongoose/model.js'][509] = 0;
_$jscoverage['mongoose/model.js'][523] = 0;
_$jscoverage['mongoose/model.js'][524] = 0;
_$jscoverage['mongoose/model.js'][525] = 0;
_$jscoverage['mongoose/model.js'][527] = 0;
_$jscoverage['mongoose/model.js'][528] = 0;
_$jscoverage['mongoose/model.js'][531] = 0;
_$jscoverage['mongoose/model.js'][532] = 0;
_$jscoverage['mongoose/model.js'][534] = 0;
_$jscoverage['mongoose/model.js'][535] = 0;
_$jscoverage['mongoose/model.js'][536] = 0;
_$jscoverage['mongoose/model.js'][537] = 0;
_$jscoverage['mongoose/model.js'][539] = 0;
_$jscoverage['mongoose/model.js'][540] = 0;
_$jscoverage['mongoose/model.js'][541] = 0;
_$jscoverage['mongoose/model.js'][542] = 0;
_$jscoverage['mongoose/model.js'][543] = 0;
_$jscoverage['mongoose/model.js'][557] = 0;
_$jscoverage['mongoose/model.js'][558] = 0;
_$jscoverage['mongoose/model.js'][560] = 0;
_$jscoverage['mongoose/model.js'][561] = 0;
_$jscoverage['mongoose/model.js'][562] = 0;
_$jscoverage['mongoose/model.js'][575] = 0;
_$jscoverage['mongoose/model.js'][544] = 0;
_$jscoverage['mongoose/model.js'][545] = 0;
_$jscoverage['mongoose/model.js'][546] = 0;
_$jscoverage['mongoose/model.js'][547] = 0;
_$jscoverage['mongoose/model.js'][548] = 0;
_$jscoverage['mongoose/model.js'][549] = 0;
_$jscoverage['mongoose/model.js'][550] = 0;
_$jscoverage['mongoose/model.js'][576] = 0;

@@ -207,139 +205,139 @@ _$jscoverage['mongoose/model.js'][577] = 0;

_$jscoverage['mongoose/model.js'][579] = 0;
_$jscoverage['mongoose/model.js'][604] = 0;
_$jscoverage['mongoose/model.js'][581] = 0;
_$jscoverage['mongoose/model.js'][582] = 0;
_$jscoverage['mongoose/model.js'][583] = 0;
_$jscoverage['mongoose/model.js'][585] = 0;
_$jscoverage['mongoose/model.js'][599] = 0;
_$jscoverage['mongoose/model.js'][601] = 0;
_$jscoverage['mongoose/model.js'][602] = 0;
_$jscoverage['mongoose/model.js'][603] = 0;
_$jscoverage['mongoose/model.js'][605] = 0;
_$jscoverage['mongoose/model.js'][606] = 0;
_$jscoverage['mongoose/model.js'][607] = 0;
_$jscoverage['mongoose/model.js'][608] = 0;
_$jscoverage['mongoose/model.js'][612] = 0;
_$jscoverage['mongoose/model.js'][627] = 0;
_$jscoverage['mongoose/model.js'][629] = 0;
_$jscoverage['mongoose/model.js'][630] = 0;
_$jscoverage['mongoose/model.js'][631] = 0;
_$jscoverage['mongoose/model.js'][633] = 0;
_$jscoverage['mongoose/model.js'][634] = 0;
_$jscoverage['mongoose/model.js'][635] = 0;
_$jscoverage['mongoose/model.js'][636] = 0;
_$jscoverage['mongoose/model.js'][637] = 0;
_$jscoverage['mongoose/model.js'][638] = 0;
_$jscoverage['mongoose/model.js'][639] = 0;
_$jscoverage['mongoose/model.js'][642] = 0;
_$jscoverage['mongoose/model.js'][643] = 0;
_$jscoverage['mongoose/model.js'][646] = 0;
_$jscoverage['mongoose/model.js'][647] = 0;
_$jscoverage['mongoose/model.js'][649] = 0;
_$jscoverage['mongoose/model.js'][609] = 0;
_$jscoverage['mongoose/model.js'][610] = 0;
_$jscoverage['mongoose/model.js'][611] = 0;
_$jscoverage['mongoose/model.js'][614] = 0;
_$jscoverage['mongoose/model.js'][615] = 0;
_$jscoverage['mongoose/model.js'][618] = 0;
_$jscoverage['mongoose/model.js'][619] = 0;
_$jscoverage['mongoose/model.js'][622] = 0;
_$jscoverage['mongoose/model.js'][624] = 0;
}
_$jscoverage['mongoose/model.js'][6]++;
var Document = require("./document"), MongooseArray = require("./types/array"), DocumentArray = require("./types/documentarray"), MongooseError = require("./error"), Query = require("./query").Query, FindQuery = require("./query").FindQuery, EventEmitter = require("./utils").EventEmitter, Promise = require("./promise");
_$jscoverage['mongoose/model.js'][22]++;
var Document = require("./document"), MongooseArray = require("./types/array"), DocumentArray = require("./types/documentarray"), MongooseError = require("./error"), Query = require("./query").Query, FindQuery = require("./query").FindQuery, FindOneQuery = require("./query").FindOneQuery, Query = require("./query").Query, Query = require("./query").Query, Query = require("./query").Query, utils = require("./utils"), EventEmitter = utils.EventEmitter, merge = utils.merge, Promise = require("./promise");
_$jscoverage['mongoose/model.js'][28]++;
function Model(doc) {
_$jscoverage['mongoose/model.js'][23]++;
_$jscoverage['mongoose/model.js'][29]++;
Document.call(this, doc);
}
_$jscoverage['mongoose/model.js'][24]++;
_$jscoverage['mongoose/model.js'][30]++;
;
_$jscoverage['mongoose/model.js'][30]++;
_$jscoverage['mongoose/model.js'][36]++;
Model.prototype.__proto__ = Document.prototype;
_$jscoverage['mongoose/model.js'][39]++;
_$jscoverage['mongoose/model.js'][45]++;
Model.prototype.db;
_$jscoverage['mongoose/model.js'][47]++;
_$jscoverage['mongoose/model.js'][53]++;
Model.prototype.collection;
_$jscoverage['mongoose/model.js'][55]++;
_$jscoverage['mongoose/model.js'][61]++;
Model.prototype.name;
_$jscoverage['mongoose/model.js'][65]++;
_$jscoverage['mongoose/model.js'][71]++;
Model.prototype.save = (function (fn) {
_$jscoverage['mongoose/model.js'][66]++;
_$jscoverage['mongoose/model.js'][72]++;
var promise = new Promise(fn), options = {}, self = this;
_$jscoverage['mongoose/model.js'][70]++;
_$jscoverage['mongoose/model.js'][76]++;
function complete(err) {
_$jscoverage['mongoose/model.js'][71]++;
_$jscoverage['mongoose/model.js'][77]++;
if (err) {
_$jscoverage['mongoose/model.js'][71]++;
_$jscoverage['mongoose/model.js'][77]++;
return promise.error(err);
}
_$jscoverage['mongoose/model.js'][72]++;
_$jscoverage['mongoose/model.js'][78]++;
promise.complete();
_$jscoverage['mongoose/model.js'][73]++;
_$jscoverage['mongoose/model.js'][79]++;
self.emit("save");
}
_$jscoverage['mongoose/model.js'][74]++;
_$jscoverage['mongoose/model.js'][80]++;
;
_$jscoverage['mongoose/model.js'][77]++;
_$jscoverage['mongoose/model.js'][83]++;
if (this.options.safe) {
_$jscoverage['mongoose/model.js'][78]++;
_$jscoverage['mongoose/model.js'][84]++;
options.safe = true;
}
_$jscoverage['mongoose/model.js'][80]++;
_$jscoverage['mongoose/model.js'][86]++;
if (this.isNew) {
_$jscoverage['mongoose/model.js'][82]++;
_$jscoverage['mongoose/model.js'][88]++;
this.collection.insert(this.toObject(), options, complete);
_$jscoverage['mongoose/model.js'][83]++;
_$jscoverage['mongoose/model.js'][89]++;
this.isNew = false;
}
else {
_$jscoverage['mongoose/model.js'][86]++;
_$jscoverage['mongoose/model.js'][92]++;
var self = this, delta, useSet = this.options.use$SetOnSave;
_$jscoverage['mongoose/model.js'][90]++;
_$jscoverage['mongoose/model.js'][96]++;
delta = this.activePaths.map("modify", (function (path) {
_$jscoverage['mongoose/model.js'][91]++;
_$jscoverage['mongoose/model.js'][97]++;
return ({path: path, value: self.getValue(path), schema: self.schema.path(path)});
})).reduce((function (delta, data) {
_$jscoverage['mongoose/model.js'][93]++;
_$jscoverage['mongoose/model.js'][99]++;
var type = data.value, schema = data.schema;
_$jscoverage['mongoose/model.js'][97]++;
_$jscoverage['mongoose/model.js'][103]++;
if (type._path && type.doAtomics) {
_$jscoverage['mongoose/model.js'][98]++;
_$jscoverage['mongoose/model.js'][104]++;
["$push", "$pull"].forEach((function (opType) {
_$jscoverage['mongoose/model.js'][99]++;
_$jscoverage['mongoose/model.js'][105]++;
var ops = type._atomics.filter((function (op) {
_$jscoverage['mongoose/model.js'][100]++;
_$jscoverage['mongoose/model.js'][106]++;
return op[0] === opType;
})), opsAll = type._atomics.filter((function (op) {
_$jscoverage['mongoose/model.js'][103]++;
_$jscoverage['mongoose/model.js'][109]++;
return op[0] === (opType + "All");
}));
_$jscoverage['mongoose/model.js'][105]++;
_$jscoverage['mongoose/model.js'][111]++;
if (ops.length > 1 || (ops.length === 1 && opsAll.length > 0)) {
_$jscoverage['mongoose/model.js'][112]++;
_$jscoverage['mongoose/model.js'][118]++;
type._atomics = type._atomics.filter((function (op) {
_$jscoverage['mongoose/model.js'][113]++;
_$jscoverage['mongoose/model.js'][119]++;
return op[0] !== opType;
}));
_$jscoverage['mongoose/model.js'][115]++;
_$jscoverage['mongoose/model.js'][121]++;
if (opsAll.length > 0) {
_$jscoverage['mongoose/model.js'][116]++;
_$jscoverage['mongoose/model.js'][122]++;
type._atomics = type._atomics.filter((function (op) {
_$jscoverage['mongoose/model.js'][117]++;
_$jscoverage['mongoose/model.js'][123]++;
return op[0] !== (opType + "All");
}));
}
_$jscoverage['mongoose/model.js'][120]++;
_$jscoverage['mongoose/model.js'][126]++;
var whatToAll = [];
_$jscoverage['mongoose/model.js'][121]++;
_$jscoverage['mongoose/model.js'][127]++;
opsAll.forEach((function (op) {
_$jscoverage['mongoose/model.js'][122]++;
_$jscoverage['mongoose/model.js'][128]++;
whatToAll = whatToAll.concat(op[1]);
}));
_$jscoverage['mongoose/model.js'][124]++;
_$jscoverage['mongoose/model.js'][130]++;
whatToAll = whatToAll.concat(ops.map((function (op) {
_$jscoverage['mongoose/model.js'][125]++;
_$jscoverage['mongoose/model.js'][131]++;
return op[1];
})));
_$jscoverage['mongoose/model.js'][127]++;
_$jscoverage['mongoose/model.js'][133]++;
type._atomics.push([opType + "All", whatToAll]);
}
}));
_$jscoverage['mongoose/model.js'][130]++;
_$jscoverage['mongoose/model.js'][136]++;
type._atomics.forEach((function (op) {
_$jscoverage['mongoose/model.js'][131]++;
_$jscoverage['mongoose/model.js'][137]++;
var obj = delta[op[0]] = delta[op[0]] || {};
_$jscoverage['mongoose/model.js'][132]++;
_$jscoverage['mongoose/model.js'][138]++;
if (op[0] === "$pull" || op[0] === "$push") {
_$jscoverage['mongoose/model.js'][133]++;
_$jscoverage['mongoose/model.js'][139]++;
if (op[1].constructor !== Object) {
_$jscoverage['mongoose/model.js'][134]++;
_$jscoverage['mongoose/model.js'][140]++;
op[1] = schema.cast(op[1])[0];
}
}
_$jscoverage['mongoose/model.js'][137]++;
_$jscoverage['mongoose/model.js'][143]++;
obj[type._path] = op[1].toObject? op[1].toObject(): Array.isArray(op[1])? op[1].map((function (mem) {
_$jscoverage['mongoose/model.js'][141]++;
_$jscoverage['mongoose/model.js'][147]++;
return mem.toObject? mem.toObject(): mem.valueOf? mem.valueOf(): mem;

@@ -350,32 +348,32 @@ })): op[1].valueOf? op[1].valueOf(): op[1];

else {
_$jscoverage['mongoose/model.js'][153]++;
_$jscoverage['mongoose/model.js'][159]++;
if (type._path) {
_$jscoverage['mongoose/model.js'][154]++;
_$jscoverage['mongoose/model.js'][160]++;
type = type.valueOf();
}
_$jscoverage['mongoose/model.js'][156]++;
_$jscoverage['mongoose/model.js'][162]++;
if (useSet) {
_$jscoverage['mongoose/model.js'][157]++;
_$jscoverage['mongoose/model.js'][163]++;
if (! ("$set" in delta)) {
_$jscoverage['mongoose/model.js'][158]++;
_$jscoverage['mongoose/model.js'][164]++;
delta.$set = {};
}
_$jscoverage['mongoose/model.js'][160]++;
_$jscoverage['mongoose/model.js'][166]++;
delta.$set[data.path] = type;
}
else {
_$jscoverage['mongoose/model.js'][162]++;
_$jscoverage['mongoose/model.js'][168]++;
delta[data.path] = type;
}
}
_$jscoverage['mongoose/model.js'][165]++;
_$jscoverage['mongoose/model.js'][171]++;
return delta;
}), {});
_$jscoverage['mongoose/model.js'][168]++;
_$jscoverage['mongoose/model.js'][174]++;
if (Object.keys(delta).length) {
_$jscoverage['mongoose/model.js'][169]++;
_$jscoverage['mongoose/model.js'][175]++;
this.collection.update({_id: this.doc._id}, delta, options, complete);
}
else {
_$jscoverage['mongoose/model.js'][171]++;
_$jscoverage['mongoose/model.js'][177]++;
complete(null);

@@ -385,69 +383,69 @@ }

});
_$jscoverage['mongoose/model.js'][182]++;
_$jscoverage['mongoose/model.js'][188]++;
Model.prototype.remove = (function (fn) {
_$jscoverage['mongoose/model.js'][183]++;
_$jscoverage['mongoose/model.js'][189]++;
if (this.removing || this.removed) {
_$jscoverage['mongoose/model.js'][183]++;
_$jscoverage['mongoose/model.js'][189]++;
return this;
}
_$jscoverage['mongoose/model.js'][185]++;
_$jscoverage['mongoose/model.js'][191]++;
if (! this.removing) {
_$jscoverage['mongoose/model.js'][186]++;
_$jscoverage['mongoose/model.js'][192]++;
var promise = this.removing = new Promise(fn), self = this;
_$jscoverage['mongoose/model.js'][189]++;
_$jscoverage['mongoose/model.js'][195]++;
this.collection.remove({_id: this.doc._id}, (function (err) {
_$jscoverage['mongoose/model.js'][190]++;
_$jscoverage['mongoose/model.js'][196]++;
if (err) {
_$jscoverage['mongoose/model.js'][190]++;
_$jscoverage['mongoose/model.js'][196]++;
return promise.error(err);
}
_$jscoverage['mongoose/model.js'][191]++;
_$jscoverage['mongoose/model.js'][197]++;
promise.complete();
_$jscoverage['mongoose/model.js'][192]++;
_$jscoverage['mongoose/model.js'][198]++;
self.emit("remove");
}));
}
_$jscoverage['mongoose/model.js'][196]++;
_$jscoverage['mongoose/model.js'][202]++;
return this;
});
_$jscoverage['mongoose/model.js'][205]++;
_$jscoverage['mongoose/model.js'][211]++;
Model.prototype.registerHooks = (function () {
_$jscoverage['mongoose/model.js'][207]++;
_$jscoverage['mongoose/model.js'][213]++;
this.pre("save", (function (next) {
_$jscoverage['mongoose/model.js'][210]++;
_$jscoverage['mongoose/model.js'][216]++;
var subdocs = 0, error = false, self = this;
_$jscoverage['mongoose/model.js'][214]++;
_$jscoverage['mongoose/model.js'][220]++;
var arrays = this.activePaths.map("init", "modify", (function (i) {
_$jscoverage['mongoose/model.js'][216]++;
_$jscoverage['mongoose/model.js'][222]++;
return self.getValue(i);
})).filter((function (val) {
_$jscoverage['mongoose/model.js'][219]++;
_$jscoverage['mongoose/model.js'][225]++;
return (val && val instanceof DocumentArray && val.length);
}));
_$jscoverage['mongoose/model.js'][222]++;
_$jscoverage['mongoose/model.js'][228]++;
if (! arrays.length) {
_$jscoverage['mongoose/model.js'][222]++;
_$jscoverage['mongoose/model.js'][228]++;
return next();
}
_$jscoverage['mongoose/model.js'][224]++;
_$jscoverage['mongoose/model.js'][230]++;
arrays.forEach((function (array) {
_$jscoverage['mongoose/model.js'][225]++;
_$jscoverage['mongoose/model.js'][231]++;
subdocs += array.length;
_$jscoverage['mongoose/model.js'][226]++;
_$jscoverage['mongoose/model.js'][232]++;
array.forEach((function (value) {
_$jscoverage['mongoose/model.js'][227]++;
_$jscoverage['mongoose/model.js'][233]++;
if (! error) {
_$jscoverage['mongoose/model.js'][228]++;
_$jscoverage['mongoose/model.js'][234]++;
value.save((function (err) {
_$jscoverage['mongoose/model.js'][229]++;
_$jscoverage['mongoose/model.js'][235]++;
if (! error) {
_$jscoverage['mongoose/model.js'][230]++;
_$jscoverage['mongoose/model.js'][236]++;
if (err) {
_$jscoverage['mongoose/model.js'][231]++;
_$jscoverage['mongoose/model.js'][237]++;
error = true;
_$jscoverage['mongoose/model.js'][232]++;
_$jscoverage['mongoose/model.js'][238]++;
next(err);
}
else {
_$jscoverage['mongoose/model.js'][234]++;
_$jscoverage['mongoose/model.js'][240]++;
--subdocs || next();

@@ -461,24 +459,24 @@ }

}));
_$jscoverage['mongoose/model.js'][241]++;
_$jscoverage['mongoose/model.js'][247]++;
Document.prototype.registerHooks.call(this);
});
_$jscoverage['mongoose/model.js'][250]++;
_$jscoverage['mongoose/model.js'][256]++;
Model.prototype.__defineGetter__("options", (function () {
_$jscoverage['mongoose/model.js'][251]++;
_$jscoverage['mongoose/model.js'][257]++;
return this.schema? this.schema.options: {};
}));
_$jscoverage['mongoose/model.js'][258]++;
_$jscoverage['mongoose/model.js'][264]++;
for (var i in EventEmitter.prototype) {
_$jscoverage['mongoose/model.js'][259]++;
_$jscoverage['mongoose/model.js'][265]++;
Model[i] = EventEmitter.prototype[i];
}
_$jscoverage['mongoose/model.js'][267]++;
_$jscoverage['mongoose/model.js'][273]++;
Model.init = (function () {
_$jscoverage['mongoose/model.js'][269]++;
_$jscoverage['mongoose/model.js'][275]++;
var self = this, indexes = this.schema.indexes, count = indexes.length;
_$jscoverage['mongoose/model.js'][273]++;
_$jscoverage['mongoose/model.js'][279]++;
indexes.forEach((function (index) {
_$jscoverage['mongoose/model.js'][274]++;
_$jscoverage['mongoose/model.js'][280]++;
self.collection.ensureIndex(index[0], index[1], (function () {
_$jscoverage['mongoose/model.js'][275]++;
_$jscoverage['mongoose/model.js'][281]++;
--count || self.emit("index");

@@ -488,128 +486,67 @@ }));

});
_$jscoverage['mongoose/model.js'][286]++;
_$jscoverage['mongoose/model.js'][292]++;
Model.schema;
_$jscoverage['mongoose/model.js'][294]++;
_$jscoverage['mongoose/model.js'][300]++;
Model.db;
_$jscoverage['mongoose/model.js'][302]++;
_$jscoverage['mongoose/model.js'][308]++;
Model.collection;
_$jscoverage['mongoose/model.js'][308]++;
_$jscoverage['mongoose/model.js'][314]++;
["db", "collection", "schema", "options"].forEach((function (prop) {
_$jscoverage['mongoose/model.js'][309]++;
_$jscoverage['mongoose/model.js'][315]++;
Model.__defineGetter__(prop, (function () {
_$jscoverage['mongoose/model.js'][310]++;
_$jscoverage['mongoose/model.js'][316]++;
return this.prototype[prop];
}));
}));
_$jscoverage['mongoose/model.js'][318]++;
_$jscoverage['mongoose/model.js'][324]++;
Document.registerHooks.call(Model, "save", "remove", "init");
_$jscoverage['mongoose/model.js'][324]++;
_$jscoverage['mongoose/model.js'][330]++;
module.exports = exports = Model;
_$jscoverage['mongoose/model.js'][326]++;
Model.remove = (function (query, callback) {
_$jscoverage['mongoose/model.js'][327]++;
var self = this;
_$jscoverage['mongoose/model.js'][328]++;
this.query(query, {}, callback, (function () {
_$jscoverage['mongoose/model.js'][329]++;
var casted = self.castQuery(this.query), queryComplete = this.queryComplete.bind(this);
_$jscoverage['mongoose/model.js'][331]++;
self.collection.remove(casted, queryComplete);
}));
});
_$jscoverage['mongoose/model.js'][345]++;
Model.query = (function (query, options, callback, onExecute) {
_$jscoverage['mongoose/model.js'][347]++;
if ("function" == typeof options) {
_$jscoverage['mongoose/model.js'][348]++;
callback = options;
_$jscoverage['mongoose/model.js'][349]++;
options = {};
_$jscoverage['mongoose/model.js'][332]++;
Model.remove = (function (conditions, callback) {
_$jscoverage['mongoose/model.js'][333]++;
var query = new Query(conditions).bind(this);
_$jscoverage['mongoose/model.js'][334]++;
if ("undefined" === typeof callback) {
_$jscoverage['mongoose/model.js'][335]++;
return query;
}
_$jscoverage['mongoose/model.js'][352]++;
if (! options) {
_$jscoverage['mongoose/model.js'][353]++;
options = {};
}
_$jscoverage['mongoose/model.js'][356]++;
if (! ("safe" in options)) {
_$jscoverage['mongoose/model.js'][357]++;
options.safe = this.options.safe;
}
_$jscoverage['mongoose/model.js'][359]++;
var query = new Query(query, options, onExecute);
_$jscoverage['mongoose/model.js'][361]++;
if (callback) {
_$jscoverage['mongoose/model.js'][362]++;
query.addBack(callback);
_$jscoverage['mongoose/model.js'][363]++;
query.run();
}
_$jscoverage['mongoose/model.js'][366]++;
return query;
_$jscoverage['mongoose/model.js'][337]++;
return query.remove(callback);
});
_$jscoverage['mongoose/model.js'][380]++;
Model.findQuery = (function (query, fields, options, callback, onExecute) {
_$jscoverage['mongoose/model.js'][381]++;
if ("function" == typeof fields) {
_$jscoverage['mongoose/model.js'][382]++;
callback = fields;
_$jscoverage['mongoose/model.js'][383]++;
fields = {};
_$jscoverage['mongoose/model.js'][384]++;
options = {};
}
else {
_$jscoverage['mongoose/model.js'][385]++;
if ("function" == typeof options) {
_$jscoverage['mongoose/model.js'][386]++;
callback = options;
_$jscoverage['mongoose/model.js'][387]++;
options = {};
}
}
_$jscoverage['mongoose/model.js'][390]++;
var query = new FindQuery(query, fields, options, onExecute);
_$jscoverage['mongoose/model.js'][392]++;
if (callback) {
_$jscoverage['mongoose/model.js'][393]++;
query.run(callback);
}
_$jscoverage['mongoose/model.js'][396]++;
return query;
});
_$jscoverage['mongoose/model.js'][411]++;
_$jscoverage['mongoose/model.js'][352]++;
Model.castQuery = (function (query) {
_$jscoverage['mongoose/model.js'][412]++;
_$jscoverage['mongoose/model.js'][353]++;
var ret = {}, self = this;
_$jscoverage['mongoose/model.js'][415]++;
_$jscoverage['mongoose/model.js'][356]++;
for (var i in query) {
_$jscoverage['mongoose/model.js'][416]++;
_$jscoverage['mongoose/model.js'][357]++;
if (query[i] === null || query[i] === undefined) {
_$jscoverage['mongoose/model.js'][417]++;
_$jscoverage['mongoose/model.js'][358]++;
ret[i] = query[i];
}
else {
_$jscoverage['mongoose/model.js'][418]++;
_$jscoverage['mongoose/model.js'][359]++;
if (query[i].constructor == Object) {
_$jscoverage['mongoose/model.js'][419]++;
_$jscoverage['mongoose/model.js'][360]++;
ret[i] = query[i];
_$jscoverage['mongoose/model.js'][420]++;
_$jscoverage['mongoose/model.js'][361]++;
Object.keys(query[i]).filter((function (key) {
_$jscoverage['mongoose/model.js'][421]++;
_$jscoverage['mongoose/model.js'][362]++;
return key.charAt(0) === "$";
})).forEach((function (key) {
_$jscoverage['mongoose/model.js'][423]++;
_$jscoverage['mongoose/model.js'][364]++;
var schema = self.schema.path(i);
_$jscoverage['mongoose/model.js'][425]++;
_$jscoverage['mongoose/model.js'][366]++;
if (key == "$in") {
_$jscoverage['mongoose/model.js'][427]++;
_$jscoverage['mongoose/model.js'][368]++;
ret[i][key] = ret[i][key].map(schema.cast);
}
else {
_$jscoverage['mongoose/model.js'][429]++;
_$jscoverage['mongoose/model.js'][370]++;
ret[i][key] = schema.cast(query[i][key]);
}
_$jscoverage['mongoose/model.js'][433]++;
_$jscoverage['mongoose/model.js'][374]++;
if (ret[i][key]._path) {
_$jscoverage['mongoose/model.js'][434]++;
_$jscoverage['mongoose/model.js'][375]++;
ret[i][key] = ret[i][key].valueOf();

@@ -620,17 +557,17 @@ }

else {
_$jscoverage['mongoose/model.js'][437]++;
_$jscoverage['mongoose/model.js'][378]++;
if (query[i].constructor == RegExp || Array.isArray(query[i])) {
_$jscoverage['mongoose/model.js'][438]++;
_$jscoverage['mongoose/model.js'][379]++;
ret[i] = query[i];
}
else {
_$jscoverage['mongoose/model.js'][440]++;
_$jscoverage['mongoose/model.js'][381]++;
ret[i] = this.schema.path(i).cast(query[i]);
_$jscoverage['mongoose/model.js'][442]++;
_$jscoverage['mongoose/model.js'][383]++;
if (ret[i] instanceof MongooseArray) {
_$jscoverage['mongoose/model.js'][443]++;
_$jscoverage['mongoose/model.js'][384]++;
var arr = ret[i];
_$jscoverage['mongoose/model.js'][444]++;
_$jscoverage['mongoose/model.js'][385]++;
delete ret[i];
_$jscoverage['mongoose/model.js'][445]++;
_$jscoverage['mongoose/model.js'][386]++;
ret[i] = {$all: arr};

@@ -642,180 +579,227 @@ }

}
_$jscoverage['mongoose/model.js'][452]++;
_$jscoverage['mongoose/model.js'][393]++;
return ret;
});
_$jscoverage['mongoose/model.js'][471]++;
Model.find = (function (query, fields, options, callback) {
_$jscoverage['mongoose/model.js'][472]++;
var self = this;
_$jscoverage['mongoose/model.js'][474]++;
return this.findQuery(query, fields, options, callback, (function (query) {
_$jscoverage['mongoose/model.js'][475]++;
var q = this, casted = self.castQuery(this.query);
_$jscoverage['mongoose/model.js'][478]++;
if (this.fields) {
_$jscoverage['mongoose/model.js'][479]++;
this.options.fields = this.fields;
_$jscoverage['mongoose/model.js'][412]++;
Model.find = (function (conditions, fields, options, callback) {
_$jscoverage['mongoose/model.js'][413]++;
if ("function" === typeof fields) {
_$jscoverage['mongoose/model.js'][414]++;
callback = fields;
_$jscoverage['mongoose/model.js'][415]++;
fields = null;
_$jscoverage['mongoose/model.js'][416]++;
options = null;
}
_$jscoverage['mongoose/model.js'][481]++;
self.collection.find(casted, this.options, (function (err, cursor) {
_$jscoverage['mongoose/model.js'][482]++;
if (err) {
_$jscoverage['mongoose/model.js'][482]++;
return q.queryComplete(err);
else {
_$jscoverage['mongoose/model.js'][417]++;
if ("function" === typeof options) {
_$jscoverage['mongoose/model.js'][418]++;
callback = options;
_$jscoverage['mongoose/model.js'][419]++;
options = null;
}
else {
_$jscoverage['mongoose/model.js'][420]++;
if ("function" === typeof conditions) {
_$jscoverage['mongoose/model.js'][421]++;
callback = conditions;
_$jscoverage['mongoose/model.js'][422]++;
conditions = {};
_$jscoverage['mongoose/model.js'][423]++;
fields = null;
_$jscoverage['mongoose/model.js'][424]++;
options = null;
}
}
}
_$jscoverage['mongoose/model.js'][484]++;
cursor.toArray((function (err, docs) {
_$jscoverage['mongoose/model.js'][485]++;
if (err) {
_$jscoverage['mongoose/model.js'][485]++;
return q.queryComplete(err);
_$jscoverage['mongoose/model.js'][426]++;
var query = new Query(conditions, options).select(fields).bind(this);
_$jscoverage['mongoose/model.js'][427]++;
if ("undefined" === typeof callback) {
_$jscoverage['mongoose/model.js'][427]++;
return query;
}
_$jscoverage['mongoose/model.js'][487]++;
var arr = [], count = docs.length;
_$jscoverage['mongoose/model.js'][490]++;
if (! count) {
_$jscoverage['mongoose/model.js'][490]++;
return q.queryComplete(null, []);
_$jscoverage['mongoose/model.js'][429]++;
var cQuery;
_$jscoverage['mongoose/model.js'][430]++;
if (cQuery = this._cumulativeQuery) {
_$jscoverage['mongoose/model.js'][431]++;
merge(query._conditions, cQuery._conditions);
}
_$jscoverage['mongoose/model.js'][492]++;
for (var i = 0, l = docs.length; i < l; i++) {
_$jscoverage['mongoose/model.js'][493]++;
arr[i] = new self();
_$jscoverage['mongoose/model.js'][494]++;
arr[i].init(docs[i], (function (err) {
_$jscoverage['mongoose/model.js'][495]++;
if (err) {
_$jscoverage['mongoose/model.js'][495]++;
return q.queryComplete(err);
_$jscoverage['mongoose/model.js'][432]++;
if (! query.model) {
_$jscoverage['mongoose/model.js'][432]++;
query.bind(this);
}
_$jscoverage['mongoose/model.js'][496]++;
--count || q.queryComplete(null, arr);
}));
}
}));
}));
}));
_$jscoverage['mongoose/model.js'][433]++;
delete this._cumulativeQuery;
_$jscoverage['mongoose/model.js'][434]++;
return query.find(callback);
});
_$jscoverage['mongoose/model.js'][511]++;
_$jscoverage['mongoose/model.js'][444]++;
Model.findById = (function (id, fields, options, callback) {
_$jscoverage['mongoose/model.js'][512]++;
_$jscoverage['mongoose/model.js'][445]++;
return this.findOne({_id: id}, fields, options, callback);
});
_$jscoverage['mongoose/model.js'][524]++;
Model.findOne = (function (query, fields, options, callback) {
_$jscoverage['mongoose/model.js'][525]++;
var self = this;
_$jscoverage['mongoose/model.js'][527]++;
return this.findQuery(query, fields, options, callback, (function () {
_$jscoverage['mongoose/model.js'][528]++;
var q = this, casted = self.castQuery(this.query);
_$jscoverage['mongoose/model.js'][531]++;
if (this.fields) {
_$jscoverage['mongoose/model.js'][532]++;
this.options.fields = this.fields;
_$jscoverage['mongoose/model.js'][457]++;
Model.findOne = (function (conditions, fields, options, callback) {
_$jscoverage['mongoose/model.js'][458]++;
if ("function" === typeof options) {
_$jscoverage['mongoose/model.js'][459]++;
callback = options;
_$jscoverage['mongoose/model.js'][460]++;
options = null;
}
_$jscoverage['mongoose/model.js'][534]++;
self.collection.findOne(casted, this.options, (function (err, doc) {
_$jscoverage['mongoose/model.js'][535]++;
if (err) {
_$jscoverage['mongoose/model.js'][535]++;
return q.queryComplete(err);
else {
_$jscoverage['mongoose/model.js'][461]++;
if ("function" === typeof fields) {
_$jscoverage['mongoose/model.js'][462]++;
callback = fields;
_$jscoverage['mongoose/model.js'][463]++;
fields = null;
_$jscoverage['mongoose/model.js'][464]++;
options = null;
}
else {
_$jscoverage['mongoose/model.js'][465]++;
if ("function" === typeof conditions) {
_$jscoverage['mongoose/model.js'][466]++;
callback = conditions;
_$jscoverage['mongoose/model.js'][467]++;
conditions = {};
_$jscoverage['mongoose/model.js'][468]++;
fields = null;
_$jscoverage['mongoose/model.js'][469]++;
options = null;
}
}
}
_$jscoverage['mongoose/model.js'][471]++;
var query = new Query(conditions, options).select(fields).bind(this);
_$jscoverage['mongoose/model.js'][472]++;
if ("undefined" === typeof callback) {
_$jscoverage['mongoose/model.js'][472]++;
return query;
}
_$jscoverage['mongoose/model.js'][473]++;
return query.findOne(callback);
});
_$jscoverage['mongoose/model.js'][484]++;
Model.count = (function (conditions, callback) {
_$jscoverage['mongoose/model.js'][485]++;
var query = new Query(conditions).bind(this);
_$jscoverage['mongoose/model.js'][486]++;
if ("undefined" === typeof callback) {
_$jscoverage['mongoose/model.js'][486]++;
return query;
}
_$jscoverage['mongoose/model.js'][487]++;
return query.count(callback);
});
_$jscoverage['mongoose/model.js'][507]++;
Model["with"] = (function (path, val) {
_$jscoverage['mongoose/model.js'][508]++;
var q = new Query().bind(this);
_$jscoverage['mongoose/model.js'][509]++;
return q["with"].apply(q, arguments);
});
_$jscoverage['mongoose/model.js'][523]++;
Model.$where = (function () {
_$jscoverage['mongoose/model.js'][524]++;
var q = new Query().bind(this);
_$jscoverage['mongoose/model.js'][525]++;
return q.$where.apply(q, arguments);
});
_$jscoverage['mongoose/model.js'][536]++;
Model.create = (function (doc, fn) {
_$jscoverage['mongoose/model.js'][537]++;
if (! doc) {
_$jscoverage['mongoose/model.js'][537]++;
return q.queryComplete(null, null);
var args = [].slice.call(arguments), lastArg = args[args.length - 1], count, docs = [];
_$jscoverage['mongoose/model.js'][540]++;
if (typeof lastArg === "function") {
_$jscoverage['mongoose/model.js'][541]++;
fn = args.pop();
}
_$jscoverage['mongoose/model.js'][539]++;
var casted = new self();
_$jscoverage['mongoose/model.js'][541]++;
casted.init(doc, (function (err) {
_$jscoverage['mongoose/model.js'][542]++;
_$jscoverage['mongoose/model.js'][543]++;
count = args.length;
_$jscoverage['mongoose/model.js'][544]++;
var self = this;
_$jscoverage['mongoose/model.js'][545]++;
args.forEach((function (arg, i) {
_$jscoverage['mongoose/model.js'][546]++;
var doc = new self(arg);
_$jscoverage['mongoose/model.js'][547]++;
docs[i] = doc;
_$jscoverage['mongoose/model.js'][548]++;
doc.save((function (err) {
_$jscoverage['mongoose/model.js'][549]++;
if (err) {
_$jscoverage['mongoose/model.js'][542]++;
return q.queryComplete(err);
_$jscoverage['mongoose/model.js'][549]++;
return fn(err);
}
_$jscoverage['mongoose/model.js'][543]++;
q.queryComplete(null, casted);
_$jscoverage['mongoose/model.js'][550]++;
--count || fn.apply(null, [null].concat(docs));
}));
}));
}));
});
_$jscoverage['mongoose/model.js'][557]++;
Model.count = (function (query, callback) {
_$jscoverage['mongoose/model.js'][558]++;
var self = this;
_$jscoverage['mongoose/model.js'][560]++;
return this.query(query, {}, callback, (function () {
_$jscoverage['mongoose/model.js'][561]++;
var casted = self.castQuery(this.query);
_$jscoverage['mongoose/model.js'][562]++;
self.collection.count(casted, this.queryComplete.bind(this));
}));
});
_$jscoverage['mongoose/model.js'][575]++;
Model.create = (function (doc, fn) {
_$jscoverage['mongoose/model.js'][576]++;
var document = new this(doc);
_$jscoverage['mongoose/model.js'][576]++;
Model.update = (function (conditions, doc, options, callback) {
_$jscoverage['mongoose/model.js'][577]++;
document.save((function (err) {
_$jscoverage['mongoose/model.js'][578]++;
if (err) {
if ("function" === typeof options) {
_$jscoverage['mongoose/model.js'][578]++;
fn(err);
}
else {
callback = options;
_$jscoverage['mongoose/model.js'][579]++;
fn(null, document);
options = null;
}
}));
_$jscoverage['mongoose/model.js'][581]++;
var query = new Query(conditions, options).bind(this);
_$jscoverage['mongoose/model.js'][582]++;
if ("undefined" === typeof callback) {
_$jscoverage['mongoose/model.js'][583]++;
return query;
}
_$jscoverage['mongoose/model.js'][585]++;
return query.update(doc, callback);
});
_$jscoverage['mongoose/model.js'][604]++;
Model.update = (function (query, doc, options, callback) {
_$jscoverage['mongoose/model.js'][605]++;
var self = this;
_$jscoverage['mongoose/model.js'][607]++;
return this.query(query, options, callback, (function () {
_$jscoverage['mongoose/model.js'][608]++;
var castQuery = self.castQuery(this.query), castDoc = self.castQuery(doc), queryComplete = this.queryComplete.bind(this);
_$jscoverage['mongoose/model.js'][612]++;
self.collection.update(castQuery, castDoc, this.options, queryComplete);
}));
});
_$jscoverage['mongoose/model.js'][627]++;
_$jscoverage['mongoose/model.js'][599]++;
Model.compile = (function (name, schema, collectionName, connection, base) {
_$jscoverage['mongoose/model.js'][629]++;
_$jscoverage['mongoose/model.js'][601]++;
function model() {
_$jscoverage['mongoose/model.js'][630]++;
_$jscoverage['mongoose/model.js'][602]++;
Model.apply(this, arguments);
}
_$jscoverage['mongoose/model.js'][631]++;
_$jscoverage['mongoose/model.js'][603]++;
;
_$jscoverage['mongoose/model.js'][633]++;
_$jscoverage['mongoose/model.js'][605]++;
model.name = name;
_$jscoverage['mongoose/model.js'][634]++;
_$jscoverage['mongoose/model.js'][606]++;
model.__proto__ = Model;
_$jscoverage['mongoose/model.js'][635]++;
_$jscoverage['mongoose/model.js'][607]++;
model.prototype.__proto__ = Model.prototype;
_$jscoverage['mongoose/model.js'][636]++;
_$jscoverage['mongoose/model.js'][608]++;
model.prototype.base = base;
_$jscoverage['mongoose/model.js'][637]++;
_$jscoverage['mongoose/model.js'][609]++;
model.prototype.schema = schema;
_$jscoverage['mongoose/model.js'][638]++;
_$jscoverage['mongoose/model.js'][610]++;
model.prototype.db = connection;
_$jscoverage['mongoose/model.js'][639]++;
_$jscoverage['mongoose/model.js'][611]++;
model.prototype.collection = connection.collection(collectionName);
_$jscoverage['mongoose/model.js'][642]++;
_$jscoverage['mongoose/model.js'][614]++;
for (var i in schema.methods) {
_$jscoverage['mongoose/model.js'][643]++;
_$jscoverage['mongoose/model.js'][615]++;
model.prototype[i] = schema.methods[i];
}
_$jscoverage['mongoose/model.js'][646]++;
_$jscoverage['mongoose/model.js'][618]++;
for (var i in schema.statics) {
_$jscoverage['mongoose/model.js'][647]++;
_$jscoverage['mongoose/model.js'][619]++;
model[i] = schema.statics[i];
}
_$jscoverage['mongoose/model.js'][649]++;
_$jscoverage['mongoose/model.js'][622]++;
if (schema.namedScopes) {
_$jscoverage['mongoose/model.js'][622]++;
schema.namedScopes.compile(model);
}
_$jscoverage['mongoose/model.js'][624]++;
return model;
});
_$jscoverage['mongoose/model.js'].source = ["","/**"," * Module dependencies."," */","","var Document = require('./document')"," , MongooseArray = require('./types/array')"," , DocumentArray = require('./types/documentarray')"," , MongooseError = require('./error')"," , Query = require('./query').Query"," , FindQuery = require('./query').FindQuery"," , EventEmitter = require('./utils').EventEmitter"," , Promise = require('./promise');","","/**"," * Model constructor"," *"," * @param {Object} values to set"," * @api public"," */","","function Model (doc) {"," Document.call(this, doc);","};","","/**"," * Inherits from Document."," */","","Model.prototype.__proto__ = Document.prototype;","","/**"," * Connection the model uses. Set by the Connection or if absent set to the"," * default mongoose connection;"," *"," * @api public"," */","","Model.prototype.db;","","/**"," * Collection the model uses. Set by Mongoose instance"," *"," * @api public"," */","","Model.prototype.collection;","","/**"," * Model name."," *"," * @api public"," */","","Model.prototype.name;","","/**"," * Saves the document."," *"," * @see Model#registerHooks"," * @param {Function} callback"," * @api public"," */","","Model.prototype.save = function (fn) {"," var promise = new Promise(fn)"," , options = {}"," , self = this;",""," function complete (err) {"," if (err) return promise.error(err);"," promise.complete();"," self.emit('save');"," };",""," // support for safe mode"," if (this.options.safe)"," options.safe = true;",""," if (this.isNew) {"," // send entire doc"," this.collection.insert(this.toObject(), options, complete);"," this.isNew = false;"," } else {"," // send delta"," var self = this"," , delta"," , useSet = this.options['use$SetOnSave'];",""," delta = this.activePaths.map('modify', function (path) {"," return { path: path, value: self.getValue(path), schema: self.schema.path(path) };"," }).reduce( function (delta, data) {"," var type = data.value"," , schema = data.schema;",""," // a MongooseArray or MongooseNumber"," if (type._path &amp;&amp; type.doAtomics) {"," ['$push', '$pull'].forEach( function (opType) {"," var ops = type._atomics.filter( function (op) {"," return op[0] === opType;"," })"," , opsAll = type._atomics.filter( function (op) {"," return op[0] === (opType + 'All');"," });"," if (ops.length &gt; 1 || (ops.length === 1 &amp;&amp; opsAll.length &gt; 0)) {"," // If we have more than one $push (or $pull)"," // Or if we have at least one $push and at least one $pushAll"," // (or $pull and $pullAll)",""," // Then collapse everything into one $pushAll (or $pullAll)",""," type._atomics = type._atomics.filter( function (op) {"," return op[0] !== opType;"," });"," if (opsAll.length &gt; 0) {"," type._atomics = type._atomics.filter( function (op) {"," return op[0] !== (opType + 'All');"," });"," }"," var whatToAll = [];"," opsAll.forEach( function (op) {"," whatToAll = whatToAll.concat(op[1]);"," });"," whatToAll = whatToAll.concat( ops.map( function (op) {"," return op[1];"," }) );"," type._atomics.push([opType + 'All', whatToAll]);"," }"," });"," type._atomics.forEach( function (op) {"," var obj = delta[op[0]] = delta[op[0]] || {};"," if (op[0] === '$pull' || op[0] === '$push') {"," if (op[1].constructor !== Object) {"," op[1] = schema.cast(op[1])[0];"," }"," }"," obj[type._path] = op[1].toObject"," ? op[1].toObject() // If the value is an array"," : Array.isArray(op[1])"," ? op[1].map( function (mem) { "," return mem.toObject"," ? mem.toObject()"," : mem.valueOf"," ? mem.valueOf()"," : mem;"," })"," : op[1].valueOf"," ? op[1].valueOf() // Numbers"," : op[1];"," });"," } else {"," // normalize MongooseArray or MongooseNumber"," if (type._path)"," type = type.valueOf();",""," if (useSet) {"," if (!('$set' in delta))"," delta['$set'] = {};",""," delta['$set'][data.path] = type;"," } else"," delta[data.path] = type;"," }",""," return delta;"," }, {});",""," if (Object.keys(delta).length)"," this.collection.update({ _id: this.doc._id }, delta, options, complete);"," else"," complete(null);"," // TODO Clear 'modify'('dirty') cache"," }","};","","/**"," * Remove the document"," *"," * @param {Function} callback"," */","","Model.prototype.remove = function (fn) {"," if (this.removing || this.removed) return this;",""," if (!this.removing) {"," var promise = this.removing = new Promise(fn)"," , self = this;",""," this.collection.remove({ _id: this.doc._id }, function (err) {"," if (err) return promise.error(err);"," promise.complete();"," self.emit('remove');"," });"," }",""," return this;","};","","/**"," * Register hooks override"," *"," * @api private"," */","","Model.prototype.registerHooks = function () {"," // make sure to pass along all the errors from subdocuments"," this.pre('save', function (next) {"," // we keep the error semaphore to make sure we don't"," // call `save` unnecessarily (we only need 1 error)"," var subdocs = 0"," , error = false"," , self = this;",""," var arrays = this.activePaths"," .map('init', 'modify', function (i) {"," return self.getValue(i);"," })"," .filter(function (val) {"," return (val &amp;&amp; val instanceof DocumentArray &amp;&amp; val.length);"," });",""," if (!arrays.length) return next();",""," arrays.forEach(function (array) {"," subdocs += array.length;"," array.forEach(function (value) {"," if (!error)"," value.save(function (err) {"," if (!error) {"," if (err) {"," error = true;"," next(err);"," } else"," --subdocs || next();"," }"," });"," });"," });"," });",""," Document.prototype.registerHooks.call(this);","};","","/**"," * Access the options defined in the schema"," *"," * @api private"," */","","Model.prototype.__defineGetter__('options', function () {"," return this.schema ? this.schema.options : {};","});","","/**"," * Give the constructor the ability to emit events."," */","","for (var i in EventEmitter.prototype)"," Model[i] = EventEmitter.prototype[i];","","/**"," * Called when the model compiles"," *"," * @api private"," */","","Model.init = function () {"," // build indexes"," var self = this"," , indexes = this.schema.indexes"," , count = indexes.length;",""," indexes.forEach(function (index) {"," self.collection.ensureIndex(index[0], index[1], function(){"," --count || self.emit('index');"," });"," });","};","","/**"," * Document schema "," *"," * @api public"," */","","Model.schema;","","/**"," * Database instance the model uses."," *"," * @api public"," */","","Model.db;","","/**"," * Collection the model uses."," *"," * @api public"," */","","Model.collection;","","/**"," * Define properties that access the prototype."," */","","['db', 'collection', 'schema', 'options'].forEach(function(prop){"," Model.__defineGetter__(prop, function(){"," return this.prototype[prop];"," });","});","","/**"," * Register hooks for some methods."," */","","Document.registerHooks.call(Model, 'save', 'remove', 'init');","","/**"," * Module exports."," */","","module.exports = exports = Model;","","Model.remove = function (query, callback) {"," var self = this;"," this.query(query, {}, callback, function () {"," var casted = self.castQuery(this.query)"," , queryComplete = this.queryComplete.bind(this);"," self.collection.remove(casted, queryComplete);"," });","};","","/**"," * Creates a query for the signature `query, options, callback`"," *"," * @param {Object} query"," * @param {Object} options for the query"," * @param {Function} callback"," * @param {Function} function to be called when query executes"," * @api private"," */","","Model.query = function (query, options, callback, onExecute) {"," // determine callback for `query, fields, callback, options` signature"," if ('function' == typeof options) {"," callback = options;"," options = {};"," }",""," if (!options)"," options = {};",""," // merge query defaults from schema options"," if (!('safe' in options))"," options.safe = this.options.safe;",""," var query = new Query(query, options, onExecute);",""," if (callback) {"," query.addBack(callback);"," query.run();"," }",""," return query;","};","","/**"," * Creates a query for the signature `query, fields, callback, options`"," *"," * @param {Object} query"," * @param {Object} fields to get, or array of fields"," * @param {Object} options for the query"," * @param {Function} callback"," * @param {Function} function to be called when query executes"," * @api private"," */","","Model.findQuery = function (query, fields, options, callback, onExecute) {"," if ('function' == typeof fields) {"," callback = fields;"," fields = {};"," options = {};"," } else if ('function' == typeof options) {"," callback = options;"," options = {};"," }",""," var query = new FindQuery(query, fields, options, onExecute);"," "," if (callback) {"," query.run(callback);"," }",""," return query;","};","","/**"," * Casts a query"," *"," * Examples:"," * "," * // will return { _id: ObjectId }"," * castQuery({ _id: '4c40f33a37483d8e14000001' })"," * "," * @param {Object} query"," * @api private"," */","","Model.castQuery = function (query) {"," var ret = {}"," , self = this;",""," for (var i in query){"," if (query[i] === null || query[i] === undefined)"," ret[i] = query[i];"," else if (query[i].constructor == Object) {"," ret[i] = query[i];"," Object.keys(query[i]).filter( function (key) {"," return key.charAt(0) === '$';"," }).forEach( function (key) {"," var schema = self.schema.path(i);",""," if (key == '$in') {"," // cast array"," ret[i][key] = ret[i][key].map(schema.cast);"," } else"," ret[i][key] = schema.cast(query[i][key]);",""," // Take care of special case of MongooseNumber,"," // with resolves scalar via `valueOf`"," if (ret[i][key]._path)"," ret[i][key] = ret[i][key].valueOf();",""," });"," } else if (query[i].constructor == RegExp || Array.isArray(query[i]))"," ret[i] = query[i];"," else {"," ret[i] = this.schema.path(i).cast(query[i]);"," // Take care of special case of MongooseArray for checking 1 element membership"," if (ret[i] instanceof MongooseArray) {"," var arr = ret[i];"," delete ret[i];"," ret[i] = {"," $all: arr"," };"," }"," }"," }",""," return ret;","};","","/**"," * Finds documents"," *"," * Examples:"," * // retrieve only certain keys"," * MyModel.find({ name: /john/i }, ['name', 'friends'], function () { })"," *"," * // pass options"," * MyModel.find({ name: /john/i }, [], { skip: 10 } )"," *"," * @param {Object} query"," * @param {Object/Function} (optional) fields to hydrate or callback"," * @param {Function} callback"," * @api public"," */","","Model.find = function (query, fields, options, callback) {"," var self = this;",""," return this.findQuery(query, fields, options, callback, function (query) {"," var q = this"," , casted = self.castQuery(this.query);",""," if (this.fields)"," this.options.fields = this.fields;",""," self.collection.find(casted, this.options, function (err, cursor) {"," if (err) return q.queryComplete(err);",""," cursor.toArray(function(err, docs){"," if (err) return q.queryComplete(err);",""," var arr = []"," , count = docs.length;",""," if (!count) return q.queryComplete(null, []);",""," for (var i = 0, l = docs.length; i &lt; l; i++){"," arr[i] = new self();"," arr[i].init(docs[i], function (err) {"," if (err) return q.queryComplete(err);"," --count || q.queryComplete(null, arr);"," });"," }"," });"," });"," });","};","","/**"," * Finds by id"," *"," * @param {ObjectId/Object} objectid, or a value that can be casted to it"," * @api public"," */","","Model.findById = function (id, fields, options, callback) {"," return this.findOne({ _id: id }, fields, options, callback);","};","","/**"," * Finds one document"," *"," * @param {Object} query"," * @param {Object/Function} (optional) fields to hydrate or callback"," * @param {Function} callback"," * @api public"," */","","Model.findOne = function (query, fields, options, callback) {"," var self = this;",""," return this.findQuery(query, fields, options, callback, function () {"," var q = this"," , casted = self.castQuery(this.query);",""," if (this.fields)"," this.options.fields = this.fields;",""," self.collection.findOne(casted, this.options, function (err, doc) {"," if (err) return q.queryComplete(err);",""," if (!doc) return q.queryComplete(null, null);"," "," var casted = new self();",""," casted.init(doc, function (err) {"," if (err) return q.queryComplete(err);"," q.queryComplete(null, casted);"," });"," });"," });","};","","/**"," * Counts documents"," *"," * @param {Object} query"," * @param {Function} optional callback"," * @api public"," */","","Model.count = function (query, callback) {"," var self = this;",""," return this.query(query, {}, callback, function () {"," var casted = self.castQuery(this.query);"," self.collection.count(casted, this.queryComplete.bind(this));"," });","};","","","/**"," * Shortcut for creating a new Document that is automatically saved"," * to the db if valid."," *"," * @param {Object} doc"," * @param {Function} callback"," * @api public"," */","Model.create = function (doc, fn) {"," var document = new this(doc);"," document.save(function (err) {"," if (err) fn(err)"," else fn(null, document);"," });","};","","/**"," * Updates documents."," *"," * Examples:"," *"," * MyModel.update({ age: { $gt: 18 } }, { oldEnough: true }, fn);"," * MyModel.update({ name: 'Tobi' }, { ferret: true }, { multi: true }, fn);"," *"," * Valid options:"," * - safe (boolean) safe mode (defaults to value set in schema (false))"," * - upsert (boolean) whether to create the doc if it doesn't match (false)"," * - multi (boolean) whether multiple documents should be update (false)"," *"," * @param {Object} query"," * @param {Object] doc"," * @param {Object/Function} optional options or callback"," * @param {Function} callback"," * @return {Query}"," * @api public"," */","","Model.update = function (query, doc, options, callback) {"," var self = this;",""," return this.query(query, options, callback, function () {"," var castQuery = self.castQuery(this.query)"," , castDoc = self.castQuery(doc)"," , queryComplete = this.queryComplete.bind(this);",""," self.collection.update(castQuery, castDoc, this.options, queryComplete);"," });","};","","/**"," * Compiler utility."," *"," * @param {String} model name"," * @param {Schema} schema object"," * @param {String} collection name"," * @param {Connection} connection to use"," * @param {Mongoose} mongoose instance"," * @api private"," */","","Model.compile = function (name, schema, collectionName, connection, base) {"," // generate new class"," function model () {"," Model.apply(this, arguments);"," };",""," model.name = name;"," model.__proto__ = Model;"," model.prototype.__proto__ = Model.prototype;"," model.prototype.base = base;"," model.prototype.schema = schema;"," model.prototype.db = connection;"," model.prototype.collection = connection.collection(collectionName);",""," // apply methods"," for (var i in schema.methods)"," model.prototype[i] = schema.methods[i];",""," // apply statics"," for (var i in schema.statics)"," model[i] = schema.statics[i];",""," return model;","};"];
_$jscoverage['mongoose/model.js'].source = ["","/**"," * Module dependencies."," */","","var Document = require('./document')"," , MongooseArray = require('./types/array')"," , DocumentArray = require('./types/documentarray')"," , MongooseError = require('./error')"," , Query = require('./query').Query"," , FindQuery = require('./query').FindQuery"," , FindOneQuery = require('./query').FindOneQuery"," , Query = require('./query').Query"," , Query = require('./query').Query"," , Query = require('./query').Query"," , utils = require('./utils')"," , EventEmitter = utils.EventEmitter"," , merge = utils.merge"," , Promise = require('./promise');","","/**"," * Model constructor"," *"," * @param {Object} values to set"," * @api public"," */","","function Model (doc) {"," Document.call(this, doc);","};","","/**"," * Inherits from Document."," */","","Model.prototype.__proto__ = Document.prototype;","","/**"," * Connection the model uses. Set by the Connection or if absent set to the"," * default mongoose connection;"," *"," * @api public"," */","","Model.prototype.db;","","/**"," * Collection the model uses. Set by Mongoose instance"," *"," * @api public"," */","","Model.prototype.collection;","","/**"," * Model name."," *"," * @api public"," */","","Model.prototype.name;","","/**"," * Saves the document."," *"," * @see Model#registerHooks"," * @param {Function} callback"," * @api public"," */","","Model.prototype.save = function (fn) {"," var promise = new Promise(fn)"," , options = {}"," , self = this;",""," function complete (err) {"," if (err) return promise.error(err);"," promise.complete();"," self.emit('save');"," };",""," // support for safe mode"," if (this.options.safe)"," options.safe = true;",""," if (this.isNew) {"," // send entire doc"," this.collection.insert(this.toObject(), options, complete);"," this.isNew = false;"," } else {"," // send delta"," var self = this"," , delta"," , useSet = this.options['use$SetOnSave'];",""," delta = this.activePaths.map('modify', function (path) {"," return { path: path, value: self.getValue(path), schema: self.schema.path(path) };"," }).reduce( function (delta, data) {"," var type = data.value"," , schema = data.schema;",""," // a MongooseArray or MongooseNumber"," if (type._path &amp;&amp; type.doAtomics) {"," ['$push', '$pull'].forEach( function (opType) {"," var ops = type._atomics.filter( function (op) {"," return op[0] === opType;"," })"," , opsAll = type._atomics.filter( function (op) {"," return op[0] === (opType + 'All');"," });"," if (ops.length &gt; 1 || (ops.length === 1 &amp;&amp; opsAll.length &gt; 0)) {"," // If we have more than one $push (or $pull)"," // Or if we have at least one $push and at least one $pushAll"," // (or $pull and $pullAll)",""," // Then collapse everything into one $pushAll (or $pullAll)",""," type._atomics = type._atomics.filter( function (op) {"," return op[0] !== opType;"," });"," if (opsAll.length &gt; 0) {"," type._atomics = type._atomics.filter( function (op) {"," return op[0] !== (opType + 'All');"," });"," }"," var whatToAll = [];"," opsAll.forEach( function (op) {"," whatToAll = whatToAll.concat(op[1]);"," });"," whatToAll = whatToAll.concat( ops.map( function (op) {"," return op[1];"," }) );"," type._atomics.push([opType + 'All', whatToAll]);"," }"," });"," type._atomics.forEach( function (op) {"," var obj = delta[op[0]] = delta[op[0]] || {};"," if (op[0] === '$pull' || op[0] === '$push') {"," if (op[1].constructor !== Object) {"," op[1] = schema.cast(op[1])[0];"," }"," }"," obj[type._path] = op[1].toObject"," ? op[1].toObject() // If the value is an array"," : Array.isArray(op[1])"," ? op[1].map( function (mem) { "," return mem.toObject"," ? mem.toObject()"," : mem.valueOf"," ? mem.valueOf()"," : mem;"," })"," : op[1].valueOf"," ? op[1].valueOf() // Numbers"," : op[1];"," });"," } else {"," // normalize MongooseArray or MongooseNumber"," if (type._path)"," type = type.valueOf();",""," if (useSet) {"," if (!('$set' in delta))"," delta['$set'] = {};",""," delta['$set'][data.path] = type;"," } else"," delta[data.path] = type;"," }",""," return delta;"," }, {});",""," if (Object.keys(delta).length)"," this.collection.update({ _id: this.doc._id }, delta, options, complete);"," else"," complete(null);"," // TODO Clear 'modify'('dirty') cache"," }","};","","/**"," * Remove the document"," *"," * @param {Function} callback"," */","","Model.prototype.remove = function (fn) {"," if (this.removing || this.removed) return this;",""," if (!this.removing) {"," var promise = this.removing = new Promise(fn)"," , self = this;",""," this.collection.remove({ _id: this.doc._id }, function (err) {"," if (err) return promise.error(err);"," promise.complete();"," self.emit('remove');"," });"," }",""," return this;","};","","/**"," * Register hooks override"," *"," * @api private"," */","","Model.prototype.registerHooks = function () {"," // make sure to pass along all the errors from subdocuments"," this.pre('save', function (next) {"," // we keep the error semaphore to make sure we don't"," // call `save` unnecessarily (we only need 1 error)"," var subdocs = 0"," , error = false"," , self = this;",""," var arrays = this.activePaths"," .map('init', 'modify', function (i) {"," return self.getValue(i);"," })"," .filter(function (val) {"," return (val &amp;&amp; val instanceof DocumentArray &amp;&amp; val.length);"," });",""," if (!arrays.length) return next();",""," arrays.forEach(function (array) {"," subdocs += array.length;"," array.forEach(function (value) {"," if (!error)"," value.save(function (err) {"," if (!error) {"," if (err) {"," error = true;"," next(err);"," } else"," --subdocs || next();"," }"," });"," });"," });"," });",""," Document.prototype.registerHooks.call(this);","};","","/**"," * Access the options defined in the schema"," *"," * @api private"," */","","Model.prototype.__defineGetter__('options', function () {"," return this.schema ? this.schema.options : {};","});","","/**"," * Give the constructor the ability to emit events."," */","","for (var i in EventEmitter.prototype)"," Model[i] = EventEmitter.prototype[i];","","/**"," * Called when the model compiles"," *"," * @api private"," */","","Model.init = function () {"," // build indexes"," var self = this"," , indexes = this.schema.indexes"," , count = indexes.length;",""," indexes.forEach(function (index) {"," self.collection.ensureIndex(index[0], index[1], function(){"," --count || self.emit('index');"," });"," });","};","","/**"," * Document schema "," *"," * @api public"," */","","Model.schema;","","/**"," * Database instance the model uses."," *"," * @api public"," */","","Model.db;","","/**"," * Collection the model uses."," *"," * @api public"," */","","Model.collection;","","/**"," * Define properties that access the prototype."," */","","['db', 'collection', 'schema', 'options'].forEach(function(prop){"," Model.__defineGetter__(prop, function(){"," return this.prototype[prop];"," });","});","","/**"," * Register hooks for some methods."," */","","Document.registerHooks.call(Model, 'save', 'remove', 'init');","","/**"," * Module exports."," */","","module.exports = exports = Model;","","Model.remove = function (conditions, callback) {"," var query = new Query(conditions).bind(this);"," if ('undefined' === typeof callback) {"," return query;"," }"," return query.remove(callback);","};","","/**"," * Casts a query"," *"," * Examples:"," * "," * // will return { _id: ObjectId }"," * castQuery({ _id: '4c40f33a37483d8e14000001' })"," * "," * @param {Object} query"," * @api private"," */","","Model.castQuery = function (query) {"," var ret = {}"," , self = this;",""," for (var i in query){"," if (query[i] === null || query[i] === undefined)"," ret[i] = query[i];"," else if (query[i].constructor == Object) {"," ret[i] = query[i];"," Object.keys(query[i]).filter( function (key) {"," return key.charAt(0) === '$';"," }).forEach( function (key) {"," var schema = self.schema.path(i);",""," if (key == '$in') {"," // cast array"," ret[i][key] = ret[i][key].map(schema.cast);"," } else"," ret[i][key] = schema.cast(query[i][key]);",""," // Take care of special case of MongooseNumber,"," // with resolves scalar via `valueOf`"," if (ret[i][key]._path)"," ret[i][key] = ret[i][key].valueOf();",""," });"," } else if (query[i].constructor == RegExp || Array.isArray(query[i]))"," ret[i] = query[i];"," else {"," ret[i] = this.schema.path(i).cast(query[i]);"," // Take care of special case of MongooseArray for checking 1 element membership"," if (ret[i] instanceof MongooseArray) {"," var arr = ret[i];"," delete ret[i];"," ret[i] = {"," $all: arr"," };"," }"," }"," }",""," return ret;","};","","/**"," * Finds documents"," *"," * Examples:"," * // retrieve only certain keys"," * MyModel.find({ name: /john/i }, ['name', 'friends'], function () { })"," *"," * // pass options"," * MyModel.find({ name: /john/i }, [], { skip: 10 } )"," *"," * @param {Object} conditions"," * @param {Object/Function} (optional) fields to hydrate or callback"," * @param {Function} callback"," * @api public"," */","","Model.find = function (conditions, fields, options, callback) {"," if ('function' === typeof fields) {"," callback = fields;"," fields = null;"," options = null;"," } else if ('function' === typeof options) {"," callback = options;"," options = null;"," } else if ('function' === typeof conditions) {"," callback = conditions;"," conditions = {};"," fields = null;"," options = null;"," }"," var query = new Query(conditions, options).select(fields).bind(this);"," if ('undefined' === typeof callback) return query;"," // TODO Add cQuery merging into other commands"," var cQuery;"," if (cQuery = this._cumulativeQuery)"," merge(query._conditions, cQuery._conditions);"," if (!query.model) query.bind(this);"," delete this._cumulativeQuery;"," return query.find(callback);","};","","/**"," * Finds by id"," *"," * @param {ObjectId/Object} objectid, or a value that can be casted to it"," * @api public"," */","","Model.findById = function (id, fields, options, callback) {"," return this.findOne({ _id: id }, fields, options, callback);","};","","/**"," * Finds one document"," *"," * @param {Object} conditions"," * @param {Object/Function} (optional) fields to hydrate or callback"," * @param {Function} callback"," * @api public"," */","","Model.findOne = function (conditions, fields, options, callback) {"," if ('function' === typeof options) {"," callback = options;"," options = null;"," } else if ('function' === typeof fields) {"," callback = fields;"," fields = null;"," options = null;"," } else if ('function' === typeof conditions) {"," callback = conditions;"," conditions = {};"," fields = null;"," options = null;"," }"," var query = new Query(conditions, options).select(fields).bind(this);"," if ('undefined' === typeof callback) return query;"," return query.findOne(callback);","};","","/**"," * Counts documents"," *"," * @param {Object} conditions"," * @param {Function} optional callback"," * @api public"," */","","Model.count = function (conditions, callback) {"," var query = new Query(conditions).bind(this);"," if ('undefined' === typeof callback) return query;"," return query.count(callback);","};","","/**"," * `with` enables a very nice sugary api for doing your queries."," * For example, instead of writing:"," * User.find({age: {$gte: 21, $lte: 65}}, callback);"," * we can instead write more readably:"," * User.with('age').gte(21).lte(65);"," * Moreover, you can also chain a bunch of these together like:"," * User"," * .with('age').gte(21).lte(65)"," * .with('name', /^b/i) // All names that begin with b or B"," * .with('friends').slice(10);"," * @param {String} path"," * @param {Object} val (optional)"," * @return {Query}"," * @api public"," */","","Model.with = function (path, val) {"," var q = new Query().bind(this);"," return q.with.apply(q, arguments);","};","","/**"," * Sometimes you need to query for things in mongodb using a JavaScript"," * expression. You can do so via find({$where: javascript}), or you can"," * use the mongoose shortcut method $where via a Query chain or from"," * your mongoose Model."," *"," * @param {String|Function} js is a javascript string or anonymous function"," * @return {Query}"," * @api public"," */","","Model.$where = function () {"," var q = new Query().bind(this);"," return q.$where.apply(q, arguments);","};","","/**"," * Shortcut for creating a new Document that is automatically saved"," * to the db if valid."," *"," * @param {Object} doc"," * @param {Function} callback"," * @api public"," */","Model.create = function (doc, fn) {"," var args = [].slice.call(arguments)"," , lastArg = args[args.length-1]"," , count, docs = [];"," if (typeof lastArg === 'function') {"," fn = args.pop();"," }"," count = args.length;"," var self = this;"," args.forEach( function (arg, i) {"," var doc = new self(arg);"," docs[i] = doc;"," doc.save(function (err) {"," if (err) return fn(err);"," --count || fn.apply(null, [null].concat(docs));"," });"," });","};","","/**"," * Updates documents."," *"," * Examples:"," *"," * MyModel.update({ age: { $gt: 18 } }, { oldEnough: true }, fn);"," * MyModel.update({ name: 'Tobi' }, { ferret: true }, { multi: true }, fn);"," *"," * Valid options:"," * - safe (boolean) safe mode (defaults to value set in schema (false))"," * - upsert (boolean) whether to create the doc if it doesn't match (false)"," * - multi (boolean) whether multiple documents should be update (false)"," *"," * @param {Object} conditions"," * @param {Object] doc"," * @param {Object/Function} optional options or callback"," * @param {Function} callback"," * @return {Query}"," * @api public"," */","","Model.update = function (conditions, doc, options, callback) {"," if ('function' === typeof options) {"," callback = options;"," options = null;"," }"," var query = new Query(conditions, options).bind(this);"," if ('undefined' === typeof callback) {"," return query;"," }"," return query.update(doc, callback);","};","","/**"," * Compiler utility."," *"," * @param {String} model name"," * @param {Schema} schema object"," * @param {String} collection name"," * @param {Connection} connection to use"," * @param {Mongoose} mongoose instance"," * @api private"," */","","Model.compile = function (name, schema, collectionName, connection, base) {"," // generate new class"," function model () {"," Model.apply(this, arguments);"," };",""," model.name = name;"," model.__proto__ = Model;"," model.prototype.__proto__ = Model.prototype;"," model.prototype.base = base;"," model.prototype.schema = schema;"," model.prototype.db = connection;"," model.prototype.collection = connection.collection(collectionName);",""," // apply methods"," for (var i in schema.methods)"," model.prototype[i] = schema.methods[i];",""," // apply statics"," for (var i in schema.statics)"," model[i] = schema.statics[i];",""," // apply named scopes"," if(schema.namedScopes) schema.namedScopes.compile(model);",""," return model;","};"];

@@ -5,241 +5,1048 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/query.js'] = [];
_$jscoverage['mongoose/query.js'][6] = 0;
_$jscoverage['mongoose/query.js'][1] = 0;
_$jscoverage['mongoose/query.js'][11] = 0;
_$jscoverage['mongoose/query.js'][12] = 0;
_$jscoverage['mongoose/query.js'][13] = 0;
_$jscoverage['mongoose/query.js'][14] = 0;
_$jscoverage['mongoose/query.js'][15] = 0;
_$jscoverage['mongoose/query.js'][16] = 0;
_$jscoverage['mongoose/query.js'][17] = 0;
_$jscoverage['mongoose/query.js'][18] = 0;
_$jscoverage['mongoose/query.js'][19] = 0;
_$jscoverage['mongoose/query.js'][20] = 0;
_$jscoverage['mongoose/query.js'][21] = 0;
_$jscoverage['mongoose/query.js'][25] = 0;
_$jscoverage['mongoose/query.js'][26] = 0;
_$jscoverage['mongoose/query.js'][27] = 0;
_$jscoverage['mongoose/query.js'][28] = 0;
_$jscoverage['mongoose/query.js'][31] = 0;
_$jscoverage['mongoose/query.js'][32] = 0;
_$jscoverage['mongoose/query.js'][33] = 0;
_$jscoverage['mongoose/query.js'][34] = 0;
_$jscoverage['mongoose/query.js'][36] = 0;
_$jscoverage['mongoose/query.js'][38] = 0;
_$jscoverage['mongoose/query.js'][37] = 0;
_$jscoverage['mongoose/query.js'][39] = 0;
_$jscoverage['mongoose/query.js'][41] = 0;
_$jscoverage['mongoose/query.js'][42] = 0;
_$jscoverage['mongoose/query.js'][44] = 0;
_$jscoverage['mongoose/query.js'][46] = 0;
_$jscoverage['mongoose/query.js'][47] = 0;
_$jscoverage['mongoose/query.js'][48] = 0;
_$jscoverage['mongoose/query.js'][50] = 0;
_$jscoverage['mongoose/query.js'][54] = 0;
_$jscoverage['mongoose/query.js'][55] = 0;
_$jscoverage['mongoose/query.js'][57] = 0;
_$jscoverage['mongoose/query.js'][61] = 0;
_$jscoverage['mongoose/query.js'][62] = 0;
_$jscoverage['mongoose/query.js'][63] = 0;
_$jscoverage['mongoose/query.js'][65] = 0;
_$jscoverage['mongoose/query.js'][66] = 0;
_$jscoverage['mongoose/query.js'][67] = 0;
_$jscoverage['mongoose/query.js'][68] = 0;
_$jscoverage['mongoose/query.js'][69] = 0;
_$jscoverage['mongoose/query.js'][70] = 0;
_$jscoverage['mongoose/query.js'][71] = 0;
_$jscoverage['mongoose/query.js'][73] = 0;
_$jscoverage['mongoose/query.js'][74] = 0;
_$jscoverage['mongoose/query.js'][75] = 0;
_$jscoverage['mongoose/query.js'][76] = 0;
_$jscoverage['mongoose/query.js'][78] = 0;
_$jscoverage['mongoose/query.js'][79] = 0;
_$jscoverage['mongoose/query.js'][80] = 0;
_$jscoverage['mongoose/query.js'][81] = 0;
_$jscoverage['mongoose/query.js'][82] = 0;
_$jscoverage['mongoose/query.js'][84] = 0;
_$jscoverage['mongoose/query.js'][85] = 0;
_$jscoverage['mongoose/query.js'][89] = 0;
_$jscoverage['mongoose/query.js'][90] = 0;
_$jscoverage['mongoose/query.js'][91] = 0;
_$jscoverage['mongoose/query.js'][92] = 0;
_$jscoverage['mongoose/query.js'][95] = 0;
_$jscoverage['mongoose/query.js'][96] = 0;
_$jscoverage['mongoose/query.js'][97] = 0;
_$jscoverage['mongoose/query.js'][98] = 0;
_$jscoverage['mongoose/query.js'][99] = 0;
_$jscoverage['mongoose/query.js'][100] = 0;
_$jscoverage['mongoose/query.js'][101] = 0;
_$jscoverage['mongoose/query.js'][102] = 0;
_$jscoverage['mongoose/query.js'][104] = 0;
_$jscoverage['mongoose/query.js'][105] = 0;
_$jscoverage['mongoose/query.js'][106] = 0;
_$jscoverage['mongoose/query.js'][107] = 0;
_$jscoverage['mongoose/query.js'][108] = 0;
_$jscoverage['mongoose/query.js'][110] = 0;
_$jscoverage['mongoose/query.js'][111] = 0;
_$jscoverage['mongoose/query.js'][112] = 0;
_$jscoverage['mongoose/query.js'][113] = 0;
_$jscoverage['mongoose/query.js'][114] = 0;
_$jscoverage['mongoose/query.js'][115] = 0;
_$jscoverage['mongoose/query.js'][116] = 0;
_$jscoverage['mongoose/query.js'][117] = 0;
_$jscoverage['mongoose/query.js'][118] = 0;
_$jscoverage['mongoose/query.js'][119] = 0;
_$jscoverage['mongoose/query.js'][120] = 0;
_$jscoverage['mongoose/query.js'][121] = 0;
_$jscoverage['mongoose/query.js'][123] = 0;
_$jscoverage['mongoose/query.js'][127] = 0;
_$jscoverage['mongoose/query.js'][133] = 0;
_$jscoverage['mongoose/query.js'][134] = 0;
_$jscoverage['mongoose/query.js'][135] = 0;
_$jscoverage['mongoose/query.js'][137] = 0;
_$jscoverage['mongoose/query.js'][139] = 0;
_$jscoverage['mongoose/query.js'][140] = 0;
_$jscoverage['mongoose/query.js'][143] = 0;
_$jscoverage['mongoose/query.js'][136] = 0;
_$jscoverage['mongoose/query.js'][150] = 0;
_$jscoverage['mongoose/query.js'][151] = 0;
_$jscoverage['mongoose/query.js'][152] = 0;
_$jscoverage['mongoose/query.js'][153] = 0;
_$jscoverage['mongoose/query.js'][154] = 0;
_$jscoverage['mongoose/query.js'][156] = 0;
_$jscoverage['mongoose/query.js'][158] = 0;
_$jscoverage['mongoose/query.js'][167] = 0;
_$jscoverage['mongoose/query.js'][168] = 0;
_$jscoverage['mongoose/query.js'][169] = 0;
_$jscoverage['mongoose/query.js'][170] = 0;
_$jscoverage['mongoose/query.js'][176] = 0;
_$jscoverage['mongoose/query.js'][172] = 0;
_$jscoverage['mongoose/query.js'][173] = 0;
_$jscoverage['mongoose/query.js'][174] = 0;
_$jscoverage['mongoose/query.js'][175] = 0;
_$jscoverage['mongoose/query.js'][177] = 0;
_$jscoverage['mongoose/query.js'][178] = 0;
_$jscoverage['mongoose/query.js'][182] = 0;
_$jscoverage['mongoose/query.js'][183] = 0;
_$jscoverage['mongoose/query.js'][185] = 0;
_$jscoverage['mongoose/query.js'][186] = 0;
_$jscoverage['mongoose/query.js'][187] = 0;
_$jscoverage['mongoose/query.js'][189] = 0;
_$jscoverage['mongoose/query.js'][190] = 0;
_$jscoverage['mongoose/query.js'][191] = 0;
_$jscoverage['mongoose/query.js'][192] = 0;
_$jscoverage['mongoose/query.js'][193] = 0;
_$jscoverage['mongoose/query.js'][194] = 0;
_$jscoverage['mongoose/query.js'][195] = 0;
_$jscoverage['mongoose/query.js'][196] = 0;
_$jscoverage['mongoose/query.js'][197] = 0;
_$jscoverage['mongoose/query.js'][198] = 0;
_$jscoverage['mongoose/query.js'][199] = 0;
_$jscoverage['mongoose/query.js'][200] = 0;
_$jscoverage['mongoose/query.js'][201] = 0;
_$jscoverage['mongoose/query.js'][202] = 0;
_$jscoverage['mongoose/query.js'][203] = 0;
_$jscoverage['mongoose/query.js'][204] = 0;
_$jscoverage['mongoose/query.js'][205] = 0;
_$jscoverage['mongoose/query.js'][206] = 0;
_$jscoverage['mongoose/query.js'][207] = 0;
_$jscoverage['mongoose/query.js'][209] = 0;
_$jscoverage['mongoose/query.js'][210] = 0;
_$jscoverage['mongoose/query.js'][212] = 0;
_$jscoverage['mongoose/query.js'][211] = 0;
_$jscoverage['mongoose/query.js'][215] = 0;
_$jscoverage['mongoose/query.js'][217] = 0;
_$jscoverage['mongoose/query.js'][218] = 0;
_$jscoverage['mongoose/query.js'][219] = 0;
_$jscoverage['mongoose/query.js'][220] = 0;
_$jscoverage['mongoose/query.js'][221] = 0;
_$jscoverage['mongoose/query.js'][222] = 0;
_$jscoverage['mongoose/query.js'][223] = 0;
_$jscoverage['mongoose/query.js'][225] = 0;
_$jscoverage['mongoose/query.js'][228] = 0;
_$jscoverage['mongoose/query.js'][229] = 0;
_$jscoverage['mongoose/query.js'][230] = 0;
_$jscoverage['mongoose/query.js'][233] = 0;
_$jscoverage['mongoose/query.js'][235] = 0;
_$jscoverage['mongoose/query.js'][236] = 0;
_$jscoverage['mongoose/query.js'][237] = 0;
_$jscoverage['mongoose/query.js'][238] = 0;
_$jscoverage['mongoose/query.js'][239] = 0;
_$jscoverage['mongoose/query.js'][240] = 0;
_$jscoverage['mongoose/query.js'][241] = 0;
_$jscoverage['mongoose/query.js'][242] = 0;
_$jscoverage['mongoose/query.js'][243] = 0;
_$jscoverage['mongoose/query.js'][244] = 0;
_$jscoverage['mongoose/query.js'][246] = 0;
_$jscoverage['mongoose/query.js'][248] = 0;
_$jscoverage['mongoose/query.js'][249] = 0;
_$jscoverage['mongoose/query.js'][250] = 0;
_$jscoverage['mongoose/query.js'][251] = 0;
_$jscoverage['mongoose/query.js'][252] = 0;
_$jscoverage['mongoose/query.js'][254] = 0;
_$jscoverage['mongoose/query.js'][256] = 0;
_$jscoverage['mongoose/query.js'][259] = 0;
_$jscoverage['mongoose/query.js'][260] = 0;
_$jscoverage['mongoose/query.js'][261] = 0;
_$jscoverage['mongoose/query.js'][262] = 0;
_$jscoverage['mongoose/query.js'][267] = 0;
_$jscoverage['mongoose/query.js'][268] = 0;
_$jscoverage['mongoose/query.js'][279] = 0;
_$jscoverage['mongoose/query.js'][280] = 0;
_$jscoverage['mongoose/query.js'][282] = 0;
_$jscoverage['mongoose/query.js'][287] = 0;
_$jscoverage['mongoose/query.js'][289] = 0;
_$jscoverage['mongoose/query.js'][290] = 0;
_$jscoverage['mongoose/query.js'][291] = 0;
_$jscoverage['mongoose/query.js'][293] = 0;
_$jscoverage['mongoose/query.js'][294] = 0;
_$jscoverage['mongoose/query.js'][295] = 0;
_$jscoverage['mongoose/query.js'][298] = 0;
_$jscoverage['mongoose/query.js'][300] = 0;
_$jscoverage['mongoose/query.js'][301] = 0;
_$jscoverage['mongoose/query.js'][302] = 0;
_$jscoverage['mongoose/query.js'][304] = 0;
_$jscoverage['mongoose/query.js'][305] = 0;
_$jscoverage['mongoose/query.js'][306] = 0;
_$jscoverage['mongoose/query.js'][320] = 0;
_$jscoverage['mongoose/query.js'][322] = 0;
_$jscoverage['mongoose/query.js'][323] = 0;
_$jscoverage['mongoose/query.js'][324] = 0;
_$jscoverage['mongoose/query.js'][325] = 0;
_$jscoverage['mongoose/query.js'][326] = 0;
_$jscoverage['mongoose/query.js'][327] = 0;
_$jscoverage['mongoose/query.js'][329] = 0;
_$jscoverage['mongoose/query.js'][331] = 0;
_$jscoverage['mongoose/query.js'][347] = 0;
_$jscoverage['mongoose/query.js'][348] = 0;
_$jscoverage['mongoose/query.js'][349] = 0;
_$jscoverage['mongoose/query.js'][350] = 0;
_$jscoverage['mongoose/query.js'][366] = 0;
_$jscoverage['mongoose/query.js'][367] = 0;
_$jscoverage['mongoose/query.js'][368] = 0;
_$jscoverage['mongoose/query.js'][369] = 0;
_$jscoverage['mongoose/query.js'][372] = 0;
_$jscoverage['mongoose/query.js'][374] = 0;
_$jscoverage['mongoose/query.js'][375] = 0;
_$jscoverage['mongoose/query.js'][376] = 0;
_$jscoverage['mongoose/query.js'][377] = 0;
_$jscoverage['mongoose/query.js'][378] = 0;
_$jscoverage['mongoose/query.js'][379] = 0;
_$jscoverage['mongoose/query.js'][380] = 0;
_$jscoverage['mongoose/query.js'][382] = 0;
_$jscoverage['mongoose/query.js'][383] = 0;
_$jscoverage['mongoose/query.js'][385] = 0;
_$jscoverage['mongoose/query.js'][386] = 0;
_$jscoverage['mongoose/query.js'][387] = 0;
_$jscoverage['mongoose/query.js'][398] = 0;
_$jscoverage['mongoose/query.js'][399] = 0;
_$jscoverage['mongoose/query.js'][400] = 0;
_$jscoverage['mongoose/query.js'][401] = 0;
_$jscoverage['mongoose/query.js'][403] = 0;
_$jscoverage['mongoose/query.js'][405] = 0;
_$jscoverage['mongoose/query.js'][433] = 0;
_$jscoverage['mongoose/query.js'][434] = 0;
_$jscoverage['mongoose/query.js'][436] = 0;
_$jscoverage['mongoose/query.js'][437] = 0;
_$jscoverage['mongoose/query.js'][439] = 0;
_$jscoverage['mongoose/query.js'][440] = 0;
_$jscoverage['mongoose/query.js'][442] = 0;
_$jscoverage['mongoose/query.js'][443] = 0;
_$jscoverage['mongoose/query.js'][446] = 0;
_$jscoverage['mongoose/query.js'][447] = 0;
_$jscoverage['mongoose/query.js'][449] = 0;
_$jscoverage['mongoose/query.js'][450] = 0;
_$jscoverage['mongoose/query.js'][452] = 0;
_$jscoverage['mongoose/query.js'][455] = 0;
_$jscoverage['mongoose/query.js'][456] = 0;
_$jscoverage['mongoose/query.js'][470] = 0;
_$jscoverage['mongoose/query.js'][471] = 0;
_$jscoverage['mongoose/query.js'][473] = 0;
_$jscoverage['mongoose/query.js'][474] = 0;
_$jscoverage['mongoose/query.js'][476] = 0;
_$jscoverage['mongoose/query.js'][479] = 0;
_$jscoverage['mongoose/query.js'][480] = 0;
_$jscoverage['mongoose/query.js'][481] = 0;
_$jscoverage['mongoose/query.js'][482] = 0;
_$jscoverage['mongoose/query.js'][484] = 0;
_$jscoverage['mongoose/query.js'][487] = 0;
_$jscoverage['mongoose/query.js'][488] = 0;
_$jscoverage['mongoose/query.js'][489] = 0;
_$jscoverage['mongoose/query.js'][490] = 0;
_$jscoverage['mongoose/query.js'][492] = 0;
_$jscoverage['mongoose/query.js'][495] = 0;
_$jscoverage['mongoose/query.js'][496] = 0;
_$jscoverage['mongoose/query.js'][497] = 0;
_$jscoverage['mongoose/query.js'][498] = 0;
_$jscoverage['mongoose/query.js'][502] = 0;
_$jscoverage['mongoose/query.js'][503] = 0;
_$jscoverage['mongoose/query.js'][505] = 0;
_$jscoverage['mongoose/query.js'][507] = 0;
_$jscoverage['mongoose/query.js'][508] = 0;
_$jscoverage['mongoose/query.js'][510] = 0;
_$jscoverage['mongoose/query.js'][512] = 0;
_$jscoverage['mongoose/query.js'][514] = 0;
_$jscoverage['mongoose/query.js'][515] = 0;
_$jscoverage['mongoose/query.js'][517] = 0;
_$jscoverage['mongoose/query.js'][518] = 0;
_$jscoverage['mongoose/query.js'][520] = 0;
_$jscoverage['mongoose/query.js'][523] = 0;
_$jscoverage['mongoose/query.js'][525] = 0;
_$jscoverage['mongoose/query.js'][526] = 0;
_$jscoverage['mongoose/query.js'][527] = 0;
_$jscoverage['mongoose/query.js'][528] = 0;
_$jscoverage['mongoose/query.js'][529] = 0;
_$jscoverage['mongoose/query.js'][535] = 0;
_$jscoverage['mongoose/query.js'][548] = 0;
_$jscoverage['mongoose/query.js'][549] = 0;
_$jscoverage['mongoose/query.js'][550] = 0;
_$jscoverage['mongoose/query.js'][551] = 0;
_$jscoverage['mongoose/query.js'][553] = 0;
_$jscoverage['mongoose/query.js'][554] = 0;
_$jscoverage['mongoose/query.js'][556] = 0;
_$jscoverage['mongoose/query.js'][557] = 0;
_$jscoverage['mongoose/query.js'][559] = 0;
_$jscoverage['mongoose/query.js'][561] = 0;
_$jscoverage['mongoose/query.js'][562] = 0;
_$jscoverage['mongoose/query.js'][563] = 0;
_$jscoverage['mongoose/query.js'][564] = 0;
_$jscoverage['mongoose/query.js'][567] = 0;
_$jscoverage['mongoose/query.js'][579] = 0;
_$jscoverage['mongoose/query.js'][580] = 0;
_$jscoverage['mongoose/query.js'][581] = 0;
_$jscoverage['mongoose/query.js'][582] = 0;
_$jscoverage['mongoose/query.js'][583] = 0;
_$jscoverage['mongoose/query.js'][584] = 0;
_$jscoverage['mongoose/query.js'][596] = 0;
_$jscoverage['mongoose/query.js'][597] = 0;
_$jscoverage['mongoose/query.js'][600] = 0;
_$jscoverage['mongoose/query.js'][601] = 0;
_$jscoverage['mongoose/query.js'][603] = 0;
_$jscoverage['mongoose/query.js'][604] = 0;
_$jscoverage['mongoose/query.js'][605] = 0;
_$jscoverage['mongoose/query.js'][607] = 0;
_$jscoverage['mongoose/query.js'][608] = 0;
_$jscoverage['mongoose/query.js'][621] = 0;
_$jscoverage['mongoose/query.js'][622] = 0;
_$jscoverage['mongoose/query.js'][623] = 0;
_$jscoverage['mongoose/query.js'][624] = 0;
_$jscoverage['mongoose/query.js'][625] = 0;
_$jscoverage['mongoose/query.js'][626] = 0;
_$jscoverage['mongoose/query.js'][629] = 0;
}
_$jscoverage['mongoose/query.js'][6]++;
var Promise = require("./promise"), inGroupsOf = require("./utils").inGroupsOf;
_$jscoverage['mongoose/query.js'][15]++;
function Query(query, options, onExecute) {
_$jscoverage['mongoose/query.js'][16]++;
Promise.call(this);
_$jscoverage['mongoose/query.js'][17]++;
this.query = query || {};
_$jscoverage['mongoose/query.js'][18]++;
this.options = options || {};
_$jscoverage['mongoose/query.js'][19]++;
this.onExecute = onExecute;
_$jscoverage['mongoose/query.js'][20]++;
this.executed = false;
_$jscoverage['mongoose/query.js'][1]++;
var utils = require("./utils"), merge = utils.merge, inGroupsOf = utils.inGroupsOf;
_$jscoverage['mongoose/query.js'][11]++;
function Query(criteria, options) {
_$jscoverage['mongoose/query.js'][12]++;
options = this.options = options || {};
_$jscoverage['mongoose/query.js'][13]++;
this.safe = options.safe;
_$jscoverage['mongoose/query.js'][14]++;
this._conditions = {};
_$jscoverage['mongoose/query.js'][15]++;
if (criteria) {
_$jscoverage['mongoose/query.js'][15]++;
this.find(criteria);
}
}
_$jscoverage['mongoose/query.js'][21]++;
;
_$jscoverage['mongoose/query.js'][27]++;
Query.prototype.__proto__ = Promise.prototype;
_$jscoverage['mongoose/query.js'][36]++;
Query.prototype.exec = Query.prototype.run = (function (fn) {
_$jscoverage['mongoose/query.js'][38]++;
if (this.executed) {
_$jscoverage['mongoose/query.js'][25]++;
Query.prototype.bind = (function (model) {
_$jscoverage['mongoose/query.js'][26]++;
var ret = Object.create(this);
_$jscoverage['mongoose/query.js'][27]++;
ret.model = model;
_$jscoverage['mongoose/query.js'][28]++;
return ret;
});
_$jscoverage['mongoose/query.js'][31]++;
Query.prototype.find = (function (criteria, callback) {
_$jscoverage['mongoose/query.js'][32]++;
if ("function" === typeof criteria) {
_$jscoverage['mongoose/query.js'][33]++;
callback = criteria;
_$jscoverage['mongoose/query.js'][34]++;
criteria = {};
}
_$jscoverage['mongoose/query.js'][36]++;
if (criteria instanceof Query) {
_$jscoverage['mongoose/query.js'][37]++;
merge(this._conditions, criteria._conditions);
}
else {
_$jscoverage['mongoose/query.js'][39]++;
return this;
merge(this._conditions, criteria);
}
_$jscoverage['mongoose/query.js'][41]++;
if (fn) {
_$jscoverage['mongoose/query.js'][42]++;
this.addBack(fn);
if (! callback) {
_$jscoverage['mongoose/query.js'][41]++;
return this;
}
_$jscoverage['mongoose/query.js'][44]++;
this.executed = true;
_$jscoverage['mongoose/query.js'][46]++;
if (this.onExecute) {
_$jscoverage['mongoose/query.js'][47]++;
try {
_$jscoverage['mongoose/query.js'][48]++;
this.onExecute.call(this);
_$jscoverage['mongoose/query.js'][42]++;
return this.execFind(callback);
});
_$jscoverage['mongoose/query.js'][54]++;
Query.prototype.cast = (function (model, obj) {
_$jscoverage['mongoose/query.js'][55]++;
obj || (obj = this._conditions);
_$jscoverage['mongoose/query.js'][57]++;
var schema = model.schema, paths = Object.keys(obj), i = paths.length, path, val, schematype, nested, any$conditionals, type;
_$jscoverage['mongoose/query.js'][61]++;
while (i--) {
_$jscoverage['mongoose/query.js'][62]++;
path = paths[i];
_$jscoverage['mongoose/query.js'][63]++;
val = obj[path];
_$jscoverage['mongoose/query.js'][65]++;
if (path === "$or") {
_$jscoverage['mongoose/query.js'][66]++;
var k = val.length, orComponentQuery;
_$jscoverage['mongoose/query.js'][68]++;
while (k--) {
_$jscoverage['mongoose/query.js'][69]++;
orComponentQuery = new Query(val[k]);
_$jscoverage['mongoose/query.js'][70]++;
orComponentQuery.cast(model);
_$jscoverage['mongoose/query.js'][71]++;
val[k] = orComponentQuery._conditions;
}
}
catch (e) {
_$jscoverage['mongoose/query.js'][50]++;
this.queryComplete(e);
else {
_$jscoverage['mongoose/query.js'][73]++;
if (path === "$where") {
_$jscoverage['mongoose/query.js'][74]++;
type = typeof val;
_$jscoverage['mongoose/query.js'][75]++;
if ("string" !== type && "function" !== type) {
_$jscoverage['mongoose/query.js'][76]++;
throw new Error("Must have a string or function for $where");
}
_$jscoverage['mongoose/query.js'][78]++;
if ("function" === type) {
_$jscoverage['mongoose/query.js'][78]++;
obj[path] = val.toString();
}
_$jscoverage['mongoose/query.js'][79]++;
continue;
}
else {
_$jscoverage['mongoose/query.js'][81]++;
schematype = schema.path(path);
_$jscoverage['mongoose/query.js'][82]++;
if (! schematype) {
_$jscoverage['mongoose/query.js'][84]++;
var split = path.split("."), j = split.length, pathFirstHalf, pathLastHalf, remainingConds, castingQuery;
_$jscoverage['mongoose/query.js'][89]++;
while (j--) {
_$jscoverage['mongoose/query.js'][90]++;
pathFirstHalf = split.slice(0, j).join(".");
_$jscoverage['mongoose/query.js'][91]++;
schematype = schema.path(pathFirstHalf);
_$jscoverage['mongoose/query.js'][92]++;
if (schematype) {
_$jscoverage['mongoose/query.js'][92]++;
break;
}
}
_$jscoverage['mongoose/query.js'][95]++;
if (schematype) {
_$jscoverage['mongoose/query.js'][97]++;
remainingConds = {};
_$jscoverage['mongoose/query.js'][98]++;
pathLastHalf = split.slice(j).join(".");
_$jscoverage['mongoose/query.js'][99]++;
remainingConds[pathLastHalf] = val;
_$jscoverage['mongoose/query.js'][100]++;
castingQuery = new Query(remainingConds);
_$jscoverage['mongoose/query.js'][101]++;
castingQuery.cast(schematype.caster);
_$jscoverage['mongoose/query.js'][102]++;
obj[path] = castingQuery._conditions[pathLastHalf];
}
}
else {
_$jscoverage['mongoose/query.js'][104]++;
if (val === null || val === undefined) {
_$jscoverage['mongoose/query.js'][105]++;
continue;
}
else {
_$jscoverage['mongoose/query.js'][106]++;
if (val.constructor == Object) {
_$jscoverage['mongoose/query.js'][107]++;
any$conditionals = Object.keys(val).some((function (k) {
_$jscoverage['mongoose/query.js'][108]++;
return k.charAt(0) === "$";
}));
_$jscoverage['mongoose/query.js'][110]++;
if (! any$conditionals) {
_$jscoverage['mongoose/query.js'][111]++;
obj[path] = schematype.castForQuery(val);
}
else {
_$jscoverage['mongoose/query.js'][112]++;
for (var $cond in val) {
_$jscoverage['mongoose/query.js'][113]++;
nested = val[$cond];
_$jscoverage['mongoose/query.js'][114]++;
if ($cond === "$ne" && nested === null) {
_$jscoverage['mongoose/query.js'][115]++;
continue;
}
else {
_$jscoverage['mongoose/query.js'][116]++;
if ($cond === "$exists") {
_$jscoverage['mongoose/query.js'][117]++;
if ("boolean" !== typeof nested) {
_$jscoverage['mongoose/query.js'][118]++;
throw new Error("$exists parameter must be Boolean");
}
_$jscoverage['mongoose/query.js'][119]++;
continue;
}
else {
_$jscoverage['mongoose/query.js'][120]++;
if ($cond === "$not") {
_$jscoverage['mongoose/query.js'][121]++;
this.cast(model, val[$cond]);
}
else {
_$jscoverage['mongoose/query.js'][123]++;
val[$cond] = schematype.castForQuery($cond, nested);
}
}
}
}
}
}
else {
_$jscoverage['mongoose/query.js'][127]++;
obj[path] = schematype.castForQuery(val);
}
}
}
}
}
}
});
_$jscoverage['mongoose/query.js'][133]++;
Query.prototype._optionsForExec = (function (model) {
_$jscoverage['mongoose/query.js'][134]++;
var options = utils.clone(this.options);
_$jscoverage['mongoose/query.js'][135]++;
if (! ("safe" in options)) {
_$jscoverage['mongoose/query.js'][135]++;
options.safe = model.options.safe;
}
_$jscoverage['mongoose/query.js'][54]++;
_$jscoverage['mongoose/query.js'][136]++;
return options;
});
_$jscoverage['mongoose/query.js'][150]++;
Query.prototype.$where = (function (js) {
_$jscoverage['mongoose/query.js'][151]++;
this._conditions.$where = js;
_$jscoverage['mongoose/query.js'][152]++;
return this;
});
_$jscoverage['mongoose/query.js'][65]++;
Query.prototype.set = (function (key, value) {
_$jscoverage['mongoose/query.js'][66]++;
if (arguments.length == 1) {
_$jscoverage['mongoose/query.js'][67]++;
return this.options[key];
_$jscoverage['mongoose/query.js'][172]++;
Query.prototype["with"] = (function (path, val) {
_$jscoverage['mongoose/query.js'][173]++;
var conds;
_$jscoverage['mongoose/query.js'][174]++;
if (arguments.length === 2) {
_$jscoverage['mongoose/query.js'][175]++;
this._conditions[path] = val;
}
_$jscoverage['mongoose/query.js'][68]++;
this.options[key] = value;
_$jscoverage['mongoose/query.js'][69]++;
_$jscoverage['mongoose/query.js'][177]++;
this._currPath = path;
_$jscoverage['mongoose/query.js'][178]++;
return this;
});
_$jscoverage['mongoose/query.js'][79]++;
Query.prototype.where = (function (obj, value) {
_$jscoverage['mongoose/query.js'][80]++;
if (value == undefined) {
_$jscoverage['mongoose/query.js'][81]++;
for (var i in obj) {
_$jscoverage['mongoose/query.js'][82]++;
this.query[i] = obj[i];
}
_$jscoverage['mongoose/query.js'][182]++;
["gt", "gte", "lt", "lte", "ne", "in", "nin", "all", "size"].forEach((function ($conditional) {
_$jscoverage['mongoose/query.js'][183]++;
Query.prototype["$" + $conditional] = Query.prototype[$conditional] = (function (path, val) {
_$jscoverage['mongoose/query.js'][185]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/query.js'][186]++;
val = path;
_$jscoverage['mongoose/query.js'][187]++;
path = this._currPath;
}
_$jscoverage['mongoose/query.js'][189]++;
var conds = this._conditions[path] || (this._conditions[path] = {});
_$jscoverage['mongoose/query.js'][190]++;
conds["$" + $conditional] = val;
_$jscoverage['mongoose/query.js'][191]++;
return this;
});
}));
_$jscoverage['mongoose/query.js'][195]++;
Query.prototype.notEqualTo = Query.prototype.ne;
_$jscoverage['mongoose/query.js'][197]++;
["mod", "near"].forEach((function ($conditional) {
_$jscoverage['mongoose/query.js'][198]++;
Query.prototype["$" + $conditional] = Query.prototype[$conditional] = (function (path, val) {
_$jscoverage['mongoose/query.js'][200]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/query.js'][201]++;
val = path;
_$jscoverage['mongoose/query.js'][202]++;
path = this._currPath;
}
else {
_$jscoverage['mongoose/query.js'][84]++;
this.query[obj] = value;
_$jscoverage['mongoose/query.js'][203]++;
if (arguments.length === 2 && ! Array.isArray(val)) {
_$jscoverage['mongoose/query.js'][204]++;
val = [].slice.call(arguments);
_$jscoverage['mongoose/query.js'][205]++;
path = this._currPath;
}
else {
_$jscoverage['mongoose/query.js'][206]++;
if (arguments.length === 3) {
_$jscoverage['mongoose/query.js'][207]++;
val = [].slice.call(arguments, 1);
}
}
}
_$jscoverage['mongoose/query.js'][85]++;
_$jscoverage['mongoose/query.js'][209]++;
var conds = this._conditions[path] || (this._conditions[path] = {});
_$jscoverage['mongoose/query.js'][210]++;
conds["$" + $conditional] = val;
_$jscoverage['mongoose/query.js'][211]++;
return this;
});
_$jscoverage['mongoose/query.js'][95]++;
Query.prototype.skip = (function (v) {
_$jscoverage['mongoose/query.js'][96]++;
return this.set("skip", v);
}));
_$jscoverage['mongoose/query.js'][215]++;
Query.prototype.$exists = Query.prototype.exists = (function (path, val) {
_$jscoverage['mongoose/query.js'][217]++;
if (arguments.length === 0) {
_$jscoverage['mongoose/query.js'][218]++;
path = this._currPath;
_$jscoverage['mongoose/query.js'][219]++;
val = true;
}
else {
_$jscoverage['mongoose/query.js'][220]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/query.js'][221]++;
if ("boolean" === typeof path) {
_$jscoverage['mongoose/query.js'][222]++;
val = path;
_$jscoverage['mongoose/query.js'][223]++;
path = this._currPath;
}
else {
_$jscoverage['mongoose/query.js'][225]++;
val = true;
}
}
}
_$jscoverage['mongoose/query.js'][228]++;
var conds = this._conditions[path] || (this._conditions[path] = {});
_$jscoverage['mongoose/query.js'][229]++;
conds.$exists = val;
_$jscoverage['mongoose/query.js'][230]++;
return this;
});
_$jscoverage['mongoose/query.js'][106]++;
Query.prototype.limit = (function (v) {
_$jscoverage['mongoose/query.js'][107]++;
return this.set("limit", v);
_$jscoverage['mongoose/query.js'][233]++;
Query.prototype.$elemMatch = Query.prototype.elemMatch = (function (path, criteria) {
_$jscoverage['mongoose/query.js'][235]++;
var block;
_$jscoverage['mongoose/query.js'][236]++;
if (path.constructor === Object) {
_$jscoverage['mongoose/query.js'][237]++;
criteria = path;
_$jscoverage['mongoose/query.js'][238]++;
path = this._currPath;
}
else {
_$jscoverage['mongoose/query.js'][239]++;
if ("function" === typeof path) {
_$jscoverage['mongoose/query.js'][240]++;
block = path;
_$jscoverage['mongoose/query.js'][241]++;
path = this._currPath;
}
else {
_$jscoverage['mongoose/query.js'][242]++;
if (criteria.constructor === Object) {
}
else {
_$jscoverage['mongoose/query.js'][243]++;
if ("function" === typeof criteria) {
_$jscoverage['mongoose/query.js'][244]++;
block = criteria;
}
else {
_$jscoverage['mongoose/query.js'][246]++;
throw new Error("Argument error");
}
}
}
}
_$jscoverage['mongoose/query.js'][248]++;
var conds = this._conditions[path] || (this._conditions[path] = {});
_$jscoverage['mongoose/query.js'][249]++;
if (block) {
_$jscoverage['mongoose/query.js'][250]++;
criteria = new Query();
_$jscoverage['mongoose/query.js'][251]++;
block(criteria);
_$jscoverage['mongoose/query.js'][252]++;
conds.$elemMatch = criteria._conditions;
}
else {
_$jscoverage['mongoose/query.js'][254]++;
conds.$elemMatch = criteria;
}
_$jscoverage['mongoose/query.js'][256]++;
return this;
});
_$jscoverage['mongoose/query.js'][117]++;
Query.prototype.timeout = (function (v) {
_$jscoverage['mongoose/query.js'][118]++;
return this.set("timeout", v);
_$jscoverage['mongoose/query.js'][259]++;
["maxscan"].forEach((function (method) {
_$jscoverage['mongoose/query.js'][260]++;
Query.prototype[method] = (function (v) {
_$jscoverage['mongoose/query.js'][261]++;
this.options[method] = v;
_$jscoverage['mongoose/query.js'][262]++;
return this;
});
_$jscoverage['mongoose/query.js'][133]++;
Query.prototype.sort = (function () {
_$jscoverage['mongoose/query.js'][134]++;
if (! this.options.sort) {
_$jscoverage['mongoose/query.js'][135]++;
this.options.sort = [];
}
_$jscoverage['mongoose/query.js'][137]++;
var args = [].slice.call(arguments), query = this;
_$jscoverage['mongoose/query.js'][139]++;
inGroupsOf(2, args, (function (field, value) {
_$jscoverage['mongoose/query.js'][140]++;
query.options.sort.push([field, value]);
}));
_$jscoverage['mongoose/query.js'][143]++;
_$jscoverage['mongoose/query.js'][267]++;
Query.prototype.explain = (function () {
_$jscoverage['mongoose/query.js'][268]++;
throw new Error("Unimplemented");
});
_$jscoverage['mongoose/query.js'][279]++;
["within", "$within"].forEach((function (getter) {
_$jscoverage['mongoose/query.js'][280]++;
Object.defineProperty(Query.prototype, getter, {get: (function () {
_$jscoverage['mongoose/query.js'][282]++;
return this;
})});
}));
_$jscoverage['mongoose/query.js'][287]++;
Query.prototype.$box = Query.prototype.box = (function (path, val) {
_$jscoverage['mongoose/query.js'][289]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/query.js'][290]++;
val = path;
_$jscoverage['mongoose/query.js'][291]++;
path = this._currPath;
}
_$jscoverage['mongoose/query.js'][293]++;
var conds = this._conditions[path] || (this._conditions[path] = {});
_$jscoverage['mongoose/query.js'][294]++;
conds.$within = {"$box": [val.ll, val.ur]};
_$jscoverage['mongoose/query.js'][295]++;
return this;
});
_$jscoverage['mongoose/query.js'][152]++;
Query.prototype.queryComplete = (function (err) {
_$jscoverage['mongoose/query.js'][153]++;
if (err) {
_$jscoverage['mongoose/query.js'][154]++;
this.error(err);
_$jscoverage['mongoose/query.js'][298]++;
Query.prototype.$center = Query.prototype.center = (function (path, val) {
_$jscoverage['mongoose/query.js'][300]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/query.js'][301]++;
val = path;
_$jscoverage['mongoose/query.js'][302]++;
path = this._currPath;
}
_$jscoverage['mongoose/query.js'][304]++;
var conds = this._conditions[path] || (this._conditions[path] = {});
_$jscoverage['mongoose/query.js'][305]++;
conds.$within = {"$center": [val.center, val.radius]};
_$jscoverage['mongoose/query.js'][306]++;
return this;
});
_$jscoverage['mongoose/query.js'][320]++;
Query.prototype.select = Query.prototype.fields = (function () {
_$jscoverage['mongoose/query.js'][322]++;
var arg0 = arguments[0];
_$jscoverage['mongoose/query.js'][323]++;
if (! arg0) {
_$jscoverage['mongoose/query.js'][323]++;
return this;
}
_$jscoverage['mongoose/query.js'][324]++;
if (arg0.constructor === Object || Array.isArray(arg0)) {
_$jscoverage['mongoose/query.js'][325]++;
this._applyFields(arg0);
}
else {
_$jscoverage['mongoose/query.js'][156]++;
this.complete.apply(this, Array.prototype.slice.call(arguments, 1));
_$jscoverage['mongoose/query.js'][326]++;
if (arguments.length === 1 && typeof arg0 === "string") {
_$jscoverage['mongoose/query.js'][327]++;
this._applyFields({only: arg0});
}
else {
_$jscoverage['mongoose/query.js'][329]++;
this._applyFields({only: this._parseOnlyExcludeFields.apply(this, arguments)});
}
}
_$jscoverage['mongoose/query.js'][158]++;
_$jscoverage['mongoose/query.js'][331]++;
return this;
});
_$jscoverage['mongoose/query.js'][167]++;
function FindQuery(query, fields, options, onExecute) {
_$jscoverage['mongoose/query.js'][168]++;
this.fields = fields || {};
_$jscoverage['mongoose/query.js'][169]++;
Query.call(this, query, options, onExecute);
}
_$jscoverage['mongoose/query.js'][170]++;
;
_$jscoverage['mongoose/query.js'][176]++;
FindQuery.prototype.__proto__ = Query.prototype;
_$jscoverage['mongoose/query.js'][191]++;
FindQuery.prototype.select = (function () {
_$jscoverage['mongoose/query.js'][192]++;
for (var i = 0, l = arguments.length; i < l; i++) {
_$jscoverage['mongoose/query.js'][193]++;
if (Array.isArray(arguments[i])) {
_$jscoverage['mongoose/query.js'][194]++;
for (var a = 0, l = arguments[i].length; a < l; a++) {
_$jscoverage['mongoose/query.js'][195]++;
this.fields[arguments[i][a]] = 1;
}
_$jscoverage['mongoose/query.js'][347]++;
Query.prototype.only = (function (fields) {
_$jscoverage['mongoose/query.js'][348]++;
fields = this._parseOnlyExcludeFields.apply(this, arguments);
_$jscoverage['mongoose/query.js'][349]++;
this._applyFields({only: fields});
_$jscoverage['mongoose/query.js'][350]++;
return this;
});
_$jscoverage['mongoose/query.js'][366]++;
Query.prototype.exclude = (function (fields) {
_$jscoverage['mongoose/query.js'][367]++;
fields = this._parseOnlyExcludeFields.apply(this, arguments);
_$jscoverage['mongoose/query.js'][368]++;
this._applyFields({exclude: fields});
_$jscoverage['mongoose/query.js'][369]++;
return this;
});
_$jscoverage['mongoose/query.js'][372]++;
Query.prototype.$slice = Query.prototype.slice = (function (path, val) {
_$jscoverage['mongoose/query.js'][374]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/query.js'][375]++;
val = path;
_$jscoverage['mongoose/query.js'][376]++;
path = this._currPath;
}
else {
_$jscoverage['mongoose/query.js'][377]++;
if (arguments.length === 2) {
_$jscoverage['mongoose/query.js'][378]++;
if ("number" === typeof path) {
_$jscoverage['mongoose/query.js'][379]++;
val = [path, val];
_$jscoverage['mongoose/query.js'][380]++;
path = this._currPath;
}
}
else {
_$jscoverage['mongoose/query.js'][196]++;
if ("object" == typeof arguments[i]) {
_$jscoverage['mongoose/query.js'][197]++;
for (var a in arguments[i]) {
_$jscoverage['mongoose/query.js'][198]++;
this.fields[a] = arguments[i][a];
}
_$jscoverage['mongoose/query.js'][382]++;
if (arguments.length === 3) {
_$jscoverage['mongoose/query.js'][383]++;
val = [].slice.call(arguments, 1);
}
}
}
_$jscoverage['mongoose/query.js'][385]++;
var myFields = this._fields || (this._fields = {});
_$jscoverage['mongoose/query.js'][386]++;
myFields[path] = {"$slice": val};
_$jscoverage['mongoose/query.js'][387]++;
return this;
});
_$jscoverage['mongoose/query.js'][398]++;
Query.prototype._parseOnlyExcludeFields = (function (fields) {
_$jscoverage['mongoose/query.js'][399]++;
if (1 === arguments.length && "string" === typeof fields) {
_$jscoverage['mongoose/query.js'][400]++;
fields = fields.split(" ");
}
else {
_$jscoverage['mongoose/query.js'][401]++;
if (Array.isArray(fields)) {
}
else {
_$jscoverage['mongoose/query.js'][403]++;
fields = [].slice.call(arguments);
}
}
_$jscoverage['mongoose/query.js'][405]++;
return fields;
});
_$jscoverage['mongoose/query.js'][433]++;
Query.prototype._applyFields = (function (fields) {
_$jscoverage['mongoose/query.js'][434]++;
var $fields, pathList;
_$jscoverage['mongoose/query.js'][436]++;
if (Array.isArray(fields)) {
_$jscoverage['mongoose/query.js'][437]++;
$fields = fields.reduce((function ($fields, field) {
_$jscoverage['mongoose/query.js'][439]++;
$fields[field] = 1;
_$jscoverage['mongoose/query.js'][440]++;
return $fields;
}), {});
}
else {
_$jscoverage['mongoose/query.js'][442]++;
if (pathList = fields.only || fields.exclude) {
_$jscoverage['mongoose/query.js'][443]++;
$fields = this._parseOnlyExcludeFields(pathList).reduce((function ($fields, field) {
_$jscoverage['mongoose/query.js'][446]++;
$fields[field] = fields.only? 1: 0;
_$jscoverage['mongoose/query.js'][447]++;
return $fields;
}), {});
}
else {
_$jscoverage['mongoose/query.js'][449]++;
if (fields.constructor === Object) {
_$jscoverage['mongoose/query.js'][450]++;
$fields = fields;
}
else {
_$jscoverage['mongoose/query.js'][199]++;
if ("string" == typeof arguments[i]) {
_$jscoverage['mongoose/query.js'][200]++;
this.fields[arguments[i]] = 1;
}
_$jscoverage['mongoose/query.js'][452]++;
throw new Error("fields is invalid");
}
}
}
_$jscoverage['mongoose/query.js'][455]++;
var myFields = this._fields || (this._fields = {});
_$jscoverage['mongoose/query.js'][456]++;
for (var k in $fields) {
_$jscoverage['mongoose/query.js'][456]++;
myFields[k] = $fields[k];
}
_$jscoverage['mongoose/query.js'][203]++;
});
_$jscoverage['mongoose/query.js'][470]++;
Query.prototype.sort = (function () {
_$jscoverage['mongoose/query.js'][471]++;
var sort = this.options.sort || (this.options.sort = []), args = [].slice.call(arguments);
_$jscoverage['mongoose/query.js'][473]++;
inGroupsOf(2, args, (function (field, value) {
_$jscoverage['mongoose/query.js'][474]++;
sort.push([field, value]);
}));
_$jscoverage['mongoose/query.js'][476]++;
return this;
});
_$jscoverage['mongoose/query.js'][210]++;
_$jscoverage['mongoose/query.js'][479]++;
Query.prototype.asc = (function () {
_$jscoverage['mongoose/query.js'][480]++;
var sort = this.options.sort || (this.options.sort = []);
_$jscoverage['mongoose/query.js'][481]++;
for (var i = 0, l = arguments.length; i < l; i++) {
_$jscoverage['mongoose/query.js'][482]++;
sort.push([arguments[i], 1]);
}
_$jscoverage['mongoose/query.js'][484]++;
return this;
});
_$jscoverage['mongoose/query.js'][487]++;
Query.prototype.desc = (function () {
_$jscoverage['mongoose/query.js'][488]++;
var sort = this.options.sort || (this.options.sort = []);
_$jscoverage['mongoose/query.js'][489]++;
for (var i = 0, l = arguments.length; i < l; i++) {
_$jscoverage['mongoose/query.js'][490]++;
sort.push([arguments[i], -1]);
}
_$jscoverage['mongoose/query.js'][492]++;
return this;
});
_$jscoverage['mongoose/query.js'][495]++;
["limit", "skip", "maxscan", "snapshot"].forEach((function (method) {
_$jscoverage['mongoose/query.js'][496]++;
Query.prototype[method] = (function (v) {
_$jscoverage['mongoose/query.js'][497]++;
this.options[method] = v;
_$jscoverage['mongoose/query.js'][498]++;
return this;
});
}));
_$jscoverage['mongoose/query.js'][502]++;
Query.prototype.execFind = (function (callback) {
_$jscoverage['mongoose/query.js'][503]++;
var model = this.model, options = this._optionsForExec(model);
_$jscoverage['mongoose/query.js'][505]++;
options.fields = this._fields;
_$jscoverage['mongoose/query.js'][507]++;
try {
_$jscoverage['mongoose/query.js'][508]++;
this.cast(model);
}
catch (err) {
_$jscoverage['mongoose/query.js'][510]++;
return callback(err);
}
_$jscoverage['mongoose/query.js'][512]++;
var castQuery = this._conditions;
_$jscoverage['mongoose/query.js'][514]++;
model.collection.find(castQuery, options, (function (err, cursor) {
_$jscoverage['mongoose/query.js'][515]++;
if (err) {
_$jscoverage['mongoose/query.js'][515]++;
return callback(err);
}
_$jscoverage['mongoose/query.js'][517]++;
cursor.toArray((function (err, docs) {
_$jscoverage['mongoose/query.js'][518]++;
if (err) {
_$jscoverage['mongoose/query.js'][518]++;
callback(err);
}
_$jscoverage['mongoose/query.js'][520]++;
var arr = [], count = docs.length;
_$jscoverage['mongoose/query.js'][523]++;
if (! count) {
_$jscoverage['mongoose/query.js'][523]++;
return callback(null, []);
}
_$jscoverage['mongoose/query.js'][525]++;
for (var i = 0, l = docs.length; i < l; i++) {
_$jscoverage['mongoose/query.js'][526]++;
arr[i] = new model();
_$jscoverage['mongoose/query.js'][527]++;
arr[i].init(docs[i], (function (err) {
_$jscoverage['mongoose/query.js'][528]++;
if (err) {
_$jscoverage['mongoose/query.js'][528]++;
return callback(err);
}
_$jscoverage['mongoose/query.js'][529]++;
--count || callback(null, arr);
}));
}
}));
}));
_$jscoverage['mongoose/query.js'][535]++;
return this;
});
_$jscoverage['mongoose/query.js'][548]++;
Query.prototype.findOne = (function (callback) {
_$jscoverage['mongoose/query.js'][549]++;
var model = this.model;
_$jscoverage['mongoose/query.js'][550]++;
var options = this._optionsForExec(model);
_$jscoverage['mongoose/query.js'][551]++;
options.fields = this._fields;
_$jscoverage['mongoose/query.js'][553]++;
this.cast(model);
_$jscoverage['mongoose/query.js'][554]++;
var castQuery = this._conditions;
_$jscoverage['mongoose/query.js'][556]++;
model.collection.findOne(castQuery, options, (function (err, doc) {
_$jscoverage['mongoose/query.js'][557]++;
if (err) {
_$jscoverage['mongoose/query.js'][557]++;
return callback(err);
}
_$jscoverage['mongoose/query.js'][559]++;
if (! doc) {
_$jscoverage['mongoose/query.js'][559]++;
return callback(null, null);
}
_$jscoverage['mongoose/query.js'][561]++;
var casted = new model();
_$jscoverage['mongoose/query.js'][562]++;
casted.init(doc, (function (err) {
_$jscoverage['mongoose/query.js'][563]++;
if (err) {
_$jscoverage['mongoose/query.js'][563]++;
return callback(err);
}
_$jscoverage['mongoose/query.js'][564]++;
callback(null, casted);
}));
}));
_$jscoverage['mongoose/query.js'][567]++;
return this;
});
_$jscoverage['mongoose/query.js'][579]++;
Query.prototype.count = (function (callback) {
_$jscoverage['mongoose/query.js'][580]++;
var model = this.model;
_$jscoverage['mongoose/query.js'][581]++;
this.cast(model);
_$jscoverage['mongoose/query.js'][582]++;
var castQuery = this._conditions;
_$jscoverage['mongoose/query.js'][583]++;
model.collection.count(castQuery, callback);
_$jscoverage['mongoose/query.js'][584]++;
return this;
});
_$jscoverage['mongoose/query.js'][596]++;
Query.prototype.update = (function (doc, callback) {
_$jscoverage['mongoose/query.js'][597]++;
var model = this.model, options = this._optionsForExec(model);
_$jscoverage['mongoose/query.js'][600]++;
this.cast(model);
_$jscoverage['mongoose/query.js'][601]++;
var castQuery = this._conditions;
_$jscoverage['mongoose/query.js'][603]++;
var castingQuery = {_conditions: doc};
_$jscoverage['mongoose/query.js'][604]++;
this.cast.call(castingQuery, model);
_$jscoverage['mongoose/query.js'][605]++;
var castDoc = castingQuery._conditions;
_$jscoverage['mongoose/query.js'][607]++;
model.collection.update(castQuery, castDoc, options, callback);
_$jscoverage['mongoose/query.js'][608]++;
return this;
});
_$jscoverage['mongoose/query.js'][621]++;
Query.prototype.remove = (function (callback) {
_$jscoverage['mongoose/query.js'][622]++;
var model = this.model;
_$jscoverage['mongoose/query.js'][623]++;
this.cast(model);
_$jscoverage['mongoose/query.js'][624]++;
var castQuery = this._conditions;
_$jscoverage['mongoose/query.js'][625]++;
model.collection.remove(castQuery, callback);
_$jscoverage['mongoose/query.js'][626]++;
return this;
});
_$jscoverage['mongoose/query.js'][629]++;
exports.Query = Query;
_$jscoverage['mongoose/query.js'][212]++;
exports.FindQuery = FindQuery;
_$jscoverage['mongoose/query.js'].source = ["","/**"," * Module dependencies."," */","","var Promise = require('./promise')"," , inGroupsOf = require('./utils').inGroupsOf;","","/**"," * Query constructor"," *"," * @api private"," */","","function Query (query, options, onExecute) {"," Promise.call(this);"," this.query = query || {};"," this.options = options || {};"," this.onExecute = onExecute;"," this.executed = false;","};","","/**"," * Inherits from Promise."," */","","Query.prototype.__proto__ = Promise.prototype;","","/**"," * Runs the Query"," *"," * @param {Function} optional back"," * @api private"," */","","Query.prototype.exec = ","Query.prototype.run = function (fn) {"," if (this.executed)"," return this;",""," if (fn)"," this.addBack(fn);",""," this.executed = true;"," "," if (this.onExecute) {"," try {"," this.onExecute.call(this);"," } catch (e) {"," this.queryComplete(e);"," }"," }",""," return this;","};","","/**"," * Sets an option"," *"," * @param {String} key"," * @param {Object} optional value"," * @api public"," */","","Query.prototype.set = function (key, value) {"," if (arguments.length == 1)"," return this.options[key];"," this.options[key] = value;"," return this;","};","","/**"," * Add conditions to query"," *"," * @param {Object} query"," * @api public"," */","","Query.prototype.where = function (obj, value) {"," if (value == undefined)"," for (var i in obj)"," this.query[i] = obj[i];"," else"," this.query[obj] = value;"," return this;","};","","/**"," * Sets the `skip` option"," *"," * @param {Number} value"," * @api public"," */","","Query.prototype.skip = function (v) {"," return this.set('skip', v);","};","","/**"," * Sets the `limit` option"," *"," * @param {Number} value"," * @api public"," */","","Query.prototype.limit = function (v) {"," return this.set('limit', v);","};","","/**"," * Sets the `timeout` option"," *"," * @param {Number} value"," * @api public"," */","","Query.prototype.timeout = function (v) {"," return this.set('timeout', v);","};","","/**"," * Sets the sort"," *"," * Examples:"," * query.sort('test', 1)"," * query.sort('field', -1)"," * query.sort('field', -1, 'test', 1)"," *"," * @param {Object} fields"," * @api public"," */","","Query.prototype.sort = function () {"," if (!this.options.sort)"," this.options.sort = [];",""," var args = [].slice.call(arguments)"," , query = this;"," inGroupsOf(2, args, function (field, value) {"," query.options.sort.push([field, value]);"," });",""," return this;","};","","/**"," * Resolves the promise from a driver response"," *"," * @api private"," */","","Query.prototype.queryComplete = function (err) {"," if (err)"," this.error(err);"," else"," this.complete.apply(this, Array.prototype.slice.call(arguments, 1));",""," return this;","};","","/**"," * Find Query constructor (for queries that retrieve docs)"," *"," * @api private"," */","","function FindQuery (query, fields, options, onExecute) {"," this.fields = fields || {};"," Query.call(this, query, options, onExecute);","};","","/**"," * Inherits from Query."," */","","FindQuery.prototype.__proto__ = Query.prototype;","","/**"," * Specifies fields to return"," *"," * Examples:"," *"," * // these three are equivalent"," * query.select('field', 'field2')"," * query.select({ field: 1, field2: 1 })"," * query.select(('field', 'field2');"," *"," * @api public"," */","","FindQuery.prototype.select = function () {"," for (var i = 0, l = arguments.length; i &lt; l; i++) {"," if (Array.isArray(arguments[i])) {"," for (var a = 0, l = arguments[i].length; a &lt; l; a++)"," this.fields[arguments[i][a]] = 1;"," } else if ('object' == typeof arguments[i]) {"," for (var a in arguments[i])"," this.fields[a] = arguments[i][a];"," } else if ('string' == typeof arguments[i]) {"," this.fields[arguments[i]] = 1;"," }"," }"," return this;","};","","/**"," * Module exports"," */","","exports.Query = Query;","","exports.FindQuery = FindQuery;"];
_$jscoverage['mongoose/query.js'].source = ["var utils = require('./utils')"," , merge = utils.merge"," , inGroupsOf = utils.inGroupsOf;","","/**"," * Query constructor"," *"," * @api private"," */","","function Query (criteria, options) {"," options = this.options = options || {};"," this.safe = options.safe"," this._conditions = {};"," if (criteria) this.find(criteria);","}","","/**"," * Spawns a new query that's bound to a new model."," * @param {Function} param"," * @return {Query}"," * @api public"," */","","Query.prototype.bind = function (model) {"," var ret = Object.create(this);"," ret.model = model;"," return ret;","};","","Query.prototype.find = function (criteria, callback) {"," if ('function' === typeof criteria) {"," callback = criteria;"," criteria = {};"," }"," if (criteria instanceof Query) {"," merge(this._conditions, criteria._conditions);"," } else {"," merge(this._conditions, criteria);"," }"," if (!callback) return this;"," return this.execFind(callback);","};","","/**"," * Casts obj, or if obj is not present, then this._conditions,"," * based on the model's schema."," *"," * @param {Function} model"," * @param {Object} obj (optional)"," * @api public"," */","","Query.prototype.cast = function (model, obj) {"," obj || (obj= this._conditions);",""," var schema = model.schema"," , paths = Object.keys(obj)"," , i = paths.length, path, val, schematype, nested"," , any$conditionals, type;"," while (i--) {"," path = paths[i];"," val = obj[path];",""," if (path === '$or') {"," var k = val.length"," , orComponentQuery;"," while (k--) {"," orComponentQuery = new Query(val[k])"," orComponentQuery.cast(model);"," val[k] = orComponentQuery._conditions;"," }"," } else if (path === '$where') {"," type = typeof val;"," if ('string' !== type &amp;&amp; 'function' !== type) {"," throw new Error(\"Must have a string or function for $where\");"," }"," if ('function' === type) obj[path] = val.toString();"," continue;"," } else {"," schematype = schema.path(path);"," if (!schematype) {"," // Handle potential embedded array queries"," var split = path.split('.')"," , j = split.length"," , pathFirstHalf, pathLastHalf"," , remainingConds, castingQuery;"," // Find the part of the var path that is a path of the Schema"," while (j--) {"," pathFirstHalf = split.slice(0, j).join('.');"," schematype = schema.path(pathFirstHalf);"," if (schematype) break;"," }"," // If a substring of the input path resolves to an actual real path..."," if (schematype) {"," // Apply the casting; similar code for $elemMatch in schema/array.js"," remainingConds = {};"," pathLastHalf = split.slice(j).join('.');"," remainingConds[pathLastHalf] = val;"," castingQuery = new Query(remainingConds);"," castingQuery.cast(schematype.caster);"," obj[path] = castingQuery._conditions[pathLastHalf];"," }"," } else if (val === null || val === undefined) {"," continue;"," } else if (val.constructor == Object) {"," any$conditionals = Object.keys(val).some( function (k) {"," return k.charAt(0) === '$';"," });"," if (!any$conditionals) {"," obj[path] = schematype.castForQuery(val);"," } else for (var $cond in val) {"," nested = val[$cond];"," if ($cond === '$ne' &amp;&amp; nested === null) {"," continue;"," } else if ($cond === '$exists') {"," if ('boolean' !== typeof nested)"," throw new Error(\"$exists parameter must be Boolean\");"," continue;"," } else if ($cond === '$not') {"," this.cast(model, val[$cond]);"," } else {"," val[$cond] = schematype.castForQuery($cond, nested);"," }"," }"," } else {"," obj[path] = schematype.castForQuery(val);"," }"," }"," }","};","","Query.prototype._optionsForExec = function (model) {"," var options = utils.clone(this.options);"," if (! ('safe' in options)) options.safe = model.options.safe;"," return options;","};","","/**"," * Sometimes you need to query for things in mongodb using a JavaScript"," * expression. You can do so via find({$where: javascript}), or you can"," * use the mongoose shortcut method $where via a Query chain or from"," * your mongoose Model."," *"," * @param {String|Function} js is a javascript string or anonymous function"," * @return {Query}"," * @api public"," */","","Query.prototype.$where = function (js) {"," this._conditions['$where'] = js;"," return this;","};","","/**"," * `with` enables a very nice sugary api for doing your queries."," * For example, instead of writing:"," * User.find({age: {$gte: 21, $lte: 65}}, callback);"," * we can instead write more readably:"," * User.with('age').gte(21).lte(65);"," * Moreover, you can also chain a bunch of these together like:"," * User"," * .with('age').gte(21).lte(65)"," * .with('name', /^b/i) // All names that begin with b or B"," * .with('friends').slice(10);"," * @param {String} path"," * @param {Object} val (optional)"," * @return {Query}"," * @api public"," */","","Query.prototype.with = function (path, val) {"," var conds;"," if (arguments.length === 2) {"," this._conditions[path] = val;"," }"," this._currPath = path;"," return this;","};","","// $lt, $lte, $gt, $gte can be used on Numbers or Dates","['gt', 'gte', 'lt', 'lte', 'ne', 'in', 'nin', 'all', 'size'].forEach( function ($conditional) {"," Query.prototype['$' + $conditional] ="," Query.prototype[$conditional] = function (path, val) {"," if (arguments.length === 1) {"," val = path;"," path = this._currPath"," }"," var conds = this._conditions[path] || (this._conditions[path] = {});"," conds['$' + $conditional] = val;"," return this;"," };","});","","Query.prototype.notEqualTo = Query.prototype.ne;","","['mod', 'near'].forEach( function ($conditional) {"," Query.prototype['$' + $conditional] ="," Query.prototype[$conditional] = function (path, val) {"," if (arguments.length === 1) {"," val = path;"," path = this._currPath"," } else if (arguments.length === 2 &amp;&amp; !Array.isArray(val)) {"," val = [].slice.call(arguments);"," path = this._currPath;"," } else if (arguments.length === 3) {"," val = [].slice.call(arguments, 1);"," }"," var conds = this._conditions[path] || (this._conditions[path] = {});"," conds['$' + $conditional] = val;"," return this;"," };","});","","Query.prototype['$exists'] =","Query.prototype.exists = function (path, val) {"," if (arguments.length === 0) {"," path = this._currPath"," val = true;"," } else if (arguments.length === 1) {"," if ('boolean' === typeof path) {"," val = path;"," path = this._currPath;"," } else {"," val = true;"," }"," }"," var conds = this._conditions[path] || (this._conditions[path] = {});"," conds['$exists'] = val;"," return this;","};","","Query.prototype['$elemMatch'] =","Query.prototype.elemMatch = function (path, criteria) {"," var block;"," if (path.constructor === Object) {"," criteria = path;"," path = this._currPath;"," } else if ('function' === typeof path) {"," block = path;"," path = this._currPath;"," } else if (criteria.constructor === Object) {"," } else if ('function' === typeof criteria) {"," block = criteria;"," } else {"," throw new Error(\"Argument error\");"," }"," var conds = this._conditions[path] || (this._conditions[path] = {});"," if (block) {"," criteria = new Query();"," block(criteria);"," conds['$elemMatch'] = criteria._conditions;"," } else {"," conds['$elemMatch'] = criteria;"," }"," return this;","};","","['maxscan'].forEach( function (method) {"," Query.prototype[method] = function (v) {"," this.options[method] = v;"," return this;"," };","});","","// TODO","Query.prototype.explain = function () {"," throw new Error(\"Unimplemented\");","};","","// TODO Add being able to skip casting -- e.g., this would be nice for scenarios like","// if you're migrating to usernames from user id numbers:","// query.with('user_id').in([4444, 'brian']);","","// TODO \"immortal\" cursors","// TODO geoNear command","","// To be used idiomatically with Query#box and Query#center","['within', '$within'].forEach( function (getter) {"," Object.defineProperty(Query.prototype, getter, {"," get: function () {"," return this;"," }"," });","});","","Query.prototype['$box'] =","Query.prototype.box = function (path, val) {"," if (arguments.length === 1) {"," val = path;"," path = this._currPath;"," }"," var conds = this._conditions[path] || (this._conditions[path] = {});"," conds['$within'] = { '$box': [val.ll, val.ur] };"," return this;","};","","Query.prototype['$center'] =","Query.prototype.center = function (path, val) {"," if (arguments.length === 1) {"," val = path;"," path = this._currPath;"," }"," var conds = this._conditions[path] || (this._conditions[path] = {});"," conds['$within'] = { '$center': [val.center, val.radius] };"," return this;","};","","/**"," * Chainable method for specifying which fields"," * to include or exclude from the document that is"," * returned from MongoDB."," *"," * Examples:"," * query.fields({a: 1, b: 1, c: 1, _id: 0});"," * query.fields('a b c');"," *"," * @param {Object}"," */","Query.prototype.select =","Query.prototype.fields = function () {"," var arg0 = arguments[0];"," if (!arg0) return this;"," if (arg0.constructor === Object || Array.isArray(arg0)) {"," this._applyFields(arg0);"," } else if (arguments.length === 1 &amp;&amp; typeof arg0 === 'string') {"," this._applyFields({only: arg0});"," } else {"," this._applyFields({only: this._parseOnlyExcludeFields.apply(this, arguments)});"," }"," return this;","};","","/**"," * Chainable method for adding the specified fields to the "," * object of fields to only include."," *"," * Examples:"," * query.only('a b c');"," * query.only('a', 'b', 'c');"," * query.only(['a', 'b', 'c']);"," * @param {String|Array} space separated list of fields OR"," * an array of field names"," * We can also take arguments as the \"array\" of field names"," * @api public"," */","Query.prototype.only = function (fields) {"," fields = this._parseOnlyExcludeFields.apply(this, arguments);"," this._applyFields({ only: fields });"," return this;","};","","/**"," * Chainable method for adding the specified fields to the "," * object of fields to exclude."," *"," * Examples:"," * query.exclude('a b c');"," * query.exclude('a', 'b', 'c');"," * query.exclude(['a', 'b', 'c']);"," * @param {String|Array} space separated list of fields OR"," * an array of field names"," * We can also take arguments as the \"array\" of field names"," * @api public"," */","Query.prototype.exclude = function (fields) {"," fields = this._parseOnlyExcludeFields.apply(this, arguments);"," this._applyFields({ exclude: fields });"," return this;","};","","Query.prototype['$slice'] =","Query.prototype.slice = function (path, val) {"," if (arguments.length === 1) {"," val = path;"," path = this._currPath"," } else if (arguments.length === 2) {"," if ('number' === typeof path) {"," val = [path, val];"," path = this._currPath;"," }"," } else if (arguments.length === 3) {"," val = [].slice.call(arguments, 1);"," }"," var myFields = this._fields || (this._fields = {});"," myFields[path] = { '$slice': val };"," return this;","};","","/**"," * Private method for interpreting the different ways"," * you can pass in fields to both Query.prototype.only"," * and Query.prototype.exclude."," *"," * @param {String|Array|Object} fields"," * @api private"," */","Query.prototype._parseOnlyExcludeFields = function (fields) {"," if (1 === arguments.length &amp;&amp; 'string' === typeof fields) {"," fields = fields.split(' ');"," } else if (Array.isArray(fields)) {"," } else {"," fields = [].slice.call(arguments);"," }"," return fields;","};","","/**"," * Private method for interpreting and applying the different"," * ways you can specify which fields you want to include"," * or exclude."," *"," * Example 1: Include fields 'a', 'b', and 'c' via an Array"," * query.fields('a', 'b', 'c');"," * query.fields(['a', 'b', 'c']);"," *"," * Example 2: Include fields via 'only' shortcut"," * query.only('a b c');"," *"," * Example 3: Exclude fields via 'exclude' shortcut"," * query.exclude('a b c');"," *"," * Example 4: Include fields via MongoDB's native format"," * query.fields({a: 1, b: 1, c: 1})"," *"," * Example 5: Exclude fields via MongoDB's native format"," * query.fields({a: 0, b: 0, c: 0});"," *"," * @param {Object|Array} the formatted collection of fields to"," * include and/or exclude"," * @api private"," */","Query.prototype._applyFields = function (fields) {"," var $fields"," , pathList;"," if (Array.isArray(fields)) {"," $fields = "," fields.reduce( function ($fields, field) {"," $fields[field] = 1;"," return $fields;"," }, {});"," } else if (pathList = fields.only || fields.exclude) {"," $fields = "," this._parseOnlyExcludeFields(pathList)"," .reduce( function ($fields, field) {"," $fields[field] = fields.only ? 1: 0;"," return $fields;"," }, {});"," } else if (fields.constructor === Object) {"," $fields = fields;"," } else {"," throw new Error(\"fields is invalid\");"," }",""," var myFields = this._fields || (this._fields = {});"," for (var k in $fields) myFields[k] = $fields[k];","};","","/**"," * Sets the sort"," *"," * Examples:"," * query.sort('test', 1)"," * query.sort('field', -1)"," * query.sort('field', -1, 'test', 1)"," *"," * @api public"," */","","Query.prototype.sort = function () {"," var sort = this.options.sort || (this.options.sort = [])"," , args = [].slice.call(arguments);"," inGroupsOf(2, args, function (field, value) {"," sort.push([field, value]);"," });"," return this;","};","","Query.prototype.asc = function () {"," var sort = this.options.sort || (this.options.sort = []);"," for (var i = 0, l = arguments.length; i &lt; l; i++) {"," sort.push([arguments[i], 1]);"," }"," return this;","};","","Query.prototype.desc = function () {"," var sort = this.options.sort || (this.options.sort = []);"," for (var i = 0, l = arguments.length; i &lt; l; i++) {"," sort.push([arguments[i], -1]);"," }"," return this;","};","","['limit', 'skip', 'maxscan', 'snapshot'].forEach( function (method) {"," Query.prototype[method] = function (v) {"," this.options[method] = v;"," return this;"," };","});","","Query.prototype.execFind = function (callback) {"," var model = this.model"," , options = this._optionsForExec(model);"," options.fields = this._fields;",""," try {"," this.cast(model);"," } catch (err) {"," return callback(err);"," }"," var castQuery = this._conditions;",""," model.collection.find(castQuery, options, function (err, cursor) {"," if (err) return callback(err);",""," cursor.toArray( function (err, docs) {"," if (err) callback(err);",""," var arr = []"," , count = docs.length;",""," if (!count) return callback(null, []);",""," for (var i = 0, l = docs.length; i &lt; l; i++) {"," arr[i] = new model();"," arr[i].init(docs[i], function (err) {"," if (err) return callback(err);"," --count || callback(null, arr);"," });"," }"," });",""," });"," return this;","};","","/**"," * Casts the query, sends the findOne command to mongodb."," * Upon receiving the document, we initialize a mongoose"," * document based on the returned document from mongodb,"," * and then we invoke a callback on our mongoose document."," *"," * @param {Function} callback function (err, found)"," * @api public"," */","","Query.prototype.findOne = function (callback) {"," var model = this.model;"," var options = this._optionsForExec(model);"," options.fields = this._fields;"," "," this.cast(model);"," var castQuery = this._conditions;",""," model.collection.findOne(castQuery, options, function (err, doc) {"," if (err) return callback(err);",""," if (!doc) return callback(null, null);",""," var casted = new model();"," casted.init(doc, function (err) {"," if (err) return callback(err);"," callback(null, casted);"," });"," });"," return this;","};","","/**"," * Casts this._conditions and sends a count"," * command to mongodb. Invokes a callback upon"," * receiving results"," *"," * @param {Function} callback fn(err, cardinality)"," * @api public"," */","","Query.prototype.count = function (callback) {"," var model = this.model;"," this.cast(model);"," var castQuery = this._conditions;"," model.collection.count(castQuery, callback);"," return this;","};","","/**"," * Casts the query, sends the update command to mongodb."," * If there is an error, the callback handles it. Otherwise,"," * we just invoke the callback without passing it an error."," *"," * @param {Function} callback fn(err)"," * @api public"," */","","Query.prototype.update = function (doc, callback) {"," var model = this.model"," , options = this._optionsForExec(model);",""," this.cast(model);"," var castQuery = this._conditions;",""," var castingQuery = {_conditions: doc};"," this.cast.call(castingQuery, model);"," var castDoc = castingQuery._conditions;",""," model.collection.update(castQuery, castDoc, options, callback);"," return this;","};","","/**"," * Casts the query, sends the remove command to "," * mongodb with the query contents, and then"," * invokes a callback upon receiving the command"," * result."," *"," * @param {Function} callback fn(err)"," * @api public"," */","","Query.prototype.remove = function (callback) {"," var model = this.model;"," this.cast(model);"," var castQuery = this._conditions;"," model.collection.remove(castQuery, callback);"," return this;","};","","exports.Query = Query;"];

@@ -54,63 +54,118 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema.js'][151] = 0;
_$jscoverage['mongoose/schema.js'][162] = 0;
_$jscoverage['mongoose/schema.js'][163] = 0;
_$jscoverage['mongoose/schema.js'][164] = 0;
_$jscoverage['mongoose/schema.js'][165] = 0;
_$jscoverage['mongoose/schema.js'][176] = 0;
_$jscoverage['mongoose/schema.js'][177] = 0;
_$jscoverage['mongoose/schema.js'][178] = 0;
_$jscoverage['mongoose/schema.js'][189] = 0;
_$jscoverage['mongoose/schema.js'][190] = 0;
_$jscoverage['mongoose/schema.js'][201] = 0;
_$jscoverage['mongoose/schema.js'][202] = 0;
_$jscoverage['mongoose/schema.js'][212] = 0;
_$jscoverage['mongoose/schema.js'][213] = 0;
_$jscoverage['mongoose/schema.js'][214] = 0;
_$jscoverage['mongoose/schema.js'][225] = 0;
_$jscoverage['mongoose/schema.js'][226] = 0;
_$jscoverage['mongoose/schema.js'][227] = 0;
_$jscoverage['mongoose/schema.js'][228] = 0;
_$jscoverage['mongoose/schema.js'][230] = 0;
_$jscoverage['mongoose/schema.js'][231] = 0;
_$jscoverage['mongoose/schema.js'][242] = 0;
_$jscoverage['mongoose/schema.js'][243] = 0;
_$jscoverage['mongoose/schema.js'][244] = 0;
_$jscoverage['mongoose/schema.js'][245] = 0;
_$jscoverage['mongoose/schema.js'][159] = 0;
_$jscoverage['mongoose/schema.js'][161] = 0;
_$jscoverage['mongoose/schema.js'][166] = 0;
_$jscoverage['mongoose/schema.js'][167] = 0;
_$jscoverage['mongoose/schema.js'][168] = 0;
_$jscoverage['mongoose/schema.js'][169] = 0;
_$jscoverage['mongoose/schema.js'][171] = 0;
_$jscoverage['mongoose/schema.js'][183] = 0;
_$jscoverage['mongoose/schema.js'][184] = 0;
_$jscoverage['mongoose/schema.js'][185] = 0;
_$jscoverage['mongoose/schema.js'][186] = 0;
_$jscoverage['mongoose/schema.js'][197] = 0;
_$jscoverage['mongoose/schema.js'][198] = 0;
_$jscoverage['mongoose/schema.js'][199] = 0;
_$jscoverage['mongoose/schema.js'][210] = 0;
_$jscoverage['mongoose/schema.js'][211] = 0;
_$jscoverage['mongoose/schema.js'][222] = 0;
_$jscoverage['mongoose/schema.js'][223] = 0;
_$jscoverage['mongoose/schema.js'][233] = 0;
_$jscoverage['mongoose/schema.js'][234] = 0;
_$jscoverage['mongoose/schema.js'][235] = 0;
_$jscoverage['mongoose/schema.js'][246] = 0;
_$jscoverage['mongoose/schema.js'][247] = 0;
_$jscoverage['mongoose/schema.js'][248] = 0;
_$jscoverage['mongoose/schema.js'][261] = 0;
_$jscoverage['mongoose/schema.js'][262] = 0;
_$jscoverage['mongoose/schema.js'][249] = 0;
_$jscoverage['mongoose/schema.js'][251] = 0;
_$jscoverage['mongoose/schema.js'][252] = 0;
_$jscoverage['mongoose/schema.js'][263] = 0;
_$jscoverage['mongoose/schema.js'][274] = 0;
_$jscoverage['mongoose/schema.js'][275] = 0;
_$jscoverage['mongoose/schema.js'][276] = 0;
_$jscoverage['mongoose/schema.js'][277] = 0;
_$jscoverage['mongoose/schema.js'][278] = 0;
_$jscoverage['mongoose/schema.js'][287] = 0;
_$jscoverage['mongoose/schema.js'][288] = 0;
_$jscoverage['mongoose/schema.js'][292] = 0;
_$jscoverage['mongoose/schema.js'][293] = 0;
_$jscoverage['mongoose/schema.js'][264] = 0;
_$jscoverage['mongoose/schema.js'][265] = 0;
_$jscoverage['mongoose/schema.js'][266] = 0;
_$jscoverage['mongoose/schema.js'][268] = 0;
_$jscoverage['mongoose/schema.js'][269] = 0;
_$jscoverage['mongoose/schema.js'][282] = 0;
_$jscoverage['mongoose/schema.js'][283] = 0;
_$jscoverage['mongoose/schema.js'][284] = 0;
_$jscoverage['mongoose/schema.js'][295] = 0;
_$jscoverage['mongoose/schema.js'][296] = 0;
_$jscoverage['mongoose/schema.js'][297] = 0;
_$jscoverage['mongoose/schema.js'][298] = 0;
_$jscoverage['mongoose/schema.js'][299] = 0;
_$jscoverage['mongoose/schema.js'][300] = 0;
_$jscoverage['mongoose/schema.js'][301] = 0;
_$jscoverage['mongoose/schema.js'][304] = 0;
_$jscoverage['mongoose/schema.js'][306] = 0;
_$jscoverage['mongoose/schema.js'][307] = 0;
_$jscoverage['mongoose/schema.js'][308] = 0;
_$jscoverage['mongoose/schema.js'][309] = 0;
_$jscoverage['mongoose/schema.js'][313] = 0;
_$jscoverage['mongoose/schema.js'][314] = 0;
_$jscoverage['mongoose/schema.js'][316] = 0;
_$jscoverage['mongoose/schema.js'][317] = 0;
_$jscoverage['mongoose/schema.js'][318] = 0;
_$jscoverage['mongoose/schema.js'][320] = 0;
_$jscoverage['mongoose/schema.js'][321] = 0;
_$jscoverage['mongoose/schema.js'][322] = 0;
_$jscoverage['mongoose/schema.js'][325] = 0;
_$jscoverage['mongoose/schema.js'][327] = 0;
_$jscoverage['mongoose/schema.js'][328] = 0;
_$jscoverage['mongoose/schema.js'][329] = 0;
_$jscoverage['mongoose/schema.js'][330] = 0;
_$jscoverage['mongoose/schema.js'][342] = 0;
_$jscoverage['mongoose/schema.js'][343] = 0;
_$jscoverage['mongoose/schema.js'][352] = 0;
_$jscoverage['mongoose/schema.js'][353] = 0;
_$jscoverage['mongoose/schema.js'][361] = 0;
_$jscoverage['mongoose/schema.js'][337] = 0;
_$jscoverage['mongoose/schema.js'][339] = 0;
_$jscoverage['mongoose/schema.js'][349] = 0;
_$jscoverage['mongoose/schema.js'][350] = 0;
_$jscoverage['mongoose/schema.js'][351] = 0;
_$jscoverage['mongoose/schema.js'][363] = 0;
_$jscoverage['mongoose/schema.js'][365] = 0;
_$jscoverage['mongoose/schema.js'][364] = 0;
_$jscoverage['mongoose/schema.js'][368] = 0;
_$jscoverage['mongoose/schema.js'][369] = 0;
_$jscoverage['mongoose/schema.js'][371] = 0;
_$jscoverage['mongoose/schema.js'][373] = 0;
_$jscoverage['mongoose/schema.js'][374] = 0;
_$jscoverage['mongoose/schema.js'][375] = 0;
_$jscoverage['mongoose/schema.js'][376] = 0;
_$jscoverage['mongoose/schema.js'][383] = 0;
_$jscoverage['mongoose/schema.js'][384] = 0;
_$jscoverage['mongoose/schema.js'][387] = 0;
_$jscoverage['mongoose/schema.js'][388] = 0;
_$jscoverage['mongoose/schema.js'][389] = 0;
_$jscoverage['mongoose/schema.js'][393] = 0;
_$jscoverage['mongoose/schema.js'][396] = 0;
_$jscoverage['mongoose/schema.js'][402] = 0;
_$jscoverage['mongoose/schema.js'][403] = 0;
_$jscoverage['mongoose/schema.js'][405] = 0;
_$jscoverage['mongoose/schema.js'][406] = 0;
_$jscoverage['mongoose/schema.js'][407] = 0;
_$jscoverage['mongoose/schema.js'][409] = 0;
_$jscoverage['mongoose/schema.js'][410] = 0;
_$jscoverage['mongoose/schema.js'][411] = 0;
_$jscoverage['mongoose/schema.js'][412] = 0;
_$jscoverage['mongoose/schema.js'][416] = 0;
_$jscoverage['mongoose/schema.js'][417] = 0;
_$jscoverage['mongoose/schema.js'][418] = 0;
_$jscoverage['mongoose/schema.js'][419] = 0;
_$jscoverage['mongoose/schema.js'][423] = 0;
_$jscoverage['mongoose/schema.js'][424] = 0;
_$jscoverage['mongoose/schema.js'][425] = 0;
_$jscoverage['mongoose/schema.js'][426] = 0;
_$jscoverage['mongoose/schema.js'][433] = 0;
_$jscoverage['mongoose/schema.js'][434] = 0;
_$jscoverage['mongoose/schema.js'][437] = 0;
_$jscoverage['mongoose/schema.js'][438] = 0;
_$jscoverage['mongoose/schema.js'][439] = 0;
_$jscoverage['mongoose/schema.js'][440] = 0;
_$jscoverage['mongoose/schema.js'][441] = 0;
_$jscoverage['mongoose/schema.js'][443] = 0;
_$jscoverage['mongoose/schema.js'][444] = 0;
_$jscoverage['mongoose/schema.js'][445] = 0;
_$jscoverage['mongoose/schema.js'][449] = 0;
_$jscoverage['mongoose/schema.js'][450] = 0;
_$jscoverage['mongoose/schema.js'][451] = 0;
_$jscoverage['mongoose/schema.js'][455] = 0;
_$jscoverage['mongoose/schema.js'][456] = 0;
_$jscoverage['mongoose/schema.js'][457] = 0;
_$jscoverage['mongoose/schema.js'][461] = 0;
_$jscoverage['mongoose/schema.js'][470] = 0;
_$jscoverage['mongoose/schema.js'][471] = 0;
_$jscoverage['mongoose/schema.js'][479] = 0;
_$jscoverage['mongoose/schema.js'][481] = 0;
_$jscoverage['mongoose/schema.js'][483] = 0;
}

@@ -147,3 +202,3 @@ _$jscoverage['mongoose/schema.js'][6]++;

_$jscoverage['mongoose/schema.js'][39]++;
this.add({_id: ObjectId});
this.add({_id: {type: ObjectId, auto: true}});
}

@@ -243,48 +298,67 @@ }

});
_$jscoverage['mongoose/schema.js'][162]++;
_$jscoverage['mongoose/schema.js'][159]++;
Object.defineProperty(Schema.prototype, "requiredPaths", {get: (function () {
_$jscoverage['mongoose/schema.js'][161]++;
var paths = this.paths, pathnames = Object.keys(paths), i = pathnames.length, pathname, path, requiredPaths = [];
_$jscoverage['mongoose/schema.js'][166]++;
while (i--) {
_$jscoverage['mongoose/schema.js'][167]++;
pathname = pathnames[i];
_$jscoverage['mongoose/schema.js'][168]++;
path = paths[pathname];
_$jscoverage['mongoose/schema.js'][169]++;
if (path.isRequired) {
_$jscoverage['mongoose/schema.js'][169]++;
requiredPaths.push(pathname);
}
}
_$jscoverage['mongoose/schema.js'][171]++;
return requiredPaths;
})});
_$jscoverage['mongoose/schema.js'][183]++;
Schema.prototype.pathType = (function (path) {
_$jscoverage['mongoose/schema.js'][163]++;
_$jscoverage['mongoose/schema.js'][184]++;
if (path in this.paths) {
_$jscoverage['mongoose/schema.js'][163]++;
_$jscoverage['mongoose/schema.js'][184]++;
return "real";
}
_$jscoverage['mongoose/schema.js'][164]++;
_$jscoverage['mongoose/schema.js'][185]++;
if (path in this.virtuals) {
_$jscoverage['mongoose/schema.js'][164]++;
_$jscoverage['mongoose/schema.js'][185]++;
return "virtual";
}
_$jscoverage['mongoose/schema.js'][165]++;
_$jscoverage['mongoose/schema.js'][186]++;
return "adhocOrUndefined";
});
_$jscoverage['mongoose/schema.js'][176]++;
_$jscoverage['mongoose/schema.js'][197]++;
Schema.prototype.queue = (function (name, args) {
_$jscoverage['mongoose/schema.js'][177]++;
_$jscoverage['mongoose/schema.js'][198]++;
this.callQueue.push([name, args]);
_$jscoverage['mongoose/schema.js'][178]++;
_$jscoverage['mongoose/schema.js'][199]++;
return this;
});
_$jscoverage['mongoose/schema.js'][189]++;
_$jscoverage['mongoose/schema.js'][210]++;
Schema.prototype.pre = (function () {
_$jscoverage['mongoose/schema.js'][190]++;
_$jscoverage['mongoose/schema.js'][211]++;
return this.queue("pre", arguments);
});
_$jscoverage['mongoose/schema.js'][201]++;
_$jscoverage['mongoose/schema.js'][222]++;
Schema.prototype.post = (function (method, fn) {
_$jscoverage['mongoose/schema.js'][202]++;
_$jscoverage['mongoose/schema.js'][223]++;
return this.queue("on", arguments);
});
_$jscoverage['mongoose/schema.js'][212]++;
_$jscoverage['mongoose/schema.js'][233]++;
Schema.prototype.plugin = (function (fn, opts) {
_$jscoverage['mongoose/schema.js'][213]++;
_$jscoverage['mongoose/schema.js'][234]++;
fn(this, opts);
_$jscoverage['mongoose/schema.js'][214]++;
_$jscoverage['mongoose/schema.js'][235]++;
return this;
});
_$jscoverage['mongoose/schema.js'][225]++;
_$jscoverage['mongoose/schema.js'][246]++;
Schema.prototype.method = (function (name, fn) {
_$jscoverage['mongoose/schema.js'][226]++;
_$jscoverage['mongoose/schema.js'][247]++;
if ("string" != typeof name) {
_$jscoverage['mongoose/schema.js'][227]++;
_$jscoverage['mongoose/schema.js'][248]++;
for (var i in name) {
_$jscoverage['mongoose/schema.js'][228]++;
_$jscoverage['mongoose/schema.js'][249]++;
this.methods[i] = name[i];

@@ -294,15 +368,15 @@ }

else {
_$jscoverage['mongoose/schema.js'][230]++;
_$jscoverage['mongoose/schema.js'][251]++;
this.methods[name] = fn;
}
_$jscoverage['mongoose/schema.js'][231]++;
_$jscoverage['mongoose/schema.js'][252]++;
return this;
});
_$jscoverage['mongoose/schema.js'][242]++;
_$jscoverage['mongoose/schema.js'][263]++;
Schema.prototype["static"] = (function (name, fn) {
_$jscoverage['mongoose/schema.js'][243]++;
_$jscoverage['mongoose/schema.js'][264]++;
if ("string" != typeof name) {
_$jscoverage['mongoose/schema.js'][244]++;
_$jscoverage['mongoose/schema.js'][265]++;
for (var i in name) {
_$jscoverage['mongoose/schema.js'][245]++;
_$jscoverage['mongoose/schema.js'][266]++;
this.statics[i] = name[i];

@@ -312,46 +386,46 @@ }

else {
_$jscoverage['mongoose/schema.js'][247]++;
_$jscoverage['mongoose/schema.js'][268]++;
this.statics[name] = fn;
}
_$jscoverage['mongoose/schema.js'][248]++;
_$jscoverage['mongoose/schema.js'][269]++;
return this;
});
_$jscoverage['mongoose/schema.js'][261]++;
_$jscoverage['mongoose/schema.js'][282]++;
Schema.prototype.index = (function (fields, options) {
_$jscoverage['mongoose/schema.js'][262]++;
_$jscoverage['mongoose/schema.js'][283]++;
this._indexes.push([fields, options || {}]);
_$jscoverage['mongoose/schema.js'][263]++;
_$jscoverage['mongoose/schema.js'][284]++;
return this;
});
_$jscoverage['mongoose/schema.js'][274]++;
_$jscoverage['mongoose/schema.js'][295]++;
Schema.prototype.set = (function (key, value) {
_$jscoverage['mongoose/schema.js'][275]++;
_$jscoverage['mongoose/schema.js'][296]++;
if (arguments.length == 1) {
_$jscoverage['mongoose/schema.js'][276]++;
_$jscoverage['mongoose/schema.js'][297]++;
return this.options[key];
}
_$jscoverage['mongoose/schema.js'][277]++;
_$jscoverage['mongoose/schema.js'][298]++;
this.options[key] = value;
_$jscoverage['mongoose/schema.js'][278]++;
_$jscoverage['mongoose/schema.js'][299]++;
return this;
});
_$jscoverage['mongoose/schema.js'][287]++;
_$jscoverage['mongoose/schema.js'][308]++;
Schema.prototype.__defineGetter__("indexes", (function () {
_$jscoverage['mongoose/schema.js'][288]++;
_$jscoverage['mongoose/schema.js'][309]++;
var index, indexes = [], seenSchemas = [];
_$jscoverage['mongoose/schema.js'][292]++;
_$jscoverage['mongoose/schema.js'][313]++;
function collectIndexes(paths, prefix) {
_$jscoverage['mongoose/schema.js'][293]++;
_$jscoverage['mongoose/schema.js'][314]++;
prefix = prefix || "";
_$jscoverage['mongoose/schema.js'][295]++;
_$jscoverage['mongoose/schema.js'][316]++;
for (var i in paths) {
_$jscoverage['mongoose/schema.js'][296]++;
_$jscoverage['mongoose/schema.js'][317]++;
if (paths[i]) {
_$jscoverage['mongoose/schema.js'][297]++;
_$jscoverage['mongoose/schema.js'][318]++;
if (paths[i] instanceof Types.DocumentArray) {
_$jscoverage['mongoose/schema.js'][299]++;
_$jscoverage['mongoose/schema.js'][320]++;
if (! (~ seenSchemas.indexOf(paths[i].schema))) {
_$jscoverage['mongoose/schema.js'][300]++;
_$jscoverage['mongoose/schema.js'][321]++;
seenSchemas.push(paths[i].schema);
_$jscoverage['mongoose/schema.js'][301]++;
_$jscoverage['mongoose/schema.js'][322]++;
collectIndexes(paths[i].schema.paths, i + ".");

@@ -361,11 +435,11 @@ }

else {
_$jscoverage['mongoose/schema.js'][304]++;
_$jscoverage['mongoose/schema.js'][325]++;
index = paths[i]._index;
_$jscoverage['mongoose/schema.js'][306]++;
_$jscoverage['mongoose/schema.js'][327]++;
if (index !== false && index !== null) {
_$jscoverage['mongoose/schema.js'][307]++;
_$jscoverage['mongoose/schema.js'][328]++;
var field = {};
_$jscoverage['mongoose/schema.js'][308]++;
_$jscoverage['mongoose/schema.js'][329]++;
field[prefix + i] = 1;
_$jscoverage['mongoose/schema.js'][309]++;
_$jscoverage['mongoose/schema.js'][330]++;
indexes.push([field, index.constructor == Object? index: {}]);

@@ -377,30 +451,150 @@ }

}
_$jscoverage['mongoose/schema.js'][316]++;
_$jscoverage['mongoose/schema.js'][337]++;
collectIndexes(this.paths);
_$jscoverage['mongoose/schema.js'][318]++;
_$jscoverage['mongoose/schema.js'][339]++;
return indexes.concat(this._indexes);
}));
_$jscoverage['mongoose/schema.js'][328]++;
_$jscoverage['mongoose/schema.js'][349]++;
Schema.prototype.virtual = (function (name) {
_$jscoverage['mongoose/schema.js'][329]++;
_$jscoverage['mongoose/schema.js'][350]++;
var virtuals = this.virtuals || (this.virtuals = {});
_$jscoverage['mongoose/schema.js'][330]++;
_$jscoverage['mongoose/schema.js'][351]++;
return virtuals[name] || (virtuals[name] = this.tree[name] = new VirtualType());
});
_$jscoverage['mongoose/schema.js'][342]++;
_$jscoverage['mongoose/schema.js'][363]++;
Schema.prototype.virtualpath = (function (name) {
_$jscoverage['mongoose/schema.js'][343]++;
_$jscoverage['mongoose/schema.js'][364]++;
return this.virtuals[name];
});
_$jscoverage['mongoose/schema.js'][352]++;
_$jscoverage['mongoose/schema.js'][368]++;
var Query = require("./query").Query;
_$jscoverage['mongoose/schema.js'][369]++;
function NamedScope() {
}
_$jscoverage['mongoose/schema.js'][371]++;
NamedScope.prototype.query;
_$jscoverage['mongoose/schema.js'][373]++;
NamedScope.prototype["with"] = (function () {
_$jscoverage['mongoose/schema.js'][374]++;
var q = this.query || (this.query = new Query());
_$jscoverage['mongoose/schema.js'][375]++;
q["with"].apply(q, arguments);
_$jscoverage['mongoose/schema.js'][376]++;
return q;
});
_$jscoverage['mongoose/schema.js'][383]++;
NamedScope.prototype.decorate = (function (target, getters) {
_$jscoverage['mongoose/schema.js'][384]++;
var name = this.name, block = this.block, query = this.query;
_$jscoverage['mongoose/schema.js'][387]++;
if (block) {
_$jscoverage['mongoose/schema.js'][388]++;
if (block.length === 0) {
_$jscoverage['mongoose/schema.js'][389]++;
Object.defineProperty(target, name, {get: getters.block0(block)});
}
else {
_$jscoverage['mongoose/schema.js'][393]++;
target[name] = getters.blockN(block);
}
}
else {
_$jscoverage['mongoose/schema.js'][396]++;
Object.defineProperty(target, name, {get: getters.basic(query)});
}
});
_$jscoverage['mongoose/schema.js'][402]++;
NamedScope.prototype.compile = (function (model) {
_$jscoverage['mongoose/schema.js'][403]++;
var allScopes = this.scopesByName, scope;
_$jscoverage['mongoose/schema.js'][405]++;
for (var k in allScopes) {
_$jscoverage['mongoose/schema.js'][406]++;
scope = allScopes[k];
_$jscoverage['mongoose/schema.js'][407]++;
scope.decorate(model, {block0: (function (block) {
_$jscoverage['mongoose/schema.js'][409]++;
return (function () {
_$jscoverage['mongoose/schema.js'][410]++;
var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));
_$jscoverage['mongoose/schema.js'][411]++;
block.call(cquery);
_$jscoverage['mongoose/schema.js'][412]++;
return this;
});
}), blockN: (function (block) {
_$jscoverage['mongoose/schema.js'][416]++;
return (function () {
_$jscoverage['mongoose/schema.js'][417]++;
var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));
_$jscoverage['mongoose/schema.js'][418]++;
block.apply(cquery, arguments);
_$jscoverage['mongoose/schema.js'][419]++;
return this;
});
}), basic: (function (query) {
_$jscoverage['mongoose/schema.js'][423]++;
return (function () {
_$jscoverage['mongoose/schema.js'][424]++;
var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));
_$jscoverage['mongoose/schema.js'][425]++;
cquery.find(query);
_$jscoverage['mongoose/schema.js'][426]++;
return this;
});
})});
}
});
_$jscoverage['mongoose/schema.js'][433]++;
Schema.prototype.namedScope = (function (name, fn) {
_$jscoverage['mongoose/schema.js'][434]++;
var namedScopes = this.namedScopes || (this.namedScopes = new NamedScope()), newScope = Object.create(namedScopes), allScopes = namedScopes.scopesByName || (namedScopes.scopesByName = {});
_$jscoverage['mongoose/schema.js'][437]++;
allScopes[name] = newScope;
_$jscoverage['mongoose/schema.js'][438]++;
newScope.name = name;
_$jscoverage['mongoose/schema.js'][439]++;
newScope.block = fn;
_$jscoverage['mongoose/schema.js'][440]++;
newScope.query = new Query();
_$jscoverage['mongoose/schema.js'][441]++;
newScope.decorate(namedScopes, {block0: (function (block) {
_$jscoverage['mongoose/schema.js'][443]++;
return (function () {
_$jscoverage['mongoose/schema.js'][444]++;
block.call(this.query);
_$jscoverage['mongoose/schema.js'][445]++;
return this;
});
}), blockN: (function (block) {
_$jscoverage['mongoose/schema.js'][449]++;
return (function () {
_$jscoverage['mongoose/schema.js'][450]++;
block.apply(this.query, arguments);
_$jscoverage['mongoose/schema.js'][451]++;
return this;
});
}), basic: (function (query) {
_$jscoverage['mongoose/schema.js'][455]++;
return (function () {
_$jscoverage['mongoose/schema.js'][456]++;
this.query.find(query);
_$jscoverage['mongoose/schema.js'][457]++;
return this;
});
})});
_$jscoverage['mongoose/schema.js'][461]++;
return newScope;
});
_$jscoverage['mongoose/schema.js'][470]++;
function ObjectId() {
_$jscoverage['mongoose/schema.js'][353]++;
_$jscoverage['mongoose/schema.js'][471]++;
throw new Error("This is an abstract interface. Its only purpose is to mark fields as ObjectId in the schema creation.");
}
_$jscoverage['mongoose/schema.js'][361]++;
_$jscoverage['mongoose/schema.js'][479]++;
module.exports = exports = Schema;
_$jscoverage['mongoose/schema.js'][363]++;
_$jscoverage['mongoose/schema.js'][481]++;
exports.Types = Types;
_$jscoverage['mongoose/schema.js'][365]++;
_$jscoverage['mongoose/schema.js'][483]++;
exports.ObjectId = ObjectId;
_$jscoverage['mongoose/schema.js'].source = ["","/**"," * Module dependencies."," */","","var EventEmitter = require('events').EventEmitter"," , Types = require('./schema/index')"," , VirtualType = require('./virtualtype')"," , utils = require('./utils');","","/**"," * Schema constructor."," *"," * @param {Object} definition"," * @api public"," */","","function Schema (obj, options) {"," this.paths = {};"," this.virtuals = {};"," this.inherits = {};"," this.callQueue = [];"," this._indexes = [];"," this.methods = {};"," this.statics = {};"," this.tree = {};",""," // set options"," this.options = utils.options({"," safe: true"," , 'use$SetOnSave': true"," }, options);",""," // build paths"," if (obj)"," this.add(obj);",""," if (!this.paths['_id'])"," this.add({ _id: ObjectId });","};","","/**"," * Inherit from EventEmitter."," */","","Schema.prototype.__proto__ = EventEmitter.prototype;","","/**"," * Schema by paths"," *"," * Example (embedded doc):"," * {"," * 'test' : SchemaType,"," * , 'test.test' : SchemaType,"," * , 'first_name' : SchemaType"," * }"," *"," * @api private"," */","","Schema.prototype.paths;","","/**"," * Schema as a tree"," *"," * Example:"," * {"," * '_id' : ObjectId"," * , 'nested' : {"," * 'key': String"," * }"," * }"," *"," * @api private"," */","","Schema.prototype.tree;","","/**"," * Sets the keys"," *"," * @param {Object} keys"," * @param {String} prefix"," * @api public"," */","","Schema.prototype.add = function (obj, prefix) {"," prefix = prefix || '';"," for (var i in obj){"," // make sure set of keys are in `tree`"," if (!prefix &amp;&amp; !this.tree[i])"," this.tree[i] = obj[i];",""," if (obj[i].constructor == Object &amp;&amp; (!obj[i].type || obj[i].__nested)) {"," if (Object.keys(obj[i]).length)"," this.add(obj[i], prefix + i + '.');"," else"," this.path(prefix + i, obj[i]); // mixed type"," } else"," this.path(prefix + i, obj[i]);"," }","};","","/**"," * Sets a path (if arity 2)"," * Gets a path (if arity 1)"," *"," * @param {String} path"," * @param {Object} constructor"," * @api public"," */","","Schema.prototype.path = function (path, obj) {"," if (obj == undefined)"," return this.paths[path];",""," if (obj.constructor != Object)"," obj = { type: obj };",""," var type = obj.type || {}; // defaults to mixed",""," if (type.constructor == Object)"," this.paths[path] = new Types.Mixed(path, obj);"," else if (Array.isArray(type) || type == Array){"," // if it was specified through { type } look for `cast`"," var cast = type == Array ? obj.cast : type[0];",""," if (cast instanceof Schema)"," this.paths[path] = new Types.DocumentArray(path, cast, obj);"," else "," this.paths[path] = new Types.Array(path, cast, obj);"," } else"," this.paths[path] = new Types[type.name](path, obj);",""," return this;","};","","/**"," * Iterates through the schema's paths, passing the path string and type object"," * to the callback."," *"," * @param {Function} callback function - fn(pathstring, type)"," * @return {Schema} this for chaining"," * @api public"," */","","Schema.prototype.eachPath = function (fn) {"," for (var k in this.paths)"," if (this.paths.hasOwnProperty(k))"," fn(k, this.paths[k]);"," return this;","};","","/**"," * Given a path, returns whether it is a real, virtual, or"," * ad-hoc/undefined path"," *"," * @param {String} path"," * @return {String}"," * @api public"," */","Schema.prototype.pathType = function (path) {"," if (path in this.paths) return 'real';"," if (path in this.virtuals) return 'virtual';"," return 'adhocOrUndefined';","};","","/**"," * Adds a method call to the queue"," *"," * @param {String} method name"," * @param {Array} arguments"," * @api private"," */","","Schema.prototype.queue = function(name, args){"," this.callQueue.push([name, args]);"," return this;","};","","/**"," * Defines a pre for the document"," *"," * @param {String} method"," * @param {Function} callback"," * @api public"," */","","Schema.prototype.pre = function(){"," return this.queue('pre', arguments);","};","","/**"," * Defines a post for the document"," *"," * @param {String} method"," * @param {Function} callback"," * @api public"," */","","Schema.prototype.post = function(method, fn){"," return this.queue('on', arguments);","};","","/**"," * Registers a plugin for this schema"," *"," * @param {Function} plugin callback"," * @api public"," */","","Schema.prototype.plugin = function (fn, opts) {"," fn(this, opts);"," return this;","};","","/**"," * Adds a method"," *"," * @param {String} method name"," * @param {Function} handler"," * @api public"," */","","Schema.prototype.method = function (name, fn) {"," if ('string' != typeof name)"," for (var i in name)"," this.methods[i] = name[i];"," else"," this.methods[name] = fn;"," return this;","};","","/**"," * Defines a static method"," *"," * @param {String} name"," * @param {Function} handler"," * @api public"," */","","Schema.prototype.static = function(name, fn) {"," if ('string' != typeof name)"," for (var i in name)"," this.statics[i] = name[i];"," else"," this.statics[name] = fn;"," return this;","};","","/**"," * Defines an index (most likely compound)"," * Example:"," * schema.index({ first: 1, last: -1 })"," *"," * @param {Object} field"," * @param {Object} optional options object"," * @api public"," */","","Schema.prototype.index = function (fields, options) {"," this._indexes.push([fields, options || {}]);"," return this;","};","","/**"," * Sets/gets an option"," *"," * @param {String} key"," * @param {Object} optional value"," * @api public"," */","","Schema.prototype.set = function (key, value) {"," if (arguments.length == 1)"," return this.options[key];"," this.options[key] = value;"," return this;","};","","/**"," * Compiles indexes from fields and schema-level indexes"," *"," * @api public"," */","","Schema.prototype.__defineGetter__('indexes', function () {"," var index"," , indexes = []"," , seenSchemas = [];",""," function collectIndexes (paths, prefix) {"," prefix = prefix || '';",""," for (var i in paths){"," if (paths[i]) {"," if (paths[i] instanceof Types.DocumentArray) {"," // avoid recursion"," if (!(~seenSchemas.indexOf(paths[i].schema))) {"," seenSchemas.push(paths[i].schema);"," collectIndexes(paths[i].schema.paths, i + '.');"," }"," } else {"," index = paths[i]._index;",""," if (index !== false &amp;&amp; index !== null){"," var field = {};"," field[prefix + i] = 1;"," indexes.push([field, index.constructor == Object ? index : {} ]);"," }"," }"," }"," }"," }",""," collectIndexes(this.paths);",""," return indexes.concat(this._indexes);","});","","/**"," * Retrieves or creates the virtual type with the given name."," *"," * @param {String} name"," * @return {VirtualType}"," */","","Schema.prototype.virtual = function (name) {"," var virtuals = this.virtuals || (this.virtuals = {})"," return virtuals[name] || (virtuals[name] = this.tree[name] = new VirtualType()); ","};","","/**"," * Fetches the virtual type with the given name."," * Should be distinct from virtual because virtual auto-defines a new VirtualType"," * if the path doesn't exist."," *"," * @param {String} name"," * @return {VirtualType}"," */","","Schema.prototype.virtualpath = function (name) {"," return this.virtuals[name];","};","","/**"," * ObjectId schema identifier. Not an actual ObjectId, only used for Schemas."," *"," * @api public"," */","","function ObjectId () {"," throw new Error('This is an abstract interface. Its only purpose is to mark '"," + 'fields as ObjectId in the schema creation.');","}","","/**"," * Module exports."," */","","module.exports = exports = Schema;","","exports.Types = Types;","","exports.ObjectId = ObjectId;"];
_$jscoverage['mongoose/schema.js'].source = ["","/**"," * Module dependencies."," */","","var EventEmitter = require('events').EventEmitter"," , Types = require('./schema/index')"," , VirtualType = require('./virtualtype')"," , utils = require('./utils');","","/**"," * Schema constructor."," *"," * @param {Object} definition"," * @api public"," */","","function Schema (obj, options) {"," this.paths = {};"," this.virtuals = {};"," this.inherits = {};"," this.callQueue = [];"," this._indexes = [];"," this.methods = {};"," this.statics = {};"," this.tree = {};",""," // set options"," this.options = utils.options({"," safe: true"," , 'use$SetOnSave': true"," }, options);",""," // build paths"," if (obj)"," this.add(obj);",""," if (!this.paths['_id'])"," this.add({ _id: {type: ObjectId, auto: true} });","};","","/**"," * Inherit from EventEmitter."," */","","Schema.prototype.__proto__ = EventEmitter.prototype;","","/**"," * Schema by paths"," *"," * Example (embedded doc):"," * {"," * 'test' : SchemaType,"," * , 'test.test' : SchemaType,"," * , 'first_name' : SchemaType"," * }"," *"," * @api private"," */","","Schema.prototype.paths;","","/**"," * Schema as a tree"," *"," * Example:"," * {"," * '_id' : ObjectId"," * , 'nested' : {"," * 'key': String"," * }"," * }"," *"," * @api private"," */","","Schema.prototype.tree;","","/**"," * Sets the keys"," *"," * @param {Object} keys"," * @param {String} prefix"," * @api public"," */","","Schema.prototype.add = function (obj, prefix) {"," prefix = prefix || '';"," for (var i in obj){"," // make sure set of keys are in `tree`"," if (!prefix &amp;&amp; !this.tree[i])"," this.tree[i] = obj[i];",""," if (obj[i].constructor == Object &amp;&amp; (!obj[i].type || obj[i].__nested)) {"," if (Object.keys(obj[i]).length)"," this.add(obj[i], prefix + i + '.');"," else"," this.path(prefix + i, obj[i]); // mixed type"," } else"," this.path(prefix + i, obj[i]);"," }","};","","/**"," * Sets a path (if arity 2)"," * Gets a path (if arity 1)"," *"," * @param {String} path"," * @param {Object} constructor"," * @api public"," */","","Schema.prototype.path = function (path, obj) {"," if (obj == undefined)"," return this.paths[path];",""," if (obj.constructor != Object)"," obj = { type: obj };",""," var type = obj.type || {}; // defaults to mixed",""," if (type.constructor == Object)"," this.paths[path] = new Types.Mixed(path, obj);"," else if (Array.isArray(type) || type == Array){"," // if it was specified through { type } look for `cast`"," var cast = type == Array ? obj.cast : type[0];",""," if (cast instanceof Schema)"," this.paths[path] = new Types.DocumentArray(path, cast, obj);"," else "," this.paths[path] = new Types.Array(path, cast, obj);"," } else"," this.paths[path] = new Types[type.name](path, obj);",""," return this;","};","","/**"," * Iterates through the schema's paths, passing the path string and type object"," * to the callback."," *"," * @param {Function} callback function - fn(pathstring, type)"," * @return {Schema} this for chaining"," * @api public"," */","","Schema.prototype.eachPath = function (fn) {"," for (var k in this.paths)"," if (this.paths.hasOwnProperty(k))"," fn(k, this.paths[k]);"," return this;","};","","/**"," * Returns an Array of path strings that are required."," * @api public"," */","","Object.defineProperty(Schema.prototype, 'requiredPaths', {"," get: function () {"," var paths = this.paths"," , pathnames = Object.keys(paths)"," , i = pathnames.length"," , pathname, path"," , requiredPaths = [];"," while (i--) {"," pathname = pathnames[i];"," path = paths[pathname];"," if (path.isRequired) requiredPaths.push(pathname);"," }"," return requiredPaths;"," }","});","","/**"," * Given a path, returns whether it is a real, virtual, or"," * ad-hoc/undefined path"," *"," * @param {String} path"," * @return {String}"," * @api public"," */","Schema.prototype.pathType = function (path) {"," if (path in this.paths) return 'real';"," if (path in this.virtuals) return 'virtual';"," return 'adhocOrUndefined';","};","","/**"," * Adds a method call to the queue"," *"," * @param {String} method name"," * @param {Array} arguments"," * @api private"," */","","Schema.prototype.queue = function(name, args){"," this.callQueue.push([name, args]);"," return this;","};","","/**"," * Defines a pre for the document"," *"," * @param {String} method"," * @param {Function} callback"," * @api public"," */","","Schema.prototype.pre = function(){"," return this.queue('pre', arguments);","};","","/**"," * Defines a post for the document"," *"," * @param {String} method"," * @param {Function} callback"," * @api public"," */","","Schema.prototype.post = function(method, fn){"," return this.queue('on', arguments);","};","","/**"," * Registers a plugin for this schema"," *"," * @param {Function} plugin callback"," * @api public"," */","","Schema.prototype.plugin = function (fn, opts) {"," fn(this, opts);"," return this;","};","","/**"," * Adds a method"," *"," * @param {String} method name"," * @param {Function} handler"," * @api public"," */","","Schema.prototype.method = function (name, fn) {"," if ('string' != typeof name)"," for (var i in name)"," this.methods[i] = name[i];"," else"," this.methods[name] = fn;"," return this;","};","","/**"," * Defines a static method"," *"," * @param {String} name"," * @param {Function} handler"," * @api public"," */","","Schema.prototype.static = function(name, fn) {"," if ('string' != typeof name)"," for (var i in name)"," this.statics[i] = name[i];"," else"," this.statics[name] = fn;"," return this;","};","","/**"," * Defines an index (most likely compound)"," * Example:"," * schema.index({ first: 1, last: -1 })"," *"," * @param {Object} field"," * @param {Object} optional options object"," * @api public"," */","","Schema.prototype.index = function (fields, options) {"," this._indexes.push([fields, options || {}]);"," return this;","};","","/**"," * Sets/gets an option"," *"," * @param {String} key"," * @param {Object} optional value"," * @api public"," */","","Schema.prototype.set = function (key, value) {"," if (arguments.length == 1)"," return this.options[key];"," this.options[key] = value;"," return this;","};","","/**"," * Compiles indexes from fields and schema-level indexes"," *"," * @api public"," */","","Schema.prototype.__defineGetter__('indexes', function () {"," var index"," , indexes = []"," , seenSchemas = [];",""," function collectIndexes (paths, prefix) {"," prefix = prefix || '';",""," for (var i in paths){"," if (paths[i]) {"," if (paths[i] instanceof Types.DocumentArray) {"," // avoid recursion"," if (!(~seenSchemas.indexOf(paths[i].schema))) {"," seenSchemas.push(paths[i].schema);"," collectIndexes(paths[i].schema.paths, i + '.');"," }"," } else {"," index = paths[i]._index;",""," if (index !== false &amp;&amp; index !== null){"," var field = {};"," field[prefix + i] = 1;"," indexes.push([field, index.constructor == Object ? index : {} ]);"," }"," }"," }"," }"," }",""," collectIndexes(this.paths);",""," return indexes.concat(this._indexes);","});","","/**"," * Retrieves or creates the virtual type with the given name."," *"," * @param {String} name"," * @return {VirtualType}"," */","","Schema.prototype.virtual = function (name) {"," var virtuals = this.virtuals || (this.virtuals = {})"," return virtuals[name] || (virtuals[name] = this.tree[name] = new VirtualType()); ","};","","/**"," * Fetches the virtual type with the given name."," * Should be distinct from virtual because virtual auto-defines a new VirtualType"," * if the path doesn't exist."," *"," * @param {String} name"," * @return {VirtualType}"," */","","Schema.prototype.virtualpath = function (name) {"," return this.virtuals[name];","};","","","var Query = require('./query').Query;","function NamedScope () {}","","NamedScope.prototype.query;","","NamedScope.prototype.with = function () {"," var q = this.query || (this.query = new Query());"," q.with.apply(q, arguments);"," return q;","};","","/**"," * @param {NamedScope} target"," * @param {Object} getters"," */","NamedScope.prototype.decorate = function (target, getters) {"," var name = this.name"," , block = this.block"," , query = this.query;"," if (block) {"," if (block.length === 0) {"," Object.defineProperty(target, name, {"," get: getters.block0(block)"," });"," } else {"," target[name] = getters.blockN(block);"," }"," } else {"," Object.defineProperty(target, name, {"," get: getters.basic(query)"," });"," }","};","","NamedScope.prototype.compile = function (model) {"," var allScopes = this.scopesByName"," , scope;"," for (var k in allScopes) {"," scope = allScopes[k];"," scope.decorate(model, {"," block0: function (block) {"," return function () {"," var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));"," block.call(cquery);"," return this;"," };"," },"," blockN: function (block) {"," return function () {"," var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));"," block.apply(cquery, arguments);"," return this;"," };"," },"," basic: function (query) {"," return function () {"," var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));"," cquery.find(query);"," return this;"," };"," }"," });"," }","};","","Schema.prototype.namedScope = function (name, fn) {"," var namedScopes = this.namedScopes || (this.namedScopes = new NamedScope)"," , newScope = Object.create(namedScopes)"," , allScopes = namedScopes.scopesByName || (namedScopes.scopesByName = {});"," allScopes[name] = newScope;"," newScope.name = name;"," newScope.block = fn;"," newScope.query = new Query();"," newScope.decorate(namedScopes, {"," block0: function (block) {"," return function () {"," block.call(this.query);"," return this;"," };"," },"," blockN: function (block) {"," return function () {"," block.apply(this.query, arguments);"," return this;"," };"," },"," basic: function (query) {"," return function () {"," this.query.find(query);"," return this;"," };"," }"," });"," return newScope;","};","","/**"," * ObjectId schema identifier. Not an actual ObjectId, only used for Schemas."," *"," * @api public"," */","","function ObjectId () {"," throw new Error('This is an abstract interface. Its only purpose is to mark '"," + 'fields as ObjectId in the schema creation.');","}","","/**"," * Module exports."," */","","module.exports = exports = Schema;","","exports.Types = Types;","","exports.ObjectId = ObjectId;"];

@@ -6,90 +6,108 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/array.js'][5] = 0;
_$jscoverage['mongoose/schema/array.js'][25] = 0;
_$jscoverage['mongoose/schema/array.js'][26] = 0;
_$jscoverage['mongoose/schema/array.js'][28] = 0;
_$jscoverage['mongoose/schema/array.js'][27] = 0;
_$jscoverage['mongoose/schema/array.js'][29] = 0;
_$jscoverage['mongoose/schema/array.js'][32] = 0;
_$jscoverage['mongoose/schema/array.js'][35] = 0;
_$jscoverage['mongoose/schema/array.js'][30] = 0;
_$jscoverage['mongoose/schema/array.js'][33] = 0;
_$jscoverage['mongoose/schema/array.js'][36] = 0;
_$jscoverage['mongoose/schema/array.js'][37] = 0;
_$jscoverage['mongoose/schema/array.js'][39] = 0;
_$jscoverage['mongoose/schema/array.js'][45] = 0;
_$jscoverage['mongoose/schema/array.js'][53] = 0;
_$jscoverage['mongoose/schema/array.js'][38] = 0;
_$jscoverage['mongoose/schema/array.js'][40] = 0;
_$jscoverage['mongoose/schema/array.js'][46] = 0;
_$jscoverage['mongoose/schema/array.js'][54] = 0;
_$jscoverage['mongoose/schema/array.js'][65] = 0;
_$jscoverage['mongoose/schema/array.js'][55] = 0;
_$jscoverage['mongoose/schema/array.js'][66] = 0;
_$jscoverage['mongoose/schema/array.js'][67] = 0;
_$jscoverage['mongoose/schema/array.js'][68] = 0;
_$jscoverage['mongoose/schema/array.js'][70] = 0;
_$jscoverage['mongoose/schema/array.js'][72] = 0;
_$jscoverage['mongoose/schema/array.js'][69] = 0;
_$jscoverage['mongoose/schema/array.js'][71] = 0;
_$jscoverage['mongoose/schema/array.js'][73] = 0;
_$jscoverage['mongoose/schema/array.js'][74] = 0;
_$jscoverage['mongoose/schema/array.js'][75] = 0;
_$jscoverage['mongoose/schema/array.js'][78] = 0;
_$jscoverage['mongoose/schema/array.js'][82] = 0;
_$jscoverage['mongoose/schema/array.js'][84] = 0;
_$jscoverage['mongoose/schema/array.js'][87] = 0;
_$jscoverage['mongoose/schema/array.js'][76] = 0;
_$jscoverage['mongoose/schema/array.js'][79] = 0;
_$jscoverage['mongoose/schema/array.js'][83] = 0;
_$jscoverage['mongoose/schema/array.js'][85] = 0;
_$jscoverage['mongoose/schema/array.js'][88] = 0;
_$jscoverage['mongoose/schema/array.js'][91] = 0;
_$jscoverage['mongoose/schema/array.js'][93] = 0;
_$jscoverage['mongoose/schema/array.js'][98] = 0;
_$jscoverage['mongoose/schema/array.js'][99] = 0;
_$jscoverage['mongoose/schema/array.js'][100] = 0;
_$jscoverage['mongoose/schema/array.js'][102] = 0;
_$jscoverage['mongoose/schema/array.js'][104] = 0;
_$jscoverage['mongoose/schema/array.js'][103] = 0;
_$jscoverage['mongoose/schema/array.js'][106] = 0;
_$jscoverage['mongoose/schema/array.js'][109] = 0;
_$jscoverage['mongoose/schema/array.js'][110] = 0;
_$jscoverage['mongoose/schema/array.js'][111] = 0;
_$jscoverage['mongoose/schema/array.js'][112] = 0;
_$jscoverage['mongoose/schema/array.js'][113] = 0;
_$jscoverage['mongoose/schema/array.js'][114] = 0;
_$jscoverage['mongoose/schema/array.js'][115] = 0;
_$jscoverage['mongoose/schema/array.js'][117] = 0;
_$jscoverage['mongoose/schema/array.js'][118] = 0;
_$jscoverage['mongoose/schema/array.js'][119] = 0;
_$jscoverage['mongoose/schema/array.js'][121] = 0;
_$jscoverage['mongoose/schema/array.js'][134] = 0;
_$jscoverage['mongoose/schema/array.js'][135] = 0;
_$jscoverage['mongoose/schema/array.js'][136] = 0;
_$jscoverage['mongoose/schema/array.js'][138] = 0;
_$jscoverage['mongoose/schema/array.js'][140] = 0;
_$jscoverage['mongoose/schema/array.js'][147] = 0;
}
_$jscoverage['mongoose/schema/array.js'][5]++;
var SchemaType = require("../schematype"), CastError = SchemaType.CastError, ArrayNumberSchema = (function () {
}), Types = {Boolean: require("./boolean"), Date: require("./date"), Number: ArrayNumberSchema, String: require("./string"), ObjectId: require("./objectid")}, MongooseArray = require("../types").Array;
_$jscoverage['mongoose/schema/array.js'][25]++;
}), Types = {Boolean: require("./boolean"), Date: require("./date"), Number: ArrayNumberSchema, String: require("./string"), ObjectId: require("./objectid")}, MongooseArray = require("../types").Array, Query = require("../query").Query;
_$jscoverage['mongoose/schema/array.js'][26]++;
function SchemaArray(key, cast, options) {
_$jscoverage['mongoose/schema/array.js'][26]++;
_$jscoverage['mongoose/schema/array.js'][27]++;
SchemaType.call(this, key, options);
_$jscoverage['mongoose/schema/array.js'][28]++;
_$jscoverage['mongoose/schema/array.js'][29]++;
if (cast) {
_$jscoverage['mongoose/schema/array.js'][29]++;
_$jscoverage['mongoose/schema/array.js'][30]++;
this.caster = cast.name in Types? Types[cast.name]: cast;
}
_$jscoverage['mongoose/schema/array.js'][32]++;
_$jscoverage['mongoose/schema/array.js'][33]++;
var self = this, defaultArr;
_$jscoverage['mongoose/schema/array.js'][35]++;
_$jscoverage['mongoose/schema/array.js'][36]++;
if (this.defaultValue) {
_$jscoverage['mongoose/schema/array.js'][35]++;
_$jscoverage['mongoose/schema/array.js'][36]++;
defaultArr = this.defaultValue;
}
_$jscoverage['mongoose/schema/array.js'][36]++;
_$jscoverage['mongoose/schema/array.js'][37]++;
this["default"]((function () {
_$jscoverage['mongoose/schema/array.js'][37]++;
_$jscoverage['mongoose/schema/array.js'][38]++;
return new MongooseArray(defaultArr || [], self.path, this);
}));
}
_$jscoverage['mongoose/schema/array.js'][39]++;
_$jscoverage['mongoose/schema/array.js'][40]++;
;
_$jscoverage['mongoose/schema/array.js'][45]++;
_$jscoverage['mongoose/schema/array.js'][46]++;
SchemaArray.prototype.__proto__ = SchemaType.prototype;
_$jscoverage['mongoose/schema/array.js'][53]++;
_$jscoverage['mongoose/schema/array.js'][54]++;
SchemaArray.prototype.checkRequired = (function (value) {
_$jscoverage['mongoose/schema/array.js'][54]++;
_$jscoverage['mongoose/schema/array.js'][55]++;
return ! ! (value && value.length);
});
_$jscoverage['mongoose/schema/array.js'][65]++;
_$jscoverage['mongoose/schema/array.js'][66]++;
SchemaArray.prototype.cast = (function (value, doc) {
_$jscoverage['mongoose/schema/array.js'][66]++;
_$jscoverage['mongoose/schema/array.js'][67]++;
if (Array.isArray(value)) {
_$jscoverage['mongoose/schema/array.js'][67]++;
_$jscoverage['mongoose/schema/array.js'][68]++;
if (! (value instanceof MongooseArray)) {
_$jscoverage['mongoose/schema/array.js'][68]++;
_$jscoverage['mongoose/schema/array.js'][69]++;
value = new MongooseArray(value, this.path, doc);
}
_$jscoverage['mongoose/schema/array.js'][70]++;
_$jscoverage['mongoose/schema/array.js'][71]++;
var caster = this.caster;
_$jscoverage['mongoose/schema/array.js'][72]++;
_$jscoverage['mongoose/schema/array.js'][73]++;
if (caster) {
_$jscoverage['mongoose/schema/array.js'][73]++;
_$jscoverage['mongoose/schema/array.js'][74]++;
for (var i = 0, l = value.length; i < l; i++) {
_$jscoverage['mongoose/schema/array.js'][74]++;
_$jscoverage['mongoose/schema/array.js'][75]++;
try {
_$jscoverage['mongoose/schema/array.js'][75]++;
_$jscoverage['mongoose/schema/array.js'][76]++;
value[i] = caster.prototype.cast.call(null, value[i]);
}
catch (e) {
_$jscoverage['mongoose/schema/array.js'][78]++;
_$jscoverage['mongoose/schema/array.js'][79]++;
throw new CastError(e.type, value);

@@ -99,27 +117,75 @@ }

}
_$jscoverage['mongoose/schema/array.js'][82]++;
_$jscoverage['mongoose/schema/array.js'][83]++;
return value;
}
else {
_$jscoverage['mongoose/schema/array.js'][84]++;
_$jscoverage['mongoose/schema/array.js'][85]++;
return this.cast([value], doc);
}
_$jscoverage['mongoose/schema/array.js'][87]++;
_$jscoverage['mongoose/schema/array.js'][88]++;
throw new CastError("array", value, caster);
});
_$jscoverage['mongoose/schema/array.js'][98]++;
_$jscoverage['mongoose/schema/array.js'][91]++;
SchemaArray.prototype.$conditionalHandlers = {"$all": (function (val) {
_$jscoverage['mongoose/schema/array.js'][93]++;
return this.cast(val);
}), "$elemMatch": (function (val) {
_$jscoverage['mongoose/schema/array.js'][98]++;
var query = new Query(val);
_$jscoverage['mongoose/schema/array.js'][99]++;
query.cast(this.caster);
_$jscoverage['mongoose/schema/array.js'][100]++;
return query._conditions;
}), "$size": (function (val) {
_$jscoverage['mongoose/schema/array.js'][103]++;
return ArrayNumberSchema.prototype.cast.call(this, val);
}), "$ne": (function (val) {
_$jscoverage['mongoose/schema/array.js'][106]++;
return this.cast(val);
})};
_$jscoverage['mongoose/schema/array.js'][109]++;
SchemaArray.prototype.castForQuery = (function ($conditional, val) {
_$jscoverage['mongoose/schema/array.js'][110]++;
var handler;
_$jscoverage['mongoose/schema/array.js'][111]++;
if (arguments.length === 2) {
_$jscoverage['mongoose/schema/array.js'][112]++;
handler = this.$conditionalHandlers[$conditional];
_$jscoverage['mongoose/schema/array.js'][113]++;
if (! handler) {
_$jscoverage['mongoose/schema/array.js'][114]++;
throw new Error("Can't use " + $conditional + " with Array.");
}
_$jscoverage['mongoose/schema/array.js'][115]++;
return handler.call(this, val);
}
else {
_$jscoverage['mongoose/schema/array.js'][117]++;
val = $conditional;
_$jscoverage['mongoose/schema/array.js'][118]++;
if (Array.isArray(val)) {
_$jscoverage['mongoose/schema/array.js'][119]++;
return this.cast(val);
}
else {
_$jscoverage['mongoose/schema/array.js'][121]++;
return this.caster.prototype.cast.call(null, val);
}
}
});
_$jscoverage['mongoose/schema/array.js'][134]++;
ArrayNumberSchema.prototype.cast = (function (value) {
_$jscoverage['mongoose/schema/array.js'][99]++;
_$jscoverage['mongoose/schema/array.js'][135]++;
if (! isNaN(value)) {
_$jscoverage['mongoose/schema/array.js'][100]++;
_$jscoverage['mongoose/schema/array.js'][136]++;
if (value instanceof Number || typeof value == "number" || (value.toString && value.toString() == Number(value))) {
_$jscoverage['mongoose/schema/array.js'][102]++;
_$jscoverage['mongoose/schema/array.js'][138]++;
return Number(value);
}
}
_$jscoverage['mongoose/schema/array.js'][104]++;
_$jscoverage['mongoose/schema/array.js'][140]++;
throw new CastError("number", value);
});
_$jscoverage['mongoose/schema/array.js'][111]++;
_$jscoverage['mongoose/schema/array.js'][147]++;
module.exports = SchemaArray;
_$jscoverage['mongoose/schema/array.js'].source = ["/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError"," , ArrayNumberSchema = function () {}"," , Types = {"," Boolean: require('./boolean')"," , Date: require('./date')"," , Number: ArrayNumberSchema"," , String: require('./string')"," , ObjectId: require('./objectid')"," }"," , MongooseArray = require('../types').Array;","","/**"," * Array SchemaType constructor"," *"," * @param {String} key"," * @param {SchemaType} cast"," * @api private"," */","","function SchemaArray (key, cast, options) {"," SchemaType.call(this, key, options);",""," if (cast) {"," this.caster = cast.name in Types ? Types[cast.name] : cast;"," }",""," var self = this"," , defaultArr;",""," if (this.defaultValue) defaultArr = this.defaultValue;"," this.default(function(){"," return new MongooseArray(defaultArr || [], self.path, this);"," });","};","","/**"," * Inherits from SchemaType."," */","","SchemaArray.prototype.__proto__ = SchemaType.prototype;","","/**"," * Check required"," *"," * @api private"," */","","SchemaArray.prototype.checkRequired = function (value) {"," return !!(value &amp;&amp; value.length);","};","","/**"," * Casts contents"," *"," * @param {Object} value"," * @param {Document} document that triggers the casting"," * @api private"," */","","SchemaArray.prototype.cast = function (value, doc) {"," if (Array.isArray(value)){"," if (!(value instanceof MongooseArray))"," value = new MongooseArray(value, this.path, doc);",""," var caster = this.caster;",""," if (caster)"," for (var i = 0, l = value.length; i &lt; l; i++) {"," try {"," value[i] = caster.prototype.cast.call(null, value[i]);"," } catch(e){"," // rethrow"," throw new CastError(e.type, value);"," }"," }",""," return value;"," } else {"," return this.cast([value], doc);"," }",""," throw new CastError('array', value, caster);","};","","/**"," * Number casting for arrays (equivalent, but without MongoseNumber)"," *"," * @see GH-176"," * @param {Object} value"," * @api private"," */","","ArrayNumberSchema.prototype.cast = function (value) {"," if (!isNaN(value)) {"," if (value instanceof Number || typeof value == 'number' ||"," (value.toString &amp;&amp; value.toString() == Number(value)))"," return Number(value);"," }"," throw new CastError('number', value);","};","","/**"," * Module exports."," */","","module.exports = SchemaArray;"];
_$jscoverage['mongoose/schema/array.js'].source = ["/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError"," , ArrayNumberSchema = function () {}"," , Types = {"," Boolean: require('./boolean')"," , Date: require('./date')"," , Number: ArrayNumberSchema"," , String: require('./string')"," , ObjectId: require('./objectid')"," }"," , MongooseArray = require('../types').Array"," , Query = require('../query').Query;","","/**"," * Array SchemaType constructor"," *"," * @param {String} key"," * @param {SchemaType} cast"," * @api private"," */","","function SchemaArray (key, cast, options) {"," SchemaType.call(this, key, options);",""," if (cast) {"," this.caster = cast.name in Types ? Types[cast.name] : cast;"," }",""," var self = this"," , defaultArr;",""," if (this.defaultValue) defaultArr = this.defaultValue;"," this.default(function(){"," return new MongooseArray(defaultArr || [], self.path, this);"," });","};","","/**"," * Inherits from SchemaType."," */","","SchemaArray.prototype.__proto__ = SchemaType.prototype;","","/**"," * Check required"," *"," * @api private"," */","","SchemaArray.prototype.checkRequired = function (value) {"," return !!(value &amp;&amp; value.length);","};","","/**"," * Casts contents"," *"," * @param {Object} value"," * @param {Document} document that triggers the casting"," * @api private"," */","","SchemaArray.prototype.cast = function (value, doc) {"," if (Array.isArray(value)){"," if (!(value instanceof MongooseArray))"," value = new MongooseArray(value, this.path, doc);",""," var caster = this.caster;",""," if (caster)"," for (var i = 0, l = value.length; i &lt; l; i++) {"," try {"," value[i] = caster.prototype.cast.call(null, value[i]);"," } catch(e){"," // rethrow"," throw new CastError(e.type, value);"," }"," }",""," return value;"," } else {"," return this.cast([value], doc);"," }",""," throw new CastError('array', value, caster);","};","","SchemaArray.prototype.$conditionalHandlers = {"," '$all': function (val) {"," return this.cast(val);"," }",""," // TODO Move elemMatch to documentarray"," , '$elemMatch': function (val) {"," var query = new Query(val);"," query.cast(this.caster)"," return query._conditions;"," }"," , '$size': function (val) {"," return ArrayNumberSchema.prototype.cast.call(this, val);"," }"," , '$ne': function (val) {"," return this.cast(val);"," }","};","SchemaArray.prototype.castForQuery = function ($conditional, val) {"," var handler;"," if (arguments.length === 2) {"," handler = this.$conditionalHandlers[$conditional];"," if (!handler)"," throw new Error(\"Can't use \" + $conditional + \" with Array.\");"," return handler.call(this, val);"," } else {"," val = $conditional;"," if (Array.isArray(val)) {"," return this.cast(val);"," } else {"," return this.caster.prototype.cast.call(null, val);"," }"," }","};","","/**"," * Number casting for arrays (equivalent, but without MongoseNumber)"," *"," * @see GH-176"," * @param {Object} value"," * @api private"," */","","ArrayNumberSchema.prototype.cast = function (value) {"," if (!isNaN(value)) {"," if (value instanceof Number || typeof value == 'number' ||"," (value.toString &amp;&amp; value.toString() == Number(value)))"," return Number(value);"," }"," throw new CastError('number', value);","};","","/**"," * Module exports."," */","","module.exports = SchemaArray;"];

@@ -15,3 +15,7 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/boolean.js'][45] = 0;
_$jscoverage['mongoose/schema/boolean.js'][48] = 0;
_$jscoverage['mongoose/schema/boolean.js'][49] = 0;
_$jscoverage['mongoose/schema/boolean.js'][50] = 0;
_$jscoverage['mongoose/schema/boolean.js'][52] = 0;
_$jscoverage['mongoose/schema/boolean.js'][59] = 0;
}

@@ -44,4 +48,14 @@ _$jscoverage['mongoose/schema/boolean.js'][6]++;

});
_$jscoverage['mongoose/schema/boolean.js'][52]++;
_$jscoverage['mongoose/schema/boolean.js'][48]++;
SchemaBoolean.prototype.castForQuery = (function ($conditional, val) {
_$jscoverage['mongoose/schema/boolean.js'][49]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/schema/boolean.js'][50]++;
val = $conditional;
}
_$jscoverage['mongoose/schema/boolean.js'][52]++;
return this.cast(val);
});
_$jscoverage['mongoose/schema/boolean.js'][59]++;
module.exports = SchemaBoolean;
_$jscoverage['mongoose/schema/boolean.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError;","","/**"," * Boolean SchemaType constructor."," *"," * @param {String} path"," * @param {Object} options"," * @api private"," */","","function SchemaBoolean (path, options) {"," SchemaType.call(this, path, options);","};","","/**"," * Inherits from SchemaType."," */","SchemaBoolean.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for date"," *"," * @api private"," */","","SchemaBoolean.prototype.checkRequired = function (value) {"," return value === true || value === false;","};","","/**"," * Casts to boolean"," *"," * @param {Object} value to cast"," * @api private"," */","","SchemaBoolean.prototype.cast = function (value) {"," if (value === '0') return false;"," return !!value;","};","","/**"," * Module exports."," */","","module.exports = SchemaBoolean;"];
_$jscoverage['mongoose/schema/boolean.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError;","","/**"," * Boolean SchemaType constructor."," *"," * @param {String} path"," * @param {Object} options"," * @api private"," */","","function SchemaBoolean (path, options) {"," SchemaType.call(this, path, options);","};","","/**"," * Inherits from SchemaType."," */","SchemaBoolean.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for date"," *"," * @api private"," */","","SchemaBoolean.prototype.checkRequired = function (value) {"," return value === true || value === false;","};","","/**"," * Casts to boolean"," *"," * @param {Object} value to cast"," * @api private"," */","","SchemaBoolean.prototype.cast = function (value) {"," if (value === '0') return false;"," return !!value;","};","","SchemaBoolean.prototype.castForQuery = function ($conditional, val) {"," if (arguments.length === 1) {"," val = $conditional;"," }"," return this.cast(val);","};","","/**"," * Module exports."," */","","module.exports = SchemaBoolean;"];

@@ -15,11 +15,28 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/date.js'][46] = 0;
_$jscoverage['mongoose/schema/date.js'][48] = 0;
_$jscoverage['mongoose/schema/date.js'][51] = 0;
_$jscoverage['mongoose/schema/date.js'][53] = 0;
_$jscoverage['mongoose/schema/date.js'][56] = 0;
_$jscoverage['mongoose/schema/date.js'][47] = 0;
_$jscoverage['mongoose/schema/date.js'][49] = 0;
_$jscoverage['mongoose/schema/date.js'][52] = 0;
_$jscoverage['mongoose/schema/date.js'][54] = 0;
_$jscoverage['mongoose/schema/date.js'][57] = 0;
_$jscoverage['mongoose/schema/date.js'][59] = 0;
_$jscoverage['mongoose/schema/date.js'][58] = 0;
_$jscoverage['mongoose/schema/date.js'][60] = 0;
_$jscoverage['mongoose/schema/date.js'][62] = 0;
_$jscoverage['mongoose/schema/date.js'][69] = 0;
_$jscoverage['mongoose/schema/date.js'][61] = 0;
_$jscoverage['mongoose/schema/date.js'][63] = 0;
_$jscoverage['mongoose/schema/date.js'][66] = 0;
_$jscoverage['mongoose/schema/date.js'][67] = 0;
_$jscoverage['mongoose/schema/date.js'][70] = 0;
_$jscoverage['mongoose/schema/date.js'][71] = 0;
_$jscoverage['mongoose/schema/date.js'][72] = 0;
_$jscoverage['mongoose/schema/date.js'][73] = 0;
_$jscoverage['mongoose/schema/date.js'][77] = 0;
_$jscoverage['mongoose/schema/date.js'][86] = 0;
_$jscoverage['mongoose/schema/date.js'][87] = 0;
_$jscoverage['mongoose/schema/date.js'][88] = 0;
_$jscoverage['mongoose/schema/date.js'][89] = 0;
_$jscoverage['mongoose/schema/date.js'][90] = 0;
_$jscoverage['mongoose/schema/date.js'][91] = 0;
_$jscoverage['mongoose/schema/date.js'][92] = 0;
_$jscoverage['mongoose/schema/date.js'][94] = 0;
_$jscoverage['mongoose/schema/date.js'][95] = 0;
_$jscoverage['mongoose/schema/date.js'][103] = 0;
}

@@ -45,30 +62,75 @@ _$jscoverage['mongoose/schema/date.js'][6]++;

_$jscoverage['mongoose/schema/date.js'][45]++;
if (value === null) {
_$jscoverage['mongoose/schema/date.js'][45]++;
return value;
}
_$jscoverage['mongoose/schema/date.js'][46]++;
if (value instanceof Date) {
_$jscoverage['mongoose/schema/date.js'][46]++;
_$jscoverage['mongoose/schema/date.js'][47]++;
return value;
}
_$jscoverage['mongoose/schema/date.js'][48]++;
_$jscoverage['mongoose/schema/date.js'][49]++;
var date;
_$jscoverage['mongoose/schema/date.js'][51]++;
_$jscoverage['mongoose/schema/date.js'][52]++;
if (value instanceof Number || "number" == typeof value || String(value) == Number(value)) {
_$jscoverage['mongoose/schema/date.js'][53]++;
_$jscoverage['mongoose/schema/date.js'][54]++;
date = new Date(Number(value));
}
else {
_$jscoverage['mongoose/schema/date.js'][56]++;
_$jscoverage['mongoose/schema/date.js'][57]++;
if (value.toString) {
_$jscoverage['mongoose/schema/date.js'][57]++;
_$jscoverage['mongoose/schema/date.js'][58]++;
date = new Date(value.toString());
}
}
_$jscoverage['mongoose/schema/date.js'][59]++;
_$jscoverage['mongoose/schema/date.js'][60]++;
if (date.toString() != "Invalid Date") {
_$jscoverage['mongoose/schema/date.js'][60]++;
_$jscoverage['mongoose/schema/date.js'][61]++;
return date;
}
_$jscoverage['mongoose/schema/date.js'][62]++;
_$jscoverage['mongoose/schema/date.js'][63]++;
throw new CastError("date", value);
});
_$jscoverage['mongoose/schema/date.js'][69]++;
_$jscoverage['mongoose/schema/date.js'][66]++;
function handleSingle(val) {
_$jscoverage['mongoose/schema/date.js'][67]++;
return this.cast(val);
}
_$jscoverage['mongoose/schema/date.js'][70]++;
function handleArray(val) {
_$jscoverage['mongoose/schema/date.js'][71]++;
var self = this;
_$jscoverage['mongoose/schema/date.js'][72]++;
return val.map((function (m) {
_$jscoverage['mongoose/schema/date.js'][73]++;
return self.cast(m);
}));
}
_$jscoverage['mongoose/schema/date.js'][77]++;
SchemaDate.prototype.$conditionalHandlers = {"$lt": handleSingle, "$lte": handleSingle, "$gt": handleSingle, "$gte": handleSingle, "$ne": handleSingle, "$in": handleArray, "$nin": handleArray};
_$jscoverage['mongoose/schema/date.js'][86]++;
SchemaDate.prototype.castForQuery = (function ($conditional, val) {
_$jscoverage['mongoose/schema/date.js'][87]++;
var handler;
_$jscoverage['mongoose/schema/date.js'][88]++;
if (arguments.length === 2) {
_$jscoverage['mongoose/schema/date.js'][89]++;
handler = this.$conditionalHandlers[$conditional];
_$jscoverage['mongoose/schema/date.js'][90]++;
if (! handler) {
_$jscoverage['mongoose/schema/date.js'][91]++;
throw new Error("Can't use " + $conditional + " with Date.");
}
_$jscoverage['mongoose/schema/date.js'][92]++;
return handler.call(this, val);
}
else {
_$jscoverage['mongoose/schema/date.js'][94]++;
val = $conditional;
_$jscoverage['mongoose/schema/date.js'][95]++;
this.cast(val);
}
});
_$jscoverage['mongoose/schema/date.js'][103]++;
module.exports = SchemaDate;
_$jscoverage['mongoose/schema/date.js'].source = ["","/**"," * Module requirements."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError;","","/**"," * Date SchemaType constructor."," *"," * @param {String} key"," * @param {Object} options"," * @api private"," */","","function SchemaDate (key, options) {"," SchemaType.call(this, key, options);","};","","/**"," * Inherits from SchemaType."," */","","SchemaDate.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for date"," *"," * @api private"," */","","SchemaDate.prototype.checkRequired = function (value) {"," return value instanceof Date;","};","","/**"," * Casts to date"," *"," * @param {Object} value to cast"," * @api private"," */","","SchemaDate.prototype.cast = function (value) {"," if (value instanceof Date)"," return value;",""," var date;",""," // support for timestamps"," if (value instanceof Number || 'number' == typeof value "," || String(value) == Number(value))"," date = new Date(Number(value));",""," // support for date strings"," else if (value.toString)"," date = new Date(value.toString());",""," if (date.toString() != 'Invalid Date')"," return date;",""," throw new CastError('date', value);","};","","/**"," * Module exports."," */","","module.exports = SchemaDate;"];
_$jscoverage['mongoose/schema/date.js'].source = ["","/**"," * Module requirements."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError;","","/**"," * Date SchemaType constructor."," *"," * @param {String} key"," * @param {Object} options"," * @api private"," */","","function SchemaDate (key, options) {"," SchemaType.call(this, key, options);","};","","/**"," * Inherits from SchemaType."," */","","SchemaDate.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for date"," *"," * @api private"," */","","SchemaDate.prototype.checkRequired = function (value) {"," return value instanceof Date;","};","","/**"," * Casts to date"," *"," * @param {Object} value to cast"," * @api private"," */","","SchemaDate.prototype.cast = function (value) {"," if (value === null) return value;"," if (value instanceof Date)"," return value;",""," var date;",""," // support for timestamps"," if (value instanceof Number || 'number' == typeof value "," || String(value) == Number(value))"," date = new Date(Number(value));",""," // support for date strings"," else if (value.toString)"," date = new Date(value.toString());",""," if (date.toString() != 'Invalid Date')"," return date;",""," throw new CastError('date', value);","};","","function handleSingle (val) {"," return this.cast(val);","}","","function handleArray (val) {"," var self = this;"," return val.map( function (m) {"," return self.cast(m);"," });","}","","SchemaDate.prototype.$conditionalHandlers = {"," '$lt': handleSingle"," , '$lte': handleSingle"," , '$gt': handleSingle"," , '$gte': handleSingle"," , '$ne': handleSingle"," , '$in': handleArray"," , '$nin': handleArray","};","SchemaDate.prototype.castForQuery = function ($conditional, val) {"," var handler;"," if (arguments.length === 2) {"," handler = this.$conditionalHandlers[$conditional];"," if (!handler)"," throw new Error(\"Can't use \" + $conditional + \" with Date.\");"," return handler.call(this, val);"," } else {"," val = $conditional;"," this.cast(val);"," }","};","","/**"," * Module exports."," */","","module.exports = SchemaDate;"];

@@ -12,34 +12,35 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/documentarray.js'][29] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][31] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][33] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][35] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][30] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][32] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][34] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][36] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][37] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][39] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][45] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][53] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][38] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][40] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][46] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][54] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][55] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][56] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][58] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][61] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][63] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][57] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][59] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][62] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][64] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][65] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][67] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][66] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][68] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][69] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][71] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][86] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][70] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][72] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][87] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][88] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][89] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][91] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][90] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][92] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][93] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][94] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][97] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][99] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][102] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][109] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][95] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][98] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][100] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][103] = 0;
_$jscoverage['mongoose/schema/documentarray.js'][110] = 0;
}

@@ -61,51 +62,53 @@ _$jscoverage['mongoose/schema/documentarray.js'][6]++;

EmbeddedDocument.prototype.schema = schema;
_$jscoverage['mongoose/schema/documentarray.js'][31]++;
_$jscoverage['mongoose/schema/documentarray.js'][30]++;
EmbeddedDocument.schema = schema;
_$jscoverage['mongoose/schema/documentarray.js'][32]++;
ArrayType.call(this, key, EmbeddedDocument, options);
_$jscoverage['mongoose/schema/documentarray.js'][33]++;
_$jscoverage['mongoose/schema/documentarray.js'][34]++;
var self = this;
_$jscoverage['mongoose/schema/documentarray.js'][35]++;
_$jscoverage['mongoose/schema/documentarray.js'][36]++;
this.schema = schema;
_$jscoverage['mongoose/schema/documentarray.js'][36]++;
_$jscoverage['mongoose/schema/documentarray.js'][37]++;
this["default"]((function () {
_$jscoverage['mongoose/schema/documentarray.js'][37]++;
_$jscoverage['mongoose/schema/documentarray.js'][38]++;
return new MongooseDocumentArray([], self.path, this);
}));
}
_$jscoverage['mongoose/schema/documentarray.js'][39]++;
_$jscoverage['mongoose/schema/documentarray.js'][40]++;
;
_$jscoverage['mongoose/schema/documentarray.js'][45]++;
_$jscoverage['mongoose/schema/documentarray.js'][46]++;
DocumentArray.prototype.__proto__ = ArrayType.prototype;
_$jscoverage['mongoose/schema/documentarray.js'][53]++;
_$jscoverage['mongoose/schema/documentarray.js'][54]++;
DocumentArray.prototype.doValidate = (function (array, fn, scope) {
_$jscoverage['mongoose/schema/documentarray.js'][54]++;
_$jscoverage['mongoose/schema/documentarray.js'][55]++;
var self = this;
_$jscoverage['mongoose/schema/documentarray.js'][55]++;
_$jscoverage['mongoose/schema/documentarray.js'][56]++;
SchemaType.prototype.doValidate.call(this, array, (function (err) {
_$jscoverage['mongoose/schema/documentarray.js'][56]++;
_$jscoverage['mongoose/schema/documentarray.js'][57]++;
if (err) {
_$jscoverage['mongoose/schema/documentarray.js'][56]++;
_$jscoverage['mongoose/schema/documentarray.js'][57]++;
return fn(err);
}
_$jscoverage['mongoose/schema/documentarray.js'][58]++;
_$jscoverage['mongoose/schema/documentarray.js'][59]++;
var count = array.length, error = false;
_$jscoverage['mongoose/schema/documentarray.js'][61]++;
_$jscoverage['mongoose/schema/documentarray.js'][62]++;
if (! count) {
_$jscoverage['mongoose/schema/documentarray.js'][61]++;
_$jscoverage['mongoose/schema/documentarray.js'][62]++;
return fn();
}
_$jscoverage['mongoose/schema/documentarray.js'][63]++;
_$jscoverage['mongoose/schema/documentarray.js'][64]++;
array.forEach((function (doc, index) {
_$jscoverage['mongoose/schema/documentarray.js'][64]++;
_$jscoverage['mongoose/schema/documentarray.js'][65]++;
doc.validate((function (err) {
_$jscoverage['mongoose/schema/documentarray.js'][65]++;
_$jscoverage['mongoose/schema/documentarray.js'][66]++;
if (err && ! error) {
_$jscoverage['mongoose/schema/documentarray.js'][67]++;
_$jscoverage['mongoose/schema/documentarray.js'][68]++;
err.key = self.key + "." + index + "." + err.key;
_$jscoverage['mongoose/schema/documentarray.js'][68]++;
_$jscoverage['mongoose/schema/documentarray.js'][69]++;
fn(err);
_$jscoverage['mongoose/schema/documentarray.js'][69]++;
_$jscoverage['mongoose/schema/documentarray.js'][70]++;
error = true;
}
else {
_$jscoverage['mongoose/schema/documentarray.js'][71]++;
_$jscoverage['mongoose/schema/documentarray.js'][72]++;
--count || fn();

@@ -117,33 +120,33 @@ }

});
_$jscoverage['mongoose/schema/documentarray.js'][86]++;
_$jscoverage['mongoose/schema/documentarray.js'][87]++;
DocumentArray.prototype.cast = (function (value, doc) {
_$jscoverage['mongoose/schema/documentarray.js'][87]++;
_$jscoverage['mongoose/schema/documentarray.js'][88]++;
if (Array.isArray(value)) {
_$jscoverage['mongoose/schema/documentarray.js'][88]++;
_$jscoverage['mongoose/schema/documentarray.js'][89]++;
if (! (value instanceof MongooseDocumentArray)) {
_$jscoverage['mongoose/schema/documentarray.js'][89]++;
_$jscoverage['mongoose/schema/documentarray.js'][90]++;
value = new MongooseDocumentArray(value, this.path, doc);
}
_$jscoverage['mongoose/schema/documentarray.js'][91]++;
_$jscoverage['mongoose/schema/documentarray.js'][92]++;
for (var i = 0, l = value.length; i < l; i++) {
_$jscoverage['mongoose/schema/documentarray.js'][92]++;
_$jscoverage['mongoose/schema/documentarray.js'][93]++;
if (! (value[i] instanceof Subdocument)) {
_$jscoverage['mongoose/schema/documentarray.js'][93]++;
_$jscoverage['mongoose/schema/documentarray.js'][94]++;
var doc = new this.caster(null, value);
_$jscoverage['mongoose/schema/documentarray.js'][94]++;
_$jscoverage['mongoose/schema/documentarray.js'][95]++;
value[i] = doc.init(value[i]);
}
}
_$jscoverage['mongoose/schema/documentarray.js'][97]++;
_$jscoverage['mongoose/schema/documentarray.js'][98]++;
return value;
}
else {
_$jscoverage['mongoose/schema/documentarray.js'][99]++;
_$jscoverage['mongoose/schema/documentarray.js'][100]++;
return this.cast([value], doc);
}
_$jscoverage['mongoose/schema/documentarray.js'][102]++;
_$jscoverage['mongoose/schema/documentarray.js'][103]++;
throw new CastError("documentarray", value, this.caster);
});
_$jscoverage['mongoose/schema/documentarray.js'][109]++;
_$jscoverage['mongoose/schema/documentarray.js'][110]++;
module.exports = DocumentArray;
_$jscoverage['mongoose/schema/documentarray.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , ArrayType = require('./array')"," , MongooseDocumentArray = require('../types/documentarray')"," , Subdocument = require('../types/document')"," , CastError = SchemaType.CastError"," , Document = require('../document');","","/**"," * SubdocsArray SchemaType constructor"," *"," * @param {String} key"," * @param {Schema} schema"," * @param {Object} options"," * @api private"," */","","function DocumentArray (key, schema, options) {"," // compile an embedded document for this schema"," function EmbeddedDocument () {"," Subdocument.apply(this, arguments);"," };",""," EmbeddedDocument.prototype.__proto__ = Subdocument.prototype;"," EmbeddedDocument.prototype.schema = schema;",""," ArrayType.call(this, key, EmbeddedDocument, options);",""," var self = this;",""," this.schema = schema;"," this.default(function(){"," return new MongooseDocumentArray([], self.path, this);"," });","};","","/**"," * Inherits from ArrayType."," */","","DocumentArray.prototype.__proto__ = ArrayType.prototype;","","/**"," * Performs local validations first, then validations on each embedded doc"," *"," * @api private"," */","","DocumentArray.prototype.doValidate = function (array, fn, scope) {"," var self = this;"," SchemaType.prototype.doValidate.call(this, array, function(err){"," if (err) return fn(err);"," "," var count = array.length"," , error = false;",""," if (!count) return fn();",""," array.forEach(function(doc, index){"," doc.validate(function(err){"," if (err &amp;&amp; !error){"," // rewrite they key"," err.key = self.key + '.' + index + '.' + err.key;"," fn(err);"," error = true;"," } else {"," --count || fn();"," }"," });"," });"," }, scope);","};","","/**"," * Casts contents"," *"," * @param {Object} value"," * @param {Document} document that triggers the casting"," * @api private"," */","","DocumentArray.prototype.cast = function (value, doc) {"," if (Array.isArray(value)){"," if (!(value instanceof MongooseDocumentArray))"," value = new MongooseDocumentArray(value, this.path, doc);",""," for (var i = 0, l = value.length; i &lt; l; i++)"," if (!(value[i] instanceof Subdocument)){"," var doc = new this.caster(null, value);"," value[i] = doc.init(value[i]);"," }",""," return value;"," } else {"," return this.cast([value], doc);"," }",""," throw new CastError('documentarray', value, this.caster);","};","","/**"," * Module exports."," */","","module.exports = DocumentArray;"];
_$jscoverage['mongoose/schema/documentarray.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , ArrayType = require('./array')"," , MongooseDocumentArray = require('../types/documentarray')"," , Subdocument = require('../types/document')"," , CastError = SchemaType.CastError"," , Document = require('../document');","","/**"," * SubdocsArray SchemaType constructor"," *"," * @param {String} key"," * @param {Schema} schema"," * @param {Object} options"," * @api private"," */","","function DocumentArray (key, schema, options) {"," // compile an embedded document for this schema"," function EmbeddedDocument () {"," Subdocument.apply(this, arguments);"," };",""," EmbeddedDocument.prototype.__proto__ = Subdocument.prototype;"," EmbeddedDocument.prototype.schema = schema;"," EmbeddedDocument.schema = schema;",""," ArrayType.call(this, key, EmbeddedDocument, options);",""," var self = this;",""," this.schema = schema;"," this.default(function(){"," return new MongooseDocumentArray([], self.path, this);"," });","};","","/**"," * Inherits from ArrayType."," */","","DocumentArray.prototype.__proto__ = ArrayType.prototype;","","/**"," * Performs local validations first, then validations on each embedded doc"," *"," * @api private"," */","","DocumentArray.prototype.doValidate = function (array, fn, scope) {"," var self = this;"," SchemaType.prototype.doValidate.call(this, array, function(err){"," if (err) return fn(err);"," "," var count = array.length"," , error = false;",""," if (!count) return fn();",""," array.forEach(function(doc, index){"," doc.validate(function(err){"," if (err &amp;&amp; !error){"," // rewrite they key"," err.key = self.key + '.' + index + '.' + err.key;"," fn(err);"," error = true;"," } else {"," --count || fn();"," }"," });"," });"," }, scope);","};","","/**"," * Casts contents"," *"," * @param {Object} value"," * @param {Document} document that triggers the casting"," * @api private"," */","","DocumentArray.prototype.cast = function (value, doc) {"," if (Array.isArray(value)){"," if (!(value instanceof MongooseDocumentArray))"," value = new MongooseDocumentArray(value, this.path, doc);",""," for (var i = 0, l = value.length; i &lt; l; i++)"," if (!(value[i] instanceof Subdocument)){"," var doc = new this.caster(null, value);"," value[i] = doc.init(value[i]);"," }",""," return value;"," } else {"," return this.cast([value], doc);"," }",""," throw new CastError('documentarray', value, this.caster);","};","","/**"," * Module exports."," */","","module.exports = DocumentArray;"];

@@ -14,3 +14,4 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/mixed.js'][43] = 0;
_$jscoverage['mongoose/schema/mixed.js'][50] = 0;
_$jscoverage['mongoose/schema/mixed.js'][46] = 0;
_$jscoverage['mongoose/schema/mixed.js'][52] = 0;
}

@@ -38,4 +39,6 @@ _$jscoverage['mongoose/schema/mixed.js'][6]++;

});
_$jscoverage['mongoose/schema/mixed.js'][50]++;
_$jscoverage['mongoose/schema/mixed.js'][46]++;
SchemaMixed.prototype.castForQuery = SchemaMixed.prototype.cast;
_$jscoverage['mongoose/schema/mixed.js'][52]++;
module.exports = SchemaMixed;
_$jscoverage['mongoose/schema/mixed.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype');","","/**"," * Mixed SchemaType constructor."," *"," * @param {String} path"," * @param {Object} options"," * @api private"," */","","function SchemaMixed (path, options) {"," SchemaType.call(this, path, options);","};","","/**"," * Inherits from SchemaType."," */","SchemaMixed.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for mixed type"," *"," * @api private"," */","","SchemaMixed.prototype.checkRequired = function (value) {"," return true;","};","","/**"," * Noop casting"," *"," * @param {Object} value to cast"," * @api private"," */","","SchemaMixed.prototype.cast = function (value) {"," return value;","};","","/**"," * Module exports."," */","","module.exports = SchemaMixed;"];
_$jscoverage['mongoose/schema/mixed.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype');","","/**"," * Mixed SchemaType constructor."," *"," * @param {String} path"," * @param {Object} options"," * @api private"," */","","function SchemaMixed (path, options) {"," SchemaType.call(this, path, options);","};","","/**"," * Inherits from SchemaType."," */","SchemaMixed.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for mixed type"," *"," * @api private"," */","","SchemaMixed.prototype.checkRequired = function (value) {"," return true;","};","","/**"," * Noop casting"," *"," * @param {Object} value to cast"," * @api private"," */","","SchemaMixed.prototype.cast = function (value) {"," return value;","};","","SchemaMixed.prototype.castForQuery = SchemaMixed.prototype.cast;","","/**"," * Module exports."," */","","module.exports = SchemaMixed;"];

@@ -32,5 +32,22 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/number.js'][87] = 0;
_$jscoverage['mongoose/schema/number.js'][89] = 0;
_$jscoverage['mongoose/schema/number.js'][91] = 0;
_$jscoverage['mongoose/schema/number.js'][98] = 0;
_$jscoverage['mongoose/schema/number.js'][88] = 0;
_$jscoverage['mongoose/schema/number.js'][90] = 0;
_$jscoverage['mongoose/schema/number.js'][92] = 0;
_$jscoverage['mongoose/schema/number.js'][95] = 0;
_$jscoverage['mongoose/schema/number.js'][96] = 0;
_$jscoverage['mongoose/schema/number.js'][99] = 0;
_$jscoverage['mongoose/schema/number.js'][100] = 0;
_$jscoverage['mongoose/schema/number.js'][101] = 0;
_$jscoverage['mongoose/schema/number.js'][102] = 0;
_$jscoverage['mongoose/schema/number.js'][106] = 0;
_$jscoverage['mongoose/schema/number.js'][116] = 0;
_$jscoverage['mongoose/schema/number.js'][117] = 0;
_$jscoverage['mongoose/schema/number.js'][118] = 0;
_$jscoverage['mongoose/schema/number.js'][119] = 0;
_$jscoverage['mongoose/schema/number.js'][120] = 0;
_$jscoverage['mongoose/schema/number.js'][121] = 0;
_$jscoverage['mongoose/schema/number.js'][122] = 0;
_$jscoverage['mongoose/schema/number.js'][124] = 0;
_$jscoverage['mongoose/schema/number.js'][125] = 0;
_$jscoverage['mongoose/schema/number.js'][133] = 0;
}

@@ -100,17 +117,62 @@ _$jscoverage['mongoose/schema/number.js'][6]++;

_$jscoverage['mongoose/schema/number.js'][86]++;
if (value === null) {
_$jscoverage['mongoose/schema/number.js'][86]++;
return value;
}
_$jscoverage['mongoose/schema/number.js'][87]++;
if ("string" === typeof value) {
_$jscoverage['mongoose/schema/number.js'][86]++;
_$jscoverage['mongoose/schema/number.js'][87]++;
value = Number(value);
}
_$jscoverage['mongoose/schema/number.js'][87]++;
_$jscoverage['mongoose/schema/number.js'][88]++;
if (value instanceof Number || typeof value == "number" || (value.toString && value.toString() == Number(value))) {
_$jscoverage['mongoose/schema/number.js'][89]++;
_$jscoverage['mongoose/schema/number.js'][90]++;
return new MongooseNumber(value, this.path, doc);
}
}
_$jscoverage['mongoose/schema/number.js'][91]++;
_$jscoverage['mongoose/schema/number.js'][92]++;
throw new CastError("number", value);
});
_$jscoverage['mongoose/schema/number.js'][98]++;
_$jscoverage['mongoose/schema/number.js'][95]++;
function handleSingle(val) {
_$jscoverage['mongoose/schema/number.js'][96]++;
return this.cast(val).valueOf();
}
_$jscoverage['mongoose/schema/number.js'][99]++;
function handleArray(val) {
_$jscoverage['mongoose/schema/number.js'][100]++;
var self = this;
_$jscoverage['mongoose/schema/number.js'][101]++;
return val.map((function (m) {
_$jscoverage['mongoose/schema/number.js'][102]++;
return self.cast(m).valueOf();
}));
}
_$jscoverage['mongoose/schema/number.js'][106]++;
SchemaNumber.prototype.$conditionalHandlers = {"$lt": handleSingle, "$lte": handleSingle, "$gt": handleSingle, "$gte": handleSingle, "$ne": handleSingle, "$in": handleArray, "$nin": handleArray, "$mod": handleArray};
_$jscoverage['mongoose/schema/number.js'][116]++;
SchemaNumber.prototype.castForQuery = (function ($conditional, val) {
_$jscoverage['mongoose/schema/number.js'][117]++;
var handler;
_$jscoverage['mongoose/schema/number.js'][118]++;
if (arguments.length === 2) {
_$jscoverage['mongoose/schema/number.js'][119]++;
handler = this.$conditionalHandlers[$conditional];
_$jscoverage['mongoose/schema/number.js'][120]++;
if (! handler) {
_$jscoverage['mongoose/schema/number.js'][121]++;
throw new Error("Can't use " + $conditional + " with Number.");
}
_$jscoverage['mongoose/schema/number.js'][122]++;
return handler.call(this, val);
}
else {
_$jscoverage['mongoose/schema/number.js'][124]++;
val = $conditional;
_$jscoverage['mongoose/schema/number.js'][125]++;
return this.cast(val);
}
});
_$jscoverage['mongoose/schema/number.js'][133]++;
module.exports = SchemaNumber;
_$jscoverage['mongoose/schema/number.js'].source = ["","/**"," * Module requirements."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError"," , MongooseNumber = require('../types/number');","","/**"," * Number SchemaType constructor."," *"," * @param {String} key"," * @param {Object} options"," * @api private"," */","","function SchemaNumber (key, options) {"," SchemaType.call(this, key, options);","};","","/**"," * Inherits from SchemaType."," */","","SchemaNumber.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for number"," *"," * @api private"," */","","SchemaNumber.prototype.checkRequired = function (value) {"," return typeof value == 'number' || value instanceof Number;","};","","/**"," * Sets a maximum number validator"," *"," * @param {Number} minimum number"," * @api public"," */","","SchemaNumber.prototype.min = function (value, message) {"," if (this.minValidator)"," this.validators = this.validators.filter(function(v){"," return v[1] != 'min';"," });"," if (value != null)"," this.validators.push([function(v){"," return v &gt;= value;"," }, 'min']);"," return this;","};","","/**"," * Sets a maximum number validator"," *"," * @param {Number} maximum number"," * @api public"," */","","SchemaNumber.prototype.max = function (value, message) {"," if (this.maxValidator)"," this.validators = this.validators.filter(function(v){"," return v[1] != 'max';"," });"," if (value != null)"," this.validators.push([this.maxValidator = function(v){"," return v &lt;= value;"," }, 'max']);"," return this;","};","","/**"," * Casts to number"," *"," * @param {Object} value to cast"," * @param {Document} document that triggers the casting"," * @api private"," */","","SchemaNumber.prototype.cast = function (value, doc) {"," if (!isNaN(value)){"," if ('string' === typeof value) value = Number(value);"," if (value instanceof Number || typeof value == 'number' ||"," (value.toString &amp;&amp; value.toString() == Number(value)))"," return new MongooseNumber(value, this.path, doc);"," }"," throw new CastError('number', value);","};","","/**"," * Module exports."," */","","module.exports = SchemaNumber;"];
_$jscoverage['mongoose/schema/number.js'].source = ["","/**"," * Module requirements."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError"," , MongooseNumber = require('../types/number');","","/**"," * Number SchemaType constructor."," *"," * @param {String} key"," * @param {Object} options"," * @api private"," */","","function SchemaNumber (key, options) {"," SchemaType.call(this, key, options);","};","","/**"," * Inherits from SchemaType."," */","","SchemaNumber.prototype.__proto__ = SchemaType.prototype;","","/**"," * Required validator for number"," *"," * @api private"," */","","SchemaNumber.prototype.checkRequired = function (value) {"," return typeof value == 'number' || value instanceof Number;","};","","/**"," * Sets a maximum number validator"," *"," * @param {Number} minimum number"," * @api public"," */","","SchemaNumber.prototype.min = function (value, message) {"," if (this.minValidator)"," this.validators = this.validators.filter(function(v){"," return v[1] != 'min';"," });"," if (value != null)"," this.validators.push([function(v){"," return v &gt;= value;"," }, 'min']);"," return this;","};","","/**"," * Sets a maximum number validator"," *"," * @param {Number} maximum number"," * @api public"," */","","SchemaNumber.prototype.max = function (value, message) {"," if (this.maxValidator)"," this.validators = this.validators.filter(function(v){"," return v[1] != 'max';"," });"," if (value != null)"," this.validators.push([this.maxValidator = function(v){"," return v &lt;= value;"," }, 'max']);"," return this;","};","","/**"," * Casts to number"," *"," * @param {Object} value to cast"," * @param {Document} document that triggers the casting"," * @api private"," */","","SchemaNumber.prototype.cast = function (value, doc) {"," if (!isNaN(value)){"," if (value === null) return value;"," if ('string' === typeof value) value = Number(value);"," if (value instanceof Number || typeof value == 'number' ||"," (value.toString &amp;&amp; value.toString() == Number(value)))"," return new MongooseNumber(value, this.path, doc);"," }"," throw new CastError('number', value);","};","","function handleSingle (val) {"," return this.cast(val).valueOf();","}","","function handleArray (val) {"," var self = this;"," return val.map( function (m) {"," return self.cast(m).valueOf();"," });","}","","SchemaNumber.prototype.$conditionalHandlers = {"," '$lt': handleSingle"," , '$lte': handleSingle"," , '$gt': handleSingle"," , '$gte': handleSingle"," , '$ne': handleSingle"," , '$in': handleArray"," , '$nin': handleArray"," , '$mod': handleArray","};","SchemaNumber.prototype.castForQuery = function ($conditional, val) {"," var handler;"," if (arguments.length === 2) {"," handler = this.$conditionalHandlers[$conditional];"," if (!handler)"," throw new Error(\"Can't use \" + $conditional + \" with Number.\");"," return handler.call(this, val);"," } else {"," val = $conditional;"," return this.cast(val);"," }","};","","/**"," * Module exports."," */","","module.exports = SchemaNumber;"];

@@ -8,15 +8,34 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/objectid.js'][21] = 0;
_$jscoverage['mongoose/schema/objectid.js'][23] = 0;
_$jscoverage['mongoose/schema/objectid.js'][24] = 0;
_$jscoverage['mongoose/schema/objectid.js'][26] = 0;
_$jscoverage['mongoose/schema/objectid.js'][32] = 0;
_$jscoverage['mongoose/schema/objectid.js'][40] = 0;
_$jscoverage['mongoose/schema/objectid.js'][41] = 0;
_$jscoverage['mongoose/schema/objectid.js'][22] = 0;
_$jscoverage['mongoose/schema/objectid.js'][28] = 0;
_$jscoverage['mongoose/schema/objectid.js'][36] = 0;
_$jscoverage['mongoose/schema/objectid.js'][37] = 0;
_$jscoverage['mongoose/schema/objectid.js'][46] = 0;
_$jscoverage['mongoose/schema/objectid.js'][47] = 0;
_$jscoverage['mongoose/schema/objectid.js'][48] = 0;
_$jscoverage['mongoose/schema/objectid.js'][49] = 0;
_$jscoverage['mongoose/schema/objectid.js'][50] = 0;
_$jscoverage['mongoose/schema/objectid.js'][51] = 0;
_$jscoverage['mongoose/schema/objectid.js'][52] = 0;
_$jscoverage['mongoose/schema/objectid.js'][53] = 0;
_$jscoverage['mongoose/schema/objectid.js'][54] = 0;
_$jscoverage['mongoose/schema/objectid.js'][55] = 0;
_$jscoverage['mongoose/schema/objectid.js'][56] = 0;
_$jscoverage['mongoose/schema/objectid.js'][59] = 0;
_$jscoverage['mongoose/schema/objectid.js'][60] = 0;
_$jscoverage['mongoose/schema/objectid.js'][61] = 0;
_$jscoverage['mongoose/schema/objectid.js'][62] = 0;
_$jscoverage['mongoose/schema/objectid.js'][66] = 0;
_$jscoverage['mongoose/schema/objectid.js'][71] = 0;
_$jscoverage['mongoose/schema/objectid.js'][72] = 0;
_$jscoverage['mongoose/schema/objectid.js'][73] = 0;
_$jscoverage['mongoose/schema/objectid.js'][74] = 0;
_$jscoverage['mongoose/schema/objectid.js'][75] = 0;
_$jscoverage['mongoose/schema/objectid.js'][76] = 0;
_$jscoverage['mongoose/schema/objectid.js'][77] = 0;
_$jscoverage['mongoose/schema/objectid.js'][79] = 0;
_$jscoverage['mongoose/schema/objectid.js'][80] = 0;
_$jscoverage['mongoose/schema/objectid.js'][89] = 0;
_$jscoverage['mongoose/schema/objectid.js'][90] = 0;
_$jscoverage['mongoose/schema/objectid.js'][91] = 0;
_$jscoverage['mongoose/schema/objectid.js'][92] = 0;
_$jscoverage['mongoose/schema/objectid.js'][101] = 0;
}

@@ -29,34 +48,85 @@ _$jscoverage['mongoose/schema/objectid.js'][6]++;

SchemaType.call(this, key, options);
_$jscoverage['mongoose/schema/objectid.js'][23]++;
this["default"]((function () {
_$jscoverage['mongoose/schema/objectid.js'][24]++;
return new oid();
}));
}
_$jscoverage['mongoose/schema/objectid.js'][26]++;
_$jscoverage['mongoose/schema/objectid.js'][22]++;
;
_$jscoverage['mongoose/schema/objectid.js'][32]++;
_$jscoverage['mongoose/schema/objectid.js'][28]++;
ObjectId.prototype.__proto__ = SchemaType.prototype;
_$jscoverage['mongoose/schema/objectid.js'][40]++;
_$jscoverage['mongoose/schema/objectid.js'][36]++;
ObjectId.prototype.checkRequired = (function (value) {
_$jscoverage['mongoose/schema/objectid.js'][41]++;
_$jscoverage['mongoose/schema/objectid.js'][37]++;
return value && value instanceof oid;
});
_$jscoverage['mongoose/schema/objectid.js'][50]++;
_$jscoverage['mongoose/schema/objectid.js'][46]++;
ObjectId.prototype.cast = (function (value) {
_$jscoverage['mongoose/schema/objectid.js'][51]++;
_$jscoverage['mongoose/schema/objectid.js'][47]++;
if (value === null) {
_$jscoverage['mongoose/schema/objectid.js'][47]++;
return value;
}
_$jscoverage['mongoose/schema/objectid.js'][48]++;
if (value instanceof oid) {
_$jscoverage['mongoose/schema/objectid.js'][52]++;
_$jscoverage['mongoose/schema/objectid.js'][49]++;
return value;
}
_$jscoverage['mongoose/schema/objectid.js'][53]++;
_$jscoverage['mongoose/schema/objectid.js'][50]++;
if (value.toString) {
_$jscoverage['mongoose/schema/objectid.js'][54]++;
_$jscoverage['mongoose/schema/objectid.js'][51]++;
return oid.fromString(value.toString());
}
_$jscoverage['mongoose/schema/objectid.js'][55]++;
_$jscoverage['mongoose/schema/objectid.js'][52]++;
throw new CastError("object id", value);
});
_$jscoverage['mongoose/schema/objectid.js'][62]++;
_$jscoverage['mongoose/schema/objectid.js'][55]++;
function handleSingle(val) {
_$jscoverage['mongoose/schema/objectid.js'][56]++;
return this.cast(val);
}
_$jscoverage['mongoose/schema/objectid.js'][59]++;
function handleArray(val) {
_$jscoverage['mongoose/schema/objectid.js'][60]++;
var self = this;
_$jscoverage['mongoose/schema/objectid.js'][61]++;
return val.map((function (m) {
_$jscoverage['mongoose/schema/objectid.js'][62]++;
return self.cast(m);
}));
}
_$jscoverage['mongoose/schema/objectid.js'][66]++;
ObjectId.prototype.$conditionalHandlers = {"$ne": handleSingle, "$in": handleArray, "$nin": handleArray};
_$jscoverage['mongoose/schema/objectid.js'][71]++;
ObjectId.prototype.castForQuery = (function ($conditional, val) {
_$jscoverage['mongoose/schema/objectid.js'][72]++;
var handler;
_$jscoverage['mongoose/schema/objectid.js'][73]++;
if (arguments.length === 2) {
_$jscoverage['mongoose/schema/objectid.js'][74]++;
handler = this.$conditionalHandlers[$conditional];
_$jscoverage['mongoose/schema/objectid.js'][75]++;
if (! handler) {
_$jscoverage['mongoose/schema/objectid.js'][76]++;
throw new Error("Can't use " + $conditional + " with ObjectId.");
}
_$jscoverage['mongoose/schema/objectid.js'][77]++;
return handler.call(this, val);
}
else {
_$jscoverage['mongoose/schema/objectid.js'][79]++;
val = $conditional;
_$jscoverage['mongoose/schema/objectid.js'][80]++;
return this.cast(val);
}
});
_$jscoverage['mongoose/schema/objectid.js'][89]++;
ObjectId.prototype.auto = (function (turnOn) {
_$jscoverage['mongoose/schema/objectid.js'][90]++;
if (turnOn) {
_$jscoverage['mongoose/schema/objectid.js'][91]++;
this["default"]((function () {
_$jscoverage['mongoose/schema/objectid.js'][92]++;
return new oid();
}));
}
});
_$jscoverage['mongoose/schema/objectid.js'][101]++;
module.exports = ObjectId;
_$jscoverage['mongoose/schema/objectid.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError"," , driver = global.MONGOOSE_DRIVER_PATH || './../drivers/node-mongodb-native'"," , oid = require('../types/objectid');","","","/**"," * ObjectId SchemaType constructor."," *"," * @param {String} key"," * @param {Object} options"," * @api private"," */","","function ObjectId (key, options) {"," SchemaType.call(this, key, options);",""," this.default(function(){"," return new oid();"," });","};","","/**"," * Inherits from SchemaType."," */","","ObjectId.prototype.__proto__ = SchemaType.prototype;","","/**"," * Check required"," *"," * @api private"," */","","ObjectId.prototype.checkRequired = function(value){"," return value &amp;&amp; value instanceof oid;","};","","/**"," * Casts to String "," *"," * @api private"," */","","ObjectId.prototype.cast = function (value) {"," if (value instanceof oid)"," return value;"," if (value.toString)"," return oid.fromString(value.toString());"," throw new CastError('object id', value);","};","","/**"," * Module exports."," */","","module.exports = ObjectId;"];
_$jscoverage['mongoose/schema/objectid.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError"," , driver = global.MONGOOSE_DRIVER_PATH || './../drivers/node-mongodb-native'"," , oid = require('../types/objectid');","","","/**"," * ObjectId SchemaType constructor."," *"," * @param {String} key"," * @param {Object} options"," * @api private"," */","","function ObjectId (key, options) {"," SchemaType.call(this, key, options);","};","","/**"," * Inherits from SchemaType."," */","","ObjectId.prototype.__proto__ = SchemaType.prototype;","","/**"," * Check required"," *"," * @api private"," */","","ObjectId.prototype.checkRequired = function(value){"," return value &amp;&amp; value instanceof oid;","};","","/**"," * Casts to String "," *"," * @api private"," */","","ObjectId.prototype.cast = function (value) {"," if (value === null) return value;"," if (value instanceof oid)"," return value;"," if (value.toString)"," return oid.fromString(value.toString());"," throw new CastError('object id', value);","};","","function handleSingle (val) {"," return this.cast(val);","}","","function handleArray (val) {"," var self = this;"," return val.map( function (m) {"," return self.cast(m);"," });","}","","ObjectId.prototype.$conditionalHandlers = {"," '$ne': handleSingle"," , '$in': handleArray"," , '$nin': handleArray","};","ObjectId.prototype.castForQuery = function ($conditional, val) {"," var handler;"," if (arguments.length === 2) {"," handler = this.$conditionalHandlers[$conditional];"," if (!handler)"," throw new Error(\"Can't use \" + $conditional + \" with ObjectId.\");"," return handler.call(this, val);"," } else {"," val = $conditional;"," return this.cast(val);"," }","};","","/**"," * Adds an auto-generated ObjectId default if turnOn is true."," * @param {Boolean} turnOn auto generated ObjectId defaults"," * @api private"," */","ObjectId.prototype.auto = function (turnOn) {"," if (turnOn) {"," this.default(function(){"," return new oid();"," });"," }","};","","/**"," * Module exports."," */","","module.exports = ObjectId;"];

@@ -34,3 +34,21 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schema/string.js'][91] = 0;
_$jscoverage['mongoose/schema/string.js'][98] = 0;
_$jscoverage['mongoose/schema/string.js'][92] = 0;
_$jscoverage['mongoose/schema/string.js'][95] = 0;
_$jscoverage['mongoose/schema/string.js'][96] = 0;
_$jscoverage['mongoose/schema/string.js'][99] = 0;
_$jscoverage['mongoose/schema/string.js'][100] = 0;
_$jscoverage['mongoose/schema/string.js'][101] = 0;
_$jscoverage['mongoose/schema/string.js'][102] = 0;
_$jscoverage['mongoose/schema/string.js'][106] = 0;
_$jscoverage['mongoose/schema/string.js'][111] = 0;
_$jscoverage['mongoose/schema/string.js'][112] = 0;
_$jscoverage['mongoose/schema/string.js'][113] = 0;
_$jscoverage['mongoose/schema/string.js'][114] = 0;
_$jscoverage['mongoose/schema/string.js'][115] = 0;
_$jscoverage['mongoose/schema/string.js'][116] = 0;
_$jscoverage['mongoose/schema/string.js'][117] = 0;
_$jscoverage['mongoose/schema/string.js'][119] = 0;
_$jscoverage['mongoose/schema/string.js'][120] = 0;
_$jscoverage['mongoose/schema/string.js'][121] = 0;
_$jscoverage['mongoose/schema/string.js'][129] = 0;
}

@@ -105,11 +123,61 @@ _$jscoverage['mongoose/schema/string.js'][6]++;

_$jscoverage['mongoose/schema/string.js'][90]++;
if (value === null) {
_$jscoverage['mongoose/schema/string.js'][90]++;
return value;
}
_$jscoverage['mongoose/schema/string.js'][91]++;
if (value.toString) {
_$jscoverage['mongoose/schema/string.js'][90]++;
_$jscoverage['mongoose/schema/string.js'][91]++;
return value.toString();
}
_$jscoverage['mongoose/schema/string.js'][91]++;
_$jscoverage['mongoose/schema/string.js'][92]++;
throw new CastError("string", value);
});
_$jscoverage['mongoose/schema/string.js'][98]++;
_$jscoverage['mongoose/schema/string.js'][95]++;
function handleSingle(val) {
_$jscoverage['mongoose/schema/string.js'][96]++;
return this.castForQuery(val);
}
_$jscoverage['mongoose/schema/string.js'][99]++;
function handleArray(val) {
_$jscoverage['mongoose/schema/string.js'][100]++;
var self = this;
_$jscoverage['mongoose/schema/string.js'][101]++;
return val.map((function (m) {
_$jscoverage['mongoose/schema/string.js'][102]++;
return self.castForQuery(m);
}));
}
_$jscoverage['mongoose/schema/string.js'][106]++;
SchemaString.prototype.$conditionalHandlers = {"$ne": handleSingle, "$in": handleArray, "$nin": handleArray};
_$jscoverage['mongoose/schema/string.js'][111]++;
SchemaString.prototype.castForQuery = (function ($conditional, val) {
_$jscoverage['mongoose/schema/string.js'][112]++;
var handler;
_$jscoverage['mongoose/schema/string.js'][113]++;
if (arguments.length === 2) {
_$jscoverage['mongoose/schema/string.js'][114]++;
handler = this.$conditionalHandlers[$conditional];
_$jscoverage['mongoose/schema/string.js'][115]++;
if (! handler) {
_$jscoverage['mongoose/schema/string.js'][116]++;
throw new Error("Can't use " + $conditional + " with String.");
}
_$jscoverage['mongoose/schema/string.js'][117]++;
return handler.call(this, val);
}
else {
_$jscoverage['mongoose/schema/string.js'][119]++;
val = $conditional;
_$jscoverage['mongoose/schema/string.js'][120]++;
if (val instanceof RegExp) {
_$jscoverage['mongoose/schema/string.js'][120]++;
return val;
}
_$jscoverage['mongoose/schema/string.js'][121]++;
return this.cast(val);
}
});
_$jscoverage['mongoose/schema/string.js'][129]++;
module.exports = SchemaString;
_$jscoverage['mongoose/schema/string.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError;","","/**"," * String SchemaType constructor."," *"," * @param {String} key"," * @api private"," */","","function SchemaString (key, options) {"," this.enumValues = [];"," this.regExp = null;"," SchemaType.call(this, key, options);","};","","/**"," * Inherits from SchemaType."," */","","SchemaString.prototype.__proto__ = SchemaType.prototype;","","/**"," * Adds enumeration values"," *"," * @param {multiple} enumeration values"," * @api public"," */","","SchemaString.prototype.enum = function(){"," for (var i = 0, l = arguments.length; i &lt; l; i++){"," if (arguments[i] == null){"," if (this.enumValidator){"," this.enumValidator = false;"," this.validators = this.validators.filter(function(v){"," return v[1] != 'enum';"," });"," }"," break;"," } else"," this.enumValues.push(this.cast(arguments[i]));"," }",""," if (!this.enumValidator){"," var values = this.enumValues;"," this.enumValidator = function(v){"," return ~values.indexOf(v);"," };"," this.validators.push([this.enumValidator, 'enum']);"," }","};","","/**"," * Sets a regexp test"," *"," * @param {RegExp} regular expression to test against"," * @param {String} optional validator message"," * @api public"," */","","SchemaString.prototype.match = function(regExp){"," this.validators.push([function(v){"," return regExp.test(v);"," }, 'regexp']);","};","","/**"," * Check required"," *"," * @api private"," */","","SchemaString.prototype.checkRequired = function (v) {"," return (v instanceof String || typeof v == 'string') &amp;&amp; v.length;","};","","","/**"," * Casts to String"," *"," * @api private"," */","","SchemaString.prototype.cast = function (value) {"," if (value.toString) return value.toString();"," throw new CastError('string', value);","};","","/**"," * Module exports."," */","","module.exports = SchemaString;"];
_$jscoverage['mongoose/schema/string.js'].source = ["","/**"," * Module dependencies."," */","","var SchemaType = require('../schematype')"," , CastError = SchemaType.CastError;","","/**"," * String SchemaType constructor."," *"," * @param {String} key"," * @api private"," */","","function SchemaString (key, options) {"," this.enumValues = [];"," this.regExp = null;"," SchemaType.call(this, key, options);","};","","/**"," * Inherits from SchemaType."," */","","SchemaString.prototype.__proto__ = SchemaType.prototype;","","/**"," * Adds enumeration values"," *"," * @param {multiple} enumeration values"," * @api public"," */","","SchemaString.prototype.enum = function(){"," for (var i = 0, l = arguments.length; i &lt; l; i++){"," if (arguments[i] == null){"," if (this.enumValidator){"," this.enumValidator = false;"," this.validators = this.validators.filter(function(v){"," return v[1] != 'enum';"," });"," }"," break;"," } else"," this.enumValues.push(this.cast(arguments[i]));"," }",""," if (!this.enumValidator){"," var values = this.enumValues;"," this.enumValidator = function(v){"," return ~values.indexOf(v);"," };"," this.validators.push([this.enumValidator, 'enum']);"," }","};","","/**"," * Sets a regexp test"," *"," * @param {RegExp} regular expression to test against"," * @param {String} optional validator message"," * @api public"," */","","SchemaString.prototype.match = function(regExp){"," this.validators.push([function(v){"," return regExp.test(v);"," }, 'regexp']);","};","","/**"," * Check required"," *"," * @api private"," */","","SchemaString.prototype.checkRequired = function (v) {"," return (v instanceof String || typeof v == 'string') &amp;&amp; v.length;","};","","","/**"," * Casts to String"," *"," * @api private"," */","","SchemaString.prototype.cast = function (value) {"," if (value === null) return value;"," if (value.toString) return value.toString();"," throw new CastError('string', value);","};","","function handleSingle (val) {"," return this.castForQuery(val);","}","","function handleArray (val) {"," var self = this;"," return val.map( function (m) {"," return self.castForQuery(m);"," });","}","","SchemaString.prototype.$conditionalHandlers = {"," '$ne': handleSingle"," , '$in': handleArray"," , '$nin': handleArray","};","SchemaString.prototype.castForQuery = function ($conditional, val) {"," var handler;"," if (arguments.length === 2) {"," handler = this.$conditionalHandlers[$conditional];"," if (!handler)"," throw new Error(\"Can't use \" + $conditional + \" with String.\");"," return handler.call(this, val);"," } else {"," val = $conditional;"," if (val instanceof RegExp) return val;"," return this.cast(val);"," }","};","","/**"," * Module exports."," */","","module.exports = SchemaString;"];

@@ -17,44 +17,43 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/schematype.js'][25] = 0;
_$jscoverage['mongoose/schematype.js'][26] = 0;
_$jscoverage['mongoose/schematype.js'][28] = 0;
_$jscoverage['mongoose/schematype.js'][36] = 0;
_$jscoverage['mongoose/schematype.js'][27] = 0;
_$jscoverage['mongoose/schematype.js'][35] = 0;
_$jscoverage['mongoose/schematype.js'][44] = 0;
_$jscoverage['mongoose/schematype.js'][45] = 0;
_$jscoverage['mongoose/schematype.js'][46] = 0;
_$jscoverage['mongoose/schematype.js'][47] = 0;
_$jscoverage['mongoose/schematype.js'][48] = 0;
_$jscoverage['mongoose/schematype.js'][49] = 0;
_$jscoverage['mongoose/schematype.js'][50] = 0;
_$jscoverage['mongoose/schematype.js'][52] = 0;
_$jscoverage['mongoose/schematype.js'][68] = 0;
_$jscoverage['mongoose/schematype.js'][51] = 0;
_$jscoverage['mongoose/schematype.js'][53] = 0;
_$jscoverage['mongoose/schematype.js'][69] = 0;
_$jscoverage['mongoose/schematype.js'][70] = 0;
_$jscoverage['mongoose/schematype.js'][80] = 0;
_$jscoverage['mongoose/schematype.js'][71] = 0;
_$jscoverage['mongoose/schematype.js'][81] = 0;
_$jscoverage['mongoose/schematype.js'][82] = 0;
_$jscoverage['mongoose/schematype.js'][92] = 0;
_$jscoverage['mongoose/schematype.js'][83] = 0;
_$jscoverage['mongoose/schematype.js'][93] = 0;
_$jscoverage['mongoose/schematype.js'][94] = 0;
_$jscoverage['mongoose/schematype.js'][104] = 0;
_$jscoverage['mongoose/schematype.js'][95] = 0;
_$jscoverage['mongoose/schematype.js'][105] = 0;
_$jscoverage['mongoose/schematype.js'][106] = 0;
_$jscoverage['mongoose/schematype.js'][117] = 0;
_$jscoverage['mongoose/schematype.js'][107] = 0;
_$jscoverage['mongoose/schematype.js'][118] = 0;
_$jscoverage['mongoose/schematype.js'][119] = 0;
_$jscoverage['mongoose/schematype.js'][129] = 0;
_$jscoverage['mongoose/schematype.js'][120] = 0;
_$jscoverage['mongoose/schematype.js'][130] = 0;
_$jscoverage['mongoose/schematype.js'][131] = 0;
_$jscoverage['mongoose/schematype.js'][132] = 0;
_$jscoverage['mongoose/schematype.js'][133] = 0;
_$jscoverage['mongoose/schematype.js'][134] = 0;
_$jscoverage['mongoose/schematype.js'][137] = 0;
_$jscoverage['mongoose/schematype.js'][135] = 0;
_$jscoverage['mongoose/schematype.js'][136] = 0;
_$jscoverage['mongoose/schematype.js'][139] = 0;
_$jscoverage['mongoose/schematype.js'][149] = 0;
_$jscoverage['mongoose/schematype.js'][150] = 0;
_$jscoverage['mongoose/schematype.js'][141] = 0;
_$jscoverage['mongoose/schematype.js'][151] = 0;
_$jscoverage['mongoose/schematype.js'][153] = 0;
_$jscoverage['mongoose/schematype.js'][152] = 0;
_$jscoverage['mongoose/schematype.js'][154] = 0;
_$jscoverage['mongoose/schematype.js'][155] = 0;
_$jscoverage['mongoose/schematype.js'][156] = 0;
_$jscoverage['mongoose/schematype.js'][158] = 0;
_$jscoverage['mongoose/schematype.js'][157] = 0;
_$jscoverage['mongoose/schematype.js'][159] = 0;
_$jscoverage['mongoose/schematype.js'][160] = 0;
_$jscoverage['mongoose/schematype.js'][161] = 0;
_$jscoverage['mongoose/schematype.js'][163] = 0;
_$jscoverage['mongoose/schematype.js'][162] = 0;
_$jscoverage['mongoose/schematype.js'][173] = 0;
_$jscoverage['mongoose/schematype.js'][174] = 0;

@@ -65,4 +64,4 @@ _$jscoverage['mongoose/schematype.js'][175] = 0;

_$jscoverage['mongoose/schematype.js'][178] = 0;
_$jscoverage['mongoose/schematype.js'][179] = 0;
_$jscoverage['mongoose/schematype.js'][181] = 0;
_$jscoverage['mongoose/schematype.js'][180] = 0;
_$jscoverage['mongoose/schematype.js'][191] = 0;
_$jscoverage['mongoose/schematype.js'][192] = 0;

@@ -73,15 +72,15 @@ _$jscoverage['mongoose/schematype.js'][193] = 0;

_$jscoverage['mongoose/schematype.js'][196] = 0;
_$jscoverage['mongoose/schematype.js'][197] = 0;
_$jscoverage['mongoose/schematype.js'][199] = 0;
_$jscoverage['mongoose/schematype.js'][198] = 0;
_$jscoverage['mongoose/schematype.js'][209] = 0;
_$jscoverage['mongoose/schematype.js'][210] = 0;
_$jscoverage['mongoose/schematype.js'][211] = 0;
_$jscoverage['mongoose/schematype.js'][215] = 0;
_$jscoverage['mongoose/schematype.js'][214] = 0;
_$jscoverage['mongoose/schematype.js'][216] = 0;
_$jscoverage['mongoose/schematype.js'][217] = 0;
_$jscoverage['mongoose/schematype.js'][218] = 0;
_$jscoverage['mongoose/schematype.js'][219] = 0;
_$jscoverage['mongoose/schematype.js'][220] = 0;
_$jscoverage['mongoose/schematype.js'][221] = 0;
_$jscoverage['mongoose/schematype.js'][222] = 0;
_$jscoverage['mongoose/schematype.js'][223] = 0;
_$jscoverage['mongoose/schematype.js'][226] = 0;
_$jscoverage['mongoose/schematype.js'][227] = 0;
_$jscoverage['mongoose/schematype.js'][228] = 0;
_$jscoverage['mongoose/schematype.js'][229] = 0;
_$jscoverage['mongoose/schematype.js'][230] = 0;

@@ -92,4 +91,4 @@ _$jscoverage['mongoose/schematype.js'][231] = 0;

_$jscoverage['mongoose/schematype.js'][234] = 0;
_$jscoverage['mongoose/schematype.js'][235] = 0;
_$jscoverage['mongoose/schematype.js'][238] = 0;
_$jscoverage['mongoose/schematype.js'][237] = 0;
_$jscoverage['mongoose/schematype.js'][249] = 0;
_$jscoverage['mongoose/schematype.js'][250] = 0;

@@ -100,4 +99,4 @@ _$jscoverage['mongoose/schematype.js'][251] = 0;

_$jscoverage['mongoose/schematype.js'][254] = 0;
_$jscoverage['mongoose/schematype.js'][255] = 0;
_$jscoverage['mongoose/schematype.js'][261] = 0;
_$jscoverage['mongoose/schematype.js'][260] = 0;
_$jscoverage['mongoose/schematype.js'][268] = 0;
_$jscoverage['mongoose/schematype.js'][269] = 0;

@@ -110,7 +109,6 @@ _$jscoverage['mongoose/schematype.js'][270] = 0;

_$jscoverage['mongoose/schematype.js'][275] = 0;
_$jscoverage['mongoose/schematype.js'][276] = 0;
_$jscoverage['mongoose/schematype.js'][282] = 0;
_$jscoverage['mongoose/schematype.js'][288] = 0;
_$jscoverage['mongoose/schematype.js'][290] = 0;
_$jscoverage['mongoose/schematype.js'][292] = 0;
_$jscoverage['mongoose/schematype.js'][281] = 0;
_$jscoverage['mongoose/schematype.js'][287] = 0;
_$jscoverage['mongoose/schematype.js'][289] = 0;
_$jscoverage['mongoose/schematype.js'][291] = 0;
}

@@ -124,20 +122,18 @@ _$jscoverage['mongoose/schematype.js'][6]++;

_$jscoverage['mongoose/schematype.js'][17]++;
this.defaultValue = null;
this.validators = [];
_$jscoverage['mongoose/schematype.js'][18]++;
this.validators = [];
this.setters = [];
_$jscoverage['mongoose/schematype.js'][19]++;
this.setters = [];
this.getters = [];
_$jscoverage['mongoose/schematype.js'][20]++;
this.getters = [];
this.options = options;
_$jscoverage['mongoose/schematype.js'][21]++;
this.options = options;
this._index = null;
_$jscoverage['mongoose/schematype.js'][22]++;
this._index = null;
_$jscoverage['mongoose/schematype.js'][23]++;
for (var i in options) {
_$jscoverage['mongoose/schematype.js'][24]++;
_$jscoverage['mongoose/schematype.js'][23]++;
if (this[i] && "function" == typeof this[i]) {
_$jscoverage['mongoose/schematype.js'][24]++;
var opts = Array.isArray(options[i])? options[i]: [options[i]];
_$jscoverage['mongoose/schematype.js'][25]++;
var opts = Array.isArray(options[i])? options[i]: [options[i]];
_$jscoverage['mongoose/schematype.js'][26]++;
this[i].apply(this, opts);

@@ -147,69 +143,71 @@ }

}
_$jscoverage['mongoose/schematype.js'][28]++;
_$jscoverage['mongoose/schematype.js'][27]++;
;
_$jscoverage['mongoose/schematype.js'][36]++;
_$jscoverage['mongoose/schematype.js'][35]++;
SchemaType.prototype.base;
_$jscoverage['mongoose/schematype.js'][45]++;
_$jscoverage['mongoose/schematype.js'][44]++;
SchemaType.prototype["default"] = (function (val) {
_$jscoverage['mongoose/schematype.js'][46]++;
_$jscoverage['mongoose/schematype.js'][45]++;
if (arguments.length === 1) {
_$jscoverage['mongoose/schematype.js'][47]++;
this.defaultValue = val;
_$jscoverage['mongoose/schematype.js'][48]++;
_$jscoverage['mongoose/schematype.js'][46]++;
this.defaultValue = (typeof val === "function")? val: this.cast(val);
_$jscoverage['mongoose/schematype.js'][49]++;
return this;
}
else {
_$jscoverage['mongoose/schematype.js'][49]++;
_$jscoverage['mongoose/schematype.js'][50]++;
if (arguments.length > 1) {
_$jscoverage['mongoose/schematype.js'][50]++;
_$jscoverage['mongoose/schematype.js'][51]++;
this.defaultValue = [].slice.call(arguments);
}
}
_$jscoverage['mongoose/schematype.js'][52]++;
_$jscoverage['mongoose/schematype.js'][53]++;
return this.defaultValue;
});
_$jscoverage['mongoose/schematype.js'][68]++;
_$jscoverage['mongoose/schematype.js'][69]++;
SchemaType.prototype.index = (function (index) {
_$jscoverage['mongoose/schematype.js'][69]++;
_$jscoverage['mongoose/schematype.js'][70]++;
this._index = index;
_$jscoverage['mongoose/schematype.js'][70]++;
_$jscoverage['mongoose/schematype.js'][71]++;
return this;
});
_$jscoverage['mongoose/schematype.js'][80]++;
_$jscoverage['mongoose/schematype.js'][81]++;
SchemaType.prototype.unique = (function (bool) {
_$jscoverage['mongoose/schematype.js'][81]++;
_$jscoverage['mongoose/schematype.js'][82]++;
this._index = bool? {unique: true}: null;
_$jscoverage['mongoose/schematype.js'][82]++;
_$jscoverage['mongoose/schematype.js'][83]++;
return this;
});
_$jscoverage['mongoose/schematype.js'][92]++;
_$jscoverage['mongoose/schematype.js'][93]++;
SchemaType.prototype.set = (function (fn) {
_$jscoverage['mongoose/schematype.js'][93]++;
_$jscoverage['mongoose/schematype.js'][94]++;
this.setters.push(fn);
_$jscoverage['mongoose/schematype.js'][94]++;
_$jscoverage['mongoose/schematype.js'][95]++;
return this;
});
_$jscoverage['mongoose/schematype.js'][104]++;
_$jscoverage['mongoose/schematype.js'][105]++;
SchemaType.prototype.get = (function (fn) {
_$jscoverage['mongoose/schematype.js'][105]++;
_$jscoverage['mongoose/schematype.js'][106]++;
this.getters.push(fn);
_$jscoverage['mongoose/schematype.js'][106]++;
_$jscoverage['mongoose/schematype.js'][107]++;
return this;
});
_$jscoverage['mongoose/schematype.js'][117]++;
_$jscoverage['mongoose/schematype.js'][118]++;
SchemaType.prototype.validate = (function (obj, error) {
_$jscoverage['mongoose/schematype.js'][118]++;
_$jscoverage['mongoose/schematype.js'][119]++;
this.validators.push([obj, error]);
_$jscoverage['mongoose/schematype.js'][119]++;
_$jscoverage['mongoose/schematype.js'][120]++;
return this;
});
_$jscoverage['mongoose/schematype.js'][129]++;
_$jscoverage['mongoose/schematype.js'][130]++;
SchemaType.prototype.required = (function (required) {
_$jscoverage['mongoose/schematype.js'][130]++;
_$jscoverage['mongoose/schematype.js'][131]++;
var checkRequired = this.checkRequired.bind(this);
_$jscoverage['mongoose/schematype.js'][132]++;
this.isRequired = true;
_$jscoverage['mongoose/schematype.js'][134]++;
if (false === required) {
_$jscoverage['mongoose/schematype.js'][133]++;
_$jscoverage['mongoose/schematype.js'][135]++;
this.validators = this.validators.filter((function (v) {
_$jscoverage['mongoose/schematype.js'][134]++;
_$jscoverage['mongoose/schematype.js'][136]++;
return v[0] !== checkRequired;

@@ -219,117 +217,112 @@ }));

else {
_$jscoverage['mongoose/schematype.js'][137]++;
_$jscoverage['mongoose/schematype.js'][139]++;
this.validators.push([checkRequired, "required"]);
}
_$jscoverage['mongoose/schematype.js'][139]++;
_$jscoverage['mongoose/schematype.js'][141]++;
return this;
});
_$jscoverage['mongoose/schematype.js'][149]++;
_$jscoverage['mongoose/schematype.js'][151]++;
SchemaType.prototype.getDefault = (function (scope) {
_$jscoverage['mongoose/schematype.js'][150]++;
if (this.defaultValue === undefined) {
_$jscoverage['mongoose/schematype.js'][151]++;
return null;
}
_$jscoverage['mongoose/schematype.js'][153]++;
_$jscoverage['mongoose/schematype.js'][152]++;
var ret;
_$jscoverage['mongoose/schematype.js'][155]++;
_$jscoverage['mongoose/schematype.js'][154]++;
if ("function" == typeof this.defaultValue) {
_$jscoverage['mongoose/schematype.js'][156]++;
_$jscoverage['mongoose/schematype.js'][155]++;
ret = this.defaultValue.call(scope);
}
else {
_$jscoverage['mongoose/schematype.js'][158]++;
_$jscoverage['mongoose/schematype.js'][157]++;
ret = this.defaultValue;
}
_$jscoverage['mongoose/schematype.js'][160]++;
_$jscoverage['mongoose/schematype.js'][159]++;
if (ret !== null && ret !== undefined) {
_$jscoverage['mongoose/schematype.js'][161]++;
_$jscoverage['mongoose/schematype.js'][160]++;
ret = this.cast(ret, scope);
}
_$jscoverage['mongoose/schematype.js'][163]++;
_$jscoverage['mongoose/schematype.js'][162]++;
return ret;
});
_$jscoverage['mongoose/schematype.js'][174]++;
_$jscoverage['mongoose/schematype.js'][173]++;
SchemaType.prototype.applySetters = (function (value, scope) {
_$jscoverage['mongoose/schematype.js'][174]++;
var v = value;
_$jscoverage['mongoose/schematype.js'][175]++;
var v = value;
_$jscoverage['mongoose/schematype.js'][176]++;
for (var l = this.setters.length - 1; l >= 0; l--) {
_$jscoverage['mongoose/schematype.js'][176]++;
v = this.setters[l].call(scope, v);
_$jscoverage['mongoose/schematype.js'][177]++;
v = this.setters[l].call(scope, v);
_$jscoverage['mongoose/schematype.js'][178]++;
if (v === null || v === undefined) {
_$jscoverage['mongoose/schematype.js'][178]++;
_$jscoverage['mongoose/schematype.js'][177]++;
return v;
}
_$jscoverage['mongoose/schematype.js'][179]++;
_$jscoverage['mongoose/schematype.js'][178]++;
v = this.cast(v, scope);
}
_$jscoverage['mongoose/schematype.js'][181]++;
_$jscoverage['mongoose/schematype.js'][180]++;
return v;
});
_$jscoverage['mongoose/schematype.js'][192]++;
_$jscoverage['mongoose/schematype.js'][191]++;
SchemaType.prototype.applyGetters = (function (value, scope) {
_$jscoverage['mongoose/schematype.js'][192]++;
var v = value;
_$jscoverage['mongoose/schematype.js'][193]++;
var v = value;
_$jscoverage['mongoose/schematype.js'][194]++;
for (var l = this.getters.length - 1; l >= 0; l--) {
_$jscoverage['mongoose/schematype.js'][194]++;
v = this.getters[l].call(scope, v);
_$jscoverage['mongoose/schematype.js'][195]++;
v = this.getters[l].call(scope, v);
_$jscoverage['mongoose/schematype.js'][196]++;
if (v === null || v === undefined) {
_$jscoverage['mongoose/schematype.js'][196]++;
_$jscoverage['mongoose/schematype.js'][195]++;
return v;
}
_$jscoverage['mongoose/schematype.js'][197]++;
_$jscoverage['mongoose/schematype.js'][196]++;
v = this.cast(v, scope);
}
_$jscoverage['mongoose/schematype.js'][199]++;
_$jscoverage['mongoose/schematype.js'][198]++;
return v;
});
_$jscoverage['mongoose/schematype.js'][210]++;
_$jscoverage['mongoose/schematype.js'][209]++;
SchemaType.prototype.doValidate = (function (value, fn, scope) {
_$jscoverage['mongoose/schematype.js'][211]++;
_$jscoverage['mongoose/schematype.js'][210]++;
var err = false, path = this.path, count = this.validators.length;
_$jscoverage['mongoose/schematype.js'][215]++;
_$jscoverage['mongoose/schematype.js'][214]++;
if (! count) {
_$jscoverage['mongoose/schematype.js'][215]++;
_$jscoverage['mongoose/schematype.js'][214]++;
return fn(null);
}
_$jscoverage['mongoose/schematype.js'][217]++;
_$jscoverage['mongoose/schematype.js'][216]++;
function validate(val, msg) {
_$jscoverage['mongoose/schematype.js'][218]++;
_$jscoverage['mongoose/schematype.js'][217]++;
if (err) {
_$jscoverage['mongoose/schematype.js'][218]++;
_$jscoverage['mongoose/schematype.js'][217]++;
return;
}
_$jscoverage['mongoose/schematype.js'][219]++;
_$jscoverage['mongoose/schematype.js'][218]++;
if (val === undefined || val) {
_$jscoverage['mongoose/schematype.js'][220]++;
_$jscoverage['mongoose/schematype.js'][219]++;
--count || fn(null);
}
else {
_$jscoverage['mongoose/schematype.js'][221]++;
fn(new ValidatorError(path, msg));
_$jscoverage['mongoose/schematype.js'][222]++;
fn(new ValidatorError(path, msg));
_$jscoverage['mongoose/schematype.js'][223]++;
err = true;
}
}
_$jscoverage['mongoose/schematype.js'][226]++;
this.validators.forEach((function (v) {
_$jscoverage['mongoose/schematype.js'][227]++;
this.validators.forEach((function (v) {
_$jscoverage['mongoose/schematype.js'][228]++;
var validator = v[0], message = v[1];
_$jscoverage['mongoose/schematype.js'][230]++;
_$jscoverage['mongoose/schematype.js'][229]++;
if (validator instanceof RegExp) {
_$jscoverage['mongoose/schematype.js'][231]++;
_$jscoverage['mongoose/schematype.js'][230]++;
validate(validator.test(value), message);
}
else {
_$jscoverage['mongoose/schematype.js'][232]++;
_$jscoverage['mongoose/schematype.js'][231]++;
if ("function" == typeof validator) {
_$jscoverage['mongoose/schematype.js'][233]++;
_$jscoverage['mongoose/schematype.js'][232]++;
if (2 == validator.length) {
_$jscoverage['mongoose/schematype.js'][234]++;
_$jscoverage['mongoose/schematype.js'][233]++;
validator.call(scope, value, (function (val) {
_$jscoverage['mongoose/schematype.js'][235]++;
_$jscoverage['mongoose/schematype.js'][234]++;
validate(val, message);

@@ -339,3 +332,3 @@ }));

else {
_$jscoverage['mongoose/schematype.js'][238]++;
_$jscoverage['mongoose/schematype.js'][237]++;
validate(validator.call(scope, value), message);

@@ -347,42 +340,42 @@ }

});
_$jscoverage['mongoose/schematype.js'][250]++;
_$jscoverage['mongoose/schematype.js'][249]++;
function ValidatorError(path, msg) {
_$jscoverage['mongoose/schematype.js'][250]++;
MongooseError.call(this, "Validator \"" + msg + "\" failed for path " + path);
_$jscoverage['mongoose/schematype.js'][251]++;
MongooseError.call(this, "Validator \"" + msg + "\" failed for path " + path);
Error.captureStackTrace(this, arguments.callee);
_$jscoverage['mongoose/schematype.js'][252]++;
Error.captureStackTrace(this, arguments.callee);
this.name = "ValidatorError";
_$jscoverage['mongoose/schematype.js'][253]++;
this.name = "ValidatorError";
_$jscoverage['mongoose/schematype.js'][254]++;
this.path = path;
}
_$jscoverage['mongoose/schematype.js'][255]++;
_$jscoverage['mongoose/schematype.js'][254]++;
;
_$jscoverage['mongoose/schematype.js'][261]++;
_$jscoverage['mongoose/schematype.js'][260]++;
ValidatorError.prototype.__proto__ = MongooseError.prototype;
_$jscoverage['mongoose/schematype.js'][269]++;
_$jscoverage['mongoose/schematype.js'][268]++;
function CastError(type, path, type, value) {
_$jscoverage['mongoose/schematype.js'][269]++;
MongooseError.call(this, "Cast to " + type + " failed for value \"" + value + "\"");
_$jscoverage['mongoose/schematype.js'][270]++;
MongooseError.call(this, "Cast to " + type + " failed for value \"" + value + "\"");
Error.captureStackTrace(this, arguments.callee);
_$jscoverage['mongoose/schematype.js'][271]++;
Error.captureStackTrace(this, arguments.callee);
this.name = "CastError";
_$jscoverage['mongoose/schematype.js'][272]++;
this.name = "CastError";
this.path = path;
_$jscoverage['mongoose/schematype.js'][273]++;
this.path = path;
this.type = type;
_$jscoverage['mongoose/schematype.js'][274]++;
this.type = type;
_$jscoverage['mongoose/schematype.js'][275]++;
this.value = value;
}
_$jscoverage['mongoose/schematype.js'][276]++;
_$jscoverage['mongoose/schematype.js'][275]++;
;
_$jscoverage['mongoose/schematype.js'][282]++;
_$jscoverage['mongoose/schematype.js'][281]++;
CastError.prototype.__proto__ = MongooseError.prototype;
_$jscoverage['mongoose/schematype.js'][288]++;
_$jscoverage['mongoose/schematype.js'][287]++;
module.exports = exports = SchemaType;
_$jscoverage['mongoose/schematype.js'][290]++;
_$jscoverage['mongoose/schematype.js'][289]++;
exports.CastError = CastError;
_$jscoverage['mongoose/schematype.js'][292]++;
_$jscoverage['mongoose/schematype.js'][291]++;
exports.ValidatorError = ValidatorError;
_$jscoverage['mongoose/schematype.js'].source = ["","/**"," * Module dependencies."," */","","var MongooseError = require('./error');","","/**"," * SchemaType constructor"," *"," * @param {String} path"," * @api public"," */","","function SchemaType (path, options) {"," this.path = path;"," this.defaultValue = null;"," this.validators = [];"," this.setters = [];"," this.getters = [];"," this.options = options;"," this._index = null;"," for (var i in options)"," if (this[i] &amp;&amp; 'function' == typeof this[i]){"," var opts = Array.isArray(options[i]) ? options[i] : [options[i]];"," this[i].apply(this, opts);"," }","};","","/**"," * Base schema. Set by Schema when instantiated."," *"," * @api private"," */","","SchemaType.prototype.base;","","/**"," * Sets a default"," *"," * @param {Object} default value"," * @api public"," */","","SchemaType.prototype.default = function (val) {"," if (arguments.length === 1){"," this.defaultValue = val;"," return this;"," } else if (arguments.length &gt; 1) {"," this.defaultValue = [].slice.call(arguments);"," }"," return this.defaultValue;","};","","/**"," * Sets index. It can be a boolean or a hash of options"," * Example:"," * Schema.path('my.path').index(true);"," * Schema.path('my.path').index({ unique: true });"," *"," * \"Direction doesn't matter for single key indexes\""," * http://www.mongodb.org/display/DOCS/Indexes#Indexes-CompoundKeysIndexes"," *"," * @param {Object} true/"," * @api public"," */","","SchemaType.prototype.index = function (index) {"," this._index = index;"," return this;","};","","/**"," * Adds an unique index"," *"," * @param {Boolean}"," * @api private"," */","","SchemaType.prototype.unique = function (bool) {"," this._index = bool ? { unique: true } : null;"," return this;","};","","/**"," * Adds a setter"," *"," * @param {Function} setter"," * @api public"," */","","SchemaType.prototype.set = function (fn) {"," this.setters.push(fn);"," return this;","};","","/**"," * Adds a getter"," *"," * @param {Function} getter"," * @api public"," */","","SchemaType.prototype.get = function (fn) {"," this.getters.push(fn);"," return this;","};","","/**"," * Adds a validator"," *"," * @param {Object} validator"," * @param {String} optional error message"," * @api public"," */","","SchemaType.prototype.validate = function(obj, error){"," this.validators.push([obj, error]);"," return this;","};","","/**"," * Adds a required validator"," *"," * @param {Boolean} enable/disable the validator"," * @api public"," */","","SchemaType.prototype.required = function(required){"," var checkRequired = this.checkRequired.bind(this);",""," if (false === required){"," this.validators = this.validators.filter(function(v){"," return v[0] !== checkRequired;"," });"," } else "," this.validators.push([checkRequired, 'required']);",""," return this;","};","","/**"," * Gets the default value"," *"," * @param {Object} scope for callback defaults"," * @api private"," */","","SchemaType.prototype.getDefault = function (scope) {"," if (this.defaultValue === undefined)"," return null;",""," var ret;",""," if ('function' == typeof this.defaultValue)"," ret = this.defaultValue.call(scope);"," else"," ret = this.defaultValue;",""," if (ret !== null &amp;&amp; ret !== undefined)"," ret = this.cast(ret, scope);",""," return ret;","};","","/**"," * Applies setters"," *"," * @param {Object} value"," * @param {Object} scope"," * @api private"," */","","SchemaType.prototype.applySetters = function (value, scope) {"," var v = value;"," for (var l = this.setters.length - 1; l &gt;= 0; l--){"," v = this.setters[l].call(scope, v);"," if (v === null || v === undefined) return v;"," v = this.cast(v, scope);"," }"," return v;","};","","/**"," * Applies getters to a value"," *"," * @param {Object} value"," * @param {Object} scope"," * @api private"," */","","SchemaType.prototype.applyGetters = function (value, scope) {"," var v = value;"," for (var l = this.getters.length - 1; l &gt;= 0; l--){"," v = this.getters[l].call(scope, v);"," if (v === null || v === undefined) return v;"," v = this.cast(v, scope);"," }"," return v;","};","","/**"," * Performs a validation"," *"," * @param {Function} callback"," * @param {Object} scope"," * @api private"," */","","SchemaType.prototype.doValidate = function (value, fn, scope) {"," var err = false"," , path = this.path"," , count = this.validators.length;",""," if (!count) return fn(null);",""," function validate (val, msg) {"," if (err) return;"," if (val === undefined || val) {"," --count || fn(null);"," } else {"," fn(new ValidatorError(path, msg));"," err = true;"," }"," }",""," this.validators.forEach(function (v){"," var validator = v[0]"," , message = v[1];"," if (validator instanceof RegExp)"," validate(validator.test(value), message);"," else if ('function' == typeof validator)"," if (2 == validator.length)"," validator.call(scope, value, function(val){"," validate(val, message);"," })"," else"," validate(validator.call(scope, value), message);"," });","};","","/**"," * Validator error"," *"," * @param {String} path"," * @param {String} msg"," * @api private"," */","","function ValidatorError (path, msg) {"," MongooseError.call(this, 'Validator \"' + msg + '\" failed for path ' + path);"," Error.captureStackTrace(this, arguments.callee);"," this.name = 'ValidatorError';"," this.path = path;","};","","/**"," * Inherits from MongooseError"," */","","ValidatorError.prototype.__proto__ = MongooseError.prototype;","","/**"," * Cast error"," *"," * @api private"," */","","function CastError (type, path, type, value) {"," MongooseError.call(this, 'Cast to ' + type + ' failed for value \"' + value + '\"');"," Error.captureStackTrace(this, arguments.callee);"," this.name = 'CastError';"," this.path = path;"," this.type = type;"," this.value = value;","};","","/**"," * Inherits from MongooseError."," */","","CastError.prototype.__proto__ = MongooseError.prototype;","","/**"," * Module exports."," */","","module.exports = exports = SchemaType;","","exports.CastError = CastError;","","exports.ValidatorError = ValidatorError;"];
_$jscoverage['mongoose/schematype.js'].source = ["","/**"," * Module dependencies."," */","","var MongooseError = require('./error');","","/**"," * SchemaType constructor"," *"," * @param {String} path"," * @api public"," */","","function SchemaType (path, options) {"," this.path = path;"," this.validators = [];"," this.setters = [];"," this.getters = [];"," this.options = options;"," this._index = null;"," for (var i in options)"," if (this[i] &amp;&amp; 'function' == typeof this[i]){"," var opts = Array.isArray(options[i]) ? options[i] : [options[i]];"," this[i].apply(this, opts);"," }","};","","/**"," * Base schema. Set by Schema when instantiated."," *"," * @api private"," */","","SchemaType.prototype.base;","","/**"," * Sets a default"," *"," * @param {Object} default value"," * @api public"," */","","SchemaType.prototype.default = function (val) {"," if (arguments.length === 1) {"," this.defaultValue = (typeof val === 'function')"," ? val"," : this.cast(val);"," return this;"," } else if (arguments.length &gt; 1) {"," this.defaultValue = [].slice.call(arguments);"," }"," return this.defaultValue;","};","","/**"," * Sets index. It can be a boolean or a hash of options"," * Example:"," * Schema.path('my.path').index(true);"," * Schema.path('my.path').index({ unique: true });"," *"," * \"Direction doesn't matter for single key indexes\""," * http://www.mongodb.org/display/DOCS/Indexes#Indexes-CompoundKeysIndexes"," *"," * @param {Object} true/"," * @api public"," */","","SchemaType.prototype.index = function (index) {"," this._index = index;"," return this;","};","","/**"," * Adds an unique index"," *"," * @param {Boolean}"," * @api private"," */","","SchemaType.prototype.unique = function (bool) {"," this._index = bool ? { unique: true } : null;"," return this;","};","","/**"," * Adds a setter"," *"," * @param {Function} setter"," * @api public"," */","","SchemaType.prototype.set = function (fn) {"," this.setters.push(fn);"," return this;","};","","/**"," * Adds a getter"," *"," * @param {Function} getter"," * @api public"," */","","SchemaType.prototype.get = function (fn) {"," this.getters.push(fn);"," return this;","};","","/**"," * Adds a validator"," *"," * @param {Object} validator"," * @param {String} optional error message"," * @api public"," */","","SchemaType.prototype.validate = function(obj, error){"," this.validators.push([obj, error]);"," return this;","};","","/**"," * Adds a required validator"," *"," * @param {Boolean} enable/disable the validator"," * @api public"," */","","SchemaType.prototype.required = function(required){"," var checkRequired = this.checkRequired.bind(this);"," this.isRequired = true;",""," if (false === required){"," this.validators = this.validators.filter(function(v){"," return v[0] !== checkRequired;"," });"," } else "," this.validators.push([checkRequired, 'required']);",""," return this;","};","","/**"," * Gets the default value"," *"," * @param {Object} scope for callback defaults"," * @api private"," */","","SchemaType.prototype.getDefault = function (scope) {"," var ret;",""," if ('function' == typeof this.defaultValue)"," ret = this.defaultValue.call(scope);"," else"," ret = this.defaultValue;",""," if (ret !== null &amp;&amp; ret !== undefined)"," ret = this.cast(ret, scope);",""," return ret;","};","","/**"," * Applies setters"," *"," * @param {Object} value"," * @param {Object} scope"," * @api private"," */","","SchemaType.prototype.applySetters = function (value, scope) {"," var v = value;"," for (var l = this.setters.length - 1; l &gt;= 0; l--){"," v = this.setters[l].call(scope, v);"," if (v === null || v === undefined) return v;"," v = this.cast(v, scope);"," }"," return v;","};","","/**"," * Applies getters to a value"," *"," * @param {Object} value"," * @param {Object} scope"," * @api private"," */","","SchemaType.prototype.applyGetters = function (value, scope) {"," var v = value;"," for (var l = this.getters.length - 1; l &gt;= 0; l--){"," v = this.getters[l].call(scope, v);"," if (v === null || v === undefined) return v;"," v = this.cast(v, scope);"," }"," return v;","};","","/**"," * Performs a validation"," *"," * @param {Function} callback"," * @param {Object} scope"," * @api private"," */","","SchemaType.prototype.doValidate = function (value, fn, scope) {"," var err = false"," , path = this.path"," , count = this.validators.length;",""," if (!count) return fn(null);",""," function validate (val, msg) {"," if (err) return;"," if (val === undefined || val) {"," --count || fn(null);"," } else {"," fn(new ValidatorError(path, msg));"," err = true;"," }"," }",""," this.validators.forEach(function (v){"," var validator = v[0]"," , message = v[1];"," if (validator instanceof RegExp)"," validate(validator.test(value), message);"," else if ('function' == typeof validator)"," if (2 == validator.length)"," validator.call(scope, value, function(val){"," validate(val, message);"," })"," else"," validate(validator.call(scope, value), message);"," });","};","","/**"," * Validator error"," *"," * @param {String} path"," * @param {String} msg"," * @api private"," */","","function ValidatorError (path, msg) {"," MongooseError.call(this, 'Validator \"' + msg + '\" failed for path ' + path);"," Error.captureStackTrace(this, arguments.callee);"," this.name = 'ValidatorError';"," this.path = path;","};","","/**"," * Inherits from MongooseError"," */","","ValidatorError.prototype.__proto__ = MongooseError.prototype;","","/**"," * Cast error"," *"," * @api private"," */","","function CastError (type, path, type, value) {"," MongooseError.call(this, 'Cast to ' + type + ' failed for value \"' + value + '\"');"," Error.captureStackTrace(this, arguments.callee);"," this.name = 'CastError';"," this.path = path;"," this.type = type;"," this.value = value;","};","","/**"," * Inherits from MongooseError."," */","","CastError.prototype.__proto__ = MongooseError.prototype;","","/**"," * Module exports."," */","","module.exports = exports = SchemaType;","","exports.CastError = CastError;","","exports.ValidatorError = ValidatorError;"];

@@ -29,8 +29,2 @@ /* automatically generated by JSCoverage - do not edit */

_$jscoverage['mongoose/utils.js'][134] = 0;
_$jscoverage['mongoose/utils.js'][144] = 0;
_$jscoverage['mongoose/utils.js'][145] = 0;
_$jscoverage['mongoose/utils.js'][146] = 0;
_$jscoverage['mongoose/utils.js'][147] = 0;
_$jscoverage['mongoose/utils.js'][148] = 0;
_$jscoverage['mongoose/utils.js'][149] = 0;
_$jscoverage['mongoose/utils.js'][150] = 0;

@@ -40,10 +34,8 @@ _$jscoverage['mongoose/utils.js'][151] = 0;

_$jscoverage['mongoose/utils.js'][153] = 0;
_$jscoverage['mongoose/utils.js'][155] = 0;
_$jscoverage['mongoose/utils.js'][156] = 0;
_$jscoverage['mongoose/utils.js'][157] = 0;
_$jscoverage['mongoose/utils.js'][154] = 0;
_$jscoverage['mongoose/utils.js'][158] = 0;
_$jscoverage['mongoose/utils.js'][159] = 0;
_$jscoverage['mongoose/utils.js'][160] = 0;
_$jscoverage['mongoose/utils.js'][161] = 0;
_$jscoverage['mongoose/utils.js'][163] = 0;
_$jscoverage['mongoose/utils.js'][164] = 0;
_$jscoverage['mongoose/utils.js'][165] = 0;

@@ -53,10 +45,13 @@ _$jscoverage['mongoose/utils.js'][166] = 0;

_$jscoverage['mongoose/utils.js'][168] = 0;
_$jscoverage['mongoose/utils.js'][170] = 0;
_$jscoverage['mongoose/utils.js'][171] = 0;
_$jscoverage['mongoose/utils.js'][169] = 0;
_$jscoverage['mongoose/utils.js'][172] = 0;
_$jscoverage['mongoose/utils.js'][173] = 0;
_$jscoverage['mongoose/utils.js'][174] = 0;
_$jscoverage['mongoose/utils.js'][175] = 0;
_$jscoverage['mongoose/utils.js'][176] = 0;
_$jscoverage['mongoose/utils.js'][177] = 0;
_$jscoverage['mongoose/utils.js'][178] = 0;
_$jscoverage['mongoose/utils.js'][179] = 0;
_$jscoverage['mongoose/utils.js'][180] = 0;
_$jscoverage['mongoose/utils.js'][183] = 0;
_$jscoverage['mongoose/utils.js'][186] = 0;
_$jscoverage['mongoose/utils.js'][187] = 0;
_$jscoverage['mongoose/utils.js'][188] = 0;
_$jscoverage['mongoose/utils.js'][189] = 0;

@@ -66,55 +61,67 @@ _$jscoverage['mongoose/utils.js'][190] = 0;

_$jscoverage['mongoose/utils.js'][192] = 0;
_$jscoverage['mongoose/utils.js'][193] = 0;
_$jscoverage['mongoose/utils.js'][204] = 0;
_$jscoverage['mongoose/utils.js'][205] = 0;
_$jscoverage['mongoose/utils.js'][206] = 0;
_$jscoverage['mongoose/utils.js'][215] = 0;
_$jscoverage['mongoose/utils.js'][216] = 0;
_$jscoverage['mongoose/utils.js'][227] = 0;
_$jscoverage['mongoose/utils.js'][228] = 0;
_$jscoverage['mongoose/utils.js'][229] = 0;
_$jscoverage['mongoose/utils.js'][207] = 0;
_$jscoverage['mongoose/utils.js'][208] = 0;
_$jscoverage['mongoose/utils.js'][209] = 0;
_$jscoverage['mongoose/utils.js'][210] = 0;
_$jscoverage['mongoose/utils.js'][222] = 0;
_$jscoverage['mongoose/utils.js'][223] = 0;
_$jscoverage['mongoose/utils.js'][224] = 0;
_$jscoverage['mongoose/utils.js'][233] = 0;
_$jscoverage['mongoose/utils.js'][234] = 0;
_$jscoverage['mongoose/utils.js'][245] = 0;
_$jscoverage['mongoose/utils.js'][246] = 0;
_$jscoverage['mongoose/utils.js'][247] = 0;
_$jscoverage['mongoose/utils.js'][248] = 0;
_$jscoverage['mongoose/utils.js'][249] = 0;
_$jscoverage['mongoose/utils.js'][250] = 0;
_$jscoverage['mongoose/utils.js'][251] = 0;
_$jscoverage['mongoose/utils.js'][253] = 0;
_$jscoverage['mongoose/utils.js'][254] = 0;
_$jscoverage['mongoose/utils.js'][255] = 0;
_$jscoverage['mongoose/utils.js'][259] = 0;
_$jscoverage['mongoose/utils.js'][260] = 0;
_$jscoverage['mongoose/utils.js'][264] = 0;
_$jscoverage['mongoose/utils.js'][265] = 0;
_$jscoverage['mongoose/utils.js'][266] = 0;
_$jscoverage['mongoose/utils.js'][267] = 0;
_$jscoverage['mongoose/utils.js'][268] = 0;
_$jscoverage['mongoose/utils.js'][269] = 0;
_$jscoverage['mongoose/utils.js'][271] = 0;
_$jscoverage['mongoose/utils.js'][281] = 0;
_$jscoverage['mongoose/utils.js'][272] = 0;
_$jscoverage['mongoose/utils.js'][273] = 0;
_$jscoverage['mongoose/utils.js'][277] = 0;
_$jscoverage['mongoose/utils.js'][278] = 0;
_$jscoverage['mongoose/utils.js'][282] = 0;
_$jscoverage['mongoose/utils.js'][283] = 0;
_$jscoverage['mongoose/utils.js'][284] = 0;
_$jscoverage['mongoose/utils.js'][286] = 0;
_$jscoverage['mongoose/utils.js'][287] = 0;
_$jscoverage['mongoose/utils.js'][291] = 0;
_$jscoverage['mongoose/utils.js'][289] = 0;
_$jscoverage['mongoose/utils.js'][299] = 0;
_$jscoverage['mongoose/utils.js'][301] = 0;
_$jscoverage['mongoose/utils.js'][302] = 0;
_$jscoverage['mongoose/utils.js'][303] = 0;
_$jscoverage['mongoose/utils.js'][304] = 0;
_$jscoverage['mongoose/utils.js'][318] = 0;
_$jscoverage['mongoose/utils.js'][319] = 0;
_$jscoverage['mongoose/utils.js'][305] = 0;
_$jscoverage['mongoose/utils.js'][309] = 0;
_$jscoverage['mongoose/utils.js'][320] = 0;
_$jscoverage['mongoose/utils.js'][321] = 0;
_$jscoverage['mongoose/utils.js'][322] = 0;
_$jscoverage['mongoose/utils.js'][323] = 0;
_$jscoverage['mongoose/utils.js'][324] = 0;
_$jscoverage['mongoose/utils.js'][325] = 0;
_$jscoverage['mongoose/utils.js'][328] = 0;
_$jscoverage['mongoose/utils.js'][329] = 0;
_$jscoverage['mongoose/utils.js'][349] = 0;
_$jscoverage['mongoose/utils.js'][350] = 0;
_$jscoverage['mongoose/utils.js'][369] = 0;
_$jscoverage['mongoose/utils.js'][370] = 0;
_$jscoverage['mongoose/utils.js'][374] = 0;
_$jscoverage['mongoose/utils.js'][376] = 0;
_$jscoverage['mongoose/utils.js'][377] = 0;
_$jscoverage['mongoose/utils.js'][378] = 0;
_$jscoverage['mongoose/utils.js'][379] = 0;
_$jscoverage['mongoose/utils.js'][380] = 0;
_$jscoverage['mongoose/utils.js'][381] = 0;
_$jscoverage['mongoose/utils.js'][383] = 0;
_$jscoverage['mongoose/utils.js'][385] = 0;
_$jscoverage['mongoose/utils.js'][336] = 0;
_$jscoverage['mongoose/utils.js'][337] = 0;
_$jscoverage['mongoose/utils.js'][340] = 0;
_$jscoverage['mongoose/utils.js'][341] = 0;
_$jscoverage['mongoose/utils.js'][342] = 0;
_$jscoverage['mongoose/utils.js'][343] = 0;
_$jscoverage['mongoose/utils.js'][346] = 0;
_$jscoverage['mongoose/utils.js'][347] = 0;
_$jscoverage['mongoose/utils.js'][367] = 0;
_$jscoverage['mongoose/utils.js'][368] = 0;
_$jscoverage['mongoose/utils.js'][387] = 0;
_$jscoverage['mongoose/utils.js'][388] = 0;
_$jscoverage['mongoose/utils.js'][392] = 0;
_$jscoverage['mongoose/utils.js'][394] = 0;
_$jscoverage['mongoose/utils.js'][395] = 0;
_$jscoverage['mongoose/utils.js'][396] = 0;
_$jscoverage['mongoose/utils.js'][397] = 0;
_$jscoverage['mongoose/utils.js'][398] = 0;
_$jscoverage['mongoose/utils.js'][399] = 0;
_$jscoverage['mongoose/utils.js'][401] = 0;
_$jscoverage['mongoose/utils.js'][403] = 0;
_$jscoverage['mongoose/utils.js'][406] = 0;
_$jscoverage['mongoose/utils.js'][407] = 0;
_$jscoverage['mongoose/utils.js'][408] = 0;
_$jscoverage['mongoose/utils.js'][409] = 0;
_$jscoverage['mongoose/utils.js'][411] = 0;
}

@@ -180,92 +187,97 @@ _$jscoverage['mongoose/utils.js'][6]++;

exports.EventEmitter = Events;
_$jscoverage['mongoose/utils.js'][144]++;
var clone = exports.clone = (function (obj) {
_$jscoverage['mongoose/utils.js'][145]++;
_$jscoverage['mongoose/utils.js'][150]++;
var clone = exports.clone = (function (obj, shouldMinimizeData) {
_$jscoverage['mongoose/utils.js'][151]++;
if (obj === undefined || obj === null) {
_$jscoverage['mongoose/utils.js'][146]++;
_$jscoverage['mongoose/utils.js'][152]++;
return obj;
}
_$jscoverage['mongoose/utils.js'][147]++;
_$jscoverage['mongoose/utils.js'][153]++;
if (Array.isArray(obj)) {
_$jscoverage['mongoose/utils.js'][148]++;
return cloneArray(obj);
_$jscoverage['mongoose/utils.js'][154]++;
return (obj.length || ! shouldMinimizeData)? cloneArray(obj, shouldMinimizeData): undefined;
}
_$jscoverage['mongoose/utils.js'][149]++;
_$jscoverage['mongoose/utils.js'][158]++;
if (obj.toObject) {
_$jscoverage['mongoose/utils.js'][150]++;
_$jscoverage['mongoose/utils.js'][159]++;
return obj.toObject();
}
_$jscoverage['mongoose/utils.js'][151]++;
_$jscoverage['mongoose/utils.js'][160]++;
if (obj.constructor == Object) {
_$jscoverage['mongoose/utils.js'][152]++;
return cloneObject(obj);
_$jscoverage['mongoose/utils.js'][161]++;
return cloneObject(obj, shouldMinimizeData);
}
_$jscoverage['mongoose/utils.js'][153]++;
_$jscoverage['mongoose/utils.js'][163]++;
if (obj.constructor == Date || obj.constructor == RegExp || obj.constructor == Function) {
_$jscoverage['mongoose/utils.js'][155]++;
_$jscoverage['mongoose/utils.js'][165]++;
return new obj.constructor(+ obj);
}
_$jscoverage['mongoose/utils.js'][156]++;
_$jscoverage['mongoose/utils.js'][166]++;
if (obj instanceof ObjectId) {
_$jscoverage['mongoose/utils.js'][157]++;
_$jscoverage['mongoose/utils.js'][167]++;
return ObjectId.fromString(ObjectId.toString(obj));
}
_$jscoverage['mongoose/utils.js'][158]++;
_$jscoverage['mongoose/utils.js'][168]++;
if (obj.valueOf) {
_$jscoverage['mongoose/utils.js'][159]++;
_$jscoverage['mongoose/utils.js'][169]++;
return obj.valueOf();
}
_$jscoverage['mongoose/utils.js'][160]++;
return obj;
});
_$jscoverage['mongoose/utils.js'][163]++;
function cloneObject(obj) {
_$jscoverage['mongoose/utils.js'][164]++;
var ret = {};
_$jscoverage['mongoose/utils.js'][165]++;
for (var i in obj) {
_$jscoverage['mongoose/utils.js'][166]++;
ret[i] = clone(obj[i]);
_$jscoverage['mongoose/utils.js'][172]++;
function cloneObject(obj, shouldMinimizeData) {
_$jscoverage['mongoose/utils.js'][173]++;
var ret = {}, val, hasKeys;
_$jscoverage['mongoose/utils.js'][176]++;
for (var k in obj) {
_$jscoverage['mongoose/utils.js'][177]++;
val = clone(obj[k], shouldMinimizeData);
_$jscoverage['mongoose/utils.js'][178]++;
if (! shouldMinimizeData || ("undefined" !== typeof val)) {
_$jscoverage['mongoose/utils.js'][179]++;
hasKeys || (hasKeys = true);
_$jscoverage['mongoose/utils.js'][180]++;
ret[k] = val;
}
}
_$jscoverage['mongoose/utils.js'][167]++;
return ret;
_$jscoverage['mongoose/utils.js'][183]++;
return shouldMinimizeData? hasKeys && ret: ret;
}
_$jscoverage['mongoose/utils.js'][168]++;
_$jscoverage['mongoose/utils.js'][186]++;
;
_$jscoverage['mongoose/utils.js'][170]++;
function cloneArray(arr) {
_$jscoverage['mongoose/utils.js'][171]++;
_$jscoverage['mongoose/utils.js'][188]++;
function cloneArray(arr, shouldMinimizeData) {
_$jscoverage['mongoose/utils.js'][189]++;
var ret = [];
_$jscoverage['mongoose/utils.js'][172]++;
_$jscoverage['mongoose/utils.js'][190]++;
for (var i = 0, l = arr.length; i < l; i++) {
_$jscoverage['mongoose/utils.js'][173]++;
ret.push(clone(arr[i]));
_$jscoverage['mongoose/utils.js'][191]++;
ret.push(clone(arr[i], shouldMinimizeData));
}
_$jscoverage['mongoose/utils.js'][174]++;
_$jscoverage['mongoose/utils.js'][192]++;
return ret;
}
_$jscoverage['mongoose/utils.js'][175]++;
_$jscoverage['mongoose/utils.js'][193]++;
;
_$jscoverage['mongoose/utils.js'][186]++;
_$jscoverage['mongoose/utils.js'][204]++;
exports.options = (function (defaults, opts) {
_$jscoverage['mongoose/utils.js'][187]++;
var opts = opts || {}, c = clone(opts);
_$jscoverage['mongoose/utils.js'][189]++;
_$jscoverage['mongoose/utils.js'][205]++;
var opts = opts || {}, c = opts;
_$jscoverage['mongoose/utils.js'][207]++;
for (var i in defaults) {
_$jscoverage['mongoose/utils.js'][190]++;
_$jscoverage['mongoose/utils.js'][208]++;
if (! (i in opts)) {
_$jscoverage['mongoose/utils.js'][191]++;
c[i] = clone(defaults[i]);
_$jscoverage['mongoose/utils.js'][209]++;
c[i] = defaults[i];
}
}
_$jscoverage['mongoose/utils.js'][192]++;
_$jscoverage['mongoose/utils.js'][210]++;
return c;
});
_$jscoverage['mongoose/utils.js'][204]++;
_$jscoverage['mongoose/utils.js'][222]++;
exports.erase = (function (arr, item) {
_$jscoverage['mongoose/utils.js'][205]++;
_$jscoverage['mongoose/utils.js'][223]++;
for (var i = 0, l = arr.length; i < l; i++) {
_$jscoverage['mongoose/utils.js'][206]++;
_$jscoverage['mongoose/utils.js'][224]++;
if (arr[i] === item) {
_$jscoverage['mongoose/utils.js'][206]++;
_$jscoverage['mongoose/utils.js'][224]++;
arr.splice(i, 1);

@@ -275,93 +287,93 @@ }

});
_$jscoverage['mongoose/utils.js'][215]++;
_$jscoverage['mongoose/utils.js'][233]++;
exports.random = (function () {
_$jscoverage['mongoose/utils.js'][216]++;
_$jscoverage['mongoose/utils.js'][234]++;
return Math.random().toString().substr(3);
});
_$jscoverage['mongoose/utils.js'][227]++;
_$jscoverage['mongoose/utils.js'][245]++;
function StateMachine() {
_$jscoverage['mongoose/utils.js'][228]++;
_$jscoverage['mongoose/utils.js'][246]++;
this.paths = {};
_$jscoverage['mongoose/utils.js'][229]++;
_$jscoverage['mongoose/utils.js'][247]++;
this.states = {};
}
_$jscoverage['mongoose/utils.js'][246]++;
_$jscoverage['mongoose/utils.js'][264]++;
StateMachine.ctor = (function () {
_$jscoverage['mongoose/utils.js'][247]++;
_$jscoverage['mongoose/utils.js'][265]++;
var states = [].slice.call(arguments);
_$jscoverage['mongoose/utils.js'][248]++;
_$jscoverage['mongoose/utils.js'][266]++;
var ctor = (function () {
_$jscoverage['mongoose/utils.js'][249]++;
_$jscoverage['mongoose/utils.js'][267]++;
StateMachine.apply(this, arguments);
_$jscoverage['mongoose/utils.js'][250]++;
_$jscoverage['mongoose/utils.js'][268]++;
this.stateNames = states;
_$jscoverage['mongoose/utils.js'][251]++;
_$jscoverage['mongoose/utils.js'][269]++;
var i = states.length, state;
_$jscoverage['mongoose/utils.js'][253]++;
_$jscoverage['mongoose/utils.js'][271]++;
while (i--) {
_$jscoverage['mongoose/utils.js'][254]++;
_$jscoverage['mongoose/utils.js'][272]++;
state = states[i];
_$jscoverage['mongoose/utils.js'][255]++;
_$jscoverage['mongoose/utils.js'][273]++;
this.states[state] = {};
}
});
_$jscoverage['mongoose/utils.js'][259]++;
_$jscoverage['mongoose/utils.js'][277]++;
ctor.prototype.__proto__ = StateMachine.prototype;
_$jscoverage['mongoose/utils.js'][260]++;
_$jscoverage['mongoose/utils.js'][278]++;
states.forEach((function (state) {
_$jscoverage['mongoose/utils.js'][264]++;
_$jscoverage['mongoose/utils.js'][282]++;
ctor.prototype[state] = (function (path) {
_$jscoverage['mongoose/utils.js'][265]++;
_$jscoverage['mongoose/utils.js'][283]++;
this._changeState(path, state);
});
}));
_$jscoverage['mongoose/utils.js'][268]++;
_$jscoverage['mongoose/utils.js'][286]++;
return ctor;
});
_$jscoverage['mongoose/utils.js'][271]++;
_$jscoverage['mongoose/utils.js'][289]++;
StateMachine.prototype = {_changeState: (function (path, nextState) {
_$jscoverage['mongoose/utils.js'][281]++;
_$jscoverage['mongoose/utils.js'][299]++;
var prevState = this.paths[path], prevBucket = this.states[prevState];
_$jscoverage['mongoose/utils.js'][283]++;
_$jscoverage['mongoose/utils.js'][301]++;
delete this.paths[path];
_$jscoverage['mongoose/utils.js'][284]++;
_$jscoverage['mongoose/utils.js'][302]++;
if (prevBucket) {
_$jscoverage['mongoose/utils.js'][284]++;
_$jscoverage['mongoose/utils.js'][302]++;
delete prevBucket[path];
}
_$jscoverage['mongoose/utils.js'][286]++;
_$jscoverage['mongoose/utils.js'][304]++;
this.paths[path] = nextState;
_$jscoverage['mongoose/utils.js'][287]++;
_$jscoverage['mongoose/utils.js'][305]++;
this.states[nextState][path] = true;
}), stateOf: (function (path) {
_$jscoverage['mongoose/utils.js'][291]++;
_$jscoverage['mongoose/utils.js'][309]++;
return this.paths[path];
}), some: (function () {
_$jscoverage['mongoose/utils.js'][302]++;
_$jscoverage['mongoose/utils.js'][320]++;
var self = this;
_$jscoverage['mongoose/utils.js'][303]++;
_$jscoverage['mongoose/utils.js'][321]++;
return Array.prototype.some.call(arguments.length? arguments: this.stateNames, (function (state) {
_$jscoverage['mongoose/utils.js'][304]++;
_$jscoverage['mongoose/utils.js'][322]++;
return Object.keys(self.states[state]).length;
}));
}), _iter: (function (iterMethod) {
_$jscoverage['mongoose/utils.js'][318]++;
_$jscoverage['mongoose/utils.js'][336]++;
return (function () {
_$jscoverage['mongoose/utils.js'][319]++;
_$jscoverage['mongoose/utils.js'][337]++;
var numArgs = arguments.length, states = [].slice.call(arguments, 0, numArgs - 1), callback = arguments[arguments.length - 1];
_$jscoverage['mongoose/utils.js'][322]++;
_$jscoverage['mongoose/utils.js'][340]++;
if (! states.length) {
_$jscoverage['mongoose/utils.js'][322]++;
_$jscoverage['mongoose/utils.js'][340]++;
states = this.stateNames;
}
_$jscoverage['mongoose/utils.js'][323]++;
_$jscoverage['mongoose/utils.js'][341]++;
var self = this;
_$jscoverage['mongoose/utils.js'][324]++;
_$jscoverage['mongoose/utils.js'][342]++;
var paths = states.reduce((function (paths, state) {
_$jscoverage['mongoose/utils.js'][325]++;
_$jscoverage['mongoose/utils.js'][343]++;
return paths.concat(Object.keys(self.states[state]));
}), []);
_$jscoverage['mongoose/utils.js'][328]++;
_$jscoverage['mongoose/utils.js'][346]++;
return paths[iterMethod]((function (path) {
_$jscoverage['mongoose/utils.js'][329]++;
_$jscoverage['mongoose/utils.js'][347]++;
return callback(path);

@@ -371,33 +383,48 @@ }));

}), forEach: (function () {
_$jscoverage['mongoose/utils.js'][349]++;
_$jscoverage['mongoose/utils.js'][367]++;
this.forEach = this._iter("forEach");
_$jscoverage['mongoose/utils.js'][350]++;
_$jscoverage['mongoose/utils.js'][368]++;
return this.forEach.apply(this, arguments);
}), map: (function () {
_$jscoverage['mongoose/utils.js'][369]++;
_$jscoverage['mongoose/utils.js'][387]++;
this.map = this._iter("map");
_$jscoverage['mongoose/utils.js'][370]++;
_$jscoverage['mongoose/utils.js'][388]++;
return this.map.apply(this, arguments);
})};
_$jscoverage['mongoose/utils.js'][374]++;
_$jscoverage['mongoose/utils.js'][392]++;
exports.StateMachine = StateMachine;
_$jscoverage['mongoose/utils.js'][376]++;
_$jscoverage['mongoose/utils.js'][394]++;
exports.inGroupsOf = (function inGroupsOf(card, arr, fn) {
_$jscoverage['mongoose/utils.js'][377]++;
_$jscoverage['mongoose/utils.js'][395]++;
var group = [];
_$jscoverage['mongoose/utils.js'][378]++;
_$jscoverage['mongoose/utils.js'][396]++;
for (var i = 0, l = arr.length; i < l; i++) {
_$jscoverage['mongoose/utils.js'][379]++;
_$jscoverage['mongoose/utils.js'][397]++;
if (i && i % card === 0) {
_$jscoverage['mongoose/utils.js'][380]++;
_$jscoverage['mongoose/utils.js'][398]++;
fn.apply(this, group);
_$jscoverage['mongoose/utils.js'][381]++;
_$jscoverage['mongoose/utils.js'][399]++;
group.length = 0;
}
_$jscoverage['mongoose/utils.js'][383]++;
_$jscoverage['mongoose/utils.js'][401]++;
group.push(arr[i]);
}
_$jscoverage['mongoose/utils.js'][385]++;
_$jscoverage['mongoose/utils.js'][403]++;
fn.apply(this, group);
});
_$jscoverage['mongoose/utils.js'].source = ["","/**"," * Module dependencies."," */","","var EventEmitter = require('events').EventEmitter"," , ObjectId = require('./types/objectid')","","/**"," * Produces a collection name from a model name"," *"," * @param {String} model name"," * @return {String} collection name"," * @api private"," */","","exports.toCollectionName = function(name) {"," return pluralize(name.toLowerCase());","};","","/**"," * Pluralization rules."," */","","var rules = ["," [/(m)an$/gi, '$1en'],"," [/(pe)rson$/gi, '$1ople'],"," [/(child)$/gi, '$1ren'],"," [/^(ox)$/gi, '$1en'],"," [/(ax|test)is$/gi, '$1es'],"," [/(octop|vir)us$/gi, '$1i'],"," [/(alias|status)$/gi, '$1es'],"," [/(bu)s$/gi, '$1ses'],"," [/(buffal|tomat|potat)o$/gi, '$1oes'],"," [/([ti])um$/gi, '$1a'],"," [/sis$/gi, 'ses'],"," [/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'],"," [/(hive)$/gi, '$1s'],"," [/([^aeiouy]|qu)y$/gi, '$1ies'],"," [/(x|ch|ss|sh)$/gi, '$1es'],"," [/(matr|vert|ind)ix|ex$/gi, '$1ices'],"," [/([m|l])ouse$/gi, '$1ice'],"," [/(quiz)$/gi, '$1zes'],"," [/s$/gi, 's'],"," [/$/gi, 's']","];","","/**"," * Uncountable words."," */","","var uncountables = ["," 'advice',"," 'energy',"," 'excretion',"," 'digestion',"," 'cooperation',"," 'health',"," 'justice',"," 'labour',"," 'machinery',"," 'equipment',"," 'information',"," 'pollution',"," 'sewage',"," 'paprer',"," 'money',"," 'species',"," 'series',"," 'rain',"," 'rice',"," 'fish',"," 'sheep',"," 'moose',"," 'deer',"," 'news'","];","","/**"," * Pluralize function."," *"," * @author TJ Holowaychuk (extracted from _ext.js_)"," * @param {String} string to pluralize"," * @api private"," */","","function pluralize (str) {"," var rule, found;"," if (!~uncountables.indexOf(str.lowercase)){"," found = rules.filter(function(rule){"," return str.match(rule[0]);"," });"," if (found[0]) return str.replace(found[0][0], found[0][1]);"," }"," return str;","};","","/**"," * Add `once` to EventEmitter if absent"," *"," * @param {String} event name"," * @param {Function} listener"," * @api private"," */","","var Events = EventEmitter;","","if (!('once' in EventEmitter.prototype)){"," "," Events = function () {"," EventEmitter.apply(this, arguments);"," };",""," /**"," * Inherit from EventEmitter."," */",""," Events.prototype.__proto__ = EventEmitter.prototype;"," "," /**"," * Add `once`."," */"," "," Events.prototype.once = function (type, listener) {"," var self = this;"," self.on(type, function g(){"," self.removeListener(type, g);"," listener.apply(this, arguments);"," });"," };","","}","","exports.EventEmitter = Events;","","/**"," * Object clone with Mongoose natives support"," *"," * @param {Object} object to clone"," * @return {Object} cloned object"," * @api private"," */","","var clone = exports.clone = function (obj) {"," if (obj === undefined || obj === null)"," return obj;"," if (Array.isArray(obj))"," return cloneArray(obj);"," if (obj.toObject)"," return obj.toObject();"," if (obj.constructor == Object)"," return cloneObject(obj);"," if (obj.constructor == Date || obj.constructor == RegExp"," || obj.constructor == Function)"," return new obj.constructor(+obj);"," if (obj instanceof ObjectId)"," return ObjectId.fromString(ObjectId.toString(obj));"," if (obj.valueOf)"," return obj.valueOf();"," return obj;","};","","function cloneObject (obj) {"," var ret = {};"," for (var i in obj)"," ret[i] = clone(obj[i]);"," return ret;","};","","function cloneArray (arr) {"," var ret = [];"," for (var i = 0, l = arr.length; i &lt; l; i++)"," ret.push(clone(arr[i]));"," return ret;","};","","/**"," * Copies and merges options with defaults."," *"," * @param {Object} defaults"," * @param {Object} supplied options"," * @return {Object} new (merged) object"," * @api private"," */","","exports.options = function (defaults, opts){"," var opts = opts || {}"," , c = clone(opts);"," for (var i in defaults)"," if (!(i in opts))"," c[i] = clone(defaults[i]);"," return c;","};","","/**"," * Erases an item from an array"," *"," * @param {Array} array"," * @param {Object} value"," * @return undefined"," * @api private"," */","","exports.erase = function (arr, item) {"," for (var i = 0, l = arr.length; i &lt; l; i++)"," if (arr[i] === item) arr.splice(i, 1);","};","","/**"," * Generates a random string"," *"," * @api private"," */","","exports.random = function () {"," return Math.random().toString().substr(3);","};","","","/**"," * A StateMachine represents a minimal `interface` for the"," * constructors it builds via StateMachine.ctor(...)."," *"," * @api private"," */","","function StateMachine () {"," this.paths = {};"," this.states = {};","}","","/**"," * StateMachine.ctor('state1', 'state2', ...)"," * A factory method for subclassing StateMachine."," * The arguments are a list of states. For each state,"," * the constructor's prototype gets state transition"," * methods named after each state. These transition methods"," * place their path argument into the given state."," *"," * @param {String} state"," * @param {String} [state]"," * @return {Function} subclass constructor"," * @api public"," */","","StateMachine.ctor = function () {"," var states = [].slice.call(arguments);"," var ctor = function () {"," StateMachine.apply(this, arguments);"," this.stateNames = states;"," var i = states.length"," , state;"," while (i--) {"," state = states[i];"," this.states[state] = {};"," }"," };",""," ctor.prototype.__proto__ = StateMachine.prototype;"," states.forEach( function (state) {"," /**"," * Changes the `path`'s state to `state`."," */"," ctor.prototype[state] = function (path) {"," this._changeState(path, state);"," }"," });"," return ctor;","};","","StateMachine.prototype = {"," /**"," * This function is wrapped by the state change functions:"," * - `require(path)`"," * - `modify(path)`"," * - `init(path)`"," * @api private"," */",""," _changeState: function (path, nextState) {"," var prevState = this.paths[path]"," , prevBucket = this.states[prevState];"," delete this.paths[path];"," if (prevBucket) delete prevBucket[path];",""," this.paths[path] = nextState;"," this.states[nextState][path] = true;"," },",""," stateOf: function (path) {"," return this.paths[path];"," },",""," /**"," * Checks to see if at least one path is in the states passed in via `arguments`"," * e.g., this.some('required', 'inited')"," * @param {String} state that we want to check for."," * @api public"," */",""," some: function () {"," var self = this;"," return Array.prototype.some.call(arguments.length ? arguments : this.stateNames, function (state) {"," return Object.keys(self.states[state]).length;"," });"," },",""," /**"," * This function builds the functions that get assigned to `forEach` and `map`,"," * since both of those methods share a lot of the same logic."," *"," * @param {String} iterMethod is either 'forEach' or 'map'"," * @return {Function}"," * @api private"," */",""," _iter: function (iterMethod) {"," return function () {"," var numArgs = arguments.length"," , states = [].slice.call(arguments, 0, numArgs-1)"," , callback = arguments[arguments.length-1];"," if (!states.length) states = this.stateNames;"," var self = this;"," var paths = states.reduce( function (paths, state) {"," return paths.concat(Object.keys(self.states[state]));"," "," }, []);"," return paths[iterMethod]( function (path) {"," return callback(path);"," });"," };"," },",""," /**"," * Iterates over the paths that belong to one of the parameter states."," *"," * The function profile can look like:"," * this.forEach(state1, fn); // iterates over all paths in state1"," * this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2"," * this.forEach(fn); // iterates over all paths in all states"," *"," * @param {String} [state]"," * @param {String} [state]"," * @param {Function} callback"," * @api public"," */",""," forEach: function () {"," this.forEach = this._iter('forEach');"," return this.forEach.apply(this, arguments);"," },",""," /**"," * Maps over the paths that belong to one of the parameter states."," *"," * The function profile can look like:"," * this.forEach(state1, fn); // iterates over all paths in state1"," * this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2"," * this.forEach(fn); // iterates over all paths in all states"," *"," * @param {String} [state]"," * @param {String} [state]"," * @param {Function} callback"," * @return {Array}"," * @api public"," */",""," map: function () {"," this.map = this._iter('map');"," return this.map.apply(this, arguments);"," }","};","","exports.StateMachine = StateMachine;","","exports.inGroupsOf = function inGroupsOf (card, arr, fn) {"," var group = [];"," for (var i = 0, l = arr.length; i &lt; l; i++) {"," if (i &amp;&amp; i % card === 0) {"," fn.apply(this, group);"," group.length = 0;"," }"," group.push(arr[i]);"," }"," fn.apply(this, group);","};"];
_$jscoverage['mongoose/utils.js'][406]++;
exports.merge = (function merge(objA, objB) {
_$jscoverage['mongoose/utils.js'][407]++;
for (var k in objB) {
_$jscoverage['mongoose/utils.js'][408]++;
if ("undefined" === typeof objA[k]) {
_$jscoverage['mongoose/utils.js'][409]++;
objA[k] = objB[k];
}
else {
_$jscoverage['mongoose/utils.js'][411]++;
merge(objA[k], objB[k]);
}
}
});
_$jscoverage['mongoose/utils.js'].source = ["","/**"," * Module dependencies."," */","","var EventEmitter = require('events').EventEmitter"," , ObjectId = require('./types/objectid')","","/**"," * Produces a collection name from a model name"," *"," * @param {String} model name"," * @return {String} collection name"," * @api private"," */","","exports.toCollectionName = function(name) {"," return pluralize(name.toLowerCase());","};","","/**"," * Pluralization rules."," */","","var rules = ["," [/(m)an$/gi, '$1en'],"," [/(pe)rson$/gi, '$1ople'],"," [/(child)$/gi, '$1ren'],"," [/^(ox)$/gi, '$1en'],"," [/(ax|test)is$/gi, '$1es'],"," [/(octop|vir)us$/gi, '$1i'],"," [/(alias|status)$/gi, '$1es'],"," [/(bu)s$/gi, '$1ses'],"," [/(buffal|tomat|potat)o$/gi, '$1oes'],"," [/([ti])um$/gi, '$1a'],"," [/sis$/gi, 'ses'],"," [/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'],"," [/(hive)$/gi, '$1s'],"," [/([^aeiouy]|qu)y$/gi, '$1ies'],"," [/(x|ch|ss|sh)$/gi, '$1es'],"," [/(matr|vert|ind)ix|ex$/gi, '$1ices'],"," [/([m|l])ouse$/gi, '$1ice'],"," [/(quiz)$/gi, '$1zes'],"," [/s$/gi, 's'],"," [/$/gi, 's']","];","","/**"," * Uncountable words."," */","","var uncountables = ["," 'advice',"," 'energy',"," 'excretion',"," 'digestion',"," 'cooperation',"," 'health',"," 'justice',"," 'labour',"," 'machinery',"," 'equipment',"," 'information',"," 'pollution',"," 'sewage',"," 'paprer',"," 'money',"," 'species',"," 'series',"," 'rain',"," 'rice',"," 'fish',"," 'sheep',"," 'moose',"," 'deer',"," 'news'","];","","/**"," * Pluralize function."," *"," * @author TJ Holowaychuk (extracted from _ext.js_)"," * @param {String} string to pluralize"," * @api private"," */","","function pluralize (str) {"," var rule, found;"," if (!~uncountables.indexOf(str.lowercase)){"," found = rules.filter(function(rule){"," return str.match(rule[0]);"," });"," if (found[0]) return str.replace(found[0][0], found[0][1]);"," }"," return str;","};","","/**"," * Add `once` to EventEmitter if absent"," *"," * @param {String} event name"," * @param {Function} listener"," * @api private"," */","","var Events = EventEmitter;","","if (!('once' in EventEmitter.prototype)){"," "," Events = function () {"," EventEmitter.apply(this, arguments);"," };",""," /**"," * Inherit from EventEmitter."," */",""," Events.prototype.__proto__ = EventEmitter.prototype;"," "," /**"," * Add `once`."," */"," "," Events.prototype.once = function (type, listener) {"," var self = this;"," self.on(type, function g(){"," self.removeListener(type, g);"," listener.apply(this, arguments);"," });"," };","","}","","exports.EventEmitter = Events;","","/**"," * Object clone with Mongoose natives support."," * Creates a minimal data Object."," * It does not clone empty Arrays, empty Objects,"," * and undefined values."," * This makes the data payload sent to MonboDB as minimal"," * as possible."," *"," * @param {Object} object to clone"," * @param {Boolean} shouldMinimizeData"," * @return {Object} cloned object"," * @api private"," */","","var clone = exports.clone = function (obj, shouldMinimizeData) {"," if (obj === undefined || obj === null)"," return obj"," if (Array.isArray(obj)) {"," return (obj.length || !shouldMinimizeData)"," ? cloneArray(obj, shouldMinimizeData) "," : undefined;"," }"," if (obj.toObject)"," return obj.toObject();"," if (obj.constructor == Object) {"," return cloneObject(obj, shouldMinimizeData);"," }"," if (obj.constructor == Date || obj.constructor == RegExp"," || obj.constructor == Function)"," return new obj.constructor(+obj);"," if (obj instanceof ObjectId)"," return ObjectId.fromString(ObjectId.toString(obj));"," if (obj.valueOf)"," return obj.valueOf();","};","","function cloneObject (obj, shouldMinimizeData) {"," var ret = {}"," , val"," , hasKeys;"," for (var k in obj) {"," val = clone(obj[k], shouldMinimizeData);"," if (!shouldMinimizeData || ('undefined' !== typeof val)) {"," hasKeys || (hasKeys = true);"," ret[k] = val;"," }"," }"," return shouldMinimizeData"," ? hasKeys &amp;&amp; ret"," : ret;","};","","function cloneArray (arr, shouldMinimizeData) {"," var ret = [];"," for (var i = 0, l = arr.length; i &lt; l; i++)"," ret.push(clone(arr[i], shouldMinimizeData));"," return ret;","};","","/**"," * Copies and merges options with defaults."," *"," * @param {Object} defaults"," * @param {Object} supplied options"," * @return {Object} new (merged) object"," * @api private"," */","","exports.options = function (defaults, opts){"," var opts = opts || {}"," , c = opts;"," for (var i in defaults)"," if (!(i in opts))"," c[i] = defaults[i];"," return c;","};","","/**"," * Erases an item from an array"," *"," * @param {Array} array"," * @param {Object} value"," * @return undefined"," * @api private"," */","","exports.erase = function (arr, item) {"," for (var i = 0, l = arr.length; i &lt; l; i++)"," if (arr[i] === item) arr.splice(i, 1);","};","","/**"," * Generates a random string"," *"," * @api private"," */","","exports.random = function () {"," return Math.random().toString().substr(3);","};","","","/**"," * A StateMachine represents a minimal `interface` for the"," * constructors it builds via StateMachine.ctor(...)."," *"," * @api private"," */","","function StateMachine () {"," this.paths = {};"," this.states = {};","}","","/**"," * StateMachine.ctor('state1', 'state2', ...)"," * A factory method for subclassing StateMachine."," * The arguments are a list of states. For each state,"," * the constructor's prototype gets state transition"," * methods named after each state. These transition methods"," * place their path argument into the given state."," *"," * @param {String} state"," * @param {String} [state]"," * @return {Function} subclass constructor"," * @api public"," */","","StateMachine.ctor = function () {"," var states = [].slice.call(arguments);"," var ctor = function () {"," StateMachine.apply(this, arguments);"," this.stateNames = states;"," var i = states.length"," , state;"," while (i--) {"," state = states[i];"," this.states[state] = {};"," }"," };",""," ctor.prototype.__proto__ = StateMachine.prototype;"," states.forEach( function (state) {"," /**"," * Changes the `path`'s state to `state`."," */"," ctor.prototype[state] = function (path) {"," this._changeState(path, state);"," }"," });"," return ctor;","};","","StateMachine.prototype = {"," /**"," * This function is wrapped by the state change functions:"," * - `require(path)`"," * - `modify(path)`"," * - `init(path)`"," * @api private"," */",""," _changeState: function (path, nextState) {"," var prevState = this.paths[path]"," , prevBucket = this.states[prevState];"," delete this.paths[path];"," if (prevBucket) delete prevBucket[path];",""," this.paths[path] = nextState;"," this.states[nextState][path] = true;"," },",""," stateOf: function (path) {"," return this.paths[path];"," },",""," /**"," * Checks to see if at least one path is in the states passed in via `arguments`"," * e.g., this.some('required', 'inited')"," * @param {String} state that we want to check for."," * @api public"," */",""," some: function () {"," var self = this;"," return Array.prototype.some.call(arguments.length ? arguments : this.stateNames, function (state) {"," return Object.keys(self.states[state]).length;"," });"," },",""," /**"," * This function builds the functions that get assigned to `forEach` and `map`,"," * since both of those methods share a lot of the same logic."," *"," * @param {String} iterMethod is either 'forEach' or 'map'"," * @return {Function}"," * @api private"," */",""," _iter: function (iterMethod) {"," return function () {"," var numArgs = arguments.length"," , states = [].slice.call(arguments, 0, numArgs-1)"," , callback = arguments[arguments.length-1];"," if (!states.length) states = this.stateNames;"," var self = this;"," var paths = states.reduce( function (paths, state) {"," return paths.concat(Object.keys(self.states[state]));"," "," }, []);"," return paths[iterMethod]( function (path) {"," return callback(path);"," });"," };"," },",""," /**"," * Iterates over the paths that belong to one of the parameter states."," *"," * The function profile can look like:"," * this.forEach(state1, fn); // iterates over all paths in state1"," * this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2"," * this.forEach(fn); // iterates over all paths in all states"," *"," * @param {String} [state]"," * @param {String} [state]"," * @param {Function} callback"," * @api public"," */",""," forEach: function () {"," this.forEach = this._iter('forEach');"," return this.forEach.apply(this, arguments);"," },",""," /**"," * Maps over the paths that belong to one of the parameter states."," *"," * The function profile can look like:"," * this.forEach(state1, fn); // iterates over all paths in state1"," * this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2"," * this.forEach(fn); // iterates over all paths in all states"," *"," * @param {String} [state]"," * @param {String} [state]"," * @param {Function} callback"," * @return {Array}"," * @api public"," */",""," map: function () {"," this.map = this._iter('map');"," return this.map.apply(this, arguments);"," }","};","","exports.StateMachine = StateMachine;","","exports.inGroupsOf = function inGroupsOf (card, arr, fn) {"," var group = [];"," for (var i = 0, l = arr.length; i &lt; l; i++) {"," if (i &amp;&amp; i % card === 0) {"," fn.apply(this, group);"," group.length = 0;"," }"," group.push(arr[i]);"," }"," fn.apply(this, group);","};","","exports.merge = function merge (objA, objB) {"," for (var k in objB) {"," if ('undefined' === typeof objA[k]) {"," objA[k] = objB[k];"," } else {"," merge(objA[k], objB[k]);"," }"," }","};"];

@@ -28,2 +28,6 @@

this.activePaths = new ActiveRoster();
var self = this;
this.schema.requiredPaths.forEach( function (path) {
self.activePaths.require(path);
});
this.saveError = null;

@@ -83,5 +87,8 @@ if (obj) this.set(obj);

path.reduce( function (ref, piece, i) {
if (i === len-1)
ref[piece] = type.getDefault(self);
else
var _default;
if (i === len-1) {
_default = type.getDefault(self);
if ('undefined' !== typeof _default)
ref[piece] = _default;
} else
return ref[piece] || (ref[piece] = {});

@@ -369,3 +376,3 @@ }, doc);

if (!this.activePaths.some('init', 'modify')) return next();
if (!this.activePaths.some('require', 'init', 'modify')) return next();

@@ -387,3 +394,3 @@ function validatePath (path) {

this.activePaths.forEach('init', 'modify', function (path) {
this.activePaths.forEach('require', 'init', 'modify', function (path) {
if (!didErr) validatePath(path);

@@ -525,4 +532,5 @@ });

Document.prototype.toObject = function () {
return clone(this.doc);
return clone(this.doc, true);
};

@@ -529,0 +537,0 @@

@@ -256,3 +256,3 @@

exports.version = '1.0.10';
exports.version = '1.0.11';

@@ -259,0 +259,0 @@ /**

@@ -12,3 +12,9 @@

, FindQuery = require('./query').FindQuery
, EventEmitter = require('./utils').EventEmitter
, FindOneQuery = require('./query').FindOneQuery
, Query = require('./query').Query
, Query = require('./query').Query
, Query = require('./query').Query
, utils = require('./utils')
, EventEmitter = utils.EventEmitter
, merge = utils.merge
, Promise = require('./promise');

@@ -327,132 +333,10 @@

Model.remove = function (query, callback) {
var self = this;
this.query(query, {}, callback, function () {
var casted = self.castQuery(this.query)
, queryComplete = this.queryComplete.bind(this);
self.collection.remove(casted, queryComplete);
});
Model.remove = function (conditions, callback) {
var query = new Query(conditions).bind(this);
if ('undefined' == typeof callback)
return query;
return query.remove(callback);
};
/**
* Creates a query for the signature `query, options, callback`
*
* @param {Object} query
* @param {Object} options for the query
* @param {Function} callback
* @param {Function} function to be called when query executes
* @api private
*/
Model.query = function (query, options, callback, onExecute) {
// determine callback for `query, fields, callback, options` signature
if ('function' == typeof options) {
callback = options;
options = {};
}
if (!options)
options = {};
// merge query defaults from schema options
if (!('safe' in options))
options.safe = this.options.safe;
var query = new Query(query, options, onExecute);
if (callback) {
query.addBack(callback);
query.run();
}
return query;
};
/**
* Creates a query for the signature `query, fields, callback, options`
*
* @param {Object} query
* @param {Object} fields to get, or array of fields
* @param {Object} options for the query
* @param {Function} callback
* @param {Function} function to be called when query executes
* @api private
*/
Model.findQuery = function (query, fields, options, callback, onExecute) {
if ('function' == typeof fields) {
callback = fields;
fields = {};
options = {};
} else if ('function' == typeof options) {
callback = options;
options = {};
}
var query = new FindQuery(query, fields, options, onExecute);
if (callback) {
query.run(callback);
}
return query;
};
/**
* Casts a query
*
* Examples:
*
* // will return { _id: ObjectId }
* castQuery({ _id: '4c40f33a37483d8e14000001' })
*
* @param {Object} query
* @api private
*/
Model.castQuery = function (query) {
var ret = {}
, self = this;
for (var i in query){
if (query[i] === null || query[i] === undefined)
ret[i] = query[i];
else if (query[i].constructor == Object) {
ret[i] = query[i];
Object.keys(query[i]).filter( function (key) {
return key.charAt(0) === '$';
}).forEach( function (key) {
var schema = self.schema.path(i);
if (key == '$in') {
// cast array
ret[i][key] = ret[i][key].map(schema.cast);
} else
ret[i][key] = schema.cast(query[i][key]);
// Take care of special case of MongooseNumber,
// with resolves scalar via `valueOf`
if (ret[i][key]._path)
ret[i][key] = ret[i][key].valueOf();
});
} else if (query[i].constructor == RegExp || Array.isArray(query[i]))
ret[i] = query[i];
else {
ret[i] = this.schema.path(i).cast(query[i]);
// Take care of special case of MongooseArray for checking 1 element membership
if (ret[i] instanceof MongooseArray) {
var arr = ret[i];
delete ret[i];
ret[i] = {
$all: arr
};
}
}
}
return ret;
};
/**
* Finds documents

@@ -467,3 +351,3 @@ *

*
* @param {Object} query
* @param {Object} conditions
* @param {Object/Function} (optional) fields to hydrate or callback

@@ -474,33 +358,34 @@ * @param {Function} callback

Model.find = function (query, fields, options, callback) {
var self = this;
Model.find = function (conditions, fields, options, callback) {
if ('function' == typeof fields) {
callback = fields;
fields = null;
options = null;
} else if ('function' == typeof options) {
callback = options;
options = null;
} else if ('function' == typeof conditions) {
callback = conditions;
conditions = {};
fields = null;
options = null;
}
return this.findQuery(query, fields, options, callback, function (query) {
var q = this
, casted = self.castQuery(this.query);
var query = new Query(conditions, options).select(fields).bind(this);
if (this.fields)
this.options.fields = this.fields;
if ('undefined' === typeof callback)
return query;
// TODO Add cQuery merging into other commands
var cQuery;
self.collection.find(casted, this.options, function (err, cursor) {
if (err) return q.queryComplete(err);
if (cQuery = this._cumulativeQuery)
merge(query._conditions, cQuery._conditions);
cursor.toArray(function(err, docs){
if (err) return q.queryComplete(err);
if (!query.model)
query.bind(this);
var arr = []
, count = docs.length;
delete this._cumulativeQuery;
if (!count) return q.queryComplete(null, []);
for (var i = 0, l = docs.length; i < l; i++){
arr[i] = new self();
arr[i].init(docs[i], function (err) {
if (err) return q.queryComplete(err);
--count || q.queryComplete(null, arr);
});
}
});
});
});
return query.find(callback);
};

@@ -522,3 +407,3 @@

*
* @param {Object} query
* @param {Object} conditions
* @param {Object/Function} (optional) fields to hydrate or callback

@@ -529,25 +414,23 @@ * @param {Function} callback

Model.findOne = function (query, fields, options, callback) {
var self = this;
Model.findOne = function (conditions, fields, options, callback) {
if ('function' == typeof options) {
callback = options;
options = null;
} else if ('function' == typeof fields) {
callback = fields;
fields = null;
options = null;
} else if ('function' == typeof conditions) {
callback = conditions;
conditions = {};
fields = null;
options = null;
}
return this.findQuery(query, fields, options, callback, function () {
var q = this
, casted = self.castQuery(this.query);
var query = new Query(conditions, options).select(fields).bind(this);
if (this.fields)
this.options.fields = this.fields;
if ('undefined' === typeof callback)
return query;
self.collection.findOne(casted, this.options, function (err, doc) {
if (err) return q.queryComplete(err);
if (!doc) return q.queryComplete(null, null);
var casted = new self();
casted.init(doc, function (err) {
if (err) return q.queryComplete(err);
q.queryComplete(null, casted);
});
});
});
return query.findOne(callback);
};

@@ -558,3 +441,3 @@

*
* @param {Object} query
* @param {Object} conditions
* @param {Function} optional callback

@@ -564,13 +447,50 @@ * @api public

Model.count = function (query, callback) {
var self = this;
Model.count = function (conditions, callback) {
var query = new Query(conditions).bind(this);
return this.query(query, {}, callback, function () {
var casted = self.castQuery(this.query);
self.collection.count(casted, this.queryComplete.bind(this));
});
if ('undefined' == typeof callback)
return query;
return query.count(callback);
};
/**
* `with` enables a very nice sugary api for doing your queries.
* For example, instead of writing:
* User.find({age: {$gte: 21, $lte: 65}}, callback);
* we can instead write more readably:
* User.with('age').gte(21).lte(65);
* Moreover, you can also chain a bunch of these together like:
* User
* .with('age').gte(21).lte(65)
* .with('name', /^b/i) // All names that begin with b or B
* .with('friends').slice(10);
* @param {String} path
* @param {Object} val (optional)
* @return {Query}
* @api public
*/
Model.with = function (path, val) {
var q = new Query().bind(this);
return q.with.apply(q, arguments);
};
/**
* Sometimes you need to query for things in mongodb using a JavaScript
* expression. You can do so via find({$where: javascript}), or you can
* use the mongoose shortcut method $where via a Query chain or from
* your mongoose Model.
*
* @param {String|Function} js is a javascript string or anonymous function
* @return {Query}
* @api public
*/
Model.$where = function () {
var q = new Query().bind(this);
return q.$where.apply(q, arguments);
};
/**
* Shortcut for creating a new Document that is automatically saved

@@ -584,6 +504,17 @@ * to the db if valid.

Model.create = function (doc, fn) {
var document = new this(doc);
document.save(function (err) {
if (err) fn(err)
else fn(null, document);
var args = [].slice.call(arguments)
, lastArg = args[args.length-1]
, count, docs = [];
if (typeof lastArg === 'function') {
fn = args.pop();
}
count = args.length;
var self = this;
args.forEach( function (arg, i) {
var doc = new self(arg);
docs[i] = doc;
doc.save(function (err) {
if (err) return fn(err);
--count || fn.apply(null, [null].concat(docs));
});
});

@@ -605,3 +536,3 @@ };

*
* @param {Object} query
* @param {Object} conditions
* @param {Object] doc

@@ -614,12 +545,12 @@ * @param {Object/Function} optional options or callback

Model.update = function (query, doc, options, callback) {
var self = this;
return this.query(query, options, callback, function () {
var castQuery = self.castQuery(this.query)
, castDoc = self.castQuery(doc)
, queryComplete = this.queryComplete.bind(this);
self.collection.update(castQuery, castDoc, this.options, queryComplete);
});
Model.update = function (conditions, doc, options, callback) {
if ('function' === typeof options) {
callback = options;
options = null;
}
var query = new Query(conditions, options).bind(this);
if ('undefined' === typeof callback) {
return query;
}
return query.update(doc, callback);
};

@@ -660,3 +591,6 @@

// apply named scopes
if(schema.namedScopes) schema.namedScopes.compile(model);
return model;
};

@@ -0,69 +1,331 @@

var utils = require('./utils')
, merge = utils.merge
, inGroupsOf = utils.inGroupsOf;
/**
* Module dependencies.
* Query constructor
*
* @api private
*/
var Promise = require('./promise')
, inGroupsOf = require('./utils').inGroupsOf;
function Query (criteria, options) {
options = this.options = options || {};
this.safe = options.safe
this._conditions = {};
if (criteria) this.find(criteria);
}
/**
* Query constructor
*
* @api private
* Spawns a new query that's bound to a new model.
* @param {Function} param
* @return {Query}
* @api public
*/
function Query (query, options, onExecute) {
Promise.call(this);
this.query = query || {};
this.options = options || {};
this.onExecute = onExecute;
this.executed = false;
Query.prototype.bind = function (model) {
var ret = Object.create(this);
ret.model = model;
return ret;
};
Query.prototype.find = function (criteria, callback) {
if ('function' === typeof criteria) {
callback = criteria;
criteria = {};
}
if (criteria instanceof Query) {
merge(this._conditions, criteria._conditions);
} else {
merge(this._conditions, criteria);
}
if (!callback) return this;
return this.execFind(callback);
};
/**
* Inherits from Promise.
* Casts obj, or if obj is not present, then this._conditions,
* based on the model's schema.
*
* @param {Function} model
* @param {Object} obj (optional)
* @api public
*/
Query.prototype.__proto__ = Promise.prototype;
Query.prototype.cast = function (model, obj) {
obj || (obj= this._conditions);
var schema = model.schema
, paths = Object.keys(obj)
, i = paths.length, path, val, schematype, nested
, any$conditionals, type;
while (i--) {
path = paths[i];
val = obj[path];
if (path === '$or') {
var k = val.length
, orComponentQuery;
while (k--) {
orComponentQuery = new Query(val[k])
orComponentQuery.cast(model);
val[k] = orComponentQuery._conditions;
}
} else if (path === '$where') {
type = typeof val;
if ('string' !== type && 'function' !== type) {
throw new Error("Must have a string or function for $where");
}
if ('function' === type) obj[path] = val.toString();
continue;
} else {
schematype = schema.path(path);
if (!schematype) {
// Handle potential embedded array queries
var split = path.split('.')
, j = split.length
, pathFirstHalf, pathLastHalf
, remainingConds, castingQuery;
// Find the part of the var path that is a path of the Schema
while (j--) {
pathFirstHalf = split.slice(0, j).join('.');
schematype = schema.path(pathFirstHalf);
if (schematype) break;
}
// If a substring of the input path resolves to an actual real path...
if (schematype) {
// Apply the casting; similar code for $elemMatch in schema/array.js
remainingConds = {};
pathLastHalf = split.slice(j).join('.');
remainingConds[pathLastHalf] = val;
castingQuery = new Query(remainingConds);
castingQuery.cast(schematype.caster);
obj[path] = castingQuery._conditions[pathLastHalf];
}
} else if (val === null || val === undefined) {
continue;
} else if (val.constructor == Object) {
any$conditionals = Object.keys(val).some( function (k) {
return k.charAt(0) === '$';
});
if (!any$conditionals) {
obj[path] = schematype.castForQuery(val);
} else for (var $cond in val) {
nested = val[$cond];
if ($cond === '$ne' && nested === null) {
continue;
} else if ($cond === '$exists') {
if ('boolean' !== typeof nested)
throw new Error("$exists parameter must be Boolean");
continue;
} else if ($cond === '$not') {
this.cast(model, val[$cond]);
} else {
val[$cond] = schematype.castForQuery($cond, nested);
}
}
} else {
obj[path] = schematype.castForQuery(val);
}
}
}
};
Query.prototype._optionsForExec = function (model) {
var options = utils.clone(this.options);
if (! ('safe' in options)) options.safe = model.options.safe;
return options;
};
/**
* Runs the Query
* Sometimes you need to query for things in mongodb using a JavaScript
* expression. You can do so via find({$where: javascript}), or you can
* use the mongoose shortcut method $where via a Query chain or from
* your mongoose Model.
*
* @param {Function} optional back
* @api private
* @param {String|Function} js is a javascript string or anonymous function
* @return {Query}
* @api public
*/
Query.prototype.exec =
Query.prototype.run = function (fn) {
if (this.executed)
Query.prototype.$where = function (js) {
this._conditions['$where'] = js;
return this;
};
/**
* `with` enables a very nice sugary api for doing your queries.
* For example, instead of writing:
* User.find({age: {$gte: 21, $lte: 65}}, callback);
* we can instead write more readably:
* User.with('age').gte(21).lte(65);
* Moreover, you can also chain a bunch of these together like:
* User
* .with('age').gte(21).lte(65)
* .with('name', /^b/i) // All names that begin with b or B
* .with('friends').slice(10);
* @param {String} path
* @param {Object} val (optional)
* @return {Query}
* @api public
*/
Query.prototype.with = function (path, val) {
var conds;
if (arguments.length === 2) {
this._conditions[path] = val;
}
this._currPath = path;
return this;
};
// $lt, $lte, $gt, $gte can be used on Numbers or Dates
['gt', 'gte', 'lt', 'lte', 'ne', 'in', 'nin', 'all', 'size'].forEach( function ($conditional) {
Query.prototype['$' + $conditional] =
Query.prototype[$conditional] = function (path, val) {
if (arguments.length === 1) {
val = path;
path = this._currPath
}
var conds = this._conditions[path] || (this._conditions[path] = {});
conds['$' + $conditional] = val;
return this;
};
});
if (fn)
this.addBack(fn);
Query.prototype.notEqualTo = Query.prototype.ne;
this.executed = true;
if (this.onExecute) {
try {
this.onExecute.call(this);
} catch (e) {
this.queryComplete(e);
['mod', 'near'].forEach( function ($conditional) {
Query.prototype['$' + $conditional] =
Query.prototype[$conditional] = function (path, val) {
if (arguments.length === 1) {
val = path;
path = this._currPath
} else if (arguments.length === 2 && !Array.isArray(val)) {
val = [].slice.call(arguments);
path = this._currPath;
} else if (arguments.length === 3) {
val = [].slice.call(arguments, 1);
}
var conds = this._conditions[path] || (this._conditions[path] = {});
conds['$' + $conditional] = val;
return this;
};
});
Query.prototype['$exists'] =
Query.prototype.exists = function (path, val) {
if (arguments.length === 0) {
path = this._currPath
val = true;
} else if (arguments.length === 1) {
if ('boolean' === typeof path) {
val = path;
path = this._currPath;
} else {
val = true;
}
}
var conds = this._conditions[path] || (this._conditions[path] = {});
conds['$exists'] = val;
return this;
};
Query.prototype['$elemMatch'] =
Query.prototype.elemMatch = function (path, criteria) {
var block;
if (path.constructor === Object) {
criteria = path;
path = this._currPath;
} else if ('function' === typeof path) {
block = path;
path = this._currPath;
} else if (criteria.constructor === Object) {
} else if ('function' === typeof criteria) {
block = criteria;
} else {
throw new Error("Argument error");
}
var conds = this._conditions[path] || (this._conditions[path] = {});
if (block) {
criteria = new Query();
block(criteria);
conds['$elemMatch'] = criteria._conditions;
} else {
conds['$elemMatch'] = criteria;
}
return this;
};
['maxscan'].forEach( function (method) {
Query.prototype[method] = function (v) {
this.options[method] = v;
return this;
};
});
// TODO
Query.prototype.explain = function () {
throw new Error("Unimplemented");
};
// TODO Add being able to skip casting -- e.g., this would be nice for scenarios like
// if you're migrating to usernames from user id numbers:
// query.with('user_id').in([4444, 'brian']);
// TODO "immortal" cursors
// TODO geoNear command
// To be used idiomatically with Query#box and Query#center
['within', '$within'].forEach( function (getter) {
Object.defineProperty(Query.prototype, getter, {
get: function () {
return this;
}
});
});
Query.prototype['$box'] =
Query.prototype.box = function (path, val) {
if (arguments.length === 1) {
val = path;
path = this._currPath;
}
var conds = this._conditions[path] || (this._conditions[path] = {});
conds['$within'] = { '$box': [val.ll, val.ur] };
return this;
};
Query.prototype['$center'] =
Query.prototype.center = function (path, val) {
if (arguments.length === 1) {
val = path;
path = this._currPath;
}
var conds = this._conditions[path] || (this._conditions[path] = {});
conds['$within'] = { '$center': [val.center, val.radius] };
return this;
};
/**
* Sets an option
* Chainable method for specifying which fields
* to include or exclude from the document that is
* returned from MongoDB.
*
* @param {String} key
* @param {Object} optional value
* @api public
* Examples:
* query.fields({a: 1, b: 1, c: 1, _id: 0});
* query.fields('a b c');
*
* @param {Object}
*/
Query.prototype.set = function (key, value) {
if (arguments.length == 1)
return this.options[key];
this.options[key] = value;
Query.prototype.select =
Query.prototype.fields = function () {
var arg0 = arguments[0];
if (!arg0) return this;
if (arg0.constructor === Object || Array.isArray(arg0)) {
this._applyFields(arg0);
} else if (arguments.length === 1 && typeof arg0 === 'string') {
this._applyFields({only: arg0});
} else {
this._applyFields({only: this._parseOnlyExcludeFields.apply(this, arguments)});
}
return this;

@@ -73,14 +335,17 @@ };

/**
* Add conditions to query
* Chainable method for adding the specified fields to the
* object of fields to only include.
*
* @param {Object} query
* Examples:
* query.only('a b c');
* query.only('a', 'b', 'c');
* query.only(['a', 'b', 'c']);
* @param {String|Array} space separated list of fields OR
* an array of field names
* We can also take arguments as the "array" of field names
* @api public
*/
Query.prototype.where = function (obj, value) {
if (value == undefined)
for (var i in obj)
this.query[i] = obj[i];
else
this.query[obj] = value;
Query.prototype.only = function (fields) {
fields = this._parseOnlyExcludeFields.apply(this, arguments);
this._applyFields({ only: fields });
return this;

@@ -90,32 +355,105 @@ };

/**
* Sets the `skip` option
* Chainable method for adding the specified fields to the
* object of fields to exclude.
*
* @param {Number} value
* Examples:
* query.exclude('a b c');
* query.exclude('a', 'b', 'c');
* query.exclude(['a', 'b', 'c']);
* @param {String|Array} space separated list of fields OR
* an array of field names
* We can also take arguments as the "array" of field names
* @api public
*/
Query.prototype.exclude = function (fields) {
fields = this._parseOnlyExcludeFields.apply(this, arguments);
this._applyFields({ exclude: fields });
return this;
};
Query.prototype.skip = function (v) {
return this.set('skip', v);
Query.prototype['$slice'] =
Query.prototype.slice = function (path, val) {
if (arguments.length === 1) {
val = path;
path = this._currPath
} else if (arguments.length === 2) {
if ('number' === typeof path) {
val = [path, val];
path = this._currPath;
}
} else if (arguments.length === 3) {
val = [].slice.call(arguments, 1);
}
var myFields = this._fields || (this._fields = {});
myFields[path] = { '$slice': val };
return this;
};
/**
* Sets the `limit` option
* Private method for interpreting the different ways
* you can pass in fields to both Query.prototype.only
* and Query.prototype.exclude.
*
* @param {Number} value
* @api public
* @param {String|Array|Object} fields
* @api private
*/
Query.prototype.limit = function (v) {
return this.set('limit', v);
Query.prototype._parseOnlyExcludeFields = function (fields) {
if (1 === arguments.length && 'string' === typeof fields) {
fields = fields.split(' ');
} else if (Array.isArray(fields)) {
} else {
fields = [].slice.call(arguments);
}
return fields;
};
/**
* Sets the `timeout` option
* Private method for interpreting and applying the different
* ways you can specify which fields you want to include
* or exclude.
*
* @param {Number} value
* @api public
* Example 1: Include fields 'a', 'b', and 'c' via an Array
* query.fields('a', 'b', 'c');
* query.fields(['a', 'b', 'c']);
*
* Example 2: Include fields via 'only' shortcut
* query.only('a b c');
*
* Example 3: Exclude fields via 'exclude' shortcut
* query.exclude('a b c');
*
* Example 4: Include fields via MongoDB's native format
* query.fields({a: 1, b: 1, c: 1})
*
* Example 5: Exclude fields via MongoDB's native format
* query.fields({a: 0, b: 0, c: 0});
*
* @param {Object|Array} the formatted collection of fields to
* include and/or exclude
* @api private
*/
Query.prototype._applyFields = function (fields) {
var $fields
, pathList;
if (Array.isArray(fields)) {
$fields =
fields.reduce( function ($fields, field) {
$fields[field] = 1;
return $fields;
}, {});
} else if (pathList = fields.only || fields.exclude) {
$fields =
this._parseOnlyExcludeFields(pathList)
.reduce( function ($fields, field) {
$fields[field] = fields.only ? 1: 0;
return $fields;
}, {});
} else if (fields.constructor === Object) {
$fields = fields;
} else {
throw new Error("fields is invalid");
}
Query.prototype.timeout = function (v) {
return this.set('timeout', v);
var myFields = this._fields || (this._fields = {});
for (var k in $fields) myFields[k] = $fields[k];
};

@@ -131,3 +469,2 @@

*
* @param {Object} fields
* @api public

@@ -137,26 +474,98 @@ */

Query.prototype.sort = function () {
if (!this.options.sort)
this.options.sort = [];
var args = [].slice.call(arguments)
, query = this;
var sort = this.options.sort || (this.options.sort = [])
, args = [].slice.call(arguments);
inGroupsOf(2, args, function (field, value) {
query.options.sort.push([field, value]);
sort.push([field, value]);
});
return this;
};
Query.prototype.asc = function () {
var sort = this.options.sort || (this.options.sort = []);
for (var i = 0, l = arguments.length; i < l; i++) {
sort.push([arguments[i], 1]);
}
return this;
};
Query.prototype.desc = function () {
var sort = this.options.sort || (this.options.sort = []);
for (var i = 0, l = arguments.length; i < l; i++) {
sort.push([arguments[i], -1]);
}
return this;
};
['limit', 'skip', 'maxscan', 'snapshot'].forEach( function (method) {
Query.prototype[method] = function (v) {
this.options[method] = v;
return this;
};
});
Query.prototype.execFind = function (callback) {
var model = this.model
, options = this._optionsForExec(model);
options.fields = this._fields;
try {
this.cast(model);
} catch (err) {
return callback(err);
}
var castQuery = this._conditions;
model.collection.find(castQuery, options, function (err, cursor) {
if (err) return callback(err);
cursor.toArray( function (err, docs) {
if (err) callback(err);
var arr = []
, count = docs.length;
if (!count) return callback(null, []);
for (var i = 0, l = docs.length; i < l; i++) {
arr[i] = new model();
arr[i].init(docs[i], function (err) {
if (err) return callback(err);
--count || callback(null, arr);
});
}
});
});
return this;
};
/**
* Resolves the promise from a driver response
* Casts the query, sends the findOne command to mongodb.
* Upon receiving the document, we initialize a mongoose
* document based on the returned document from mongodb,
* and then we invoke a callback on our mongoose document.
*
* @api private
* @param {Function} callback function (err, found)
* @api public
*/
Query.prototype.queryComplete = function (err) {
if (err)
this.error(err);
else
this.complete.apply(this, Array.prototype.slice.call(arguments, 1));
Query.prototype.findOne = function (callback) {
var model = this.model;
var options = this._optionsForExec(model);
options.fields = this._fields;
this.cast(model);
var castQuery = this._conditions;
model.collection.findOne(castQuery, options, function (err, doc) {
if (err) return callback(err);
if (!doc) return callback(null, null);
var casted = new model();
casted.init(doc, function (err) {
if (err) return callback(err);
callback(null, casted);
});
});
return this;

@@ -166,52 +575,60 @@ };

/**
* Find Query constructor (for queries that retrieve docs)
* Casts this._conditions and sends a count
* command to mongodb. Invokes a callback upon
* receiving results
*
* @api private
* @param {Function} callback fn(err, cardinality)
* @api public
*/
function FindQuery (query, fields, options, onExecute) {
this.fields = fields || {};
Query.call(this, query, options, onExecute);
Query.prototype.count = function (callback) {
var model = this.model;
this.cast(model);
var castQuery = this._conditions;
model.collection.count(castQuery, callback);
return this;
};
/**
* Inherits from Query.
* Casts the query, sends the update command to mongodb.
* If there is an error, the callback handles it. Otherwise,
* we just invoke the callback without passing it an error.
*
* @param {Function} callback fn(err)
* @api public
*/
FindQuery.prototype.__proto__ = Query.prototype;
Query.prototype.update = function (doc, callback) {
var model = this.model
, options = this._optionsForExec(model);
this.cast(model);
var castQuery = this._conditions;
var castingQuery = {_conditions: doc};
this.cast.call(castingQuery, model);
var castDoc = castingQuery._conditions;
model.collection.update(castQuery, castDoc, options, callback);
return this;
};
/**
* Specifies fields to return
* Casts the query, sends the remove command to
* mongodb with the query contents, and then
* invokes a callback upon receiving the command
* result.
*
* Examples:
*
* // these three are equivalent
* query.select('field', 'field2')
* query.select({ field: 1, field2: 1 })
* query.select(('field', 'field2');
*
* @param {Function} callback fn(err)
* @api public
*/
FindQuery.prototype.select = function () {
for (var i = 0, l = arguments.length; i < l; i++) {
if (Array.isArray(arguments[i])) {
for (var a = 0, l = arguments[i].length; a < l; a++)
this.fields[arguments[i][a]] = 1;
} else if ('object' == typeof arguments[i]) {
for (var a in arguments[i])
this.fields[a] = arguments[i][a];
} else if ('string' == typeof arguments[i]) {
this.fields[arguments[i]] = 1;
}
}
Query.prototype.remove = function (callback) {
var model = this.model;
this.cast(model);
var castQuery = this._conditions;
model.collection.remove(castQuery, callback);
return this;
};
/**
* Module exports
*/
exports.Query = Query;
exports.FindQuery = FindQuery;

@@ -39,3 +39,3 @@

if (!this.paths['_id'])
this.add({ _id: ObjectId });
this.add({ _id: {type: ObjectId, auto: true} });
};

@@ -156,2 +156,23 @@

/**
* Returns an Array of path strings that are required.
* @api public
*/
Object.defineProperty(Schema.prototype, 'requiredPaths', {
get: function () {
var paths = this.paths
, pathnames = Object.keys(paths)
, i = pathnames.length
, pathname, path
, requiredPaths = [];
while (i--) {
pathname = pathnames[i];
path = paths[pathname];
if (path.isRequired) requiredPaths.push(pathname);
}
return requiredPaths;
}
});
/**
* Given a path, returns whether it is a real, virtual, or

@@ -348,3 +369,100 @@ * ad-hoc/undefined path

var Query = require('./query').Query;
function NamedScope () {}
NamedScope.prototype.query;
NamedScope.prototype.with = function () {
var q = this.query || (this.query = new Query());
q.with.apply(q, arguments);
return q;
};
/**
* @param {NamedScope} target
* @param {Object} getters
*/
NamedScope.prototype.decorate = function (target, getters) {
var name = this.name
, block = this.block
, query = this.query;
if (block) {
if (block.length === 0) {
Object.defineProperty(target, name, {
get: getters.block0(block)
});
} else {
target[name] = getters.blockN(block);
}
} else {
Object.defineProperty(target, name, {
get: getters.basic(query)
});
}
};
NamedScope.prototype.compile = function (model) {
var allScopes = this.scopesByName
, scope;
for (var k in allScopes) {
scope = allScopes[k];
scope.decorate(model, {
block0: function (block) {
return function () {
var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));
block.call(cquery);
return this;
};
},
blockN: function (block) {
return function () {
var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));
block.apply(cquery, arguments);
return this;
};
},
basic: function (query) {
return function () {
var cquery = this._cumulativeQuery || (this._cumulativeQuery = new Query().bind(this));
cquery.find(query);
return this;
};
}
});
}
};
Schema.prototype.namedScope = function (name, fn) {
var namedScopes = this.namedScopes || (this.namedScopes = new NamedScope)
, newScope = Object.create(namedScopes)
, allScopes = namedScopes.scopesByName || (namedScopes.scopesByName = {});
allScopes[name] = newScope;
newScope.name = name;
newScope.block = fn;
newScope.query = new Query();
newScope.decorate(namedScopes, {
block0: function (block) {
return function () {
block.call(this.query);
return this;
};
},
blockN: function (block) {
return function () {
block.apply(this.query, arguments);
return this;
};
},
basic: function (query) {
return function () {
this.query.find(query);
return this;
};
}
});
return newScope;
};
/**
* ObjectId schema identifier. Not an actual ObjectId, only used for Schemas.

@@ -351,0 +469,0 @@ *

@@ -15,3 +15,4 @@ /**

}
, MongooseArray = require('../types').Array;
, MongooseArray = require('../types').Array
, Query = require('../query').Query;

@@ -91,2 +92,37 @@ /**

SchemaArray.prototype.$conditionalHandlers = {
'$all': function (val) {
return this.cast(val);
}
// TODO Move elemMatch to documentarray
, '$elemMatch': function (val) {
var query = new Query(val);
query.cast(this.caster)
return query._conditions;
}
, '$size': function (val) {
return ArrayNumberSchema.prototype.cast.call(this, val);
}
, '$ne': function (val) {
return this.cast(val);
}
};
SchemaArray.prototype.castForQuery = function ($conditional, val) {
var handler;
if (arguments.length === 2) {
handler = this.$conditionalHandlers[$conditional];
if (!handler)
throw new Error("Can't use " + $conditional + " with Array.");
return handler.call(this, val);
} else {
val = $conditional;
if (Array.isArray(val)) {
return this.cast(val);
} else {
return this.caster.prototype.cast.call(null, val);
}
}
};
/**

@@ -93,0 +129,0 @@ * Number casting for arrays (equivalent, but without MongoseNumber)

@@ -48,2 +48,9 @@

SchemaBoolean.prototype.castForQuery = function ($conditional, val) {
if (arguments.length === 1) {
val = $conditional;
}
return this.cast(val);
};
/**

@@ -50,0 +57,0 @@ * Module exports.

@@ -45,2 +45,3 @@

SchemaDate.prototype.cast = function (value) {
if (value === null) return value;
if (value instanceof Date)

@@ -66,2 +67,35 @@ return value;

function handleSingle (val) {
return this.cast(val);
}
function handleArray (val) {
var self = this;
return val.map( function (m) {
return self.cast(m);
});
}
SchemaDate.prototype.$conditionalHandlers = {
'$lt': handleSingle
, '$lte': handleSingle
, '$gt': handleSingle
, '$gte': handleSingle
, '$ne': handleSingle
, '$in': handleArray
, '$nin': handleArray
};
SchemaDate.prototype.castForQuery = function ($conditional, val) {
var handler;
if (arguments.length === 2) {
handler = this.$conditionalHandlers[$conditional];
if (!handler)
throw new Error("Can't use " + $conditional + " with Date.");
return handler.call(this, val);
} else {
val = $conditional;
this.cast(val);
}
};
/**

@@ -68,0 +102,0 @@ * Module exports.

@@ -30,2 +30,3 @@

EmbeddedDocument.prototype.schema = schema;
EmbeddedDocument.schema = schema;

@@ -32,0 +33,0 @@ ArrayType.call(this, key, EmbeddedDocument, options);

@@ -46,2 +46,4 @@

SchemaMixed.prototype.castForQuery = SchemaMixed.prototype.cast;
/**

@@ -48,0 +50,0 @@ * Module exports.

@@ -86,2 +86,3 @@

if (!isNaN(value)){
if (value === null) return value;
if ('string' === typeof value) value = Number(value);

@@ -95,2 +96,36 @@ if (value instanceof Number || typeof value == 'number' ||

function handleSingle (val) {
return this.cast(val).valueOf();
}
function handleArray (val) {
var self = this;
return val.map( function (m) {
return self.cast(m).valueOf();
});
}
SchemaNumber.prototype.$conditionalHandlers = {
'$lt': handleSingle
, '$lte': handleSingle
, '$gt': handleSingle
, '$gte': handleSingle
, '$ne': handleSingle
, '$in': handleArray
, '$nin': handleArray
, '$mod': handleArray
};
SchemaNumber.prototype.castForQuery = function ($conditional, val) {
var handler;
if (arguments.length === 2) {
handler = this.$conditionalHandlers[$conditional];
if (!handler)
throw new Error("Can't use " + $conditional + " with Number.");
return handler.call(this, val);
} else {
val = $conditional;
return this.cast(val);
}
};
/**

@@ -97,0 +132,0 @@ * Module exports.

@@ -22,6 +22,2 @@

SchemaType.call(this, key, options);
this.default(function(){
return new oid();
});
};

@@ -52,2 +48,3 @@

ObjectId.prototype.cast = function (value) {
if (value === null) return value;
if (value instanceof oid)

@@ -60,3 +57,45 @@ return value;

function handleSingle (val) {
return this.cast(val);
}
function handleArray (val) {
var self = this;
return val.map( function (m) {
return self.cast(m);
});
}
ObjectId.prototype.$conditionalHandlers = {
'$ne': handleSingle
, '$in': handleArray
, '$nin': handleArray
};
ObjectId.prototype.castForQuery = function ($conditional, val) {
var handler;
if (arguments.length === 2) {
handler = this.$conditionalHandlers[$conditional];
if (!handler)
throw new Error("Can't use " + $conditional + " with ObjectId.");
return handler.call(this, val);
} else {
val = $conditional;
return this.cast(val);
}
};
/**
* Adds an auto-generated ObjectId default if turnOn is true.
* @param {Boolean} turnOn auto generated ObjectId defaults
* @api private
*/
ObjectId.prototype.auto = function (turnOn) {
if (turnOn) {
this.default(function(){
return new oid();
});
}
};
/**
* Module exports.

@@ -63,0 +102,0 @@ */

@@ -90,2 +90,3 @@

SchemaString.prototype.cast = function (value) {
if (value === null) return value;
if (value.toString) return value.toString();

@@ -95,2 +96,32 @@ throw new CastError('string', value);

function handleSingle (val) {
return this.castForQuery(val);
}
function handleArray (val) {
var self = this;
return val.map( function (m) {
return self.castForQuery(m);
});
}
SchemaString.prototype.$conditionalHandlers = {
'$ne': handleSingle
, '$in': handleArray
, '$nin': handleArray
};
SchemaString.prototype.castForQuery = function ($conditional, val) {
var handler;
if (arguments.length === 2) {
handler = this.$conditionalHandlers[$conditional];
if (!handler)
throw new Error("Can't use " + $conditional + " with String.");
return handler.call(this, val);
} else {
val = $conditional;
if (val instanceof RegExp) return val;
return this.cast(val);
}
};
/**

@@ -97,0 +128,0 @@ * Module exports.

@@ -17,3 +17,2 @@

this.path = path;
this.defaultValue = null;
this.validators = [];

@@ -134,2 +133,3 @@ this.setters = [];

var checkRequired = this.checkRequired.bind(this);
this.isRequired = true;

@@ -154,5 +154,2 @@ if (false === required){

SchemaType.prototype.getDefault = function (scope) {
if (this.defaultValue === undefined)
return null;
var ret;

@@ -159,0 +156,0 @@

@@ -137,5 +137,11 @@

/**
* Object clone with Mongoose natives support
* Object clone with Mongoose natives support.
* Creates a minimal data Object.
* It does not clone empty Arrays, empty Objects,
* and undefined values.
* This makes the data payload sent to MonboDB as minimal
* as possible.
*
* @param {Object} object to clone
* @param {Boolean} shouldMinimizeData
* @return {Object} cloned object

@@ -145,11 +151,15 @@ * @api private

var clone = exports.clone = function (obj) {
var clone = exports.clone = function (obj, shouldMinimizeData) {
if (obj === undefined || obj === null)
return obj;
if (Array.isArray(obj))
return cloneArray(obj);
return obj
if (Array.isArray(obj)) {
return (obj.length || !shouldMinimizeData)
? cloneArray(obj, shouldMinimizeData)
: undefined;
}
if (obj.toObject)
return obj.toObject();
if (obj.constructor == Object)
return cloneObject(obj);
if (obj.constructor == Object) {
return cloneObject(obj, shouldMinimizeData);
}
if (obj.constructor == Date || obj.constructor == RegExp

@@ -162,16 +172,24 @@ || obj.constructor == Function)

return obj.valueOf();
return obj;
};
function cloneObject (obj) {
var ret = {};
for (var i in obj)
ret[i] = clone(obj[i]);
return ret;
function cloneObject (obj, shouldMinimizeData) {
var ret = {}
, val
, hasKeys;
for (var k in obj) {
val = clone(obj[k], shouldMinimizeData);
if (!shouldMinimizeData || ('undefined' !== typeof val)) {
hasKeys || (hasKeys = true);
ret[k] = val;
}
}
return shouldMinimizeData
? hasKeys && ret
: ret;
};
function cloneArray (arr) {
function cloneArray (arr, shouldMinimizeData) {
var ret = [];
for (var i = 0, l = arr.length; i < l; i++)
ret.push(clone(arr[i]));
ret.push(clone(arr[i], shouldMinimizeData));
return ret;

@@ -191,6 +209,6 @@ };

var opts = opts || {}
, c = clone(opts);
, c = opts;
for (var i in defaults)
if (!(i in opts))
c[i] = clone(defaults[i]);
c[i] = defaults[i];
return c;

@@ -391,1 +409,11 @@ };

};
exports.merge = function merge (objA, objB) {
for (var k in objB) {
if ('undefined' === typeof objA[k]) {
objA[k] = objB[k];
} else {
merge(objA[k], objB[k]);
}
}
};
{
"name": "mongoose"
, "description": "Mongoose MongoDB ORM"
, "version": "1.0.10"
, "version": "1.0.11"
, "author": "Guillermo Rauch <guillermo@learnboost.com>"

@@ -6,0 +6,0 @@ , "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql"]

@@ -135,3 +135,2 @@

copy.test._marked = true;
copy.oids._marked = true;
copy.nested._marked = true;

@@ -142,3 +141,2 @@ copy.nested.age._marked = true;

should.strictEqual(doc.doc.test._marked, undefined);
should.strictEqual(doc.doc.oids._marked, undefined);
should.strictEqual(doc.doc.nested._marked, undefined);

@@ -454,4 +452,12 @@ should.strictEqual(doc.doc.nested.age._marked, undefined);

obj._id.should.eql(oidString);
},
'toObject should not set undefined values to null': function () {
var doc = new TestDocument()
, obj = doc.toObject();
delete obj._id;
obj.should.eql({});
}
};

@@ -13,31 +13,552 @@

module.exports = {
'test query.fields({a: 1, b: 1, c: 1})': function () {
var query = new Query();
query.fields({a: 1, b: 1, c: 1});
query._fields.should.eql({a: 1, b: 1, c: 1});
},
'test query.fields({only: "a b c"})': function () {
var query = new Query();
query.fields({only: "a b c"});
query._fields.should.eql({a: 1, b: 1, c: 1});
},
'test query.fields({only: ["a", "b", "c"]})': function () {
var query = new Query();
query.fields({only: ['a', 'b', 'c']});
query._fields.should.eql({a: 1, b: 1, c: 1});
},
'test query.fields("a b c")': function () {
var query = new Query();
query.fields("a b c");
query._fields.should.eql({a: 1, b: 1, c: 1});
},
'test query.fields("a", "b", "c")': function () {
var query = new Query();
query.fields('a', 'b', 'c');
query._fields.should.eql({a: 1, b: 1, c: 1});
},
"test query.fields(['a', 'b', 'c'])": function () {
var query = new Query();
query.fields(['a', 'b', 'c']);
query._fields.should.eql({a: 1, b: 1, c: 1});
},
"Query#fields should not over-ride fields set in prior calls to Query#fields": function () {
var query = new Query();
query.fields('a');
query._fields.should.eql({a: 1});
query.fields('b');
query._fields.should.eql({a: 1, b: 1});
},
// "Query#fields should be able to over-ride fields set in prior calls to Query#fields if you specify override": function () {
// var query = new Query();
// query.fields('a');
// query._fields.should.eql({a: 1});
// query.override.fields('b');
// query._fields.should.eql({b: 1});
// }
'test Query#skip': function () {
"test query.only('a b c')": function () {
var query = new Query();
query.only("a b c");
query._fields.should.eql({a: 1, b: 1, c: 1});
},
"test query.only('a', 'b', 'c')": function () {
var query = new Query();
query.only('a', 'b', 'c');
query._fields.should.eql({a: 1, b: 1, c: 1});
},
"test query.only('a', 'b', 'c')": function () {
var query = new Query();
query.only(['a', 'b', 'c']);
query._fields.should.eql({a: 1, b: 1, c: 1});
},
"Query#only should not over-ride fields set in prior calls to Query#only": function () {
var query = new Query();
query.only('a');
query._fields.should.eql({a: 1});
query.only('b');
query._fields.should.eql({a: 1, b: 1});
},
query.skip(50);
query.options.skip.should.eql(50);
"test query.exclude('a b c')": function () {
var query = new Query();
query.exclude("a b c");
query._fields.should.eql({a: 0, b: 0, c: 0});
},
"test query.exclude('a', 'b', 'c')": function () {
var query = new Query();
query.exclude('a', 'b', 'c');
query._fields.should.eql({a: 0, b: 0, c: 0});
},
"test query.exclude('a', 'b', 'c')": function () {
var query = new Query();
query.exclude(['a', 'b', 'c']);
query._fields.should.eql({a: 0, b: 0, c: 0});
},
"Query#exclude should not over-ride fields set in prior calls to Query#exclude": function () {
var query = new Query();
query.exclude('a');
query._fields.should.eql({a: 0});
query.exclude('b');
query._fields.should.eql({a: 0, b: 0});
},
'test Query#limit': function () {
'test setting a condition via with': function () {
var query = new Query();
query.with('name', 'guillermo');
query._conditions.should.eql({name: 'guillermo'});
},
query.limit(3);
query.options.limit.should.eql(3);
'test Query#gte with 2 arguments': function () {
var query = new Query();
query.gte('age', 18);
query._conditions.should.eql({age: {$gte: 18}});
},
'test Query#timeout': function () {
'test Query#gt with 2 arguments': function () {
var query = new Query();
query.gt('age', 17);
query._conditions.should.eql({age: {$gt: 17}});
},
query.timeout(1000);
query.options.timeout.should.eql(1000);
'test Query#lte with 2 arguments': function () {
var query = new Query();
query.lte('age', 65);
query._conditions.should.eql({age: {$lte: 65}});
},
'test Query#lt with 2 arguments': function () {
var query = new Query();
query.lt('age', 66);
query._conditions.should.eql({age: {$lt: 66}});
},
'test Query#gte with 1 argument': function () {
var query = new Query();
query.with("age").gte(18);
query._conditions.should.eql({age: {$gte: 18}});
},
'test Query#gt with 1 argument': function () {
var query = new Query();
query.with("age").gt(17);
query._conditions.should.eql({age: {$gt: 17}});
},
'test Query#lte with 1 argument': function () {
var query = new Query();
query.with("age").lte(65);
query._conditions.should.eql({age: {$lte: 65}});
},
'test Query#lt with 1 argument': function () {
var query = new Query();
query.with("age").lt(66);
query._conditions.should.eql({age: {$lt: 66}});
},
'test combined Query#lt and Query#gt': function () {
var query = new Query();
query.with("age").lt(66).gt(17);
query._conditions.should.eql({age: {$lt: 66, $gt: 17}});
},
'test Query#lt on one path and Query#gt on another path on the same query': function () {
var query = new Query();
query
.with("age").lt(66)
.with("height").gt(5);
query._conditions.should.eql({age: {$lt: 66}, height: {$gt: 5}});
},
'test Query#ne with 2 arguments': function () {
var query = new Query();
query.ne('age', 21);
query._conditions.should.eql({age: {$ne: 21}});
},
'test Query#gte with 1 argument': function () {
var query = new Query();
query.with("age").ne(21);
query._conditions.should.eql({age: {$ne: 21}});
},
'test Query#ne alias Query#notEqualTo': function () {
var query = new Query();
query.with('age').notEqualTo(21);
query._conditions.should.eql({age: {$ne: 21}});
query = new Query();
query.notEqualTo('age', 21);
query._conditions.should.eql({age: {$ne: 21}});
},
'test Query#in with 2 arguments': function () {
var query = new Query();
query.in('age', [21, 25, 30]);
query._conditions.should.eql({age: {$in: [21, 25, 30]}});
},
'test Query#in with 1 argument': function () {
var query = new Query();
query.with("age").in([21, 25, 30]);
query._conditions.should.eql({age: {$in: [21, 25, 30]}});
},
'test Query#in with a non-array value not via with': function () {
var query = new Query();
query.in('age', 21);
query._conditions.should.eql({age: {$in: 21}});
},
'test Query#in with a non-array value via with': function () {
var query = new Query();
query.with('age').in(21);
query._conditions.should.eql({age: {$in: 21}});
},
'test Query#nin with 2 arguments': function () {
var query = new Query();
query.nin('age', [21, 25, 30]);
query._conditions.should.eql({age: {$nin: [21, 25, 30]}});
},
'test Query#nin with 1 argument': function () {
var query = new Query();
query.with("age").nin([21, 25, 30]);
query._conditions.should.eql({age: {$nin: [21, 25, 30]}});
},
'test Query#nin with a non-array value not via with': function () {
var query = new Query();
query.nin('age', 21);
query._conditions.should.eql({age: {$nin: 21}});
},
'test Query#nin with a non-array value via with': function () {
var query = new Query();
query.with('age').nin(21);
query._conditions.should.eql({age: {$nin: 21}});
},
'test Query#mod not via with, with [a, b] param': function () {
var query = new Query();
query.mod('age', [5, 2]);
query._conditions.should.eql({age: {$mod: [5, 2]}});
},
'test Query#mod not via with, with a and b params': function () {
var query = new Query();
query.mod('age', 5, 2);
query._conditions.should.eql({age: {$mod: [5, 2]}});
},
'test Query#mod via with, with [a, b] param': function () {
var query = new Query();
query.with("age").mod([5, 2]);
query._conditions.should.eql({age: {$mod: [5, 2]}});
},
'test Query#mod via with, with a and b params': function () {
var query = new Query();
query.with("age").mod(5, 2);
query._conditions.should.eql({age: {$mod: [5, 2]}});
},
'test Query#near via with, with [lat, long] param': function () {
var query = new Query();
query.with('checkin').near([40, -72]);
query._conditions.should.eql({checkin: {$near: [40, -72]}});
},
'test Query#near via with, with lat and long params': function () {
var query = new Query();
query.with('checkin').near(40, -72);
query._conditions.should.eql({checkin: {$near: [40, -72]}});
},
'test Query#near not via with, with [lat, long] param': function () {
var query = new Query();
query.near('checkin', [40, -72]);
query._conditions.should.eql({checkin: {$near: [40, -72]}});
},
'test Query#near not via with, with lat and long params': function () {
var query = new Query();
query.near('checkin', 40, -72);
query._conditions.should.eql({checkin: {$near: [40, -72]}});
},
'test Query#within.box not via with': function () {
var query = new Query();
query.within.box('gps', {ll: [5, 25], ur: [10, 30]});
query._conditions.should.eql({gps: {$within: {$box: [[5, 25], [10, 30]]}}});
},
'test Query#within.box via with': function () {
var query = new Query();
query.with('gps').within.box({ll: [5, 25], ur: [10, 30]});
query._conditions.should.eql({gps: {$within: {$box: [[5, 25], [10, 30]]}}});
},
'test Query#within.center not via with': function () {
var query = new Query();
query.within.center('gps', {center: [5, 25], radius: 5});
query._conditions.should.eql({gps: {$within: {$center: [[5, 25], 5]}}});
},
'test Query#within.center not via with': function () {
var query = new Query();
query.with('gps').within.center({center: [5, 25], radius: 5});
query._conditions.should.eql({gps: {$within: {$center: [[5, 25], 5]}}});
},
'test Query#exists with 0 arguments via with': function () {
var query = new Query();
query.with("username").exists();
query._conditions.should.eql({username: {$exists: true}});
},
'test Query#exists with 1 argument via with': function () {
var query = new Query();
query.with("username").exists(false);
query._conditions.should.eql({username: {$exists: false}});
},
'test Query#exists with 1 argument not via with': function () {
var query = new Query();
query.exists('username');
query._conditions.should.eql({username: {$exists: true}});
},
'test Query#exists with 1 argument not via with': function () {
var query = new Query();
query.exists("username", false);
query._conditions.should.eql({username: {$exists: false}});
},
// TODO $not
'test Query#all via with': function () {
var query = new Query();
query.with('pets').all(['dog', 'cat', 'ferret']);
query._conditions.should.eql({pets: {$all: ['dog', 'cat', 'ferret']}});
},
'test Query#all not via with': function () {
var query = new Query();
query.all('pets', ['dog', 'cat', 'ferret']);
query._conditions.should.eql({pets: {$all: ['dog', 'cat', 'ferret']}});
},
'test strict array equivalence condition via Query#find': function () {
var query = new Query();
query.find({'pets': ['dog', 'cat', 'ferret']});
query._conditions.should.eql({pets: ['dog', 'cat', 'ferret']});
},
// TODO Check key.index queries
'test Query#size via with': function () {
var query = new Query();
query.with('collection').size(5);
query._conditions.should.eql({collection: {$size: 5}});
},
'test Query#size not via with': function () {
var query = new Query();
query.size('collection', 5);
query._conditions.should.eql({collection: {$size: 5}});
},
'test Query#slice via with, with just positive limit param': function () {
var query = new Query();
query.with('collection').slice(5);
query._fields.should.eql({collection: {$slice: 5}});
},
'test Query#slice via with, with just negative limit param': function () {
var query = new Query();
query.with('collection').slice(-5);
query._fields.should.eql({collection: {$slice: -5}});
},
'test Query#slice via with, with [skip, limit] param': function () {
var query = new Query();
query.with('collection').slice([14, 10]); // Return the 15th through 25th
query._fields.should.eql({collection: {$slice: [14, 10]}});
},
'test Query#slice via with, with skip and limit params': function () {
var query = new Query();
query.with('collection').slice(14, 10); // Return the 15th through 25th
query._fields.should.eql({collection: {$slice: [14, 10]}});
},
'test Query#slice via with, with just positive limit param': function () {
var query = new Query();
query.with('collection').slice(5);
query._fields.should.eql({collection: {$slice: 5}});
},
'test Query#slice via with, with just negative limit param': function () {
var query = new Query();
query.with('collection').slice(-5);
query._fields.should.eql({collection: {$slice: -5}});
},
'test Query#slice via with, with the [skip, limit] param': function () {
var query = new Query();
query.with('collection').slice([14, 10]); // Return the 15th through 25th
query._fields.should.eql({collection: {$slice: [14, 10]}});
},
'test Query#slice via with, with the skip and limit params': function () {
var query = new Query();
query.with('collection').slice(14, 10); // Return the 15th through 25th
query._fields.should.eql({collection: {$slice: [14, 10]}});
},
'test Query#slice not via with, with just positive limit param': function () {
var query = new Query();
query.slice('collection', 5);
query._fields.should.eql({collection: {$slice: 5}});
},
'test Query#slice not via with, with just negative limit param': function () {
var query = new Query();
query.slice('collection', -5);
query._fields.should.eql({collection: {$slice: -5}});
},
'test Query#slice not via with, with [skip, limit] param': function () {
var query = new Query();
query.slice('collection', [14, 10]); // Return the 15th through 25th
query._fields.should.eql({collection: {$slice: [14, 10]}});
},
'test Query#slice not via with, with skip and limit params': function () {
var query = new Query();
query.slice('collection', 14, 10); // Return the 15th through 25th
query._fields.should.eql({collection: {$slice: [14, 10]}});
},
'test Query#elemMatch not via with': function () {
var query = new Query();
query.elemMatch('comments', {author: 'bnoguchi', votes: {$gte: 5}});
query._conditions.should.eql({comments: {$elemMatch: {author: 'bnoguchi', votes: {$gte: 5}}}});
},
'test Query#elemMatch not via with, with block notation': function () {
var query = new Query();
query.elemMatch('comments', function (elem) {
elem.with('author', 'bnoguchi')
elem.with('votes').gte(5);
});
query._conditions.should.eql({comments: {$elemMatch: {author: 'bnoguchi', votes: {$gte: 5}}}});
},
'test Query#elemMatch via with': function () {
var query = new Query();
query.with('comments').elemMatch({author: 'bnoguchi', votes: {$gte: 5}});
query._conditions.should.eql({comments: {$elemMatch: {author: 'bnoguchi', votes: {$gte: 5}}}});
},
'test Query#elemMatch via with, with block notation': function () {
var query = new Query();
query.with('comments').elemMatch(function (elem) {
elem.with('author', 'bnoguchi')
elem.with('votes').gte(5);
});
query._conditions.should.eql({comments: {$elemMatch: {author: 'bnoguchi', votes: {$gte: 5}}}});
},
'test Query#$where with a function arg': function () {
var query = new Query();
function filter () {
return this.lastName === this.firstName;
}
query.$where(filter);
query._conditions.should.eql({$where: filter});
},
'test Query#where with a javascript string arg': function () {
var query = new Query();
query.$where('this.lastName === this.firstName');
query._conditions.should.eql({$where: 'this.lastName === this.firstName'});
},
'test Query#limit': function () {
var query = new Query();
query.limit(5);
query.options.limit.should.equal(5);
},
'test Query#skip': function () {
var query = new Query();
query.skip(9);
query.options.skip.should.equal(9);
},
'test Query#sort': function () {
var query = new Query();
query.sort('a', 1, 'c', -1, 'b', 1);
query.options.sort.should.eql([['a', 1], ['c', -1], ['b', 1]]);
},
query.sort('test', 1, 'nope', -1);
query.options.sort.should.eql([['test', 1], ['nope', -1]]);
}
'test Query#asc and Query#desc': function () {
var query = new Query();
query.asc('a', 'z').desc('c', 'v').asc('b');
query.options.sort.should.eql([['a', 1], ['z', 1], ['c', -1], ['v', -1], ['b', 1]]);
},
// Advanced Query options
'test Query#maxscan': function () {
var query = new Query();
query.maxscan(100);
query.options.maxscan.should.equal(100);
},
// TODO
// 'test Query#min': function () {
// var query = new Query();
// query.min(10);
// query.options.min.should.equal(10);
// },
//
//TODO
// 'test Query#max': function () {
// var query = new Query();
// query.max(100);
// query.options.max.should.equal(100);
// },
// TODO Come back to this and make better
// 'test Query#hint': function () {
// var query = new Query();
// query.hint('indexAttributeA', 'indexAttributeB');
// query.options.hint.should.equal('indexAttributeA', 'indexAttributeB');
// },
// TODO
// 'test Query#explain': function () {
// }
'test Query#snapshot': function () {
var query = new Query();
query.snapshot(true);
query.options.snapshot.should.be.true;
},
// 'queries should be composable': function () {
// var q1 = new Query({name: 'hello'})
// , q2 = new Query({age: {$gte: 21}})
// , q3 = q1.and(q2);
//
// q3.should.be.an.instanceof(Query);
// q3._conditions.should.eql({name: 'hello', age: {$gte: 21}});
// }
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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