Cleanup
This commit is contained in:
69
node_modules/mongoose/lib/schema/decimal128.js
generated
vendored
69
node_modules/mongoose/lib/schema/decimal128.js
generated
vendored
@@ -10,10 +10,6 @@ const Decimal128Type = require('../types/decimal128');
|
||||
const castDecimal128 = require('../cast/decimal128');
|
||||
const utils = require('../utils');
|
||||
|
||||
const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
|
||||
|
||||
let Document;
|
||||
|
||||
/**
|
||||
* Decimal128 SchemaType constructor.
|
||||
*
|
||||
@@ -97,18 +93,24 @@ Decimal128.cast = function cast(caster) {
|
||||
return this._cast;
|
||||
}
|
||||
if (caster === false) {
|
||||
caster = v => {
|
||||
if (v != null && !(v instanceof Decimal128Type)) {
|
||||
throw new Error();
|
||||
}
|
||||
return v;
|
||||
};
|
||||
caster = this._defaultCaster;
|
||||
}
|
||||
this._cast = caster;
|
||||
|
||||
return this._cast;
|
||||
};
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
Decimal128._defaultCaster = v => {
|
||||
if (v != null && !(v instanceof Decimal128Type)) {
|
||||
throw new Error();
|
||||
}
|
||||
return v;
|
||||
};
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
@@ -162,49 +164,22 @@ Decimal128.prototype.checkRequired = function checkRequired(value, doc) {
|
||||
|
||||
Decimal128.prototype.cast = function(value, doc, init) {
|
||||
if (SchemaType._isRef(this, value, doc, init)) {
|
||||
// wait! we may need to cast this to a document
|
||||
|
||||
if (value === null || value === undefined) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// lazy load
|
||||
Document || (Document = require('./../document'));
|
||||
|
||||
if (value instanceof Document) {
|
||||
value.$__.wasPopulated = true;
|
||||
return value;
|
||||
}
|
||||
|
||||
// setting a populated path
|
||||
if (value instanceof Decimal128Type) {
|
||||
return value;
|
||||
} else if (Buffer.isBuffer(value) || !utils.isObject(value)) {
|
||||
throw new CastError('Decimal128', value, this.path, null, this);
|
||||
}
|
||||
|
||||
// Handle the case where user directly sets a populated
|
||||
// path to a plain object; cast to the Model used in
|
||||
// the population query.
|
||||
const path = doc.$__fullPath(this.path);
|
||||
const owner = doc.ownerDocument ? doc.ownerDocument() : doc;
|
||||
const pop = owner.populated(path, true);
|
||||
let ret = value;
|
||||
if (!doc.$__.populated ||
|
||||
!doc.$__.populated[path] ||
|
||||
!doc.$__.populated[path].options ||
|
||||
!doc.$__.populated[path].options.options ||
|
||||
!doc.$__.populated[path].options.options.lean) {
|
||||
ret = new pop.options[populateModelSymbol](value);
|
||||
ret.$__.wasPopulated = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return this._castRef(value, doc, init);
|
||||
}
|
||||
|
||||
let castDecimal128;
|
||||
if (typeof this._castFunction === 'function') {
|
||||
castDecimal128 = this._castFunction;
|
||||
} else if (typeof this.constructor.cast === 'function') {
|
||||
castDecimal128 = this.constructor.cast();
|
||||
} else {
|
||||
castDecimal128 = Decimal128.cast();
|
||||
}
|
||||
|
||||
const castDecimal128 = typeof this.constructor.cast === 'function' ?
|
||||
this.constructor.cast() :
|
||||
Decimal128.cast();
|
||||
try {
|
||||
return castDecimal128(value);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user