Initial Commit
This commit is contained in:
28
node_modules/mongoose/lib/plugins/idGetter.js
generated
vendored
Normal file
28
node_modules/mongoose/lib/plugins/idGetter.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = function(schema) {
|
||||
// ensure the documents receive an id getter unless disabled
|
||||
const autoIdGetter = !schema.paths['id'] &&
|
||||
(!schema.options.noVirtualId && schema.options.id);
|
||||
if (!autoIdGetter) {
|
||||
return;
|
||||
}
|
||||
|
||||
schema.virtual('id').get(idGetter);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Returns this documents _id cast to a string.
|
||||
*/
|
||||
|
||||
function idGetter() {
|
||||
if (this._id != null) {
|
||||
return String(this._id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
31
node_modules/mongoose/lib/plugins/removeSubdocs.js
generated
vendored
Normal file
31
node_modules/mongoose/lib/plugins/removeSubdocs.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const each = require('../helpers/each');
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = function(schema) {
|
||||
const unshift = true;
|
||||
schema.s.hooks.pre('remove', false, function(next) {
|
||||
if (this.ownerDocument) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const _this = this;
|
||||
const subdocs = this.$__getAllSubdocs();
|
||||
|
||||
each(subdocs, function(subdoc, cb) {
|
||||
subdoc.$__remove(cb);
|
||||
}, function(error) {
|
||||
if (error) {
|
||||
return _this.schema.s.hooks.execPost('remove:error', _this, [_this], { error: error }, function(error) {
|
||||
next(error);
|
||||
});
|
||||
}
|
||||
next();
|
||||
});
|
||||
}, null, unshift);
|
||||
};
|
||||
66
node_modules/mongoose/lib/plugins/saveSubdocs.js
generated
vendored
Normal file
66
node_modules/mongoose/lib/plugins/saveSubdocs.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
const each = require('../helpers/each');
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = function(schema) {
|
||||
const unshift = true;
|
||||
schema.s.hooks.pre('save', false, function(next) {
|
||||
if (this.ownerDocument) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const _this = this;
|
||||
const subdocs = this.$__getAllSubdocs();
|
||||
|
||||
if (!subdocs.length) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
each(subdocs, function(subdoc, cb) {
|
||||
subdoc.schema.s.hooks.execPre('save', subdoc, function(err) {
|
||||
cb(err);
|
||||
});
|
||||
}, function(error) {
|
||||
if (error) {
|
||||
return _this.schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
|
||||
next(error);
|
||||
});
|
||||
}
|
||||
next();
|
||||
});
|
||||
}, null, unshift);
|
||||
|
||||
schema.s.hooks.post('save', function(doc, next) {
|
||||
if (this.ownerDocument) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const _this = this;
|
||||
const subdocs = this.$__getAllSubdocs();
|
||||
|
||||
if (!subdocs.length) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
each(subdocs, function(subdoc, cb) {
|
||||
subdoc.schema.s.hooks.execPost('save', subdoc, [subdoc], function(err) {
|
||||
cb(err);
|
||||
});
|
||||
}, function(error) {
|
||||
if (error) {
|
||||
return _this.schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
|
||||
next(error);
|
||||
});
|
||||
}
|
||||
next();
|
||||
});
|
||||
}, null, unshift);
|
||||
};
|
||||
83
node_modules/mongoose/lib/plugins/sharding.js
generated
vendored
Normal file
83
node_modules/mongoose/lib/plugins/sharding.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
const objectIdSymbol = require('../helpers/symbols').objectIdSymbol;
|
||||
const utils = require('../utils');
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = function shardingPlugin(schema) {
|
||||
schema.post('init', function() {
|
||||
storeShard.call(this);
|
||||
return this;
|
||||
});
|
||||
schema.pre('save', function(next) {
|
||||
applyWhere.call(this);
|
||||
next();
|
||||
});
|
||||
schema.pre('remove', function(next) {
|
||||
applyWhere.call(this);
|
||||
next();
|
||||
});
|
||||
schema.post('save', function() {
|
||||
storeShard.call(this);
|
||||
});
|
||||
};
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
function applyWhere() {
|
||||
let paths;
|
||||
let len;
|
||||
|
||||
if (this.$__.shardval) {
|
||||
paths = Object.keys(this.$__.shardval);
|
||||
len = paths.length;
|
||||
|
||||
this.$where = this.$where || {};
|
||||
for (let i = 0; i < len; ++i) {
|
||||
this.$where[paths[i]] = this.$__.shardval[paths[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports.storeShard = storeShard;
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
function storeShard() {
|
||||
// backwards compat
|
||||
const key = this.schema.options.shardKey || this.schema.options.shardkey;
|
||||
if (!utils.isPOJO(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const orig = this.$__.shardval = {};
|
||||
const paths = Object.keys(key);
|
||||
const len = paths.length;
|
||||
let val;
|
||||
|
||||
for (let i = 0; i < len; ++i) {
|
||||
val = this.$__getValue(paths[i]);
|
||||
if (val == null) {
|
||||
orig[paths[i]] = val;
|
||||
} else if (utils.isMongooseObject(val)) {
|
||||
orig[paths[i]] = val.toObject({ depopulate: true, _isNested: true });
|
||||
} else if (val instanceof Date || val[objectIdSymbol]) {
|
||||
orig[paths[i]] = val;
|
||||
} else if (typeof val.valueOf === 'function') {
|
||||
orig[paths[i]] = val.valueOf();
|
||||
} else {
|
||||
orig[paths[i]] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
node_modules/mongoose/lib/plugins/validateBeforeSave.js
generated
vendored
Normal file
45
node_modules/mongoose/lib/plugins/validateBeforeSave.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = function(schema) {
|
||||
const unshift = true;
|
||||
schema.pre('save', false, function validateBeforeSave(next, options) {
|
||||
const _this = this;
|
||||
// Nested docs have their own presave
|
||||
if (this.ownerDocument) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const hasValidateBeforeSaveOption = options &&
|
||||
(typeof options === 'object') &&
|
||||
('validateBeforeSave' in options);
|
||||
|
||||
let shouldValidate;
|
||||
if (hasValidateBeforeSaveOption) {
|
||||
shouldValidate = !!options.validateBeforeSave;
|
||||
} else {
|
||||
shouldValidate = this.schema.options.validateBeforeSave;
|
||||
}
|
||||
|
||||
// Validate
|
||||
if (shouldValidate) {
|
||||
const hasValidateModifiedOnlyOption = options &&
|
||||
(typeof options === 'object') &&
|
||||
('validateModifiedOnly' in options);
|
||||
const validateOptions = hasValidateModifiedOnlyOption ?
|
||||
{ validateModifiedOnly: options.validateModifiedOnly } :
|
||||
null;
|
||||
this.validate(validateOptions, function(error) {
|
||||
return _this.schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
|
||||
_this.$op = 'save';
|
||||
next(error);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}, null, unshift);
|
||||
};
|
||||
Reference in New Issue
Block a user