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.
Files changed (118) hide show
  1. package/lib/aggregate.js +41 -41
  2. package/lib/cast/bigint.js +2 -2
  3. package/lib/cast/boolean.js +3 -3
  4. package/lib/cast/double.js +2 -2
  5. package/lib/cast/int32.js +2 -2
  6. package/lib/cast/number.js +2 -2
  7. package/lib/cast/string.js +2 -2
  8. package/lib/cast.js +6 -6
  9. package/lib/collection.js +4 -4
  10. package/lib/connection.js +58 -58
  11. package/lib/cursor/aggregationCursor.js +6 -6
  12. package/lib/cursor/queryCursor.js +7 -7
  13. package/lib/document.js +176 -176
  14. package/lib/drivers/node-mongodb-native/collection.js +2 -2
  15. package/lib/drivers/node-mongodb-native/connection.js +8 -8
  16. package/lib/error/cast.js +2 -2
  17. package/lib/error/createCollectionsError.js +2 -2
  18. package/lib/error/divergentArray.js +1 -1
  19. package/lib/error/eachAsyncMultiError.js +1 -1
  20. package/lib/error/index.js +2 -2
  21. package/lib/error/invalidSchemaOption.js +1 -1
  22. package/lib/error/missingSchema.js +1 -1
  23. package/lib/error/objectParameter.js +3 -3
  24. package/lib/error/overwriteModel.js +1 -1
  25. package/lib/error/setOptionError.js +3 -3
  26. package/lib/error/strict.js +3 -3
  27. package/lib/error/strictPopulate.js +2 -2
  28. package/lib/error/syncIndexes.js +2 -2
  29. package/lib/error/validation.js +2 -2
  30. package/lib/error/validator.js +1 -1
  31. package/lib/error/version.js +2 -2
  32. package/lib/helpers/buildMiddlewareFilter.js +2 -2
  33. package/lib/helpers/clone.js +4 -4
  34. package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
  35. package/lib/helpers/cursor/eachAsync.js +3 -3
  36. package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  37. package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
  38. package/lib/helpers/document/applyTimestamps.js +9 -9
  39. package/lib/helpers/document/applyVirtuals.js +6 -6
  40. package/lib/helpers/document/compile.js +10 -10
  41. package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
  42. package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
  43. package/lib/helpers/indexes/isIndexEqual.js +3 -3
  44. package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
  45. package/lib/helpers/isMongooseObject.js +1 -1
  46. package/lib/helpers/isObject.js +2 -2
  47. package/lib/helpers/isSimpleValidator.js +2 -2
  48. package/lib/helpers/minimize.js +2 -2
  49. package/lib/helpers/model/applyHooks.js +1 -1
  50. package/lib/helpers/model/castBulkWrite.js +2 -2
  51. package/lib/helpers/pluralize.js +1 -1
  52. package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
  53. package/lib/helpers/populate/assignVals.js +6 -6
  54. package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
  55. package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
  56. package/lib/helpers/populate/getSchemaTypes.js +1 -1
  57. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  58. package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
  59. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  60. package/lib/helpers/projection/isPathExcluded.js +3 -3
  61. package/lib/helpers/projection/isSubpath.js +1 -1
  62. package/lib/helpers/query/castUpdate.js +14 -14
  63. package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +4 -4
  64. package/lib/helpers/query/handleImmutable.js +6 -6
  65. package/lib/helpers/schema/getIndexes.js +1 -1
  66. package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
  67. package/lib/helpers/setDefaultsOnInsert.js +3 -3
  68. package/lib/helpers/update/modifiedPaths.js +2 -2
  69. package/lib/helpers/updateValidators.js +2 -2
  70. package/lib/model.js +263 -263
  71. package/lib/mongoose.js +54 -54
  72. package/lib/options/schemaArrayOptions.js +2 -2
  73. package/lib/options/schemaBufferOptions.js +1 -1
  74. package/lib/options/schemaNumberOptions.js +3 -3
  75. package/lib/options/schemaObjectIdOptions.js +2 -2
  76. package/lib/options/schemaStringOptions.js +6 -6
  77. package/lib/options/schemaTypeOptions.js +13 -13
  78. package/lib/options/virtualOptions.js +11 -11
  79. package/lib/query.js +222 -222
  80. package/lib/queryHelpers.js +4 -4
  81. package/lib/schema/array.js +18 -18
  82. package/lib/schema/bigint.js +13 -13
  83. package/lib/schema/boolean.js +13 -13
  84. package/lib/schema/buffer.js +14 -14
  85. package/lib/schema/date.js +16 -16
  86. package/lib/schema/decimal128.js +13 -13
  87. package/lib/schema/documentArray.js +15 -15
  88. package/lib/schema/documentArrayElement.js +5 -6
  89. package/lib/schema/double.js +12 -12
  90. package/lib/schema/int32.js +13 -13
  91. package/lib/schema/map.js +10 -10
  92. package/lib/schema/mixed.js +10 -10
  93. package/lib/schema/number.js +18 -18
  94. package/lib/schema/objectId.js +14 -14
  95. package/lib/schema/operators/text.js +3 -3
  96. package/lib/schema/string.js +17 -17
  97. package/lib/schema/subdocument.js +13 -13
  98. package/lib/schema/union.js +3 -3
  99. package/lib/schema/uuid.js +16 -16
  100. package/lib/schema.js +76 -76
  101. package/lib/schemaType.js +62 -62
  102. package/lib/stateMachine.js +5 -8
  103. package/lib/types/array/index.js +1 -1
  104. package/lib/types/array/methods/index.js +12 -12
  105. package/lib/types/arraySubdocument.js +8 -8
  106. package/lib/types/buffer.js +4 -4
  107. package/lib/types/documentArray/index.js +1 -1
  108. package/lib/types/documentArray/methods/index.js +5 -5
  109. package/lib/types/map.js +3 -3
  110. package/lib/types/subdocument.js +11 -11
  111. package/lib/utils.js +45 -45
  112. package/lib/virtualType.js +18 -18
  113. package/package.json +8 -5
  114. package/types/index.d.ts +16 -15
  115. package/types/inferschematype.d.ts +10 -0
  116. package/types/models.d.ts +8 -5
  117. package/types/schemaoptions.d.ts +1 -1
  118. 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 {Boolean} [skipInvalidIds]
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|Any} match
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|Object} doc
356
+ * @param {Document|object} doc
357
357
  * @param {SchemaType} schema
