mongoose 8.0.2 → 8.0.3
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/dist/browser.umd.js +1 -1
- package/lib/document.js +2 -3
- package/lib/helpers/clone.js +1 -1
- package/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +23 -0
- package/lib/helpers/populate/assignVals.js +5 -0
- package/lib/helpers/projection/isExclusive.js +2 -3
- package/lib/model.js +1 -1
- package/lib/mongoose.js +3 -0
- package/lib/query.js +3 -6
- package/lib/queryHelpers.js +3 -2
- package/lib/schema/bigint.js +3 -3
- package/lib/schema/boolean.js +1 -3
- package/lib/schema/buffer.js +11 -11
- package/lib/schema/date.js +7 -7
- package/lib/schema/decimal128.js +7 -8
- package/lib/schema/documentArray.js +1 -7
- package/lib/schema/number.js +12 -12
- package/lib/schema/objectId.js +7 -7
- package/lib/schema/string.js +3 -2
- package/lib/schema/subdocument.js +3 -7
- package/lib/schema/uuid.js +3 -3
- package/lib/schema.js +7 -7
- package/lib/utils.js +0 -33
- package/package.json +7 -7
- package/types/inferschematype.d.ts +13 -12
- package/types/models.d.ts +11 -3
package/lib/document.js
CHANGED
|
@@ -3691,8 +3691,7 @@ Document.prototype.$toObject = function(options, json) {
|
|
|
3691
3691
|
const schemaOptions = this.$__schema && this.$__schema.options || {};
|
|
3692
3692
|
// merge base default options with Schema's set default options if available.
|
|
3693
3693
|
// `clone` is necessary here because `utils.options` directly modifies the second input.
|
|
3694
|
-
defaultOptions =
|
|
3695
|
-
defaultOptions = utils.options(defaultOptions, clone(schemaOptions[path] || {}));
|
|
3694
|
+
defaultOptions = { ...defaultOptions, ...baseOptions, ...schemaOptions[path] };
|
|
3696
3695
|
|
|
3697
3696
|
// If options do not exist or is not an object, set it to empty object
|
|
3698
3697
|
options = utils.isPOJO(options) ? { ...options } : {};
|
|
@@ -3754,7 +3753,7 @@ Document.prototype.$toObject = function(options, json) {
|
|
|
3754
3753
|
}
|
|
3755
3754
|
|
|
3756
3755
|
// merge default options with input options.
|
|
3757
|
-
options =
|
|
3756
|
+
options = { ...defaultOptions, ...options };
|
|
3758
3757
|
options._isNested = true;
|
|
3759
3758
|
options.json = json;
|
|
3760
3759
|
options.minimize = _minimize;
|
package/lib/helpers/clone.js
CHANGED
|
@@ -54,7 +54,7 @@ function clone(obj, options, isArrayChild) {
|
|
|
54
54
|
ret = obj.toObject(options);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
if (options && options.minimize && isSingleNested && Object.keys(ret).length === 0) {
|
|
57
|
+
if (options && options.minimize && !obj.constructor.$__required && isSingleNested && Object.keys(ret).length === 0) {
|
|
58
58
|
return undefined;
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = applyEmbeddedDiscriminators;
|
|
4
|
+
|
|
5
|
+
function applyEmbeddedDiscriminators(schema, seen = new WeakSet()) {
|
|
6
|
+
if (seen.has(schema)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
seen.add(schema);
|
|
10
|
+
for (const path of Object.keys(schema.paths)) {
|
|
11
|
+
const schemaType = schema.paths[path];
|
|
12
|
+
if (!schemaType.schema) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
applyEmbeddedDiscriminators(schemaType.schema, seen);
|
|
16
|
+
if (!schemaType.schema._applyDiscriminators) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
for (const disc of schemaType.schema._applyDiscriminators.keys()) {
|
|
20
|
+
schemaType.discriminator(disc, schemaType.schema._applyDiscriminators.get(disc));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -39,8 +39,10 @@ module.exports = function assignVals(o) {
|
|
|
39
39
|
const options = o.options;
|
|
40
40
|
const count = o.count && o.isVirtual;
|
|
41
41
|
let i;
|
|
42
|
+
let setValueIndex = 0;
|
|
42
43
|
|
|
43
44
|
function setValue(val) {
|
|
45
|
+
++setValueIndex;
|
|
44
46
|
if (count) {
|
|
45
47
|
return val;
|
|
46
48
|
}
|
|
@@ -80,11 +82,14 @@ module.exports = function assignVals(o) {
|
|
|
80
82
|
return valueFilter(val[0], options, populateOptions, _allIds);
|
|
81
83
|
} else if (o.justOne === false && !Array.isArray(val)) {
|
|
82
84
|
return valueFilter([val], options, populateOptions, _allIds);
|
|
85
|
+
} else if (o.justOne === true && !Array.isArray(val) && Array.isArray(_allIds)) {
|
|
86
|
+
return valueFilter(val, options, populateOptions, val == null ? val : _allIds[setValueIndex - 1]);
|
|
83
87
|
}
|
|
84
88
|
return valueFilter(val, options, populateOptions, _allIds);
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
for (i = 0; i < docs.length; ++i) {
|
|
92
|
+
setValueIndex = 0;
|
|
88
93
|
const _path = o.path.endsWith('.$*') ? o.path.slice(0, -3) : o.path;
|
|
89
94
|
const existingVal = mpath.get(_path, docs[i], lookupLocalFields);
|
|
90
95
|
if (existingVal == null && !getVirtual(o.originalModel.schema, _path)) {
|
|
@@ -12,13 +12,12 @@ module.exports = function isExclusive(projection) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const keys = Object.keys(projection);
|
|
15
|
-
let ki = keys.length;
|
|
16
15
|
let exclude = null;
|
|
17
16
|
|
|
18
|
-
if (
|
|
17
|
+
if (keys.length === 1 && keys[0] === '_id') {
|
|
19
18
|
exclude = !projection._id;
|
|
20
19
|
} else {
|
|
21
|
-
|
|
20
|
+
for (let ki = 0; ki < keys.length; ++ki) {
|
|
22
21
|
// Does this projection explicitly define inclusion/exclusion?
|
|
23
22
|
// Explicitly avoid `$meta` and `$slice`
|
|
24
23
|
const key = keys[ki];
|
package/lib/model.js
CHANGED
|
@@ -4300,7 +4300,7 @@ function populate(model, docs, options, callback) {
|
|
|
4300
4300
|
select = select.replace(excludeIdRegGlobal, ' ');
|
|
4301
4301
|
} else {
|
|
4302
4302
|
// preserve original select conditions by copying
|
|
4303
|
-
select =
|
|
4303
|
+
select = { ...select };
|
|
4304
4304
|
delete select._id;
|
|
4305
4305
|
}
|
|
4306
4306
|
}
|
package/lib/mongoose.js
CHANGED
|
@@ -30,6 +30,7 @@ const sanitizeFilter = require('./helpers/query/sanitizeFilter');
|
|
|
30
30
|
const isBsonType = require('./helpers/isBsonType');
|
|
31
31
|
const MongooseError = require('./error/mongooseError');
|
|
32
32
|
const SetOptionError = require('./error/setOptionError');
|
|
33
|
+
const applyEmbeddedDiscriminators = require('./helpers/discriminator/applyEmbeddedDiscriminators');
|
|
33
34
|
|
|
34
35
|
const defaultMongooseSymbol = Symbol.for('mongoose:default');
|
|
35
36
|
|
|
@@ -627,6 +628,8 @@ Mongoose.prototype._model = function(name, schema, collection, options) {
|
|
|
627
628
|
}
|
|
628
629
|
}
|
|
629
630
|
|
|
631
|
+
applyEmbeddedDiscriminators(schema);
|
|
632
|
+
|
|
630
633
|
return model;
|
|
631
634
|
};
|
|
632
635
|
|
package/lib/query.js
CHANGED
|
@@ -4791,16 +4791,14 @@ Query.prototype._castFields = function _castFields(fields) {
|
|
|
4791
4791
|
elemMatchKeys,
|
|
4792
4792
|
keys,
|
|
4793
4793
|
key,
|
|
4794
|
-
out
|
|
4795
|
-
i;
|
|
4794
|
+
out;
|
|
4796
4795
|
|
|
4797
4796
|
if (fields) {
|
|
4798
4797
|
keys = Object.keys(fields);
|
|
4799
4798
|
elemMatchKeys = [];
|
|
4800
|
-
i = keys.length;
|
|
4801
4799
|
|
|
4802
4800
|
// collect $elemMatch args
|
|
4803
|
-
|
|
4801
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
4804
4802
|
key = keys[i];
|
|
4805
4803
|
if (fields[key].$elemMatch) {
|
|
4806
4804
|
selected || (selected = {});
|
|
@@ -4819,8 +4817,7 @@ Query.prototype._castFields = function _castFields(fields) {
|
|
|
4819
4817
|
}
|
|
4820
4818
|
|
|
4821
4819
|
// apply the casted field args
|
|
4822
|
-
i = elemMatchKeys.length;
|
|
4823
|
-
while (i--) {
|
|
4820
|
+
for (let i = 0; i < elemMatchKeys.length; ++i) {
|
|
4824
4821
|
key = elemMatchKeys[i];
|
|
4825
4822
|
fields[key] = out[key];
|
|
4826
4823
|
}
|
package/lib/queryHelpers.js
CHANGED
|
@@ -180,11 +180,12 @@ exports.applyPaths = function applyPaths(fields, schema) {
|
|
|
180
180
|
if (!isDefiningProjection(field)) {
|
|
181
181
|
continue;
|
|
182
182
|
}
|
|
183
|
-
// `_id: 1, name: 0` is a mixed inclusive/exclusive projection in
|
|
184
|
-
// MongoDB 4.0 and earlier, but not in later versions.
|
|
185
183
|
if (keys[keyIndex] === '_id' && keys.length > 1) {
|
|
186
184
|
continue;
|
|
187
185
|
}
|
|
186
|
+
if (keys[keyIndex] === schema.options.discriminatorKey && keys.length > 1 && field != null && !field) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
188
189
|
exclude = !field;
|
|
189
190
|
break;
|
|
190
191
|
}
|
package/lib/schema/bigint.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
const CastError = require('../error/cast');
|
|
8
8
|
const SchemaType = require('../schemaType');
|
|
9
9
|
const castBigInt = require('../cast/bigint');
|
|
10
|
-
const utils = require('../utils');
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* BigInt SchemaType constructor.
|
|
@@ -177,12 +176,13 @@ SchemaBigInt.prototype.cast = function(value) {
|
|
|
177
176
|
* ignore
|
|
178
177
|
*/
|
|
179
178
|
|
|
180
|
-
SchemaBigInt.$conditionalHandlers =
|
|
179
|
+
SchemaBigInt.$conditionalHandlers = {
|
|
180
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
181
181
|
$gt: handleSingle,
|
|
182
182
|
$gte: handleSingle,
|
|
183
183
|
$lt: handleSingle,
|
|
184
184
|
$lte: handleSingle
|
|
185
|
-
}
|
|
185
|
+
};
|
|
186
186
|
|
|
187
187
|
/*!
|
|
188
188
|
* ignore
|
package/lib/schema/boolean.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
const CastError = require('../error/cast');
|
|
8
8
|
const SchemaType = require('../schemaType');
|
|
9
9
|
const castBoolean = require('../cast/boolean');
|
|
10
|
-
const utils = require('../utils');
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Boolean SchemaType constructor.
|
|
@@ -235,8 +234,7 @@ SchemaBoolean.prototype.cast = function(value) {
|
|
|
235
234
|
}
|
|
236
235
|
};
|
|
237
236
|
|
|
238
|
-
SchemaBoolean.$conditionalHandlers =
|
|
239
|
-
utils.options(SchemaType.prototype.$conditionalHandlers, {});
|
|
237
|
+
SchemaBoolean.$conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers };
|
|
240
238
|
|
|
241
239
|
/**
|
|
242
240
|
* Casts contents for queries.
|
package/lib/schema/buffer.js
CHANGED
|
@@ -250,17 +250,17 @@ function handleSingle(val, context) {
|
|
|
250
250
|
return this.castForQuery(null, val, context);
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
SchemaBuffer.prototype.$conditionalHandlers =
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
253
|
+
SchemaBuffer.prototype.$conditionalHandlers = {
|
|
254
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
255
|
+
$bitsAllClear: handleBitwiseOperator,
|
|
256
|
+
$bitsAnyClear: handleBitwiseOperator,
|
|
257
|
+
$bitsAllSet: handleBitwiseOperator,
|
|
258
|
+
$bitsAnySet: handleBitwiseOperator,
|
|
259
|
+
$gt: handleSingle,
|
|
260
|
+
$gte: handleSingle,
|
|
261
|
+
$lt: handleSingle,
|
|
262
|
+
$lte: handleSingle
|
|
263
|
+
};
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
266
|
* Casts contents for queries.
|
package/lib/schema/date.js
CHANGED
|
@@ -388,13 +388,13 @@ function handleSingle(val) {
|
|
|
388
388
|
return this.cast(val);
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
SchemaDate.prototype.$conditionalHandlers =
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
391
|
+
SchemaDate.prototype.$conditionalHandlers = {
|
|
392
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
393
|
+
$gt: handleSingle,
|
|
394
|
+
$gte: handleSingle,
|
|
395
|
+
$lt: handleSingle,
|
|
396
|
+
$lte: handleSingle
|
|
397
|
+
};
|
|
398
398
|
|
|
399
399
|
|
|
400
400
|
/**
|
package/lib/schema/decimal128.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
const SchemaType = require('../schemaType');
|
|
8
8
|
const CastError = SchemaType.CastError;
|
|
9
9
|
const castDecimal128 = require('../cast/decimal128');
|
|
10
|
-
const utils = require('../utils');
|
|
11
10
|
const isBsonType = require('../helpers/isBsonType');
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -214,13 +213,13 @@ function handleSingle(val) {
|
|
|
214
213
|
return this.cast(val);
|
|
215
214
|
}
|
|
216
215
|
|
|
217
|
-
SchemaDecimal128.prototype.$conditionalHandlers =
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
216
|
+
SchemaDecimal128.prototype.$conditionalHandlers = {
|
|
217
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
218
|
+
$gt: handleSingle,
|
|
219
|
+
$gte: handleSingle,
|
|
220
|
+
$lt: handleSingle,
|
|
221
|
+
$lte: handleSingle
|
|
222
|
+
};
|
|
224
223
|
|
|
225
224
|
/*!
|
|
226
225
|
* Module exports.
|
|
@@ -88,12 +88,6 @@ function SchemaDocumentArray(key, schema, options, schemaOptions) {
|
|
|
88
88
|
|
|
89
89
|
this.$embeddedSchemaType.caster = this.Constructor;
|
|
90
90
|
this.$embeddedSchemaType.schema = this.schema;
|
|
91
|
-
|
|
92
|
-
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) {
|
|
93
|
-
for (const disc of schema._applyDiscriminators.keys()) {
|
|
94
|
-
this.discriminator(disc, schema._applyDiscriminators.get(disc));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
91
|
}
|
|
98
92
|
|
|
99
93
|
/**
|
|
@@ -528,7 +522,7 @@ SchemaDocumentArray.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
528
522
|
|
|
529
523
|
SchemaDocumentArray.prototype.clone = function() {
|
|
530
524
|
const options = Object.assign({}, this.options);
|
|
531
|
-
const schematype = new this.constructor(this.path, this.schema,
|
|
525
|
+
const schematype = new this.constructor(this.path, this.schema, options, this.schemaOptions);
|
|
532
526
|
schematype.validators = this.validators.slice();
|
|
533
527
|
if (this.requiredValidator !== undefined) {
|
|
534
528
|
schematype.requiredValidator = this.requiredValidator;
|
package/lib/schema/number.js
CHANGED
|
@@ -399,18 +399,18 @@ function handleArray(val) {
|
|
|
399
399
|
});
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
SchemaNumber.prototype.$conditionalHandlers =
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
402
|
+
SchemaNumber.prototype.$conditionalHandlers = {
|
|
403
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
404
|
+
$bitsAllClear: handleBitwiseOperator,
|
|
405
|
+
$bitsAnyClear: handleBitwiseOperator,
|
|
406
|
+
$bitsAllSet: handleBitwiseOperator,
|
|
407
|
+
$bitsAnySet: handleBitwiseOperator,
|
|
408
|
+
$gt: handleSingle,
|
|
409
|
+
$gte: handleSingle,
|
|
410
|
+
$lt: handleSingle,
|
|
411
|
+
$lte: handleSingle,
|
|
412
|
+
$mod: handleArray
|
|
413
|
+
};
|
|
414
414
|
|
|
415
415
|
/**
|
|
416
416
|
* Casts contents for queries.
|
package/lib/schema/objectId.js
CHANGED
|
@@ -259,13 +259,13 @@ function handleSingle(val) {
|
|
|
259
259
|
return this.cast(val);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
SchemaObjectId.prototype.$conditionalHandlers =
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
262
|
+
SchemaObjectId.prototype.$conditionalHandlers = {
|
|
263
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
264
|
+
$gt: handleSingle,
|
|
265
|
+
$gte: handleSingle,
|
|
266
|
+
$lt: handleSingle,
|
|
267
|
+
$lte: handleSingle
|
|
268
|
+
};
|
|
269
269
|
|
|
270
270
|
/*!
|
|
271
271
|
* ignore
|
package/lib/schema/string.js
CHANGED
|
@@ -641,7 +641,8 @@ function handleSingleNoSetters(val) {
|
|
|
641
641
|
return this.cast(val, this);
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
-
const $conditionalHandlers =
|
|
644
|
+
const $conditionalHandlers = {
|
|
645
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
645
646
|
$all: handleArray,
|
|
646
647
|
$gt: handleSingle,
|
|
647
648
|
$gte: handleSingle,
|
|
@@ -656,7 +657,7 @@ const $conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHand
|
|
|
656
657
|
return handleSingleNoSetters.call(this, val);
|
|
657
658
|
},
|
|
658
659
|
$not: handleSingle
|
|
659
|
-
}
|
|
660
|
+
};
|
|
660
661
|
|
|
661
662
|
Object.defineProperty(SchemaString.prototype, '$conditionalHandlers', {
|
|
662
663
|
configurable: false,
|
|
@@ -48,18 +48,13 @@ function SchemaSubdocument(schema, path, options) {
|
|
|
48
48
|
|
|
49
49
|
schema = handleIdOption(schema, options);
|
|
50
50
|
|
|
51
|
-
this.caster = _createConstructor(schema);
|
|
51
|
+
this.caster = _createConstructor(schema, null, options);
|
|
52
52
|
this.caster.path = path;
|
|
53
53
|
this.caster.prototype.$basePath = path;
|
|
54
54
|
this.schema = schema;
|
|
55
55
|
this.$isSingleNested = true;
|
|
56
56
|
this.base = schema.base;
|
|
57
57
|
SchemaType.call(this, path, options, 'Embedded');
|
|
58
|
-
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) {
|
|
59
|
-
for (const disc of schema._applyDiscriminators.keys()) {
|
|
60
|
-
this.discriminator(disc, schema._applyDiscriminators.get(disc));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
58
|
}
|
|
64
59
|
|
|
65
60
|
/*!
|
|
@@ -74,7 +69,7 @@ SchemaSubdocument.prototype.OptionsConstructor = SchemaSubdocumentOptions;
|
|
|
74
69
|
* ignore
|
|
75
70
|
*/
|
|
76
71
|
|
|
77
|
-
function _createConstructor(schema, baseClass) {
|
|
72
|
+
function _createConstructor(schema, baseClass, options) {
|
|
78
73
|
// lazy load
|
|
79
74
|
SubdocumentType || (SubdocumentType = require('../types/subdocument'));
|
|
80
75
|
|
|
@@ -94,6 +89,7 @@ function _createConstructor(schema, baseClass) {
|
|
|
94
89
|
_embedded.prototype = Object.create(proto);
|
|
95
90
|
_embedded.prototype.$__setSchema(schema);
|
|
96
91
|
_embedded.prototype.constructor = _embedded;
|
|
92
|
+
_embedded.$__required = options?.required;
|
|
97
93
|
_embedded.base = schema.base;
|
|
98
94
|
_embedded.schema = schema;
|
|
99
95
|
_embedded.$isSingleNested = true;
|
package/lib/schema/uuid.js
CHANGED
|
@@ -313,8 +313,8 @@ function handleArray(val) {
|
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
-
SchemaUUID.prototype.$conditionalHandlers =
|
|
317
|
-
|
|
316
|
+
SchemaUUID.prototype.$conditionalHandlers = {
|
|
317
|
+
...SchemaType.prototype.$conditionalHandlers,
|
|
318
318
|
$bitsAllClear: handleBitwiseOperator,
|
|
319
319
|
$bitsAnyClear: handleBitwiseOperator,
|
|
320
320
|
$bitsAllSet: handleBitwiseOperator,
|
|
@@ -327,7 +327,7 @@ utils.options(SchemaType.prototype.$conditionalHandlers, {
|
|
|
327
327
|
$lte: handleSingle,
|
|
328
328
|
$ne: handleSingle,
|
|
329
329
|
$nin: handleArray
|
|
330
|
-
}
|
|
330
|
+
};
|
|
331
331
|
|
|
332
332
|
/**
|
|
333
333
|
* Casts contents for queries.
|
package/lib/schema.js
CHANGED
|
@@ -560,7 +560,7 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
560
560
|
const strict = 'strict' in baseOptions ? baseOptions.strict : true;
|
|
561
561
|
const strictQuery = 'strictQuery' in baseOptions ? baseOptions.strictQuery : false;
|
|
562
562
|
const id = 'id' in baseOptions ? baseOptions.id : true;
|
|
563
|
-
options =
|
|
563
|
+
options = {
|
|
564
564
|
strict,
|
|
565
565
|
strictQuery,
|
|
566
566
|
bufferCommands: true,
|
|
@@ -577,8 +577,9 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
577
577
|
// the following are only applied at construction time
|
|
578
578
|
_id: true,
|
|
579
579
|
id: id,
|
|
580
|
-
typeKey: 'type'
|
|
581
|
-
|
|
580
|
+
typeKey: 'type',
|
|
581
|
+
...options
|
|
582
|
+
};
|
|
582
583
|
|
|
583
584
|
if (options.versionKey && typeof options.versionKey !== 'string') {
|
|
584
585
|
throw new MongooseError('`versionKey` must be falsy or string, got `' + (typeof options.versionKey) + '`');
|
|
@@ -1122,15 +1123,14 @@ Schema.prototype.path = function(path, obj) {
|
|
|
1122
1123
|
if (_schemaType.$isMongooseDocumentArray) {
|
|
1123
1124
|
_schemaType.$embeddedSchemaType._arrayPath = arrayPath;
|
|
1124
1125
|
_schemaType.$embeddedSchemaType._arrayParentPath = path;
|
|
1125
|
-
_schemaType = _schemaType.$embeddedSchemaType
|
|
1126
|
+
_schemaType = _schemaType.$embeddedSchemaType;
|
|
1126
1127
|
} else {
|
|
1127
1128
|
_schemaType.caster._arrayPath = arrayPath;
|
|
1128
1129
|
_schemaType.caster._arrayParentPath = path;
|
|
1129
|
-
_schemaType = _schemaType.caster
|
|
1130
|
+
_schemaType = _schemaType.caster;
|
|
1130
1131
|
}
|
|
1131
1132
|
|
|
1132
|
-
|
|
1133
|
-
toAdd.push(_schemaType);
|
|
1133
|
+
this.subpaths[arrayPath] = _schemaType;
|
|
1134
1134
|
}
|
|
1135
1135
|
|
|
1136
1136
|
for (const _schemaType of toAdd) {
|
package/lib/utils.js
CHANGED
|
@@ -227,33 +227,6 @@ exports.omit = function omit(obj, keys) {
|
|
|
227
227
|
return ret;
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Shallow copies defaults into options.
|
|
233
|
-
*
|
|
234
|
-
* @param {Object} defaults
|
|
235
|
-
* @param {Object} [options]
|
|
236
|
-
* @return {Object} the merged object
|
|
237
|
-
* @api private
|
|
238
|
-
*/
|
|
239
|
-
|
|
240
|
-
exports.options = function(defaults, options) {
|
|
241
|
-
const keys = Object.keys(defaults);
|
|
242
|
-
let i = keys.length;
|
|
243
|
-
let k;
|
|
244
|
-
|
|
245
|
-
options = options || {};
|
|
246
|
-
|
|
247
|
-
while (i--) {
|
|
248
|
-
k = keys[i];
|
|
249
|
-
if (!(k in options)) {
|
|
250
|
-
options[k] = defaults[k];
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return options;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
230
|
/**
|
|
258
231
|
* Merges `from` into `to` without overwriting existing properties.
|
|
259
232
|
*
|
|
@@ -687,12 +660,6 @@ exports.object.vals = function vals(o) {
|
|
|
687
660
|
return ret;
|
|
688
661
|
};
|
|
689
662
|
|
|
690
|
-
/**
|
|
691
|
-
* @see exports.options
|
|
692
|
-
*/
|
|
693
|
-
|
|
694
|
-
exports.object.shallowCopy = exports.options;
|
|
695
|
-
|
|
696
663
|
const hop = Object.prototype.hasOwnProperty;
|
|
697
664
|
|
|
698
665
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "8.0.
|
|
4
|
+
"version": "8.0.3",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"sift": "16.0.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "7.23.
|
|
32
|
-
"@babel/preset-env": "7.
|
|
31
|
+
"@babel/core": "7.23.5",
|
|
32
|
+
"@babel/preset-env": "7.23.5",
|
|
33
33
|
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
34
34
|
"@typescript-eslint/parser": "^6.2.1",
|
|
35
35
|
"acquit": "1.3.0",
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
"crypto-browserify": "3.12.0",
|
|
46
46
|
"dotenv": "16.3.1",
|
|
47
47
|
"dox": "1.0.0",
|
|
48
|
-
"eslint": "8.
|
|
48
|
+
"eslint": "8.55.0",
|
|
49
49
|
"eslint-plugin-markdown": "^3.0.1",
|
|
50
50
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
51
51
|
"express": "^4.18.1",
|
|
52
|
-
"fs-extra": "~11.
|
|
52
|
+
"fs-extra": "~11.2.0",
|
|
53
53
|
"highlight.js": "11.8.0",
|
|
54
54
|
"lodash.isequal": "4.5.0",
|
|
55
55
|
"lodash.isequalwith": "4.4.0",
|
|
56
|
-
"markdownlint-cli2": "^0.
|
|
56
|
+
"markdownlint-cli2": "^0.11.0",
|
|
57
57
|
"marked": "4.3.0",
|
|
58
58
|
"mkdirp": "^3.0.1",
|
|
59
59
|
"mocha": "10.2.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"sinon": "17.0.1",
|
|
67
67
|
"stream-browserify": "3.0.0",
|
|
68
68
|
"tsd": "0.29.0",
|
|
69
|
-
"typescript": "5.
|
|
69
|
+
"typescript": "5.3.2",
|
|
70
70
|
"uuid": "9.0.1",
|
|
71
71
|
"webpack": "5.89.0"
|
|
72
72
|
},
|
|
@@ -262,15 +262,16 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
|
|
|
262
262
|
IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
|
|
263
263
|
IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
|
|
264
264
|
IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
|
|
265
|
-
PathValueType
|
|
266
|
-
PathValueType extends '
|
|
267
|
-
|
|
268
|
-
PathValueType extends
|
|
269
|
-
|
|
270
|
-
PathValueType extends
|
|
271
|
-
PathValueType extends
|
|
272
|
-
|
|
273
|
-
IfEquals<PathValueType,
|
|
274
|
-
PathValueType extends
|
|
275
|
-
PathValueType extends
|
|
276
|
-
|
|
265
|
+
IfEquals<PathValueType, BigInt> extends true ? bigint :
|
|
266
|
+
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
|
|
267
|
+
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
|
|
268
|
+
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
|
|
269
|
+
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
|
|
270
|
+
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
|
|
271
|
+
PathValueType extends ArrayConstructor ? any[] :
|
|
272
|
+
PathValueType extends typeof Schema.Types.Mixed ? any:
|
|
273
|
+
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
|
|
274
|
+
IfEquals<PathValueType, {}> extends true ? any:
|
|
275
|
+
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
|
|
276
|
+
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
|
|
277
|
+
unknown;
|
package/types/models.d.ts
CHANGED
|
@@ -183,6 +183,10 @@ declare module 'mongoose' {
|
|
|
183
183
|
/* Cast the given POJO to the model's schema */
|
|
184
184
|
castObject(obj: AnyObject, options?: { ignoreCastErrors?: boolean }): TRawDocType;
|
|
185
185
|
|
|
186
|
+
/* Apply defaults to the given document or POJO. */
|
|
187
|
+
applyDefaults(obj: AnyObject): AnyObject;
|
|
188
|
+
applyDefaults(obj: TRawDocType): TRawDocType;
|
|
189
|
+
|
|
186
190
|
/**
|
|
187
191
|
* Sends multiple `insertOne`, `updateOne`, `updateMany`, `replaceOne`,
|
|
188
192
|
* `deleteOne`, and/or `deleteMany` operations to the MongoDB server in one
|
|
@@ -395,6 +399,10 @@ declare module 'mongoose' {
|
|
|
395
399
|
docs: Array<TRawDocType>,
|
|
396
400
|
options: InsertManyOptions & { rawResult: true; }
|
|
397
401
|
): Promise<mongodb.InsertManyResult<Require_id<THydratedDocumentType>>>;
|
|
402
|
+
insertMany(
|
|
403
|
+
doc: Array<TRawDocType>,
|
|
404
|
+
options: InsertManyOptions
|
|
405
|
+
): Promise<Array<THydratedDocumentType>>;
|
|
398
406
|
insertMany<DocContents = TRawDocType>(
|
|
399
407
|
docs: Array<DocContents | TRawDocType>,
|
|
400
408
|
options: InsertManyOptions & { lean: true; }
|
|
@@ -608,11 +616,11 @@ declare module 'mongoose' {
|
|
|
608
616
|
'findOneAndDelete'
|
|
609
617
|
>;
|
|
610
618
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
611
|
-
filter
|
|
612
|
-
options
|
|
619
|
+
filter: FilterQuery<TRawDocType>,
|
|
620
|
+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
613
621
|
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
614
622
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
615
|
-
filter?: FilterQuery<TRawDocType
|
|
623
|
+
filter?: FilterQuery<TRawDocType> | null,
|
|
616
624
|
options?: QueryOptions<TRawDocType> | null
|
|
617
625
|
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
|
|
618
626
|
|