mongoose 8.20.2 → 8.20.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/aggregate.js +1 -1
- package/lib/cast.js +1 -1
- package/lib/connection.js +9 -9
- package/lib/document.js +26 -17
- package/lib/drivers/node-mongodb-native/connection.js +2 -2
- package/lib/error/objectParameter.js +1 -1
- package/lib/helpers/common.js +1 -1
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/model/applyMethods.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +1 -1
- package/lib/helpers/populate/getModelsMapForPopulate.js +3 -3
- package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
- package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
- package/lib/helpers/projection/applyProjection.js +2 -2
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +2 -2
- package/lib/helpers/timestamps/setupTimestamps.js +1 -1
- package/lib/helpers/update/applyTimestampsToUpdate.js +1 -1
- package/lib/helpers/update/decorateUpdateWithVersionKey.js +1 -1
- package/lib/model.js +7 -7
- package/lib/mongoose.js +3 -4
- package/lib/query.js +3 -3
- package/lib/schema/array.js +1 -1
- package/lib/schema.js +21 -21
- package/lib/schemaType.js +8 -8
- package/lib/types/array/index.js +5 -5
- package/lib/types/documentArray/index.js +6 -6
- package/lib/types/objectid.js +1 -1
- package/lib/utils.js +1 -15
- package/lib/virtualType.js +1 -1
- package/package.json +2 -1
- package/types/index.d.ts +1 -2
- package/types/inferrawdoctype.d.ts +1 -1
- package/types/inferschematype.d.ts +16 -23
- package/types/virtuals.d.ts +3 -3
package/lib/schema.js
CHANGED
|
@@ -1441,17 +1441,17 @@ Schema.prototype._gatherChildSchemas = function _gatherChildSchemas() {
|
|
|
1441
1441
|
*/
|
|
1442
1442
|
|
|
1443
1443
|
function _getPath(schema, path, cleanPath) {
|
|
1444
|
-
if (schema.paths
|
|
1444
|
+
if (Object.hasOwn(schema.paths, path)) {
|
|
1445
1445
|
return schema.paths[path];
|
|
1446
1446
|
}
|
|
1447
|
-
if (schema.subpaths
|
|
1447
|
+
if (Object.hasOwn(schema.subpaths, cleanPath)) {
|
|
1448
1448
|
const subpath = schema.subpaths[cleanPath];
|
|
1449
1449
|
if (subpath === 'nested') {
|
|
1450
1450
|
return undefined;
|
|
1451
1451
|
}
|
|
1452
1452
|
return subpath;
|
|
1453
1453
|
}
|
|
1454
|
-
if (schema.singleNestedPaths
|
|
1454
|
+
if (Object.hasOwn(schema.singleNestedPaths, cleanPath) && typeof schema.singleNestedPaths[cleanPath] === 'object') {
|
|
1455
1455
|
const singleNestedPath = schema.singleNestedPaths[cleanPath];
|
|
1456
1456
|
if (singleNestedPath === 'nested') {
|
|
1457
1457
|
return undefined;
|
|
@@ -1639,20 +1639,20 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1639
1639
|
childSchemaOptions.typeKey = options.typeKey;
|
|
1640
1640
|
}
|
|
1641
1641
|
// propagate 'strict' option to child schema
|
|
1642
|
-
if (
|
|
1642
|
+
if (Object.hasOwn(options, 'strict')) {
|
|
1643
1643
|
childSchemaOptions.strict = options.strict;
|
|
1644
1644
|
}
|
|
1645
|
-
if (
|
|
1645
|
+
if (Object.hasOwn(options, 'strictQuery')) {
|
|
1646
1646
|
childSchemaOptions.strictQuery = options.strictQuery;
|
|
1647
1647
|
}
|
|
1648
|
-
if (
|
|
1648
|
+
if (Object.hasOwn(options, 'toObject')) {
|
|
1649
1649
|
childSchemaOptions.toObject = utils.omit(options.toObject, ['transform']);
|
|
1650
1650
|
}
|
|
1651
|
-
if (
|
|
1651
|
+
if (Object.hasOwn(options, 'toJSON')) {
|
|
1652
1652
|
childSchemaOptions.toJSON = utils.omit(options.toJSON, ['transform']);
|
|
1653
1653
|
}
|
|
1654
1654
|
|
|
1655
|
-
if (this._userProvidedOptions
|
|
1655
|
+
if (Object.hasOwn(this._userProvidedOptions, '_id')) {
|
|
1656
1656
|
childSchemaOptions._id = this._userProvidedOptions._id;
|
|
1657
1657
|
} else if (Schema.Types.DocumentArray.defaultOptions._id != null) {
|
|
1658
1658
|
childSchemaOptions._id = Schema.Types.DocumentArray.defaultOptions._id;
|
|
@@ -1689,7 +1689,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1689
1689
|
`Could not determine the embedded type for array \`${path}\`. ` +
|
|
1690
1690
|
'See https://mongoosejs.com/docs/guide.html#definition for more info on supported schema syntaxes.');
|
|
1691
1691
|
}
|
|
1692
|
-
if (!
|
|
1692
|
+
if (!Object.hasOwn(MongooseTypes, name)) {
|
|
1693
1693
|
throw new TypeError('Invalid schema configuration: ' +
|
|
1694
1694
|
`\`${name}\` is not a valid type within the array \`${path}\`.` +
|
|
1695
1695
|
'See https://bit.ly/mongoose-schematypes for a list of valid schema types.');
|
|
@@ -1850,24 +1850,24 @@ Schema.prototype.indexedPaths = function indexedPaths() {
|
|
|
1850
1850
|
*/
|
|
1851
1851
|
|
|
1852
1852
|
Schema.prototype.pathType = function(path) {
|
|
1853
|
-
if (this.paths
|
|
1853
|
+
if (Object.hasOwn(this.paths, path)) {
|
|
1854
1854
|
return 'real';
|
|
1855
1855
|
}
|
|
1856
|
-
if (this.virtuals
|
|
1856
|
+
if (Object.hasOwn(this.virtuals, path)) {
|
|
1857
1857
|
return 'virtual';
|
|
1858
1858
|
}
|
|
1859
|
-
if (this.nested
|
|
1859
|
+
if (Object.hasOwn(this.nested, path)) {
|
|
1860
1860
|
return 'nested';
|
|
1861
1861
|
}
|
|
1862
1862
|
|
|
1863
1863
|
// Convert to '.$' to check subpaths re: gh-6405
|
|
1864
1864
|
const cleanPath = _pathToPositionalSyntax(path);
|
|
1865
1865
|
|
|
1866
|
-
if (this.subpaths
|
|
1866
|
+
if (Object.hasOwn(this.subpaths, cleanPath) || Object.hasOwn(this.subpaths, path)) {
|
|
1867
1867
|
return 'real';
|
|
1868
1868
|
}
|
|
1869
1869
|
|
|
1870
|
-
const singleNestedPath = this.singleNestedPaths
|
|
1870
|
+
const singleNestedPath = Object.hasOwn(this.singleNestedPaths, cleanPath) || Object.hasOwn(this.singleNestedPaths, path);
|
|
1871
1871
|
if (singleNestedPath) {
|
|
1872
1872
|
return singleNestedPath === 'nested' ? 'nested' : 'real';
|
|
1873
1873
|
}
|
|
@@ -1897,7 +1897,7 @@ Schema.prototype.hasMixedParent = function(path) {
|
|
|
1897
1897
|
path = '';
|
|
1898
1898
|
for (let i = 0; i < subpaths.length; ++i) {
|
|
1899
1899
|
path = i > 0 ? path + '.' + subpaths[i] : subpaths[i];
|
|
1900
|
-
if (this.paths
|
|
1900
|
+
if (Object.hasOwn(this.paths, path) &&
|
|
1901
1901
|
this.paths[path] instanceof MongooseTypes.Mixed) {
|
|
1902
1902
|
return this.paths[path];
|
|
1903
1903
|
}
|
|
@@ -1926,7 +1926,7 @@ Schema.prototype.setupTimestamp = function(timestamps) {
|
|
|
1926
1926
|
function getPositionalPathType(self, path, cleanPath) {
|
|
1927
1927
|
const subpaths = path.split(/\.(\d+)\.|\.(\d+)$/).filter(Boolean);
|
|
1928
1928
|
if (subpaths.length < 2) {
|
|
1929
|
-
return self.paths
|
|
1929
|
+
return Object.hasOwn(self.paths, subpaths[0]) ?
|
|
1930
1930
|
self.paths[subpaths[0]] :
|
|
1931
1931
|
'adhocOrUndefined';
|
|
1932
1932
|
}
|
|
@@ -2633,7 +2633,7 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2633
2633
|
*/
|
|
2634
2634
|
|
|
2635
2635
|
Schema.prototype.virtualpath = function(name) {
|
|
2636
|
-
return this.virtuals
|
|
2636
|
+
return Object.hasOwn(this.virtuals, name) ? this.virtuals[name] : null;
|
|
2637
2637
|
};
|
|
2638
2638
|
|
|
2639
2639
|
/**
|
|
@@ -2781,8 +2781,8 @@ Schema.prototype.loadClass = function(model, virtualsOnly) {
|
|
|
2781
2781
|
// Stop copying when hit certain base classes
|
|
2782
2782
|
if (model === Object.prototype ||
|
|
2783
2783
|
model === Function.prototype ||
|
|
2784
|
-
model.prototype
|
|
2785
|
-
model.prototype
|
|
2784
|
+
Object.hasOwn(model.prototype, '$isMongooseModelPrototype') ||
|
|
2785
|
+
Object.hasOwn(model.prototype, '$isMongooseDocumentPrototype')) {
|
|
2786
2786
|
return this;
|
|
2787
2787
|
}
|
|
2788
2788
|
|
|
@@ -2795,7 +2795,7 @@ Schema.prototype.loadClass = function(model, virtualsOnly) {
|
|
|
2795
2795
|
return;
|
|
2796
2796
|
}
|
|
2797
2797
|
const prop = Object.getOwnPropertyDescriptor(model, name);
|
|
2798
|
-
if (
|
|
2798
|
+
if (Object.hasOwn(prop, 'value')) {
|
|
2799
2799
|
this.static(name, prop.value);
|
|
2800
2800
|
}
|
|
2801
2801
|
}, this);
|
|
@@ -3021,7 +3021,7 @@ Schema.prototype._transformDuplicateKeyError = function _transformDuplicateKeyEr
|
|
|
3021
3021
|
return error;
|
|
3022
3022
|
}
|
|
3023
3023
|
const firstKey = keys[0];
|
|
3024
|
-
if (!this._duplicateKeyErrorMessagesByPath
|
|
3024
|
+
if (!Object.hasOwn(this._duplicateKeyErrorMessagesByPath, firstKey)) {
|
|
3025
3025
|
return error;
|
|
3026
3026
|
}
|
|
3027
3027
|
return new MongooseError(this._duplicateKeyErrorMessagesByPath[firstKey], { cause: error });
|
package/lib/schemaType.js
CHANGED
|
@@ -47,10 +47,10 @@ function SchemaType(path, options, instance, parentSchema) {
|
|
|
47
47
|
this.instance = instance;
|
|
48
48
|
this.schemaName = this.constructor.schemaName;
|
|
49
49
|
this.validators = [];
|
|
50
|
-
this.getters = this.constructor
|
|
50
|
+
this.getters = Object.hasOwn(this.constructor, 'getters') ?
|
|
51
51
|
this.constructor.getters.slice() :
|
|
52
52
|
[];
|
|
53
|
-
this.setters = this.constructor
|
|
53
|
+
this.setters = Object.hasOwn(this.constructor, 'setters') ?
|
|
54
54
|
this.constructor.setters.slice() :
|
|
55
55
|
[];
|
|
56
56
|
|
|
@@ -63,7 +63,7 @@ function SchemaType(path, options, instance, parentSchema) {
|
|
|
63
63
|
for (const option of defaultOptionsKeys) {
|
|
64
64
|
if (option === 'validate') {
|
|
65
65
|
this.validate(defaultOptions.validate);
|
|
66
|
-
} else if (
|
|
66
|
+
} else if (Object.hasOwn(defaultOptions, option) && !Object.hasOwn(options, option)) {
|
|
67
67
|
options[option] = defaultOptions[option];
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -340,7 +340,7 @@ SchemaType.prototype.cast = function cast() {
|
|
|
340
340
|
*/
|
|
341
341
|
|
|
342
342
|
SchemaType.set = function set(option, value) {
|
|
343
|
-
if (!
|
|
343
|
+
if (!Object.hasOwn(this, 'defaultOptions')) {
|
|
344
344
|
this.defaultOptions = Object.assign({}, this.defaultOptions);
|
|
345
345
|
}
|
|
346
346
|
this.defaultOptions[option] = value;
|
|
@@ -363,7 +363,7 @@ SchemaType.set = function set(option, value) {
|
|
|
363
363
|
*/
|
|
364
364
|
|
|
365
365
|
SchemaType.get = function(getter) {
|
|
366
|
-
this.getters =
|
|
366
|
+
this.getters = Object.hasOwn(this, 'getters') ? this.getters : [];
|
|
367
367
|
this.getters.push(getter);
|
|
368
368
|
};
|
|
369
369
|
|
|
@@ -504,7 +504,7 @@ SchemaType.prototype.unique = function unique(value, message) {
|
|
|
504
504
|
'false and `unique` set to true');
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
if (!this.options
|
|
507
|
+
if (!Object.hasOwn(this.options, 'index') && value === false) {
|
|
508
508
|
return this;
|
|
509
509
|
}
|
|
510
510
|
|
|
@@ -543,7 +543,7 @@ SchemaType.prototype.text = function(bool) {
|
|
|
543
543
|
'false and `text` set to true');
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
-
if (!this.options
|
|
546
|
+
if (!Object.hasOwn(this.options, 'index') && bool === false) {
|
|
547
547
|
return this;
|
|
548
548
|
}
|
|
549
549
|
|
|
@@ -580,7 +580,7 @@ SchemaType.prototype.sparse = function(bool) {
|
|
|
580
580
|
'false and `sparse` set to true');
|
|
581
581
|
}
|
|
582
582
|
|
|
583
|
-
if (!this.options
|
|
583
|
+
if (!Object.hasOwn(this.options, 'index') && bool === false) {
|
|
584
584
|
return this;
|
|
585
585
|
}
|
|
586
586
|
|
package/lib/types/array/index.js
CHANGED
|
@@ -79,13 +79,13 @@ function MongooseArray(values, path, doc, schematype) {
|
|
|
79
79
|
|
|
80
80
|
const proxy = new Proxy(__array, {
|
|
81
81
|
get: function(target, prop) {
|
|
82
|
-
if (
|
|
82
|
+
if (Object.hasOwn(internals, prop)) {
|
|
83
83
|
return internals[prop];
|
|
84
84
|
}
|
|
85
|
-
if (
|
|
85
|
+
if (Object.hasOwn(mongooseArrayMethods, prop)) {
|
|
86
86
|
return mongooseArrayMethods[prop];
|
|
87
87
|
}
|
|
88
|
-
if (schematype && schematype.virtuals && schematype.virtuals
|
|
88
|
+
if (schematype && schematype.virtuals && Object.hasOwn(schematype.virtuals, prop)) {
|
|
89
89
|
return schematype.virtuals[prop].applyGetters(undefined, target);
|
|
90
90
|
}
|
|
91
91
|
if (typeof prop === 'string' && numberRE.test(prop) && schematype?.$embeddedSchemaType != null) {
|
|
@@ -97,9 +97,9 @@ function MongooseArray(values, path, doc, schematype) {
|
|
|
97
97
|
set: function(target, prop, value) {
|
|
98
98
|
if (typeof prop === 'string' && numberRE.test(prop)) {
|
|
99
99
|
mongooseArrayMethods.set.call(proxy, prop, value, false);
|
|
100
|
-
} else if (
|
|
100
|
+
} else if (Object.hasOwn(internals, prop)) {
|
|
101
101
|
internals[prop] = value;
|
|
102
|
-
} else if (schematype && schematype.virtuals
|
|
102
|
+
} else if (schematype?.virtuals && Object.hasOwn(schematype.virtuals, prop)) {
|
|
103
103
|
schematype.virtuals[prop].applySetters(value, target);
|
|
104
104
|
} else {
|
|
105
105
|
__array[prop] = value;
|
|
@@ -73,16 +73,16 @@ function MongooseDocumentArray(values, path, doc, schematype) {
|
|
|
73
73
|
prop === 'isMongooseDocumentArrayProxy') {
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
76
|
-
if (
|
|
76
|
+
if (Object.hasOwn(internals, prop)) {
|
|
77
77
|
return internals[prop];
|
|
78
78
|
}
|
|
79
|
-
if (
|
|
79
|
+
if (Object.hasOwn(DocumentArrayMethods, prop)) {
|
|
80
80
|
return DocumentArrayMethods[prop];
|
|
81
81
|
}
|
|
82
|
-
if (schematype && schematype.virtuals && schematype.virtuals
|
|
82
|
+
if (schematype && schematype.virtuals && Object.hasOwn(schematype.virtuals, prop)) {
|
|
83
83
|
return schematype.virtuals[prop].applyGetters(undefined, target);
|
|
84
84
|
}
|
|
85
|
-
if (
|
|
85
|
+
if (Object.hasOwn(ArrayMethods, prop)) {
|
|
86
86
|
return ArrayMethods[prop];
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -91,9 +91,9 @@ function MongooseDocumentArray(values, path, doc, schematype) {
|
|
|
91
91
|
set: function(target, prop, value) {
|
|
92
92
|
if (typeof prop === 'string' && numberRE.test(prop)) {
|
|
93
93
|
DocumentArrayMethods.set.call(proxy, prop, value, false);
|
|
94
|
-
} else if (
|
|
94
|
+
} else if (Object.hasOwn(internals, prop)) {
|
|
95
95
|
internals[prop] = value;
|
|
96
|
-
} else if (schematype && schematype.virtuals
|
|
96
|
+
} else if (schematype?.virtuals && Object.hasOwn(schematype.virtuals, prop)) {
|
|
97
97
|
schematype.virtuals[prop].applySetters(value, target);
|
|
98
98
|
} else {
|
|
99
99
|
__array[prop] = value;
|
package/lib/types/objectid.js
CHANGED
|
@@ -30,7 +30,7 @@ Object.defineProperty(ObjectId.prototype, '_id', {
|
|
|
30
30
|
* Convenience `valueOf()` to allow comparing ObjectIds using double equals re: gh-7299
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
if (!ObjectId.prototype
|
|
33
|
+
if (!Object.hasOwn(ObjectId.prototype, 'valueOf')) {
|
|
34
34
|
ObjectId.prototype.valueOf = function objectIdValueOf() {
|
|
35
35
|
return this.toString();
|
|
36
36
|
};
|
package/lib/utils.js
CHANGED
|
@@ -708,18 +708,6 @@ exports.object.vals = function vals(o) {
|
|
|
708
708
|
return ret;
|
|
709
709
|
};
|
|
710
710
|
|
|
711
|
-
const hop = Object.prototype.hasOwnProperty;
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Safer helper for hasOwnProperty checks
|
|
715
|
-
*
|
|
716
|
-
* @param {Object} obj
|
|
717
|
-
* @param {String} prop
|
|
718
|
-
*/
|
|
719
|
-
|
|
720
|
-
exports.object.hasOwnProperty = function(obj, prop) {
|
|
721
|
-
return hop.call(obj, prop);
|
|
722
|
-
};
|
|
723
711
|
|
|
724
712
|
/**
|
|
725
713
|
* Determine if `val` is null or undefined
|
|
@@ -770,8 +758,6 @@ exports.array.flatten = function flatten(arr, filter, ret) {
|
|
|
770
758
|
* ignore
|
|
771
759
|
*/
|
|
772
760
|
|
|
773
|
-
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
774
|
-
|
|
775
761
|
exports.hasUserDefinedProperty = function(obj, key) {
|
|
776
762
|
if (obj == null) {
|
|
777
763
|
return false;
|
|
@@ -786,7 +772,7 @@ exports.hasUserDefinedProperty = function(obj, key) {
|
|
|
786
772
|
return false;
|
|
787
773
|
}
|
|
788
774
|
|
|
789
|
-
if (
|
|
775
|
+
if (Object.hasOwn(obj, key)) {
|
|
790
776
|
return true;
|
|
791
777
|
}
|
|
792
778
|
if (typeof obj === 'object' && key in obj) {
|
package/lib/virtualType.js
CHANGED
|
@@ -143,7 +143,7 @@ VirtualType.prototype.set = function(fn) {
|
|
|
143
143
|
VirtualType.prototype.applyGetters = function(value, doc) {
|
|
144
144
|
if (utils.hasUserDefinedProperty(this.options, ['ref', 'refPath']) &&
|
|
145
145
|
doc.$$populatedVirtuals &&
|
|
146
|
-
doc.$$populatedVirtuals
|
|
146
|
+
Object.hasOwn(doc.$$populatedVirtuals, this.path)) {
|
|
147
147
|
value = doc.$$populatedVirtuals[this.path];
|
|
148
148
|
}
|
|
149
149
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "8.20.
|
|
4
|
+
"version": "8.20.3",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
"tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
|
|
115
115
|
"test-coverage": "nyc --reporter=html --reporter=text npm test",
|
|
116
116
|
"ts-benchmark": "cd ./benchmarks/typescript/simple && npm install && npm run benchmark | node ../../../scripts/tsc-diagnostics-check",
|
|
117
|
+
"ts-benchmark:local": "node ./scripts/create-tarball && cd ./benchmarks/typescript/simple && rm -rf ./node_modules && npm install && npm run benchmark | node ../../../scripts/tsc-diagnostics-check",
|
|
117
118
|
"attest-benchmark": "node ./benchmarks/typescript/infer.bench.mts"
|
|
118
119
|
},
|
|
119
120
|
"main": "./index.js",
|
package/types/index.d.ts
CHANGED
|
@@ -542,8 +542,7 @@ declare module 'mongoose' {
|
|
|
542
542
|
|
|
543
543
|
/** Adds static "class" methods to Models compiled from this schema. */
|
|
544
544
|
static<K extends keyof TStaticMethods>(name: K, fn: TStaticMethods[K]): this;
|
|
545
|
-
static(obj: { [
|
|
546
|
-
static(obj: { [F in keyof TStaticMethods]: TStaticMethods[F] } & { [name: string]: (this: TModelType, ...args: any[]) => any }): this;
|
|
545
|
+
static(obj: Partial<TStaticMethods> & { [name: string]: (this: TModelType, ...args: any[]) => any }): this;
|
|
547
546
|
static(name: string, fn: (this: TModelType, ...args: any[]) => any): this;
|
|
548
547
|
|
|
549
548
|
/** Object of currently defined statics on this schema. */
|
|
@@ -97,7 +97,7 @@ declare module 'mongoose' {
|
|
|
97
97
|
ResolveRawPathType<Options['of'] extends ReadonlyArray<infer Item> ? Item : never>
|
|
98
98
|
: PathValueType extends ArrayConstructor ? any[]
|
|
99
99
|
: PathValueType extends typeof Schema.Types.Mixed ? any
|
|
100
|
-
:
|
|
100
|
+
: PathValueType extends ObjectConstructor ? any
|
|
101
101
|
: IfEquals<PathValueType, {}> extends true ? any
|
|
102
102
|
: PathValueType extends typeof SchemaType ? PathValueType['prototype']
|
|
103
103
|
: PathValueType extends Record<string, any> ? InferRawDocType<PathValueType>
|
|
@@ -127,11 +127,6 @@ declare module 'mongoose' {
|
|
|
127
127
|
: T;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
type IsPathDefaultUndefined<PathType> =
|
|
131
|
-
PathType extends { default: undefined } ? true
|
|
132
|
-
: PathType extends { default: (...args: any[]) => undefined } ? true
|
|
133
|
-
: false;
|
|
134
|
-
|
|
135
130
|
type RequiredPropertyDefinition =
|
|
136
131
|
| {
|
|
137
132
|
required: true | string | [true, string | undefined] | { isRequired: true };
|
|
@@ -150,16 +145,17 @@ type IsPathRequired<P, TypeKey extends string = DefaultTypeKey> =
|
|
|
150
145
|
P extends { required: false } ?
|
|
151
146
|
false
|
|
152
147
|
: true
|
|
153
|
-
: P extends
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
: true
|
|
157
|
-
: P extends Record<TypeKey, any> ?
|
|
158
|
-
P extends { default: any } ?
|
|
159
|
-
IfEquals<P['default'], undefined, false, true>
|
|
160
|
-
: false
|
|
148
|
+
: P extends { default: undefined | null | ((...args: any[]) => undefined) | ((...args: any[]) => null) } ? false
|
|
149
|
+
: P extends { default: any } ? true
|
|
150
|
+
: P extends Record<TypeKey, ArrayConstructor | any[]> ? true
|
|
161
151
|
: false;
|
|
162
152
|
|
|
153
|
+
// Internal type used to efficiently check for never or any types
|
|
154
|
+
// can be efficiently checked like:
|
|
155
|
+
// `[T] extends [neverOrAny] ? T : ...`
|
|
156
|
+
// to avoid edge cases
|
|
157
|
+
type neverOrAny = ' ~neverOrAny~';
|
|
158
|
+
|
|
163
159
|
/**
|
|
164
160
|
* @summary A Utility to obtain schema's required path keys.
|
|
165
161
|
* @param {T} T A generic refers to document definition.
|
|
@@ -238,6 +234,7 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> =
|
|
|
238
234
|
|
|
239
235
|
type IsSchemaTypeFromBuiltinClass<T> =
|
|
240
236
|
T extends typeof String ? true
|
|
237
|
+
: unknown extends Buffer ? false
|
|
241
238
|
: T extends typeof Number ? true
|
|
242
239
|
: T extends typeof Boolean ? true
|
|
243
240
|
: T extends typeof Buffer ? true
|
|
@@ -254,7 +251,6 @@ type IsSchemaTypeFromBuiltinClass<T> =
|
|
|
254
251
|
: T extends Types.Decimal128 ? true
|
|
255
252
|
: T extends NativeDate ? true
|
|
256
253
|
: T extends typeof Schema.Types.Mixed ? true
|
|
257
|
-
: unknown extends Buffer ? false
|
|
258
254
|
: T extends Buffer ? true
|
|
259
255
|
: false;
|
|
260
256
|
|
|
@@ -270,12 +266,10 @@ type ResolvePathType<
|
|
|
270
266
|
Options extends SchemaTypeOptions<PathValueType> = {},
|
|
271
267
|
TypeKey extends string = DefaultSchemaOptions['typeKey'],
|
|
272
268
|
TypeHint = never
|
|
273
|
-
> =
|
|
274
|
-
|
|
275
|
-
never,
|
|
276
|
-
PathValueType extends Schema ? InferSchemaType<PathValueType>
|
|
269
|
+
> = [TypeHint] extends [never]
|
|
270
|
+
? PathValueType extends Schema ? InferSchemaType<PathValueType>
|
|
277
271
|
: PathValueType extends AnyArray<infer Item> ?
|
|
278
|
-
|
|
272
|
+
[Item] extends [never]
|
|
279
273
|
? any[]
|
|
280
274
|
: Item extends Schema ?
|
|
281
275
|
// If Item is a schema, infer its type.
|
|
@@ -314,7 +308,7 @@ type ResolvePathType<
|
|
|
314
308
|
: never
|
|
315
309
|
: PathValueType extends ArrayConstructor ? any[]
|
|
316
310
|
: PathValueType extends typeof Schema.Types.Mixed ? any
|
|
317
|
-
:
|
|
311
|
+
: PathValueType extends ObjectConstructor ? any
|
|
318
312
|
: IfEquals<PathValueType, {}> extends true ? any
|
|
319
313
|
: PathValueType extends typeof SchemaType ? PathValueType['prototype']
|
|
320
314
|
: PathValueType extends Record<string, any> ?
|
|
@@ -325,6 +319,5 @@ type ResolvePathType<
|
|
|
325
319
|
typeKey: TypeKey;
|
|
326
320
|
}
|
|
327
321
|
>
|
|
328
|
-
: unknown
|
|
329
|
-
TypeHint
|
|
330
|
-
>;
|
|
322
|
+
: unknown
|
|
323
|
+
: TypeHint;
|
package/types/virtuals.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare module 'mongoose' {
|
|
|
8
8
|
type TVirtualPathFN<DocType = {}, PathType = unknown, TInstanceMethods = {}, TReturn = unknown> =
|
|
9
9
|
<T = HydratedDocument<DocType, TInstanceMethods>>(this: Document<any, any, DocType> & DocType, value: PathType, virtual: VirtualType<T>, doc: Document<any, any, DocType> & DocType) => TReturn;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type SchemaOptionsVirtualsPropertyType<DocType = any, VirtualPaths = Record<any, unknown>, TInstanceMethods = {}> = {
|
|
12
|
+
[K in keyof VirtualPaths]: VirtualPathFunctions<IsItRecordAndNotAny<DocType> extends true ? DocType : any, VirtualPaths[K], TInstanceMethods>
|
|
13
|
+
};
|
|
14
14
|
}
|