Update Node_modules
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const getDiscriminatorByValue = require('../../queryhelpers').getDiscriminatorByValue;
|
||||
|
||||
/*!
|
||||
* Find the correct constructor, taking into account discriminators
|
||||
*/
|
||||
|
||||
module.exports = function getConstructor(Constructor, value) {
|
||||
const discriminatorKey = Constructor.schema.options.discriminatorKey;
|
||||
if (value != null &&
|
||||
Constructor.discriminators &&
|
||||
value[discriminatorKey] != null) {
|
||||
if (Constructor.discriminators[value[discriminatorKey]]) {
|
||||
Constructor = Constructor.discriminators[value[discriminatorKey]];
|
||||
} else {
|
||||
const constructorByValue = getDiscriminatorByValue(Constructor, value[discriminatorKey]);
|
||||
if (constructorByValue) {
|
||||
Constructor = constructorByValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Constructor;
|
||||
};
|
||||
+1
-1
@@ -19,7 +19,7 @@ module.exports = function cleanModifiedSubpaths(doc, path, options) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (modifiedPath.indexOf(path + '.') === 0) {
|
||||
if (modifiedPath.startsWith(path + '.')) {
|
||||
delete doc.$__.activePaths.states.modify[modifiedPath];
|
||||
++deleted;
|
||||
}
|
||||
|
||||
+8
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const documentSchemaSymbol = require('../../helpers/symbols').documentSchemaSymbol;
|
||||
const get = require('../../helpers/get');
|
||||
const getSymbol = require('../../helpers/symbols').getSymbol;
|
||||
const utils = require('../../utils');
|
||||
@@ -71,6 +72,13 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
|
||||
value: prototype.schema
|
||||
});
|
||||
|
||||
Object.defineProperty(nested, documentSchemaSymbol, {
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: false,
|
||||
value: prototype.schema
|
||||
});
|
||||
|
||||
Object.defineProperty(nested, 'toObject', {
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
|
||||
+12
-2
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const middlewareFunctions = require('../query/applyQueryMiddleware').middlewareFunctions;
|
||||
const utils = require('../../utils');
|
||||
|
||||
module.exports = function applyStaticHooks(model, hooks, statics) {
|
||||
@@ -8,7 +9,16 @@ module.exports = function applyStaticHooks(model, hooks, statics) {
|
||||
numCallbackParams: 1
|
||||
};
|
||||
|
||||
hooks = hooks.filter(hook => hook.model !== false);
|
||||
hooks = hooks.filter(hook => {
|
||||
// If the custom static overwrites an existing query middleware, don't apply
|
||||
// middleware to it by default. This avoids a potential backwards breaking
|
||||
// change with plugins like `mongoose-delete` that use statics to overwrite
|
||||
// built-in Mongoose functions.
|
||||
if (middlewareFunctions.indexOf(hook.name) !== -1) {
|
||||
return !!hook.model;
|
||||
}
|
||||
return hook.model !== false;
|
||||
});
|
||||
|
||||
model.$__insertMany = hooks.createWrapper('insertMany',
|
||||
model.$__insertMany, model, kareemOptions);
|
||||
@@ -58,4 +68,4 @@ module.exports = function applyStaticHooks(model, hooks, statics) {
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
+26
-10
@@ -38,15 +38,23 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
|
||||
|
||||
const key = model.schema.options.discriminatorKey;
|
||||
|
||||
const baseSchemaAddition = {};
|
||||
baseSchemaAddition[key] = {
|
||||
default: void 0,
|
||||
select: true,
|
||||
$skipDiscriminatorCheck: true
|
||||
};
|
||||
baseSchemaAddition[key][model.schema.options.typeKey] = String;
|
||||
model.schema.add(baseSchemaAddition);
|
||||
defineKey(key, null, model.prototype, null, [key], model.schema.options);
|
||||
const existingPath = model.schema.path(key);
|
||||
if (existingPath != null) {
|
||||
if (!utils.hasUserDefinedProperty(existingPath.options, 'select')) {
|
||||
existingPath.options.select = true;
|
||||
}
|
||||
existingPath.options.$skipDiscriminatorCheck = true;
|
||||
} else {
|
||||
const baseSchemaAddition = {};
|
||||
baseSchemaAddition[key] = {
|
||||
default: void 0,
|
||||
select: true,
|
||||
$skipDiscriminatorCheck: true
|
||||
};
|
||||
baseSchemaAddition[key][model.schema.options.typeKey] = String;
|
||||
model.schema.add(baseSchemaAddition);
|
||||
defineKey(key, null, model.prototype, null, [key], model.schema.options);
|
||||
}
|
||||
|
||||
if (schema.path(key) && schema.path(key).options.$skipDiscriminatorCheck !== true) {
|
||||
throw new Error('Discriminator "' + name +
|
||||
@@ -61,6 +69,7 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
|
||||
function merge(schema, baseSchema) {
|
||||
// Retain original schema before merging base schema
|
||||
schema._originalSchema = schema.clone();
|
||||
schema._baseSchema = baseSchema;
|
||||
if (baseSchema.paths._id &&
|
||||
baseSchema.paths._id.options &&
|
||||
!baseSchema.paths._id.options.auto) {
|
||||
@@ -94,6 +103,11 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
|
||||
delete schema.paths[conflictingPaths[i]];
|
||||
}
|
||||
|
||||
// Rebuild schema models because schemas may have been merged re: #7884
|
||||
schema.childSchemas.forEach(obj => {
|
||||
obj.model.prototype.$__setSchema(obj.schema);
|
||||
});
|
||||
|
||||
const obj = {};
|
||||
obj[key] = {
|
||||
default: value,
|
||||
@@ -106,7 +120,9 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
|
||||
},
|
||||
$skipDiscriminatorCheck: true
|
||||
};
|
||||
obj[key][schema.options.typeKey] = String;
|
||||
obj[key][schema.options.typeKey] = existingPath ?
|
||||
existingPath.instance :
|
||||
String;
|
||||
schema.add(obj);
|
||||
schema.discriminatorMapping = {key: key, value: value, isRoot: false};
|
||||
|
||||
|
||||
+7
-2
@@ -90,6 +90,11 @@ module.exports = function assignVals(o) {
|
||||
const parts = o.path.split('.');
|
||||
let cur = docs[i];
|
||||
for (let j = 0; j < parts.length - 1; ++j) {
|
||||
// If we get to an array with a dotted path, like `arr.foo`, don't set
|
||||
// `foo` on the array.
|
||||
if (Array.isArray(cur) && !utils.isArrayIndex(parts[j])) {
|
||||
break;
|
||||
}
|
||||
if (cur[parts[j]] == null) {
|
||||
cur[parts[j]] = {};
|
||||
}
|
||||
@@ -190,7 +195,7 @@ function valueFilter(val, assignmentOpts, populateOptions) {
|
||||
|
||||
function maybeRemoveId(subdoc, assignmentOpts) {
|
||||
if (assignmentOpts.excludeId) {
|
||||
if (typeof subdoc.setValue === 'function') {
|
||||
if (typeof subdoc.$__setValue === 'function') {
|
||||
delete subdoc._doc._id;
|
||||
} else {
|
||||
delete subdoc._id;
|
||||
@@ -212,4 +217,4 @@ function isPopulatedObject(obj) {
|
||||
obj.$isMongooseMap ||
|
||||
obj.$__ != null ||
|
||||
leanPopulateMap.has(obj);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -9,6 +9,8 @@ const get = require('../get');
|
||||
const leanPopulateMap = require('./leanPopulateMap');
|
||||
const mpath = require('mpath');
|
||||
|
||||
const populateModelSymbol = require('../symbols').populateModelSymbol;
|
||||
|
||||
/*!
|
||||
* @param {Schema} schema
|
||||
* @param {Object} doc POJO
|
||||
@@ -138,18 +140,18 @@ module.exports = function getSchemaTypes(schema, doc, path) {
|
||||
|
||||
const fullPath = nestedPath.concat([trypath]).join('.');
|
||||
if (topLevelDoc.$__ && topLevelDoc.populated(fullPath) && p < parts.length) {
|
||||
const schema = get(doc.$__.populated[fullPath], 'options.model.schema');
|
||||
if (schema != null) {
|
||||
const model = doc.$__.populated[fullPath].options[populateModelSymbol];
|
||||
if (model != null) {
|
||||
const ret = search(
|
||||
parts.slice(p),
|
||||
schema,
|
||||
model.schema,
|
||||
subdoc ? mpath.get(trypath, subdoc) : null,
|
||||
nestedPath.concat(parts.slice(0, p))
|
||||
);
|
||||
|
||||
if (ret) {
|
||||
ret.$isUnderneathDocArray = ret.$isUnderneathDocArray ||
|
||||
!schema.$isSingleNested;
|
||||
!model.schema.$isSingleNested;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ module.exports = function isInclusive(projection) {
|
||||
for (let i = 0; i < numProps; ++i) {
|
||||
const prop = props[i];
|
||||
// Plus paths can't define the projection (see gh-7050)
|
||||
if (prop.charAt(0) === '+') {
|
||||
if (prop.startsWith('+')) {
|
||||
continue;
|
||||
}
|
||||
// If field is truthy (1, true, etc.) and not an object, then this
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../../utils');
|
||||
|
||||
module.exports = function applyGlobalMaxTimeMS(options, model) {
|
||||
if (utils.hasUserDefinedProperty(options, 'maxTimeMS')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (utils.hasUserDefinedProperty(model.db.options, 'maxTimeMS')) {
|
||||
options.maxTimeMS = model.db.options.maxTimeMS;
|
||||
} else if (utils.hasUserDefinedProperty(model.base.options, 'maxTimeMS')) {
|
||||
options.maxTimeMS = model.base.options.maxTimeMS;
|
||||
}
|
||||
};
|
||||
+3
-3
@@ -3,7 +3,7 @@
|
||||
module.exports = function castFilterPath(query, schematype, val) {
|
||||
const ctx = query;
|
||||
const any$conditionals = Object.keys(val).some(function(k) {
|
||||
return k.charAt(0) === '$' && k !== '$id' && k !== '$ref';
|
||||
return k.startsWith('$') && k !== '$id' && k !== '$ref';
|
||||
});
|
||||
|
||||
if (!any$conditionals) {
|
||||
@@ -24,7 +24,7 @@ module.exports = function castFilterPath(query, schematype, val) {
|
||||
if ($cond === '$not') {
|
||||
if (nested && schematype && !schematype.caster) {
|
||||
const _keys = Object.keys(nested);
|
||||
if (_keys.length && _keys[0].charAt(0) === '$') {
|
||||
if (_keys.length && _keys[0].startsWith('$')) {
|
||||
for (const key in nested) {
|
||||
nested[key] = schematype.castForQueryWrapper({
|
||||
$conditional: key,
|
||||
@@ -52,4 +52,4 @@ module.exports = function castFilterPath(query, schematype, val) {
|
||||
}
|
||||
|
||||
return val;
|
||||
};
|
||||
};
|
||||
|
||||
+19
-2
@@ -5,6 +5,7 @@ const StrictModeError = require('../../error/strict');
|
||||
const ValidationError = require('../../error/validation');
|
||||
const castNumber = require('../../cast/number');
|
||||
const getEmbeddedDiscriminatorPath = require('./getEmbeddedDiscriminatorPath');
|
||||
const handleImmutable = require('./handleImmutable');
|
||||
const utils = require('../../utils');
|
||||
|
||||
/*!
|
||||
@@ -70,7 +71,7 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
|
||||
while (i--) {
|
||||
const op = ops[i];
|
||||
val = ret[op];
|
||||
hasDollarKey = hasDollarKey || op.charAt(0) === '$';
|
||||
hasDollarKey = hasDollarKey || op.startsWith('$');
|
||||
|
||||
if (val &&
|
||||
typeof val === 'object' &&
|
||||
@@ -90,6 +91,10 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
|
||||
+ 'Expected an object, received ' + typeof val;
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
if (op.startsWith('$') && Object.keys(val).length === 0) {
|
||||
delete ret[op];
|
||||
}
|
||||
}
|
||||
|
||||
return hasKeys && ret;
|
||||
@@ -137,6 +142,11 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
|
||||
if (val && val.constructor.name === 'Object') {
|
||||
// watch for embedded doc schemas
|
||||
schematype = schema._getSchema(prefix + key);
|
||||
|
||||
if (handleImmutable(schematype, strict, obj, key, prefix + key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (schematype && schematype.caster && op in castOps) {
|
||||
// embedded doc schema
|
||||
if ('$each' in val) {
|
||||
@@ -218,6 +228,13 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
|
||||
const checkPath = (key === '$each' || key === '$or' || key === '$and' || key === '$in') ?
|
||||
pref : prefix + key;
|
||||
schematype = schema._getSchema(checkPath);
|
||||
|
||||
// You can use `$setOnInsert` with immutable keys
|
||||
if (op !== '$setOnInsert' &&
|
||||
handleImmutable(schematype, strict, obj, key, prefix + key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let pathDetails = schema._getPathType(checkPath);
|
||||
|
||||
// If no schema type, check for embedded discriminators
|
||||
@@ -386,7 +403,7 @@ function castUpdateVal(schema, val, op, $conditional, context, path) {
|
||||
++arrayDepth;
|
||||
}
|
||||
|
||||
let tmp = schema.cast(Array.isArray(val) ? val : [val]);
|
||||
let tmp = schema.applySetters(Array.isArray(val) ? val : [val], context);
|
||||
|
||||
for (let i = 0; i < additionalNesting; ++i) {
|
||||
tmp = tmp[0];
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const StrictModeError = require('../../error/strict');
|
||||
|
||||
module.exports = function handleImmutable(schematype, strict, obj, key, fullPath) {
|
||||
if (schematype == null || !schematype.options.immutable) {
|
||||
return false;
|
||||
}
|
||||
if (strict === false) {
|
||||
return false;
|
||||
}
|
||||
if (strict === 'throw') {
|
||||
throw new StrictModeError(null,
|
||||
`Field ${fullPath} is immutable and strict = 'throw'`);
|
||||
}
|
||||
delete obj[key];
|
||||
return true;
|
||||
};
|
||||
+1
-1
@@ -8,7 +8,7 @@ module.exports = function(obj) {
|
||||
const keys = Object.keys(obj);
|
||||
const len = keys.length;
|
||||
for (let i = 0; i < len; ++i) {
|
||||
if (keys[i].charAt(0) === '$') {
|
||||
if (keys[i].startsWith('$')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-7
@@ -15,13 +15,15 @@ module.exports = function applyPlugins(schema, plugins, options, cacheKey) {
|
||||
options = Object.assign({}, options);
|
||||
delete options.skipTopLevel;
|
||||
|
||||
for (const path of Object.keys(schema.paths)) {
|
||||
const type = schema.paths[path];
|
||||
if (type.schema != null) {
|
||||
applyPlugins(type.schema, plugins, options, cacheKey);
|
||||
if (options.applyPluginsToChildSchemas !== false) {
|
||||
for (const path of Object.keys(schema.paths)) {
|
||||
const type = schema.paths[path];
|
||||
if (type.schema != null) {
|
||||
applyPlugins(type.schema, plugins, options, cacheKey);
|
||||
|
||||
// Recompile schema because plugins may have changed it, see gh-7572
|
||||
type.caster.prototype.$__setSchema(type.schema);
|
||||
// Recompile schema because plugins may have changed it, see gh-7572
|
||||
type.caster.prototype.$__setSchema(type.schema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +42,4 @@ module.exports = function applyPlugins(schema, plugins, options, cacheKey) {
|
||||
applyPlugins(discriminatorSchema, plugins,
|
||||
{ skipTopLevel: !applyPluginsToDiscriminators }, cacheKey);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function merge(s1, s2) {
|
||||
s1.add(s2.obj);
|
||||
s1.add(s2.obj || {});
|
||||
|
||||
s1.callQueue = s1.callQueue.concat(s2.callQueue);
|
||||
s1.method(s2.methods);
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = function(schematype) {
|
||||
if (schematype.$immutable) {
|
||||
schematype.$immutableSetter = createImmutableSetter(schematype.path);
|
||||
schematype.set(schematype.$immutableSetter);
|
||||
} else if (schematype.$immutableSetter) {
|
||||
schematype.setters = schematype.setters.
|
||||
filter(fn => fn !== schematype.$immutableSetter);
|
||||
delete schematype.$immutableSetter;
|
||||
}
|
||||
};
|
||||
|
||||
function createImmutableSetter(path) {
|
||||
return function immutableSetter(v) {
|
||||
if (this.$__ == null) {
|
||||
return v;
|
||||
}
|
||||
if (this.isNew) {
|
||||
return v;
|
||||
}
|
||||
return this[path];
|
||||
};
|
||||
}
|
||||
+6
-3
@@ -29,7 +29,7 @@ module.exports = function(filter, schema, castedDoc, options) {
|
||||
}
|
||||
|
||||
for (let i = 0; i < numKeys; ++i) {
|
||||
if (keys[i].charAt(0) === '$') {
|
||||
if (keys[i].startsWith('$')) {
|
||||
modifiedPaths(castedDoc[keys[i]], '', modified);
|
||||
hasDollarUpdate = true;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ module.exports = function(filter, schema, castedDoc, options) {
|
||||
const numConditionKeys = conditionKeys.length;
|
||||
let hasDollarKey = false;
|
||||
for (let j = 0; j < numConditionKeys; ++j) {
|
||||
if (conditionKeys[j].charAt(0) === '$') {
|
||||
if (conditionKeys[j].startsWith('$')) {
|
||||
hasDollarKey = true;
|
||||
break;
|
||||
}
|
||||
@@ -69,7 +69,10 @@ module.exports = function(filter, schema, castedDoc, options) {
|
||||
}
|
||||
|
||||
schema.eachPath(function(path, schemaType) {
|
||||
if (schemaType.$isSingleNested) {
|
||||
// Skip single nested paths if underneath a map
|
||||
const isUnderneathMap = schemaType.path.endsWith('.$*') ||
|
||||
schemaType.path.indexOf('.$*.') !== -1;
|
||||
if (schemaType.$isSingleNested && !isUnderneathMap) {
|
||||
// Only handle nested schemas 1-level deep to avoid infinite
|
||||
// recursion re: https://github.com/mongodb-js/mongoose-autopopulate/issues/11
|
||||
schemaType.schema.eachPath(function(_path, _schemaType) {
|
||||
|
||||
+3
-1
@@ -5,8 +5,10 @@ exports.arrayParentSymbol = Symbol('mongoose#Array#_parent');
|
||||
exports.arrayPathSymbol = Symbol('mongoose#Array#_path');
|
||||
exports.arraySchemaSymbol = Symbol('mongoose#Array#_schema');
|
||||
exports.documentArrayParent = Symbol('mongoose:documentArrayParent');
|
||||
exports.documentSchemaSymbol = Symbol('mongoose#Document#schema');
|
||||
exports.getSymbol = Symbol('mongoose#Document#get');
|
||||
exports.modelSymbol = Symbol('mongoose#Model');
|
||||
exports.objectIdSymbol = Symbol('mongoose#ObjectId');
|
||||
exports.populateModelSymbol = Symbol('mongoose.PopulateOptions#Model');
|
||||
exports.schemaTypeSymbol = Symbol('mongoose#schemaType');
|
||||
exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
|
||||
exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ function applyTimestampsToChildren(now, update, schema) {
|
||||
let timestamps;
|
||||
let path;
|
||||
|
||||
const hasDollarKey = keys.length && keys[0].charAt(0) === '$';
|
||||
const hasDollarKey = keys.length && keys[0].startsWith('$');
|
||||
|
||||
if (hasDollarKey) {
|
||||
if (update.$push) {
|
||||
@@ -173,4 +173,4 @@ function applyTimestampsToSingleNested(subdoc, schematype, now) {
|
||||
if (createdAt != null) {
|
||||
subdoc[createdAt] = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ module.exports = function(query, schema, castedDoc, options) {
|
||||
let i;
|
||||
|
||||
for (i = 0; i < numKeys; ++i) {
|
||||
if (keys[i].charAt(0) === '$') {
|
||||
if (keys[i].startsWith('$')) {
|
||||
hasDollarUpdate = true;
|
||||
if (keys[i] === '$push' || keys[i] === '$addToSet') {
|
||||
_keys = Object.keys(castedDoc[keys[i]]);
|
||||
@@ -63,7 +63,7 @@ module.exports = function(query, schema, castedDoc, options) {
|
||||
key = keys[i];
|
||||
// With `$pull` we might flatten `$in`. Skip stuff nested under `$in`
|
||||
// for the rest of the logic, it will get handled later.
|
||||
if (updatedPath.indexOf('$') !== -1) {
|
||||
if (updatedPath.includes('$')) {
|
||||
continue;
|
||||
}
|
||||
if (key === '$set' || key === '$setOnInsert' ||
|
||||
|
||||
Reference in New Issue
Block a user