summaryrefslogtreecommitdiffstats
path: root/node_modules/mongoose/lib/helpers/query
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/mongoose/lib/helpers/query
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/mongoose/lib/helpers/query')
-rw-r--r--node_modules/mongoose/lib/helpers/query/applyGlobalMaxTimeMS.js15
-rw-r--r--node_modules/mongoose/lib/helpers/query/applyQueryMiddleware.js90
-rw-r--r--node_modules/mongoose/lib/helpers/query/castFilterPath.js55
-rw-r--r--node_modules/mongoose/lib/helpers/query/castUpdate.js538
-rw-r--r--node_modules/mongoose/lib/helpers/query/completeMany.js47
-rw-r--r--node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js68
-rw-r--r--node_modules/mongoose/lib/helpers/query/handleImmutable.js28
-rw-r--r--node_modules/mongoose/lib/helpers/query/hasDollarKeys.js19
-rw-r--r--node_modules/mongoose/lib/helpers/query/isOperator.js11
-rw-r--r--node_modules/mongoose/lib/helpers/query/selectPopulatedFields.js46
-rw-r--r--node_modules/mongoose/lib/helpers/query/wrapThunk.js18
11 files changed, 935 insertions, 0 deletions
diff --git a/node_modules/mongoose/lib/helpers/query/applyGlobalMaxTimeMS.js b/node_modules/mongoose/lib/helpers/query/applyGlobalMaxTimeMS.js
new file mode 100644
index 0000000..cb49260
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/applyGlobalMaxTimeMS.js
@@ -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;
+ }
+}; \ No newline at end of file
diff --git a/node_modules/mongoose/lib/helpers/query/applyQueryMiddleware.js b/node_modules/mongoose/lib/helpers/query/applyQueryMiddleware.js
new file mode 100644
index 0000000..a08baf8
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/applyQueryMiddleware.js
@@ -0,0 +1,90 @@
+'use strict';
+
+/*!
+ * ignore
+ */
+
+module.exports = applyQueryMiddleware;
+
+/*!
+ * ignore
+ */
+
+applyQueryMiddleware.middlewareFunctions = [
+ 'count',
+ 'countDocuments',
+ 'deleteMany',
+ 'deleteOne',
+ 'distinct',
+ 'estimatedDocumentCount',
+ 'find',
+ 'findOne',
+ 'findOneAndDelete',
+ 'findOneAndRemove',
+ 'findOneAndReplace',
+ 'findOneAndUpdate',
+ 'remove',
+ 'replaceOne',
+ 'update',
+ 'updateMany',
+ 'updateOne',
+ 'validate'
+];
+
+/*!
+ * Apply query middleware
+ *
+ * @param {Query} query constructor
+ * @param {Model} model
+ */
+
+function applyQueryMiddleware(Query, model) {
+ const kareemOptions = {
+ useErrorHandlers: true,
+ numCallbackParams: 1,
+ nullResultByDefault: true
+ };
+
+ const middleware = model.hooks.filter(hook => {
+ const contexts = _getContexts(hook);
+ if (hook.name === 'updateOne') {
+ return contexts.query == null || !!contexts.query;
+ }
+ if (hook.name === 'deleteOne') {
+ return !!contexts.query || Object.keys(contexts).length === 0;
+ }
+ if (hook.name === 'validate' || hook.name === 'remove') {
+ return !!contexts.query;
+ }
+ return true;
+ });
+
+ // `update()` thunk has a different name because `_update` was already taken
+ Query.prototype._execUpdate = middleware.createWrapper('update',
+ Query.prototype._execUpdate, null, kareemOptions);
+ // `distinct()` thunk has a different name because `_distinct` was already taken
+ Query.prototype.__distinct = middleware.createWrapper('distinct',
+ Query.prototype.__distinct, null, kareemOptions);
+
+ // `validate()` doesn't have a thunk because it doesn't execute a query.
+ Query.prototype.validate = middleware.createWrapper('validate',
+ Query.prototype.validate, null, kareemOptions);
+
+ applyQueryMiddleware.middlewareFunctions.
+ filter(v => v !== 'update' && v !== 'distinct' && v !== 'validate').
+ forEach(fn => {
+ Query.prototype[`_${fn}`] = middleware.createWrapper(fn,
+ Query.prototype[`_${fn}`], null, kareemOptions);
+ });
+}
+
+function _getContexts(hook) {
+ const ret = {};
+ if (hook.hasOwnProperty('query')) {
+ ret.query = hook.query;
+ }
+ if (hook.hasOwnProperty('document')) {
+ ret.document = hook.document;
+ }
+ return ret;
+} \ No newline at end of file
diff --git a/node_modules/mongoose/lib/helpers/query/castFilterPath.js b/node_modules/mongoose/lib/helpers/query/castFilterPath.js
new file mode 100644
index 0000000..74ff1c2
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/castFilterPath.js
@@ -0,0 +1,55 @@
+'use strict';
+
+const isOperator = require('./isOperator');
+
+module.exports = function castFilterPath(query, schematype, val) {
+ const ctx = query;
+ const any$conditionals = Object.keys(val).some(isOperator);
+
+ if (!any$conditionals) {
+ return schematype.castForQueryWrapper({
+ val: val,
+ context: ctx
+ });
+ }
+
+ const ks = Object.keys(val);
+
+ let k = ks.length;
+
+ while (k--) {
+ const $cond = ks[k];
+ const nested = val[$cond];
+
+ if ($cond === '$not') {
+ if (nested && schematype && !schematype.caster) {
+ const _keys = Object.keys(nested);
+ if (_keys.length && isOperator(_keys[0])) {
+ for (const key in nested) {
+ nested[key] = schematype.castForQueryWrapper({
+ $conditional: key,
+ val: nested[key],
+ context: ctx
+ });
+ }
+ } else {
+ val[$cond] = schematype.castForQueryWrapper({
+ $conditional: $cond,
+ val: nested,
+ context: ctx
+ });
+ }
+ continue;
+ }
+ // cast(schematype.caster ? schematype.caster.schema : schema, nested, options, context);
+ } else {
+ val[$cond] = schematype.castForQueryWrapper({
+ $conditional: $cond,
+ val: nested,
+ context: ctx
+ });
+ }
+ }
+
+ return val;
+}; \ No newline at end of file
diff --git a/node_modules/mongoose/lib/helpers/query/castUpdate.js b/node_modules/mongoose/lib/helpers/query/castUpdate.js
new file mode 100644
index 0000000..bf60e5d
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/castUpdate.js
@@ -0,0 +1,538 @@
+'use strict';
+
+const CastError = require('../../error/cast');
+const MongooseError = require('../../error/mongooseError');
+const StrictModeError = require('../../error/strict');
+const ValidationError = require('../../error/validation');
+const castNumber = require('../../cast/number');
+const cast = require('../../cast');
+const getEmbeddedDiscriminatorPath = require('./getEmbeddedDiscriminatorPath');
+const handleImmutable = require('./handleImmutable');
+const moveImmutableProperties = require('../update/moveImmutableProperties');
+const schemaMixedSymbol = require('../../schema/symbols').schemaMixedSymbol;
+const utils = require('../../utils');
+
+/*!
+ * Casts an update op based on the given schema
+ *
+ * @param {Schema} schema
+ * @param {Object} obj
+ * @param {Object} options
+ * @param {Boolean} [options.overwrite] defaults to false
+ * @param {Boolean|String} [options.strict] defaults to true
+ * @param {Query} context passed to setters
+ * @return {Boolean} true iff the update is non-empty
+ */
+
+module.exports = function castUpdate(schema, obj, options, context, filter) {
+ if (obj == null) {
+ return undefined;
+ }
+ options = options || {};
+
+ // Update pipeline
+ if (Array.isArray(obj)) {
+ const len = obj.length;
+ for (let i = 0; i < len; ++i) {
+ const ops = Object.keys(obj[i]);
+ for (const op of ops) {
+ obj[i][op] = castPipelineOperator(op, obj[i][op]);
+ }
+ }
+ return obj;
+ }
+
+ if (options.upsert) {
+ moveImmutableProperties(schema, obj, context);
+ }
+
+ const ops = Object.keys(obj);
+ let i = ops.length;
+ const ret = {};
+ let val;
+ let hasDollarKey = false;
+ const overwrite = options.overwrite;
+
+ filter = filter || {};
+
+ while (i--) {
+ const op = ops[i];
+ // if overwrite is set, don't do any of the special $set stuff
+ if (op[0] !== '$' && !overwrite) {
+ // fix up $set sugar
+ if (!ret.$set) {
+ if (obj.$set) {
+ ret.$set = obj.$set;
+ } else {
+ ret.$set = {};
+ }
+ }
+ ret.$set[op] = obj[op];
+ ops.splice(i, 1);
+ if (!~ops.indexOf('$set')) ops.push('$set');
+ } else if (op === '$set') {
+ if (!ret.$set) {
+ ret[op] = obj[op];
+ }
+ } else {
+ ret[op] = obj[op];
+ }
+ }
+
+ // cast each value
+ i = ops.length;
+
+ while (i--) {
+ const op = ops[i];
+ val = ret[op];
+ hasDollarKey = hasDollarKey || op.startsWith('$');
+
+ if (val &&
+ typeof val === 'object' &&
+ !Buffer.isBuffer(val) &&
+ (!overwrite || hasDollarKey)) {
+ walkUpdatePath(schema, val, op, options, context, filter);
+ } else if (overwrite && ret && typeof ret === 'object') {
+ walkUpdatePath(schema, ret, '$set', options, context, filter);
+ } else {
+ const msg = 'Invalid atomic update value for ' + op + '. '
+ + 'Expected an object, received ' + typeof val;
+ throw new Error(msg);
+ }
+
+ if (op.startsWith('$') && utils.isEmptyObject(val)) {
+ delete ret[op];
+ }
+ }
+
+ if (Object.keys(ret).length === 0 &&
+ options.upsert &&
+ Object.keys(filter).length > 0) {
+ // Trick the driver into allowing empty upserts to work around
+ // https://github.com/mongodb/node-mongodb-native/pull/2490
+ return { $setOnInsert: filter };
+ }
+
+ return ret;
+};
+
+/*!
+ * ignore
+ */
+
+function castPipelineOperator(op, val) {
+ if (op === '$unset') {
+ if (!Array.isArray(val) || val.find(v => typeof v !== 'string')) {
+ throw new MongooseError('Invalid $unset in pipeline, must be ' +
+ 'an array of strings');
+ }
+ return val;
+ }
+ if (op === '$project') {
+ if (val == null || typeof val !== 'object') {
+ throw new MongooseError('Invalid $project in pipeline, must be an object');
+ }
+ return val;
+ }
+ if (op === '$addFields' || op === '$set') {
+ if (val == null || typeof val !== 'object') {
+ throw new MongooseError('Invalid ' + op + ' in pipeline, must be an object');
+ }
+ return val;
+ } else if (op === '$replaceRoot' || op === '$replaceWith') {
+ if (val == null || typeof val !== 'object') {
+ throw new MongooseError('Invalid ' + op + ' in pipeline, must be an object');
+ }
+ return val;
+ }
+
+ throw new MongooseError('Invalid update pipeline operator: "' + op + '"');
+}
+
+/*!
+ * Walk each path of obj and cast its values
+ * according to its schema.
+ *
+ * @param {Schema} schema
+ * @param {Object} obj - part of a query
+ * @param {String} op - the atomic operator ($pull, $set, etc)
+ * @param {Object} options
+ * @param {Boolean|String} [options.strict]
+ * @param {Boolean} [options.omitUndefined]
+ * @param {Query} context
+ * @param {String} pref - path prefix (internal only)
+ * @return {Bool} true if this path has keys to update
+ * @api private
+ */
+
+function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
+ const strict = options.strict;
+ const prefix = pref ? pref + '.' : '';
+ const keys = Object.keys(obj);
+ let i = keys.length;
+ let hasKeys = false;
+ let schematype;
+ let key;
+ let val;
+
+ let aggregatedError = null;
+
+ let useNestedStrict;
+ if (options.useNestedStrict === undefined) {
+ useNestedStrict = schema.options.useNestedStrict;
+ } else {
+ useNestedStrict = options.useNestedStrict;
+ }
+
+ while (i--) {
+ key = keys[i];
+ val = obj[key];
+
+ // `$pull` is special because we need to cast the RHS as a query, not as
+ // an update.
+ if (op === '$pull') {
+ schematype = schema._getSchema(prefix + key);
+ if (schematype != null && schematype.schema != null) {
+ obj[key] = cast(schematype.schema, obj[key], options, context);
+ hasKeys = true;
+ continue;
+ }
+ }
+
+ if (val && val.constructor.name === 'Object') {
+ // watch for embedded doc schemas
+ schematype = schema._getSchema(prefix + key);
+
+ if (op !== '$setOnInsert' &&
+ handleImmutable(schematype, strict, obj, key, prefix + key, context)) {
+ continue;
+ }
+
+ if (schematype && schematype.caster && op in castOps) {
+ // embedded doc schema
+ if ('$each' in val) {
+ hasKeys = true;
+ try {
+ obj[key] = {
+ $each: castUpdateVal(schematype, val.$each, op, key, context, prefix + key)
+ };
+ } catch (error) {
+ aggregatedError = _handleCastError(error, context, key, aggregatedError);
+ }
+
+ if (val.$slice != null) {
+ obj[key].$slice = val.$slice | 0;
+ }
+
+ if (val.$sort) {
+ obj[key].$sort = val.$sort;
+ }
+
+ if (val.$position != null) {
+ obj[key].$position = castNumber(val.$position);
+ }
+ } else {
+ if (schematype != null && schematype.$isSingleNested) {
+ // Special case to make sure `strict` bubbles down correctly to
+ // single nested re: gh-8735
+ let _strict = strict;
+ if (useNestedStrict !== false && schematype.schema.options.hasOwnProperty('strict')) {
+ _strict = schematype.schema.options.strict;
+ } else if (useNestedStrict === false) {
+ _strict = schema.options.strict;
+ }
+ try {
+ obj[key] = schematype.castForQuery(val, context, { strict: _strict });
+ } catch (error) {
+ aggregatedError = _handleCastError(error, context, key, aggregatedError);
+ }
+ } else {
+ try {
+ obj[key] = castUpdateVal(schematype, val, op, key, context, prefix + key);
+ } catch (error) {
+ aggregatedError = _handleCastError(error, context, key, aggregatedError);
+ }
+ }
+
+ if (options.omitUndefined && obj[key] === void 0) {
+ delete obj[key];
+ continue;
+ }
+
+ hasKeys = true;
+ }
+ } else if ((op === '$currentDate') || (op in castOps && schematype)) {
+ // $currentDate can take an object
+ try {
+ obj[key] = castUpdateVal(schematype, val, op, key, context, prefix + key);
+ } catch (error) {
+ aggregatedError = _handleCastError(error, context, key, aggregatedError);
+ }
+
+ if (options.omitUndefined && obj[key] === void 0) {
+ delete obj[key];
+ continue;
+ }
+
+ hasKeys = true;
+ } else {
+ const pathToCheck = (prefix + key);
+ const v = schema._getPathType(pathToCheck);
+ let _strict = strict;
+ if (useNestedStrict &&
+ v &&
+ v.schema &&
+ 'strict' in v.schema.options) {
+ _strict = v.schema.options.strict;
+ }
+
+ if (v.pathType === 'undefined') {
+ if (_strict === 'throw') {
+ throw new StrictModeError(pathToCheck);
+ } else if (_strict) {
+ delete obj[key];
+ continue;
+ }
+ }
+
+ // gh-2314
+ // we should be able to set a schema-less field
+ // to an empty object literal
+ hasKeys |= walkUpdatePath(schema, val, op, options, context, filter, prefix + key) ||
+ (utils.isObject(val) && Object.keys(val).length === 0);
+ }
+ } else {
+ 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, context)) {
+ continue;
+ }
+
+ let pathDetails = schema._getPathType(checkPath);
+
+ // If no schema type, check for embedded discriminators because the
+ // filter or update may imply an embedded discriminator type. See #8378
+ if (schematype == null) {
+ const _res = getEmbeddedDiscriminatorPath(schema, obj, filter, checkPath);
+ if (_res.schematype != null) {
+ schematype = _res.schematype;
+ pathDetails = _res.type;
+ }
+ }
+
+ let isStrict = strict;
+ if (useNestedStrict &&
+ pathDetails &&
+ pathDetails.schema &&
+ 'strict' in pathDetails.schema.options) {
+ isStrict = pathDetails.schema.options.strict;
+ }
+
+ const skip = isStrict &&
+ !schematype &&
+ !/real|nested/.test(pathDetails.pathType);
+
+ if (skip) {
+ // Even if strict is `throw`, avoid throwing an error because of
+ // virtuals because of #6731
+ if (isStrict === 'throw' && schema.virtuals[checkPath] == null) {
+ throw new StrictModeError(prefix + key);
+ } else {
+ delete obj[key];
+ }
+ } else {
+ // gh-1845 temporary fix: ignore $rename. See gh-3027 for tracking
+ // improving this.
+ if (op === '$rename') {
+ hasKeys = true;
+ continue;
+ }
+
+ try {
+ obj[key] = castUpdateVal(schematype, val, op, key, context, prefix + key);
+ } catch (error) {
+ aggregatedError = _handleCastError(error, context, key, aggregatedError);
+ }
+
+ if (Array.isArray(obj[key]) && (op === '$addToSet' || op === '$push') && key !== '$each') {
+ if (schematype && schematype.caster && !schematype.caster.$isMongooseArray) {
+ obj[key] = { $each: obj[key] };
+ }
+ }
+
+ if (options.omitUndefined && obj[key] === void 0) {
+ delete obj[key];
+ continue;
+ }
+
+ hasKeys = true;
+ }
+ }
+ }
+
+ if (aggregatedError != null) {
+ throw aggregatedError;
+ }
+
+ return hasKeys;
+}
+
+/*!
+ * ignore
+ */
+
+function _handleCastError(error, query, key, aggregatedError) {
+ if (typeof query !== 'object' || !query.options.multipleCastError) {
+ throw error;
+ }
+ aggregatedError = aggregatedError || new ValidationError();
+ aggregatedError.addError(key, error);
+ return aggregatedError;
+}
+
+/*!
+ * These operators should be cast to numbers instead
+ * of their path schema type.
+ */
+
+const numberOps = {
+ $pop: 1,
+ $inc: 1
+};
+
+/*!
+ * These ops require no casting because the RHS doesn't do anything.
+ */
+
+const noCastOps = {
+ $unset: 1
+};
+
+/*!
+ * These operators require casting docs
+ * to real Documents for Update operations.
+ */
+
+const castOps = {
+ $push: 1,
+ $addToSet: 1,
+ $set: 1,
+ $setOnInsert: 1
+};
+
+/*!
+ * ignore
+ */
+
+const overwriteOps = {
+ $set: 1,
+ $setOnInsert: 1
+};
+
+/*!
+ * Casts `val` according to `schema` and atomic `op`.
+ *
+ * @param {SchemaType} schema
+ * @param {Object} val
+ * @param {String} op - the atomic operator ($pull, $set, etc)
+ * @param {String} $conditional
+ * @param {Query} context
+ * @api private
+ */
+
+function castUpdateVal(schema, val, op, $conditional, context, path) {
+ if (!schema) {
+ // non-existing schema path
+ if (op in numberOps) {
+ try {
+ return castNumber(val);
+ } catch (err) {
+ throw new CastError('number', val, path);
+ }
+ }
+ return val;
+ }
+
+ const cond = schema.caster && op in castOps &&
+ (utils.isObject(val) || Array.isArray(val));
+ if (cond && !overwriteOps[op]) {
+ // Cast values for ops that add data to MongoDB.
+ // Ensures embedded documents get ObjectIds etc.
+ let schemaArrayDepth = 0;
+ let cur = schema;
+ while (cur.$isMongooseArray) {
+ ++schemaArrayDepth;
+ cur = cur.caster;
+ }
+ let arrayDepth = 0;
+ let _val = val;
+ while (Array.isArray(_val)) {
+ ++arrayDepth;
+ _val = _val[0];
+ }
+
+ const additionalNesting = schemaArrayDepth - arrayDepth;
+ while (arrayDepth < schemaArrayDepth) {
+ val = [val];
+ ++arrayDepth;
+ }
+
+ let tmp = schema.applySetters(Array.isArray(val) ? val : [val], context);
+
+ for (let i = 0; i < additionalNesting; ++i) {
+ tmp = tmp[0];
+ }
+ return tmp;
+ }
+
+ if (op in noCastOps) {
+ return val;
+ }
+ if (op in numberOps) {
+ // Null and undefined not allowed for $pop, $inc
+ if (val == null) {
+ throw new CastError('number', val, schema.path);
+ }
+ if (op === '$inc') {
+ // Support `$inc` with long, int32, etc. (gh-4283)
+ return schema.castForQueryWrapper({
+ val: val,
+ context: context
+ });
+ }
+ try {
+ return castNumber(val);
+ } catch (error) {
+ throw new CastError('number', val, schema.path);
+ }
+ }
+ if (op === '$currentDate') {
+ if (typeof val === 'object') {
+ return { $type: val.$type };
+ }
+ return Boolean(val);
+ }
+
+ if (/^\$/.test($conditional)) {
+ return schema.castForQueryWrapper({
+ $conditional: $conditional,
+ val: val,
+ context: context
+ });
+ }
+
+ if (overwriteOps[op]) {
+ return schema.castForQueryWrapper({
+ val: val,
+ context: context,
+ $skipQueryCastForUpdate: val != null && schema.$isMongooseArray && schema.$fullPath != null && !schema.$fullPath.match(/\d+$/),
+ $applySetters: schema[schemaMixedSymbol] != null
+ });
+ }
+
+ return schema.castForQueryWrapper({ val: val, context: context });
+}
diff --git a/node_modules/mongoose/lib/helpers/query/completeMany.js b/node_modules/mongoose/lib/helpers/query/completeMany.js
new file mode 100644
index 0000000..aabe596
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/completeMany.js
@@ -0,0 +1,47 @@
+'use strict';
+
+const helpers = require('../../queryhelpers');
+
+module.exports = completeMany;
+
+/*!
+ * Given a model and an array of docs, hydrates all the docs to be instances
+ * of the model. Used to initialize docs returned from the db from `find()`
+ *
+ * @param {Model} model
+ * @param {Array} docs
+ * @param {Object} fields the projection used, including `select` from schemas
+ * @param {Object} userProvidedFields the user-specified projection
+ * @param {Object} opts
+ * @param {Array} [opts.populated]
+ * @param {ClientSession} [opts.session]
+ * @param {Function} callback
+ */
+
+function completeMany(model, docs, fields, userProvidedFields, opts, callback) {
+ const arr = [];
+ let count = docs.length;
+ const len = count;
+ let error = null;
+
+ function init(_error) {
+ if (_error != null) {
+ error = error || _error;
+ }
+ if (error != null) {
+ --count || process.nextTick(() => callback(error));
+ return;
+ }
+ --count || process.nextTick(() => callback(error, arr));
+ }
+
+ for (let i = 0; i < len; ++i) {
+ arr[i] = helpers.createModel(model, docs[i], fields, userProvidedFields);
+ try {
+ arr[i].init(docs[i], opts, init);
+ } catch (error) {
+ init(error);
+ }
+ arr[i].$session(opts.session);
+ }
+}
diff --git a/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js b/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js
new file mode 100644
index 0000000..395ea75
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js
@@ -0,0 +1,68 @@
+'use strict';
+
+const cleanPositionalOperators = require('../schema/cleanPositionalOperators');
+const get = require('../get');
+const getDiscriminatorByValue = require('../discriminator/getDiscriminatorByValue');
+
+/*!
+ * Like `schema.path()`, except with a document, because impossible to
+ * determine path type without knowing the embedded discriminator key.
+ */
+
+module.exports = function getEmbeddedDiscriminatorPath(schema, update, filter, path) {
+ const parts = path.split('.');
+ let schematype = null;
+ let type = 'adhocOrUndefined';
+
+ filter = filter || {};
+ update = update || {};
+
+ for (let i = 0; i < parts.length; ++i) {
+ const subpath = cleanPositionalOperators(parts.slice(0, i + 1).join('.'));
+ schematype = schema.path(subpath);
+ if (schematype == null) {
+ continue;
+ }
+
+ type = schema.pathType(subpath);
+ if ((schematype.$isSingleNested || schematype.$isMongooseDocumentArrayElement) &&
+ schematype.schema.discriminators != null) {
+ const key = get(schematype, 'schema.options.discriminatorKey');
+ const discriminatorValuePath = subpath + '.' + key;
+ const discriminatorFilterPath =
+ discriminatorValuePath.replace(/\.\d+\./, '.');
+ let discriminatorKey = null;
+
+ if (discriminatorValuePath in filter) {
+ discriminatorKey = filter[discriminatorValuePath];
+ }
+ if (discriminatorFilterPath in filter) {
+ discriminatorKey = filter[discriminatorFilterPath];
+ }
+ const wrapperPath = subpath.replace(/\.\d+$/, '');
+ if (schematype.$isMongooseDocumentArrayElement &&
+ get(filter[wrapperPath], '$elemMatch.' + key) != null) {
+ discriminatorKey = filter[wrapperPath].$elemMatch[key];
+ }
+
+ if (discriminatorValuePath in update) {
+ discriminatorKey = update[discriminatorValuePath];
+ }
+
+ if (discriminatorKey == null) {
+ continue;
+ }
+
+ const discriminatorSchema = getDiscriminatorByValue(schematype.caster, discriminatorKey).schema;
+
+ const rest = parts.slice(i + 1).join('.');
+ schematype = discriminatorSchema.path(rest);
+ if (schematype != null) {
+ type = discriminatorSchema._getPathType(rest);
+ break;
+ }
+ }
+ }
+
+ return { type: type, schematype: schematype };
+};
diff --git a/node_modules/mongoose/lib/helpers/query/handleImmutable.js b/node_modules/mongoose/lib/helpers/query/handleImmutable.js
new file mode 100644
index 0000000..22adb3c
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/handleImmutable.js
@@ -0,0 +1,28 @@
+'use strict';
+
+const StrictModeError = require('../../error/strict');
+
+module.exports = function handleImmutable(schematype, strict, obj, key, fullPath, ctx) {
+ if (schematype == null || !schematype.options || !schematype.options.immutable) {
+ return false;
+ }
+ let immutable = schematype.options.immutable;
+
+ if (typeof immutable === 'function') {
+ immutable = immutable.call(ctx, ctx);
+ }
+ if (!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;
+};
diff --git a/node_modules/mongoose/lib/helpers/query/hasDollarKeys.js b/node_modules/mongoose/lib/helpers/query/hasDollarKeys.js
new file mode 100644
index 0000000..958e1c9
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/hasDollarKeys.js
@@ -0,0 +1,19 @@
+'use strict';
+
+/*!
+ * ignore
+ */
+
+module.exports = function(obj) {
+ if (obj == null) {
+ return false;
+ }
+ const keys = Object.keys(obj);
+ const len = keys.length;
+ for (let i = 0; i < len; ++i) {
+ if (keys[i].startsWith('$')) {
+ return true;
+ }
+ }
+ return false;
+};
diff --git a/node_modules/mongoose/lib/helpers/query/isOperator.js b/node_modules/mongoose/lib/helpers/query/isOperator.js
new file mode 100644
index 0000000..3b98139
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/isOperator.js
@@ -0,0 +1,11 @@
+'use strict';
+
+const specialKeys = new Set([
+ '$ref',
+ '$id',
+ '$db'
+]);
+
+module.exports = function isOperator(path) {
+ return path.startsWith('$') && !specialKeys.has(path);
+}; \ No newline at end of file
diff --git a/node_modules/mongoose/lib/helpers/query/selectPopulatedFields.js b/node_modules/mongoose/lib/helpers/query/selectPopulatedFields.js
new file mode 100644
index 0000000..0653f18
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/selectPopulatedFields.js
@@ -0,0 +1,46 @@
+'use strict';
+
+/*!
+ * ignore
+ */
+
+module.exports = function selectPopulatedFields(query) {
+ const opts = query._mongooseOptions;
+
+ if (opts.populate != null) {
+ const paths = Object.keys(opts.populate);
+ const userProvidedFields = query._userProvidedFields || {};
+ if (query.selectedInclusively()) {
+ for (const path of paths) {
+ if (!isPathInFields(userProvidedFields, path)) {
+ query.select(path);
+ } else if (userProvidedFields[path] === 0) {
+ delete query._fields[path];
+ }
+ }
+ } else if (query.selectedExclusively()) {
+ for (const path of paths) {
+ if (userProvidedFields[path] == null) {
+ delete query._fields[path];
+ }
+ }
+ }
+ }
+};
+
+/*!
+ * ignore
+ */
+
+function isPathInFields(userProvidedFields, path) {
+ const pieces = path.split('.');
+ const len = pieces.length;
+ let cur = pieces[0];
+ for (let i = 1; i < len; ++i) {
+ if (userProvidedFields[cur] != null) {
+ return true;
+ }
+ cur += '.' + pieces[i];
+ }
+ return userProvidedFields[cur] != null;
+}
diff --git a/node_modules/mongoose/lib/helpers/query/wrapThunk.js b/node_modules/mongoose/lib/helpers/query/wrapThunk.js
new file mode 100644
index 0000000..0005c33
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/query/wrapThunk.js
@@ -0,0 +1,18 @@
+'use strict';
+
+/*!
+ * A query thunk is the function responsible for sending the query to MongoDB,
+ * like `Query#_findOne()` or `Query#_execUpdate()`. The `Query#exec()` function
+ * calls a thunk. The term "thunk" here is the traditional Node.js definition:
+ * a function that takes exactly 1 parameter, a callback.
+ *
+ * This function defines common behavior for all query thunks.
+ */
+
+module.exports = function wrapThunk(fn) {
+ return function _wrappedThunk(cb) {
+ ++this._executionCount;
+
+ fn.call(this, cb);
+ };
+}; \ No newline at end of file