mongoose 9.2.2 → 9.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aggregate.js +41 -41
- package/lib/cast/bigint.js +2 -2
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/double.js +2 -2
- package/lib/cast/int32.js +2 -2
- package/lib/cast/number.js +2 -2
- package/lib/cast/string.js +2 -2
- package/lib/cast.js +6 -6
- package/lib/collection.js +4 -4
- package/lib/connection.js +58 -58
- package/lib/cursor/aggregationCursor.js +6 -6
- package/lib/cursor/queryCursor.js +7 -7
- package/lib/document.js +176 -176
- package/lib/drivers/node-mongodb-native/collection.js +2 -2
- package/lib/drivers/node-mongodb-native/connection.js +8 -8
- package/lib/error/cast.js +2 -2
- package/lib/error/createCollectionsError.js +2 -2
- package/lib/error/divergentArray.js +1 -1
- package/lib/error/eachAsyncMultiError.js +1 -1
- package/lib/error/index.js +2 -2
- package/lib/error/invalidSchemaOption.js +1 -1
- package/lib/error/missingSchema.js +1 -1
- package/lib/error/objectParameter.js +3 -3
- package/lib/error/overwriteModel.js +1 -1
- package/lib/error/setOptionError.js +3 -3
- package/lib/error/strict.js +3 -3
- package/lib/error/strictPopulate.js +2 -2
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +2 -2
- package/lib/error/validator.js +1 -1
- package/lib/error/version.js +2 -2
- package/lib/helpers/buildMiddlewareFilter.js +2 -2
- package/lib/helpers/clone.js +4 -4
- package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
- package/lib/helpers/cursor/eachAsync.js +3 -3
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
- package/lib/helpers/document/applyTimestamps.js +9 -9
- package/lib/helpers/document/applyVirtuals.js +6 -6
- package/lib/helpers/document/compile.js +10 -10
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/lib/helpers/indexes/isIndexEqual.js +3 -3
- package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +2 -2
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +2 -2
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
- package/lib/helpers/populate/assignVals.js +6 -6
- package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
- package/lib/helpers/populate/getSchemaTypes.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/query/castUpdate.js +14 -14
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +4 -4
- package/lib/helpers/query/handleImmutable.js +6 -6
- package/lib/helpers/schema/getIndexes.js +1 -1
- package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +3 -3
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/updateValidators.js +2 -2
- package/lib/model.js +263 -263
- package/lib/mongoose.js +54 -54
- package/lib/options/schemaArrayOptions.js +2 -2
- package/lib/options/schemaBufferOptions.js +1 -1
- package/lib/options/schemaNumberOptions.js +3 -3
- package/lib/options/schemaObjectIdOptions.js +2 -2
- package/lib/options/schemaStringOptions.js +6 -6
- package/lib/options/schemaTypeOptions.js +13 -13
- package/lib/options/virtualOptions.js +11 -11
- package/lib/query.js +222 -222
- package/lib/queryHelpers.js +4 -4
- package/lib/schema/array.js +18 -18
- package/lib/schema/bigint.js +13 -13
- package/lib/schema/boolean.js +13 -13
- package/lib/schema/buffer.js +14 -14
- package/lib/schema/date.js +16 -16
- package/lib/schema/decimal128.js +13 -13
- package/lib/schema/documentArray.js +15 -15
- package/lib/schema/documentArrayElement.js +5 -6
- package/lib/schema/double.js +12 -12
- package/lib/schema/int32.js +13 -13
- package/lib/schema/map.js +10 -10
- package/lib/schema/mixed.js +10 -10
- package/lib/schema/number.js +18 -18
- package/lib/schema/objectId.js +14 -14
- package/lib/schema/operators/text.js +3 -3
- package/lib/schema/string.js +17 -17
- package/lib/schema/subdocument.js +13 -13
- package/lib/schema/union.js +3 -3
- package/lib/schema/uuid.js +16 -16
- package/lib/schema.js +76 -76
- package/lib/schemaType.js +62 -62
- package/lib/stateMachine.js +5 -8
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/arraySubdocument.js +8 -8
- package/lib/types/buffer.js +4 -4
- package/lib/types/documentArray/index.js +1 -1
- package/lib/types/documentArray/methods/index.js +5 -5
- package/lib/types/map.js +3 -3
- package/lib/types/subdocument.js +11 -11
- package/lib/utils.js +45 -45
- package/lib/virtualType.js +18 -18
- package/package.json +8 -5
- package/types/index.d.ts +16 -15
- package/types/inferschematype.d.ts +10 -0
- package/types/models.d.ts +8 -5
- package/types/schemaoptions.d.ts +1 -1
- package/types/virtuals.d.ts +10 -10
|
@@ -60,7 +60,7 @@ module.exports = function createPopulateQueryFilter(ids, _match, _foreignField,
|
|
|
60
60
|
* to avoid cast errors (gh-7706)
|
|
61
61
|
* @param {Array} ids
|
|
62
62
|
* @param {SchemaType} foreignSchemaType
|
|
63
|
-
* @param {
|
|
63
|
+
* @param {boolean} [skipInvalidIds]
|
|
64
64
|
* @api private
|
|
65
65
|
*/
|
|
66
66
|
|
|
@@ -82,7 +82,7 @@ function _filterInvalidIds(ids, foreignSchemaType, skipInvalidIds) {
|
|
|
82
82
|
/**
|
|
83
83
|
* Format `mod.match` given that it may be an array that we need to $or if
|
|
84
84
|
* the client has multiple docs with match functions
|
|
85
|
-
* @param {Array|
|
|
85
|
+
* @param {Array|any} match
|
|
86
86
|
* @api private
|
|
87
87
|
*/
|
|
88
88
|
|
|
@@ -353,12 +353,12 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
|
|
|
353
353
|
* resolved refPath value so discriminator handling can inspect it later.
|
|
354
354
|
*
|
|
355
355
|
* @param {Function} refPath
|
|
356
|
-
* @param {Document|
|
|
356
|
+
* @param {Document|object} doc
|
|
357
357
|
* @param {SchemaType} schema
|
|
358
|
-
* @param {
|
|
358
|
+
* @param {string} populatePath
|
|
359
359
|
* @param {Schema} modelSchema
|
|
360
|
-
* @param {
|
|
361
|
-
* @returns {{modelNames:
|
|
360
|
+
* @param {object} queryProjection
|
|
361
|
+
* @returns {{modelNames: string[], refPath: string|null}}
|
|
362
362
|
* @private
|
|
363
363
|
*/
|
|
364
364
|
function _getModelNamesFromFunctionRefPath(refPath, doc, schemaType, populatePath, modelSchema, queryProjection) {
|
|
@@ -453,13 +453,13 @@ function _getModelNamesFromFunctionRefPath(refPath, doc, schemaType, populatePat
|
|
|
453
453
|
* for array subdocuments and falling back to the original populate path if
|
|
454
454
|
* normalization fails.
|
|
455
455
|
*
|
|
456
|
-
* @param {
|
|
457
|
-
* @param {Document|
|
|
458
|
-
* @param {
|
|
459
|
-
* @param {
|
|
456
|
+
* @param {string|Function} refPath
|
|
457
|
+
* @param {Document|object} doc
|
|
458
|
+
* @param {string} populatePath
|
|
459
|
+
* @param {string} indexedPath
|
|
460
460
|
* @param {Schema} modelSchema
|
|
461
|
-
* @param {
|
|
462
|
-
* @returns {
|
|
461
|
+
* @param {object} queryProjection
|
|
462
|
+
* @returns {string[]}
|
|
463
463
|
* @private
|
|
464
464
|
*/
|
|
465
465
|
function _getModelNamesFromRefPath(refPath, doc, populatePath, indexedPath, modelSchema, queryProjection) {
|
|
@@ -770,9 +770,9 @@ function _getLocalFieldValues(doc, localField, model, options, virtual, schema)
|
|
|
770
770
|
/**
|
|
771
771
|
* Retrieve the _id of `val` if a Document or Array of Documents.
|
|
772
772
|
*
|
|
773
|
-
* @param {Array|Document|
|
|
773
|
+
* @param {Array|Document|any} val
|
|
774
774
|
* @param {Schema} schema
|
|
775
|
-
* @return {Array|Document|
|
|
775
|
+
* @return {Array|Document|any}
|
|
776
776
|
* @api private
|
|
777
777
|
*/
|
|
778
778
|
|
|
@@ -20,7 +20,7 @@ const populateModelSymbol = require('../symbols').populateModelSymbol;
|
|
|
20
20
|
*
|
|
21
21
|
* @param {Model} model
|
|
22
22
|
* @param {Schema} schema
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {object} doc POJO
|
|
24
24
|
* @param {string} path
|
|
25
25
|
* @param {string[]} [parts] pass in pre-split `path` to avoid extra splitting
|
|
26
26
|
* @api private
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Set a populated virtual value on a document's `$$populatedVirtuals` value
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
10
|
-
* @returns {
|
|
6
|
+
* @param {object} populatedVirtuals A document's `$$populatedVirtuals`
|
|
7
|
+
* @param {string} name The virtual name
|
|
8
|
+
* @param {any} v The result of the populate query
|
|
9
|
+
* @param {object} options The populate options. This function handles `justOne` and `count` options.
|
|
10
|
+
* @returns {Document[]|Document|object|object[]} the populated virtual value that was set
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
module.exports = function setPopulatedVirtualValue(populatedVirtuals, name, v, options) {
|
|
@@ -5,9 +5,9 @@ const isDefiningProjection = require('./isDefiningProjection');
|
|
|
5
5
|
/**
|
|
6
6
|
* Determines if `path` is excluded by `projection`
|
|
7
7
|
*
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
10
|
-
* @return {
|
|
8
|
+
* @param {object} projection
|
|
9
|
+
* @param {string} path
|
|
10
|
+
* @return {boolean}
|
|
11
11
|
* @api private
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -39,11 +39,11 @@ const mongodbUpdateOperators = new Set([
|
|
|
39
39
|
* Casts an update op based on the given schema
|
|
40
40
|
*
|
|
41
41
|
* @param {Schema} schema
|
|
42
|
-
* @param {
|
|
43
|
-
* @param {
|
|
44
|
-
* @param {
|
|
42
|
+
* @param {object} obj
|
|
43
|
+
* @param {object} [options]
|
|
44
|
+
* @param {boolean|'throw'} [options.strict] defaults to true
|
|
45
45
|
* @param {Query} context passed to setters
|
|
46
|
-
* @return {
|
|
46
|
+
* @return {boolean} true iff the update is non-empty
|
|
47
47
|
* @api private
|
|
48
48
|
*/
|
|
49
49
|
module.exports = function castUpdate(schema, obj, options, context, filter) {
|
|
@@ -202,13 +202,13 @@ function castPipelineOperator(op, val) {
|
|
|
202
202
|
* according to its schema.
|
|
203
203
|
*
|
|
204
204
|
* @param {Schema} schema
|
|
205
|
-
* @param {
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
208
|
-
* @param {
|
|
205
|
+
* @param {object} obj part of a query
|
|
206
|
+
* @param {string} op the atomic operator ($pull, $set, etc)
|
|
207
|
+
* @param {object} [options]
|
|
208
|
+
* @param {boolean|'throw'} [options.strict]
|
|
209
209
|
* @param {Query} context
|
|
210
|
-
* @param {
|
|
211
|
-
* @param {
|
|
210
|
+
* @param {object} filter
|
|
211
|
+
* @param {string} pref path prefix (internal only)
|
|
212
212
|
* @return {Bool} true if this path has keys to update
|
|
213
213
|
* @api private
|
|
214
214
|
*/
|
|
@@ -532,11 +532,11 @@ const overwriteOps = {
|
|
|
532
532
|
* Casts `val` according to `schema` and atomic `op`.
|
|
533
533
|
*
|
|
534
534
|
* @param {SchemaType} schema
|
|
535
|
-
* @param {
|
|
536
|
-
* @param {
|
|
537
|
-
* @param {
|
|
535
|
+
* @param {object} val
|
|
536
|
+
* @param {string} op the atomic operator ($pull, $set, etc)
|
|
537
|
+
* @param {string} $conditional
|
|
538
538
|
* @param {Query} context
|
|
539
|
-
* @param {
|
|
539
|
+
* @param {string} path
|
|
540
540
|
* @api private
|
|
541
541
|
*/
|
|
542
542
|
|
|
@@ -9,10 +9,10 @@ const updatedPathsByArrayFilter = require('../update/updatedPathsByArrayFilter')
|
|
|
9
9
|
* Like `schema.path()`, except with a document, because impossible to
|
|
10
10
|
* determine path type without knowing the embedded discriminator key.
|
|
11
11
|
* @param {Schema} schema
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
12
|
+
* @param {object} [update]
|
|
13
|
+
* @param {object} [filter]
|
|
14
|
+
* @param {string} path
|
|
15
|
+
* @param {object} [options]
|
|
16
16
|
* @api private
|
|
17
17
|
*/
|
|
18
18
|
|
|
@@ -6,13 +6,13 @@ const StrictModeError = require('../../error/strict');
|
|
|
6
6
|
* Handle immutable option for a given path when casting updates based on options
|
|
7
7
|
*
|
|
8
8
|
* @param {SchemaType} schematype the resolved schematype for this path
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
9
|
+
* @param {boolean | 'throw' | null} strict whether strict mode is set for this query
|
|
10
|
+
* @param {object} obj the object containing the value being checked so we can delete
|
|
11
|
+
* @param {string} key the key in `obj` which we are checking for immutability
|
|
12
|
+
* @param {string} fullPath the full path being checked
|
|
13
|
+
* @param {object} options the query options
|
|
14
14
|
* @param {Query} ctx the query. Passed as `this` and first param to the `immutable` option, if `immutable` is a function
|
|
15
|
-
* @returns true if field was removed, false otherwise
|
|
15
|
+
* @returns {boolean} true if field was removed, false otherwise
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
module.exports = function handleImmutable(schematype, strict, obj, key, fullPath, options, ctx) {
|
|
@@ -4,10 +4,10 @@ const get = require('./get');
|
|
|
4
4
|
/**
|
|
5
5
|
* Applies defaults to update and findOneAndUpdate operations.
|
|
6
6
|
*
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {object} filter
|
|
8
8
|
* @param {Schema} schema
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
9
|
+
* @param {object} castedDoc
|
|
10
|
+
* @param {object} options
|
|
11
11
|
* @method setDefaultsOnInsert
|
|
12
12
|
* @api private
|
|
13
13
|
*/
|
|
@@ -10,8 +10,8 @@ const _modifiedPaths = require('../common').modifiedPaths;
|
|
|
10
10
|
* will get wrapped in a `$set`. The Mongoose Query is responsible for wrapping
|
|
11
11
|
* top-level keys in `$set`.
|
|
12
12
|
*
|
|
13
|
-
* @param {
|
|
14
|
-
* @return {
|
|
13
|
+
* @param {object} update
|
|
14
|
+
* @return {object} modified
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
module.exports = function modifiedPaths(update) {
|
|
@@ -14,8 +14,8 @@ const flatten = require('./common').flatten;
|
|
|
14
14
|
*
|
|
15
15
|
* @param {Query} query
|
|
16
16
|
* @param {Schema} schema
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
17
|
+
* @param {object} castedDoc
|
|
18
|
+
* @param {object} options
|
|
19
19
|
* @method runValidatorsOnUpdate
|
|
20
20
|
* @api private
|
|
21
21
|
*/
|