358
- * @param {String} populatePath
358
+ * @param {string} populatePath
359
359
  * @param {Schema} modelSchema
360
- * @param {Object} queryProjection
361
- * @returns {{modelNames: String[], refPath: String|null}}
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 {String|Function} refPath
457
- * @param {Document|Object} doc
458
- * @param {String} populatePath
459
- * @param {String} indexedPath
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 {Object} queryProjection
462
- * @returns {String[]}
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|Any} val
773
+ * @param {Array|Document|any} val
774
774
  * @param {Schema} schema
775
- * @return {Array|Document|Any}
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 {Object} doc POJO
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
@@ -12,7 +12,7 @@ const utils = require('../../utils');
12
12
  * doc.comments[0].populated('author'); // Should be set
13
13
  *
14
14
  * @param {Document} doc
15
- * @param {Object} [populated]
15
+ * @param {object} [populated]
16
16
  * @api private
17
17
  */
18
18
 
@@ -3,11 +3,11 @@
3
3
  /**
4
4
  * Set a populated virtual value on a document's `$$populatedVirtuals` value
5
5
  *
6
- * @param {*} populatedVirtuals A document's `$$populatedVirtuals`
7
- * @param {*} name The virtual name
8
- * @param {*} v The result of the populate query
9
- * @param {*} options The populate options. This function handles `justOne` and `count` options.
10
- * @returns {Array<Document>|Document|Object|Array<Object>} the populated virtual value that was set
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) {
@@ -12,7 +12,7 @@
12
12
  * res['a.b.c']; // 1
13
13
  * res['a.c']; // undefined
14
14
  *
15
- * @param {Object} fields
15
+ * @param {object} fields
16
16
  * @api private
17
17
  */
18
18
 
@@ -5,9 +5,9 @@ const isDefiningProjection = require('./isDefiningProjection');
5
5
  /**
6
6
  * Determines if `path` is excluded by `projection`
7
7
  *
8
- * @param {Object} projection
9
- * @param {String} path
10
- * @return {Boolean}
8
+ * @param {object} projection
9
+ * @param {string} path
10
+ * @return {boolean}
11
11
  * @api private
12
12
  */
13
13
 
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @param {string} path1
7
7
  * @param {string} path2
8
- * @return {Boolean}
8
+ * @return {boolean}
9
9
  * @api private
10
10
  */
11
11
 
@@ -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 {Object} obj
43
- * @param {Object} [options]
44
- * @param {Boolean|'throw'} [options.strict] defaults to true
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 {Boolean} true iff the update is non-empty
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 {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]
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 {Object} filter
211
- * @param {String} pref path prefix (internal only)
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 {Object} val
536
- * @param {String} op the atomic operator ($pull, $set, etc)
537
- * @param {String} $conditional
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 {String} path
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 {Object} [update]
13
- * @param {Object} [filter]
14
- * @param {String} path
15
- * @param {Object} [options]
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 {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
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) {
@@ -135,7 +135,7 @@ module.exports = function getIndexes(schema) {
135
135
  *
136
136
  * schema._indexes = [ [indexObj, options], [indexObj, options] ..]
137
137
  * @param {Schema} schema
138
- * @param {String} prefix
138
+ * @param {string} prefix
139
139
  * @api private
140
140
  */
141
141
 
@@ -7,7 +7,7 @@
7
7
  * default, not the top-level document's.
8
8
  *
9
9
  * @param {Schema} schema
10
- * @param {String[]} parts
10
+ * @param {string[]} parts
11
11
  * @returns {boolean | 'throw' | undefined}
12
12
  */
13
13
 
@@ -4,10 +4,10 @@ const get = require('./get');
4
4
  /**
5
5
  * Applies defaults to update and findOneAndUpdate operations.
6
6
  *
7
- * @param {Object} filter
7
+ * @param {object} filter
8
8
  * @param {Schema} schema
9
- * @param {Object} castedDoc
10
- * @param {Object} options
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 {Object} update
14
- * @return {Object} modified
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 {Object} castedDoc
18
- * @param {Object} options
17
+ * @param {object} castedDoc
18
+ * @param {object} options
19
19
  * @method runValidatorsOnUpdate
20
20
  * @api private
21
21
  */