Cleanup
This commit is contained in:
49
node_modules/mongoose/lib/schema/buffer.js
generated
vendored
49
node_modules/mongoose/lib/schema/buffer.js
generated
vendored
@@ -10,11 +10,8 @@ const SchemaType = require('../schematype');
|
||||
const handleBitwiseOperator = require('./operators/bitwise');
|
||||
const utils = require('../utils');
|
||||
|
||||
const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
|
||||
|
||||
const Binary = MongooseBuffer.Binary;
|
||||
const CastError = SchemaType.CastError;
|
||||
let Document;
|
||||
|
||||
/**
|
||||
* Buffer SchemaType constructor
|
||||
@@ -124,36 +121,30 @@ SchemaBuffer.prototype.checkRequired = function(value, doc) {
|
||||
SchemaBuffer.prototype.cast = function(value, doc, init) {
|
||||
let ret;
|
||||
if (SchemaType._isRef(this, value, doc, init)) {
|
||||
// wait! we may need to cast this to a document
|
||||
|
||||
if (value === null || value === undefined) {
|
||||
if (value && value.isMongooseBuffer) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// lazy load
|
||||
Document || (Document = require('./../document'));
|
||||
|
||||
if (value instanceof Document) {
|
||||
value.$__.wasPopulated = true;
|
||||
return value;
|
||||
}
|
||||
|
||||
// setting a populated path
|
||||
if (Buffer.isBuffer(value)) {
|
||||
if (!value || !value.isMongooseBuffer) {
|
||||
value = new MongooseBuffer(value, [this.path, doc]);
|
||||
if (this.options.subtype != null) {
|
||||
value._subtype = this.options.subtype;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
} else if (!utils.isObject(value)) {
|
||||
throw new CastError('Buffer', 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);
|
||||
ret = new pop.options[populateModelSymbol](value);
|
||||
ret.$__.wasPopulated = true;
|
||||
return ret;
|
||||
if (value instanceof Binary) {
|
||||
ret = new MongooseBuffer(value.value(true), [this.path, doc]);
|
||||
if (typeof value.sub_type !== 'number') {
|
||||
throw new CastError('Buffer', value, this.path, null, this);
|
||||
}
|
||||
ret._subtype = value.sub_type;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return this._castRef(value, doc, init);
|
||||
}
|
||||
|
||||
// documents
|
||||
@@ -213,9 +204,9 @@ SchemaBuffer.prototype.cast = function(value, doc, init) {
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var s = new Schema({ uuid: { type: Buffer, subtype: 4 });
|
||||
* var M = db.model('M', s);
|
||||
* var m = new M({ uuid: 'test string' });
|
||||
* const s = new Schema({ uuid: { type: Buffer, subtype: 4 });
|
||||
* const M = db.model('M', s);
|
||||
* const m = new M({ uuid: 'test string' });
|
||||
* m.uuid._subtype; // 4
|
||||
*
|
||||
* @param {Number} subtype the default subtype
|
||||
|
||||
Reference in New Issue
Block a user