mongoose 8.17.1 → 8.18.0

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/document.js CHANGED
@@ -4070,15 +4070,17 @@ Document.prototype.$__toObjectShallow = function $__toObjectShallow(schemaFields
4070
4070
  *
4071
4071
  * If you want to skip transformations, use `transform: false`:
4072
4072
  *
4073
- * schema.options.toObject.hide = '_id';
4074
- * schema.options.toObject.transform = function (doc, ret, options) {
4075
- * if (options.hide) {
4076
- * options.hide.split(' ').forEach(function (prop) {
4077
- * delete ret[prop];
4078
- * });
4073
+ * schema.options.toObject = {
4074
+ * hide: '_id',
4075
+ * transform: function(doc, ret, options) {
4076
+ * if (options.hide) {
4077
+ * options.hide.split(' ').forEach(function(prop) {
4078
+ * delete ret[prop];
4079
+ * });
4080
+ * }
4081
+ * return ret;
4079
4082
  * }
4080
- * return ret;
4081
- * }
4083
+ * };
4082
4084
  *
4083
4085
  * const doc = new Doc({ _id: 'anId', secret: 47, name: 'Wreck-it Ralph' });
4084
4086
  * doc.toObject(); // { secret: 47, name: 'Wreck-it Ralph' }
@@ -43,5 +43,5 @@ msg.Date.max = 'Path `{PATH}` ({VALUE}) is after maximum allowed value ({MAX}).'
43
43
  msg.String = {};
44
44
  msg.String.enum = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
45
45
  msg.String.match = 'Path `{PATH}` is invalid ({VALUE}).';
46
- msg.String.minlength = 'Path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).';
47
- msg.String.maxlength = 'Path `{PATH}` (`{VALUE}`) is longer than the maximum allowed length ({MAXLENGTH}).';
46
+ msg.String.minlength = 'Path `{PATH}` (`{VALUE}`, length {LENGTH}) is shorter than the minimum allowed length ({MINLENGTH}).';
47
+ msg.String.maxlength = 'Path `{PATH}` (`{VALUE}`, length {LENGTH}) is longer than the maximum allowed length ({MAXLENGTH}).';
package/lib/model.js CHANGED
@@ -4304,6 +4304,10 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
4304
4304
  let remaining = paths.size;
4305
4305
 
4306
4306
  return new Promise((resolve, reject) => {
4307
+ if (remaining === 0) {
4308
+ return settle();
4309
+ }
4310
+
4307
4311
  for (const path of paths) {
4308
4312
  const schemaType = schema.path(path);
4309
4313
  if (schemaType == null) {
@@ -4328,13 +4332,17 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
4328
4332
  }, context, { path: path });
4329
4333
  }
4330
4334
 
4335
+ function settle() {
4336
+ if (error) {
4337
+ reject(error);
4338
+ } else {
4339
+ resolve(obj);
4340
+ }
4341
+ }
4342
+
4331
4343
  function _checkDone() {
4332
4344
  if (--remaining <= 0) {
4333
- if (error) {
4334
- reject(error);
4335
- } else {
4336
- resolve(obj);
4337
- }
4345
+ return settle();
4338
4346
  }
4339
4347
  }
4340
4348
  });
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ const SchemaTypeOptions = require('./schemaTypeOptions');
4
+
5
+ /**
6
+ * The options defined on a Union schematype.
7
+ *
8
+ * @api public
9
+ * @inherits SchemaTypeOptions
10
+ * @constructor SchemaUnionOptions
11
+ */
12
+
13
+ class SchemaUnionOptions extends SchemaTypeOptions {}
14
+
15
+ const opts = require('./propertyOptions');
16
+
17
+ /**
18
+ * If set, specifies the types that this union can take. Mongoose will cast
19
+ * the value to one of the given types.
20
+ *
21
+ * If not set, Mongoose will not cast the value to any specific type.
22
+ *
23
+ * @api public
24
+ * @property of
25
+ * @memberOf SchemaUnionOptions
26
+ * @type {Function|Function[]|string|string[]}
27
+ * @instance
28
+ */
29
+
30
+ Object.defineProperty(SchemaUnionOptions.prototype, 'of', opts);
31
+
32
+ module.exports = SchemaUnionOptions;
@@ -654,6 +654,8 @@ function cast$elemMatch(val, context) {
654
654
  * For example, `$conditionalHandlers.$all` is the function Mongoose calls to cast `$all` filter operators.
655
655
  *
656
656
  * @property $conditionalHandlers
657
+ * @memberOf SchemaArray
658
+ * @instance
657
659
  * @api public
658
660
  */
659
661
 
@@ -100,7 +100,7 @@ SchemaBigInt.get = SchemaType.get;
100
100
  *
101
101
  * @param {Function} caster
102
102
  * @return {Function}
103
- * @function get
103
+ * @function cast
104
104
  * @static
105
105
  * @api public
106
106
  */
@@ -190,6 +190,8 @@ const $conditionalHandlers = {
190
190
  * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
191
191
  *
192
192
  * @property $conditionalHandlers
193
+ * @memberOf SchemaBigInt
194
+ * @instance
193
195
  * @api public
194
196
  */
195
197
 
@@ -105,7 +105,7 @@ SchemaBoolean.get = SchemaType.get;
105
105
  *
106
106
  * @param {Function} caster
107
107
  * @return {Function}
108
- * @function get
108
+ * @function cast
109
109
  * @static
110
110
  * @api public
111
111
  */
@@ -242,6 +242,8 @@ const $conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers };
242
242
  * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
243
243
  *
244
244
  * @property $conditionalHandlers
245
+ * @memberOf SchemaBoolean
246
+ * @instance
245
247
  * @api public
246
248
  */
247
249
 
@@ -276,6 +276,8 @@ const $conditionalHandlers = {
276
276
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
277
277
  *
278
278
  * @property $conditionalHandlers
279
+ * @memberOf SchemaBuffer
280
+ * @instance
279
281
  * @api public
280
282
  */
281
283
 
@@ -111,7 +111,7 @@ SchemaDate.get = SchemaType.get;
111
111
  *
112
112
  * @param {Function} caster
113
113
  * @return {Function}
114
- * @function get
114
+ * @function cast
115
115
  * @static
116
116
  * @api public
117
117
  */
@@ -402,6 +402,8 @@ const $conditionalHandlers = {
402
402
  * For example, `$conditionalHandlers.$gte` is the function Mongoose calls to cast `$gte` filter operators.
403
403
  *
404
404
  * @property $conditionalHandlers
405
+ * @memberOf SchemaDate
406
+ * @instance
405
407
  * @api public
406
408
  */
407
409
 
@@ -227,6 +227,8 @@ const $conditionalHandlers = {
227
227
  * For example, `$conditionalHandlers.$lte` is the function Mongoose calls to cast `$lte` filter operators.
228
228
  *
229
229
  * @property $conditionalHandlers
230
+ * @memberOf SchemaDecimal128
231
+ * @instance
230
232
  * @api public
231
233
  */
232
234
 
@@ -122,6 +122,8 @@ SchemaDocumentArray.prototype.OptionsConstructor = SchemaDocumentArrayOptions;
122
122
  * For example, `$conditionalHandlers.$size` is the function Mongoose calls to cast `$size` filter operators.
123
123
  *
124
124
  * @property $conditionalHandlers
125
+ * @memberOf SchemaDocumentArray
126
+ * @instance
125
127
  * @api public
126
128
  */
127
129
 
@@ -115,7 +115,7 @@ SchemaDouble._defaultCaster = v => {
115
115
  *
116
116
  * @param {Function} caster
117
117
  * @return {Function}
118
- * @function get
118
+ * @function cast
119
119
  * @static
120
120
  * @api public
121
121
  */
@@ -210,6 +210,8 @@ const $conditionalHandlers = {
210
210
  * For example, `$conditionalHandlers.$lt` is the function Mongoose calls to cast `$lt` filter operators.
211
211
  *
212
212
  * @property $conditionalHandlers
213
+ * @memberOf SchemaDouble
214
+ * @instance
213
215
  * @api public
214
216
  */
215
217
 
@@ -12,6 +12,8 @@ exports.Buffer = require('./buffer');
12
12
  exports.Date = require('./date');
13
13
  exports.Decimal128 = exports.Decimal = require('./decimal128');
14
14
  exports.DocumentArray = require('./documentArray');
15
+ exports.Double = require('./double');
16
+ exports.Int32 = require('./int32');
15
17
  exports.Map = require('./map');
16
18
  exports.Mixed = require('./mixed');
17
19
  exports.Number = require('./number');
@@ -19,8 +21,7 @@ exports.ObjectId = require('./objectId');
19
21
  exports.String = require('./string');
20
22
  exports.Subdocument = require('./subdocument');
21
23
  exports.UUID = require('./uuid');
22
- exports.Double = require('./double');
23
- exports.Int32 = require('./int32');
24
+ exports.Union = require('./union');
24
25
 
25
26
  // alias
26
27
 
@@ -119,7 +119,7 @@ SchemaInt32._defaultCaster = v => {
119
119
  *
120
120
  * @param {Function} caster
121
121
  * @return {Function}
122
- * @function get
122
+ * @function cast
123
123
  * @static
124
124
  * @api public
125
125
  */
@@ -214,6 +214,8 @@ const $conditionalHandlers = {
214
214
  * For example, `$conditionalHandlers.$gt` is the function Mongoose calls to cast `$gt` filter operators.
215
215
  *
216
216
  * @property $conditionalHandlers
217
+ * @memberOf SchemaInt32
218
+ * @instance
217
219
  * @api public
218
220
  */
219
221
 
@@ -93,7 +93,7 @@ SchemaNumber._cast = castNumber;
93
93
  *
94
94
  * @param {Function} caster
95
95
  * @return {Function}
96
- * @function get
96
+ * @function cast
97
97
  * @static
98
98
  * @api public
99
99
  */
@@ -418,6 +418,8 @@ const $conditionalHandlers = {
418
418
  * For example, `$conditionalHandlers.$gte` is the function Mongoose calls to cast `$gte` filter operators.
419
419
  *
420
420
  * @property $conditionalHandlers
421
+ * @memberOf SchemaNumber
422
+ * @instance
421
423
  * @api public
422
424
  */
423
425
 
@@ -143,7 +143,7 @@ SchemaObjectId._cast = castObjectId;
143
143
  *
144
144
  * @param {Function} caster
145
145
  * @return {Function}
146
- * @function get
146
+ * @function cast
147
147
  * @static
148
148
  * @api public
149
149
  */
@@ -273,6 +273,8 @@ const $conditionalHandlers = {
273
273
  * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
274
274
  *
275
275
  * @property $conditionalHandlers
276
+ * @memberOf SchemaObjectId
277
+ * @instance
276
278
  * @api public
277
279
  */
278
280
 
@@ -310,6 +312,7 @@ function resetId(v) {
310
312
  * @param [options]
311
313
  * @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
312
314
  * @returns {Object} JSON schema properties
315
+ * @api public
313
316
  */
314
317
 
315
318
  SchemaObjectId.prototype.toJSONSchema = function toJSONSchema(options) {
@@ -75,7 +75,7 @@ SchemaString._cast = castString;
75
75
  *
76
76
  * @param {Function} caster
77
77
  * @return {Function}
78
- * @function get
78
+ * @function cast
79
79
  * @static
80
80
  * @api public
81
81
  */
@@ -665,6 +665,8 @@ const $conditionalHandlers = {
665
665
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
666
666
  *
667
667
  * @property $conditionalHandlers
668
+ * @memberOf SchemaString
669
+ * @instance
668
670
  * @api public
669
671
  */
670
672
 
@@ -158,6 +158,8 @@ $conditionalHandlers.$exists = $exists;
158
158
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
159
159
  *
160
160
  * @property $conditionalHandlers
161
+ * @memberOf SchemaSubdocument
162
+ * @instance
161
163
  * @api public
162
164
  */
163
165
 
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ /*!
4
+ * ignore
5
+ */
6
+
7
+ const SchemaUnionOptions = require('../options/schemaUnionOptions');
8
+ const SchemaType = require('../schemaType');
9
+
10
+ const firstValueSymbol = Symbol('firstValue');
11
+
12
+ /*!
13
+ * ignore
14
+ */
15
+
16
+ class Union extends SchemaType {
17
+ constructor(key, options, schemaOptions = {}) {
18
+ super(key, options, 'Union');
19
+ if (!options || !Array.isArray(options.of) || options.of.length === 0) {
20
+ throw new Error('Union schema type requires an array of types');
21
+ }
22
+ this.schemaTypes = options.of.map(obj => options.parentSchema.interpretAsType(key, obj, schemaOptions));
23
+ }
24
+
25
+ cast(val, doc, init, prev, options) {
26
+ let firstValue = firstValueSymbol;
27
+ let lastError;
28
+ // Loop through each schema type in the union. If one of the schematypes returns a value that is `=== val`, then
29
+ // use `val`. Otherwise, if one of the schematypes casted successfully, use the first successfully casted value.
30
+ // Finally, if none of the schematypes casted successfully, throw the error from the last schema type in the union.
31
+ // The `=== val` check is a workaround to ensure that the original value is returned if it matches one of the schema types,
32
+ // avoiding cases like where numbers are casted to strings or dates even if the schema type is a number.
33
+ for (let i = 0; i < this.schemaTypes.length; ++i) {
34
+ try {
35
+ const casted = this.schemaTypes[i].cast(val, doc, init, prev, options);
36
+ if (casted === val) {
37
+ return casted;
38
+ }
39
+ if (firstValue === firstValueSymbol) {
40
+ firstValue = casted;
41
+ }
42
+ } catch (error) {
43
+ lastError = error;
44
+ }
45
+ }
46
+ if (firstValue !== firstValueSymbol) {
47
+ return firstValue;
48
+ }
49
+ throw lastError;
50
+ }
51
+
52
+ // Setters also need to be aware of casting - we need to apply the setters of the entry in the union we choose.
53
+ applySetters(val, doc, init, prev, options) {
54
+ let firstValue = firstValueSymbol;
55
+ let lastError;
56
+ // Loop through each schema type in the union. If one of the schematypes returns a value that is `=== val`, then
57
+ // use `val`. Otherwise, if one of the schematypes casted successfully, use the first successfully casted value.
58
+ // Finally, if none of the schematypes casted successfully, throw the error from the last schema type in the union.
59
+ // The `=== val` check is a workaround to ensure that the original value is returned if it matches one of the schema types,
60
+ // avoiding cases like where numbers are casted to strings or dates even if the schema type is a number.
61
+ for (let i = 0; i < this.schemaTypes.length; ++i) {
62
+ try {
63
+ let castedVal = this.schemaTypes[i]._applySetters(val, doc, init, prev, options);
64
+ if (castedVal == null) {
65
+ castedVal = this.schemaTypes[i]._castNullish(castedVal);
66
+ } else {
67
+ castedVal = this.schemaTypes[i].cast(castedVal, doc, init, prev, options);
68
+ }
69
+ if (castedVal === val) {
70
+ return castedVal;
71
+ }
72
+ if (firstValue === firstValueSymbol) {
73
+ firstValue = castedVal;
74
+ }
75
+ } catch (error) {
76
+ lastError = error;
77
+ }
78
+ }
79
+ if (firstValue !== firstValueSymbol) {
80
+ return firstValue;
81
+ }
82
+ throw lastError;
83
+ }
84
+
85
+ clone() {
86
+ const schematype = super.clone();
87
+
88
+ schematype.schemaTypes = this.schemaTypes.map(schemaType => schemaType.clone());
89
+ return schematype;
90
+ }
91
+ }
92
+
93
+ /**
94
+ * This schema type's name, to defend against minifiers that mangle
95
+ * function names.
96
+ *
97
+ * @api public
98
+ */
99
+ Union.schemaName = 'Union';
100
+
101
+ Union.defaultOptions = {};
102
+
103
+ Union.prototype.OptionsConstructor = SchemaUnionOptions;
104
+
105
+ module.exports = Union;
@@ -263,6 +263,8 @@ const $conditionalHandlers = {
263
263
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
264
264
  *
265
265
  * @property $conditionalHandlers
266
+ * @memberOf SchemaUUID
267
+ * @instance
266
268
  * @api public
267
269
  */
268
270
 
package/lib/schema.js CHANGED
@@ -1525,7 +1525,7 @@ Object.defineProperty(Schema.prototype, 'base', {
1525
1525
  *
1526
1526
  * @param {String} path
1527
1527
  * @param {Object} obj constructor
1528
- * @param {Object} options
1528
+ * @param {Object} options schema options
1529
1529
  * @api private
1530
1530
  */
1531
1531
 
@@ -1539,7 +1539,6 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
1539
1539
  return clone;
1540
1540
  }
1541
1541
 
1542
-
1543
1542
  // If this schema has an associated Mongoose object, use the Mongoose object's
1544
1543
  // copy of SchemaTypes re: gh-7158 gh-6933
1545
1544
  const MongooseTypes = this.base != null ? this.base.Schema.Types : Schema.Types;
@@ -1740,7 +1739,10 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
1740
1739
  'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
1741
1740
  }
1742
1741
 
1743
- const schemaType = new MongooseTypes[name](path, obj);
1742
+ if (name === 'Union') {
1743
+ obj.parentSchema = this;
1744
+ }
1745
+ const schemaType = new MongooseTypes[name](path, obj, options);
1744
1746
 
1745
1747
  if (schemaType.$isSchemaMap) {
1746
1748
  createMapNestedSchemaType(this, schemaType, path, obj, options);
package/lib/schemaType.js CHANGED
@@ -1349,6 +1349,12 @@ SchemaType.prototype.doValidate = function(value, fn, scope, options) {
1349
1349
  validatorProperties.path = options && options.path ? options.path : path;
1350
1350
  validatorProperties.fullPath = this.$fullPath;
1351
1351
  validatorProperties.value = value;
1352
+ if (typeof value === 'string') {
1353
+ validatorProperties.length = value.length;
1354
+ if (validatorProperties.value.length > 30) {
1355
+ validatorProperties.value = validatorProperties.value.slice(0, 30) + '...';
1356
+ }
1357
+ }
1352
1358
 
1353
1359
  if (validator instanceof RegExp) {
1354
1360
  validate(validator.test(value), validatorProperties, scope);
@@ -1470,6 +1476,12 @@ SchemaType.prototype.doValidateSync = function(value, scope, options) {
1470
1476
  validatorProperties.path = options && options.path ? options.path : path;
1471
1477
  validatorProperties.fullPath = this.$fullPath;
1472
1478
  validatorProperties.value = value;
1479
+ if (typeof value === 'string') {
1480
+ validatorProperties.length = value.length;
1481
+ if (validatorProperties.value.length > 30) {
1482
+ validatorProperties.value = validatorProperties.value.slice(0, 30) + '...';
1483
+ }
1484
+ }
1473
1485
  let ok = false;
1474
1486
 
1475
1487
  // Skip any explicit async validators. Validators that return a promise
@@ -1643,6 +1655,8 @@ function handle$in(val, context) {
1643
1655
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
1644
1656
  *
1645
1657
  * @property $conditionalHandlers
1658
+ * @memberOf SchemaType
1659
+ * @instance
1646
1660
  * @api public
1647
1661
  */
1648
1662
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.17.1",
4
+ "version": "8.18.0",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -1,46 +1,49 @@
1
1
  declare module 'mongoose' {
2
2
  import mongodb = require('mongodb');
3
3
 
4
- /*
5
- * section collection.js
6
- */
7
- interface CollectionBase<T extends mongodb.Document> extends mongodb.Collection<T> {
8
- /*
9
- * Abstract methods. Some of these are already defined on the
10
- * mongodb.Collection interface so they've been commented out.
4
+ export class BaseCollection<T extends mongodb.Document> extends mongodb.Collection<T> {
5
+ /**
6
+ * Collection constructor
7
+ * @param name name of the collection
8
+ * @param conn A MongooseConnection instance
9
+ * @param opts optional collection options
11
10
  */
11
+ constructor(name: string, conn: Connection, opts?: any);
12
+
13
+ /*
14
+ * Abstract methods. Some of these are already defined on the
15
+ * mongodb.Collection interface so they've been commented out.
16
+ */
12
17
  ensureIndex(...args: any[]): any;
13
18
  findAndModify(...args: any[]): any;
14
19
  getIndexes(...args: any[]): any;
15
20
 
21
+ /** Formatter for debug print args */
22
+ $format(arg: any, color?: boolean, shell?: boolean): string;
23
+ /** Debug print helper */
24
+ $print(name: string, i: string | number, args: any[], color?: boolean, shell?: boolean): void;
25
+
16
26
  /** The collection name */
17
- collectionName: string;
27
+ get collectionName(): string;
18
28
  /** The Connection instance */
19
29
  conn: Connection;
20
30
  /** The collection name */
21
31
  name: string;
22
32
  }
23
33
 
24
- export type BaseCollection<T extends mongodb.Document> = CollectionBase<T>;
25
-
26
34
  /*
27
35
  * section drivers/node-mongodb-native/collection.js
28
36
  */
29
- interface Collection<T extends mongodb.Document = mongodb.Document> extends CollectionBase<T> {
37
+ class Collection<T extends mongodb.Document = mongodb.Document> extends BaseCollection<T> {
30
38
  /**
31
39
  * Collection constructor
32
40
  * @param name name of the collection
33
41
  * @param conn A MongooseConnection instance
34
42
  * @param opts optional collection options
35
43
  */
36
- // eslint-disable-next-line @typescript-eslint/no-misused-new
37
- new(name: string, conn: Connection, opts?: any): Collection<T>;
38
- /** Formatter for debug print args */
39
- $format(arg: any, color?: boolean, shell?: boolean): string;
40
- /** Debug print helper */
41
- $print(name: string, i: string | number, args: any[], color?: boolean, shell?: boolean): void;
44
+ constructor(name: string, conn: Connection, opts?: any);
45
+
42
46
  /** Retrieves information about this collections indexes. */
43
47
  getIndexes(): ReturnType<mongodb.Collection<T>['indexInformation']>;
44
48
  }
45
- let Collection: Collection;
46
49
  }
@@ -71,8 +71,6 @@ declare module 'mongoose' {
71
71
  };
72
72
  }[keyof SchemaMap];
73
73
 
74
- export type BaseConnection = Connection;
75
-
76
74
  class Connection extends events.EventEmitter implements SessionStarter {
77
75
  /** Runs a [db-level aggregate()](https://www.mongodb.com/docs/manual/reference/method/db.aggregate/) on this connection's underlying `db` */
78
76
  aggregate<ResultType = unknown>(pipeline?: PipelineStage[] | null, options?: AggregateOptions): Aggregate<Array<ResultType>>;
@@ -286,4 +284,5 @@ declare module 'mongoose' {
286
284
  withSession<T = any>(executor: (session: ClientSession) => Promise<T>): Promise<T>;
287
285
  }
288
286
 
287
+ export class BaseConnection extends Connection {}
289
288
  }
@@ -256,12 +256,17 @@ declare module 'mongoose' {
256
256
  set(value: string | Record<string, any>): this;
257
257
 
258
258
  /** The return value of this method is used in calls to JSON.stringify(doc). */
259
- toJSON(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, TSchemaOptions>;
260
- toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>;
261
- toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>;
262
- toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>>;
263
- toJSON(options: ToObjectOptions & { flattenMaps: false }): Default__v<Require_id<DocType>, TSchemaOptions>;
264
- toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType>, TSchemaOptions>>;
259
+ toJSON(options: ToObjectOptions & { versionKey: false, virtuals: true, flattenObjectIds: true }): Omit<ObjectIdToString<FlattenMaps<Require_id<DocType & TVirtuals>>>, '__v'>;
260
+ toJSON(options: ToObjectOptions & { virtuals: true, flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>>>;
261
+ toJSON(options: ToObjectOptions & { versionKey: false, virtuals: true }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
262
+ toJSON(options: ToObjectOptions & { versionKey: false, flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Omit<Require_id<DocType>, '__v'>>>;
263
+ toJSON(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>;
264
+ toJSON(options: ToObjectOptions & { versionKey: false }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
265
+ toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>;
266
+ toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>;
267
+ toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>>;
268
+ toJSON(options: ToObjectOptions & { flattenMaps: false }): Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>;
269
+ toJSON(options: ToObjectOptions & { flattenMaps: false, flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>;
265
270
 
266
271
  toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>;
267
272
  toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>;
@@ -270,9 +275,15 @@ declare module 'mongoose' {
270
275
  toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenMaps: false, flattenObjectIds: true }): ObjectIdToString<T>;
271
276
 
272
277
  /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
273
- toObject(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, TSchemaOptions>;
274
- toObject(options?: ToObjectOptions): Default__v<Require_id<DocType>, TSchemaOptions>;
275
- toObject<T>(options?: ToObjectOptions): Default__v<Require_id<T>, TSchemaOptions>;
278
+ toObject(options: ToObjectOptions & { versionKey: false, virtuals: true, flattenObjectIds: true }): Omit<ObjectIdToString<Require_id<DocType & TVirtuals>>, '__v'>;
279
+ toObject(options: ToObjectOptions & { virtuals: true, flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>>;
280
+ toObject(options: ToObjectOptions & { versionKey: false, flattenObjectIds: true }): Omit<ObjectIdToString<Require_id<DocType & TVirtuals>>, '__v'>;
281
+ toObject(options: ToObjectOptions & { versionKey: false, virtuals: true }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
282
+ toObject(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>;
283
+ toObject(options: ToObjectOptions & { versionKey: false }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
284
+ toObject(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>>;
285
+ toObject(options?: ToObjectOptions): Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>;
286
+ toObject<T>(options?: ToObjectOptions): Default__v<Require_id<T>, ResolveSchemaOptions<TSchemaOptions>>;
276
287
 
277
288
  /** Clears the modified state on the specified path. */
278
289
  unmarkModified<T extends keyof DocType>(path: T): void;