Cleanup
This commit is contained in:
57
node_modules/mongoose/lib/schema/boolean.js
generated
vendored
57
node_modules/mongoose/lib/schema/boolean.js
generated
vendored
@@ -94,18 +94,24 @@ SchemaBoolean.cast = function cast(caster) {
|
||||
return this._cast;
|
||||
}
|
||||
if (caster === false) {
|
||||
caster = v => {
|
||||
if (v != null && typeof v !== 'boolean') {
|
||||
throw new Error();
|
||||
}
|
||||
return v;
|
||||
};
|
||||
caster = this._defaultCaster;
|
||||
}
|
||||
this._cast = caster;
|
||||
|
||||
return this._cast;
|
||||
};
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
SchemaBoolean._defaultCaster = v => {
|
||||
if (v != null && typeof v !== 'boolean') {
|
||||
throw new Error();
|
||||
}
|
||||
return v;
|
||||
};
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
@@ -188,9 +194,15 @@ Object.defineProperty(SchemaBoolean, 'convertToFalse', {
|
||||
*/
|
||||
|
||||
SchemaBoolean.prototype.cast = function(value) {
|
||||
const castBoolean = typeof this.constructor.cast === 'function' ?
|
||||
this.constructor.cast() :
|
||||
SchemaBoolean.cast();
|
||||
let castBoolean;
|
||||
if (typeof this._castFunction === 'function') {
|
||||
castBoolean = this._castFunction;
|
||||
} else if (typeof this.constructor.cast === 'function') {
|
||||
castBoolean = this.constructor.cast();
|
||||
} else {
|
||||
castBoolean = SchemaBoolean.cast();
|
||||
}
|
||||
|
||||
try {
|
||||
return castBoolean(value);
|
||||
} catch (error) {
|
||||
@@ -224,6 +236,33 @@ SchemaBoolean.prototype.castForQuery = function($conditional, val) {
|
||||
return this._castForQuery($conditional);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SchemaBoolean.prototype._castNullish = function _castNullish(v) {
|
||||
if (typeof v === 'undefined' &&
|
||||
this.$$context != null &&
|
||||
this.$$context._mongooseOptions != null &&
|
||||
this.$$context._mongooseOptions.omitUndefined) {
|
||||
return v;
|
||||
}
|
||||
const castBoolean = typeof this.constructor.cast === 'function' ?
|
||||
this.constructor.cast() :
|
||||
SchemaBoolean.cast();
|
||||
if (castBoolean == null) {
|
||||
return v;
|
||||
}
|
||||
if (castBoolean.convertToFalse instanceof Set && castBoolean.convertToFalse.has(v)) {
|
||||
return false;
|
||||
}
|
||||
if (castBoolean.convertToTrue instanceof Set && castBoolean.convertToTrue.has(v)) {
|
||||
return true;
|
||||
}
|
||||
return v;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user