mongoose 6.6.3 → 6.6.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/.mocharc.yml CHANGED
@@ -1,2 +1,4 @@
1
1
  reporter: spec # better to identify failing / slow tests than "dot"
2
2
  ui: bdd # explicitly setting, even though it is mocha default
3
+ require:
4
+ - test/mocha-fixtures.js
@@ -12,6 +12,10 @@ const isDefiningProjection = require('./isDefiningProjection');
12
12
  */
13
13
 
14
14
  module.exports = function isPathExcluded(projection, path) {
15
+ if (projection == null) {
16
+ return false;
17
+ }
18
+
15
19
  if (path === '_id') {
16
20
  return projection._id === 0;
17
21
  }
package/lib/model.js CHANGED
@@ -51,11 +51,13 @@ const {
51
51
  getRelatedDBIndexes,
52
52
  getRelatedSchemaIndexes
53
53
  } = require('./helpers/indexes/getRelatedIndexes');
54
+ const isPathExcluded = require('./helpers/projection/isPathExcluded');
54
55
  const decorateDiscriminatorIndexOptions = require('./helpers/indexes/decorateDiscriminatorIndexOptions');
55
56
  const isPathSelectedInclusive = require('./helpers/projection/isPathSelectedInclusive');
56
57
  const leanPopulateMap = require('./helpers/populate/leanPopulateMap');
57
58
  const modifiedPaths = require('./helpers/update/modifiedPaths');
58
59
  const parallelLimit = require('./helpers/parallelLimit');
60
+ const parentPaths = require('./helpers/path/parentPaths');
59
61
  const prepareDiscriminatorPipeline = require('./helpers/aggregate/prepareDiscriminatorPipeline');
60
62
  const pushNestedArrayPaths = require('./helpers/model/pushNestedArrayPaths');
61
63
  const removeDeselectedForeignField = require('./helpers/populate/removeDeselectedForeignField');
@@ -760,6 +762,19 @@ Model.prototype.$__delta = function() {
760
762
  }
761
763
  }
762
764
 
765
+ // If this path is set to default, and either this path or one of
766
+ // its parents is excluded, don't treat this path as dirty.
767
+ if (this.$isDefault(data.path) && this.$__.selected) {
768
+ if (data.path.indexOf('.') === -1 && isPathExcluded(this.$__.selected, data.path)) {
769
+ continue;
770
+ }
771
+
772
+ const pathsToCheck = parentPaths(data.path);
773
+ if (pathsToCheck.find(path => isPathExcluded(this.$__.isSelected, path))) {
774
+ continue;
775
+ }
776
+ }
777
+
763
778
  if (divergent.length) continue;
