mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Updated mongoose
This commit is contained in:
88
node_modules/mongoose/lib/schema/objectid.js
generated
vendored
88
node_modules/mongoose/lib/schema/objectid.js
generated
vendored
@ -1,13 +1,14 @@
|
||||
/* eslint no-empty: 1 */
|
||||
|
||||
/*!
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var SchemaType = require('../schematype')
|
||||
, CastError = SchemaType.CastError
|
||||
, driver = global.MONGOOSE_DRIVER_PATH || './../drivers/node-mongodb-native'
|
||||
, oid = require('../types/objectid')
|
||||
, utils = require('../utils')
|
||||
, Document
|
||||
var SchemaType = require('../schematype'),
|
||||
CastError = SchemaType.CastError,
|
||||
oid = require('../types/objectid'),
|
||||
utils = require('../utils'),
|
||||
Document;
|
||||
|
||||
/**
|
||||
* ObjectId SchemaType constructor.
|
||||
@ -18,15 +19,23 @@ var SchemaType = require('../schematype')
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function ObjectId (key, options) {
|
||||
function ObjectId(key, options) {
|
||||
SchemaType.call(this, key, options, 'ObjectID');
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This schema type's name, to defend against minifiers that mangle
|
||||
* function names.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
ObjectId.schemaName = 'ObjectId';
|
||||
|
||||
/*!
|
||||
* Inherits from SchemaType.
|
||||
*/
|
||||
|
||||
ObjectId.prototype.__proto__ = SchemaType.prototype;
|
||||
ObjectId.prototype = Object.create( SchemaType.prototype );
|
||||
ObjectId.prototype.constructor = ObjectId;
|
||||
|
||||
/**
|
||||
* Adds an auto-generated ObjectId default if turnOn is true.
|
||||
@ -35,10 +44,10 @@ ObjectId.prototype.__proto__ = SchemaType.prototype;
|
||||
* @return {SchemaType} this
|
||||
*/
|
||||
|
||||
ObjectId.prototype.auto = function (turnOn) {
|
||||
ObjectId.prototype.auto = function(turnOn) {
|
||||
if (turnOn) {
|
||||
this.default(defaultId);
|
||||
this.set(resetId)
|
||||
this.set(resetId);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -50,7 +59,7 @@ ObjectId.prototype.auto = function (turnOn) {
|
||||
* @api private
|
||||
*/
|
||||
|
||||
ObjectId.prototype.checkRequired = function checkRequired (value, doc) {
|
||||
ObjectId.prototype.checkRequired = function checkRequired(value, doc) {
|
||||
if (SchemaType._isRef(this, value, doc, true)) {
|
||||
return null != value;
|
||||
} else {
|
||||
@ -67,7 +76,7 @@ ObjectId.prototype.checkRequired = function checkRequired (value, doc) {
|
||||
* @api private
|
||||
*/
|
||||
|
||||
ObjectId.prototype.cast = function (value, doc, init) {
|
||||
ObjectId.prototype.cast = function(value, doc, init) {
|
||||
if (SchemaType._isRef(this, value, doc, init)) {
|
||||
// wait! we may need to cast this to a document
|
||||
|
||||
@ -101,17 +110,26 @@ ObjectId.prototype.cast = function (value, doc, init) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (value === null) return value;
|
||||
// If null or undefined
|
||||
if (value == null) return value;
|
||||
|
||||
if (value instanceof oid)
|
||||
return value;
|
||||
|
||||
if (value._id && value._id instanceof oid)
|
||||
return value._id;
|
||||
if (value._id) {
|
||||
if (value._id instanceof oid) {
|
||||
return value._id;
|
||||
}
|
||||
if (value._id.toString instanceof Function) {
|
||||
try {
|
||||
return oid.createFromHexString(value._id.toString());
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (value.toString) {
|
||||
if (value.toString instanceof Function) {
|
||||
try {
|
||||
return oid.fromString(value.toString());
|
||||
return oid.createFromHexString(value.toString());
|
||||
} catch (err) {
|
||||
throw new CastError('ObjectId', value, this.path);
|
||||
}
|
||||
@ -124,27 +142,17 @@ ObjectId.prototype.cast = function (value, doc, init) {
|
||||
* ignore
|
||||
*/
|
||||
|
||||
function handleSingle (val) {
|
||||
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 =
|
||||
utils.options(SchemaType.prototype.$conditionalHandlers, {
|
||||
'$gt': handleSingle,
|
||||
'$gte': handleSingle,
|
||||
'$lt': handleSingle,
|
||||
'$lte': handleSingle
|
||||
});
|
||||
}
|
||||
|
||||
ObjectId.prototype.$conditionalHandlers = {
|
||||
'$ne': handleSingle
|
||||
, '$in': handleArray
|
||||
, '$nin': handleArray
|
||||
, '$gt': handleSingle
|
||||
, '$lt': handleSingle
|
||||
, '$gte': handleSingle
|
||||
, '$lte': handleSingle
|
||||
, '$all': handleArray
|
||||
};
|
||||
|
||||
/**
|
||||
* Casts contents for queries.
|
||||
@ -154,7 +162,7 @@ ObjectId.prototype.$conditionalHandlers = {
|
||||
* @api private
|
||||
*/
|
||||
|
||||
ObjectId.prototype.castForQuery = function ($conditional, val) {
|
||||
ObjectId.prototype.castForQuery = function($conditional, val) {
|
||||
var handler;
|
||||
if (arguments.length === 2) {
|
||||
handler = this.$conditionalHandlers[$conditional];
|
||||
@ -170,11 +178,11 @@ ObjectId.prototype.castForQuery = function ($conditional, val) {
|
||||
* ignore
|
||||
*/
|
||||
|
||||
function defaultId () {
|
||||
function defaultId() {
|
||||
return new oid();
|
||||
};
|
||||
}
|
||||
|
||||
function resetId (v) {
|
||||
function resetId(v) {
|
||||
this.$__._id = null;
|
||||
return v;
|
||||
}
|
||||
|
Reference in New Issue
Block a user