764
779
  if (value === undefined) {
765
780
  operand(this, where, delta, data, 1, '$unset');
@@ -798,6 +813,11 @@ Model.prototype.$__delta = function() {
798
813
  if (this.$__.version) {
799
814
  this.$__version(where, delta);
800
815
  }
816
+
817
+ if (Object.keys(delta).length === 0) {
818
+ return [where, null];
819
+ }
820
+
801
821
  return [where, delta];
802
822
  };
803
823
 
@@ -1196,7 +1216,6 @@ Model.exists = function exists(filter, options, callback) {
1196
1216
  */
1197
1217
 
1198
1218
  Model.discriminator = function(name, schema, options) {
1199
-
1200
1219
  let model;
1201
1220
  if (typeof name === 'function') {
1202
1221
  model = name;
package/lib/schema.js CHANGED
@@ -502,25 +502,21 @@ Schema.prototype.defaultOptions = function(options) {
502
502
  *
503
503
  * #### Example:
504
504
  *
505
- * const options = { discriminatorKey: 'kind' };
505
+ * const eventSchema = new mongoose.Schema({ timestamp: Date }, { discriminatorKey: 'kind' });
506
+ *
507
+ * const clickedEventSchema = new mongoose.Schema({ element: String }, { discriminatorKey: 'kind' });
508
+ * const ClickedModel = eventSchema.discriminator('clicked', clickedEventSchema);
506
509
  *
507
- * const eventSchema = new mongoose.Schema({ time: Date }, options);
508
510
  * const Event = mongoose.model('Event', eventSchema);
509
511
  *
510
- * // ClickedLinkEvent is a special type of Event that has
511
- * // a URL.
512
- * const ClickedLinkEvent = Event.discriminator('ClickedLink',
513
- * new mongoose.Schema({ url: String }, options));
512
+ * Event.discriminators['clicked']; // Model { clicked }
514
513
  *
515
- * // When you create a generic event, it can't have a URL field...
516
- * const genericEvent = new Event({ time: Date.now(), url: 'google.com' });
517
- * assert.ok(!genericEvent.url);
518
- * // But a ClickedLinkEvent can
519
- * const clickedEvent = new ClickedLinkEvent({ time: Date.now(), url: 'google.com' });
520
- * assert.ok(clickedEvent.url);
514
+ * const doc = await Event.create({ kind: 'clicked', element: '#hero' });
515
+ * doc.element; // '#hero'
516
+ * doc instanceof ClickedModel; // true
521
517
  *
522
518
  * @param {String} name the name of the discriminator
523
- * @param {Schema} schema the Schema of the discriminated Schema
519
+ * @param {Schema} schema the discriminated Schema
524
520
  * @return {Schema} the Schema instance
525
521
  * @api public
526
522
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.6.3",
4
+ "version": "6.6.4",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -28,9 +28,9 @@
28
28
  "sift": "16.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@babel/core": "7.19.0",
32
- "@typescript-eslint/eslint-plugin": "5.36.2",
33
- "@typescript-eslint/parser": "5.36.2",
31
+ "@babel/core": "7.19.3",
32
+ "@typescript-eslint/eslint-plugin": "5.38.1",
33
+ "@typescript-eslint/parser": "5.38.1",
34
34
  "acquit": "1.2.1",
35
35
  "acquit-ignore": "0.2.0",
36
36
  "acquit-require": "0.1.1",
@@ -43,13 +43,13 @@
43
43
  "cheerio": "1.0.0-rc.12",
44
44
  "crypto-browserify": "3.12.0",
45
45
  "dox": "1.0.0",
46
- "eslint": "8.23.0",
46
+ "eslint": "8.24.0",
47
47
  "eslint-plugin-mocha-no-only": "1.1.1",
48
48
  "express": "^4.18.1",
49
49
  "highlight.js": "11.6.0",
50
50
  "lodash.isequal": "4.5.0",
51
51
  "lodash.isequalwith": "4.4.0",
52
- "marked": "4.1.0",
52
+ "marked": "4.1.1",
53
53
  "mkdirp": "^1.0.4",
54
54
  "mocha": "10.0.0",
55
55
  "moment": "2.x",
@@ -61,8 +61,8 @@
61
61
  "sinon": "14.0.0",
62
62
  "stream-browserify": "3.0.0",
63
63
  "ts-benchmark": "^1.1.10",
64
- "tsd": "0.23.0",
65
- "typescript": "4.8.3",
64
+ "tsd": "0.24.1",
65
+ "typescript": "4.8.4",
66
66
  "uuid": "9.0.0",
67
67
  "webpack": "5.74.0"
68
68
  },
package/types/models.d.ts CHANGED
@@ -146,9 +146,9 @@ declare module 'mongoose' {
146
146
  * if you use `create()`) because with `bulkWrite()` there is only one network
147
147
  * round trip to the MongoDB server.
148
148
  */
149
- bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends {} ? T : any>>, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback<mongodb.BulkWriteResult>): void;
150
- bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends {} ? T : any>>, callback: Callback<mongodb.BulkWriteResult>): void;
151
- bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends {} ? T : any>>, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise<mongodb.BulkWriteResult>;
149
+ bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends Document ? any : (T extends {} ? T : any)>>, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback<mongodb.BulkWriteResult>): void;
150
+ bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends Document ? any : (T extends {} ? T : any)>>, callback: Callback<mongodb.BulkWriteResult>): void;
151
+ bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends Document ? any : (T extends {} ? T : any)>>, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise<mongodb.BulkWriteResult>;
152
152
 
153
153
  /**
154
154
  * Sends multiple `save()` calls in a single `bulkWrite()`. This is faster than
package/types/query.d.ts CHANGED
@@ -616,7 +616,7 @@ declare module 'mongoose' {
616
616
  then: Promise<ResultType>['then'];
617
617
 
618
618
  /** Converts this query to a customized, reusable query constructor with all arguments and options retained. */
619
- toConstructor(): typeof this;
619
+ toConstructor(): typeof Query<ResultType, DocType, THelpers, RawDocType>;
620
620
 
621
621
  /** Declare and/or execute this query as an update() operation. */
622
622
  update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
@@ -201,7 +201,7 @@ declare module 'mongoose' {
201
201
  /**
202
202
  * Query helper functions.
203
203
  */
204
- query?: Record<any, <T extends QueryWithHelpers<unknown, DocType>>(this: T, ...args: any) => T> | QueryHelpers,
204
+ query?: Record<any, <T extends QueryWithHelpers<unknown, HydratedDocument<DocType>>>(this: T, ...args: any) => T> | QueryHelpers,
205
205
 
206
206
  /**
207
207
  * Set whether to cast non-array values to arrays.