mongoose 6.4.2 → 6.4.5
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/.eslintrc.json +2 -1
- package/lib/aggregate.js +3 -2
- package/lib/connection.js +9 -9
- package/lib/cursor/AggregationCursor.js +3 -2
- package/lib/cursor/QueryCursor.js +5 -4
- package/lib/document.js +48 -16
- package/lib/error/index.js +12 -12
- package/lib/error/messages.js +2 -2
- package/lib/helpers/query/castUpdate.js +4 -4
- package/lib/helpers/timestamps/setDocumentTimestamps.js +26 -0
- package/lib/helpers/timestamps/setupTimestamps.js +14 -18
- package/lib/helpers/topology/isAtlas.js +14 -9
- package/lib/index.js +6 -2
- package/lib/model.js +129 -170
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +3 -3
- package/lib/options/SchemaDocumentArrayOptions.js +2 -2
- package/lib/options/SchemaMapOptions.js +1 -1
- package/lib/options/SchemaNumberOptions.js +4 -4
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +8 -8
- package/lib/options/SchemaSubdocumentOptions.js +1 -1
- package/lib/options/SchemaTypeOptions.js +14 -14
- package/lib/options/VirtualOptions.js +11 -11
- package/lib/query.js +74 -71
- package/lib/schema/SubdocumentPath.js +10 -6
- package/lib/schema/array.js +3 -3
- package/lib/schema/boolean.js +5 -5
- package/lib/schema/buffer.js +2 -2
- package/lib/schema/date.js +2 -2
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +12 -8
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +2 -2
- package/lib/schema/objectid.js +2 -2
- package/lib/schema/string.js +2 -2
- package/lib/schema.js +69 -34
- package/lib/schematype.js +9 -10
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/lib/types/buffer.js +30 -28
- package/lib/types/decimal128.js +4 -4
- package/lib/types/map.js +70 -0
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +1 -1
- package/lib/virtualtype.js +5 -5
- package/package.json +15 -15
- package/types/expressions.d.ts +30 -10
- package/types/index.d.ts +10 -7
- package/types/indexes.d.ts +2 -2
- package/types/inferschematype.d.ts +26 -10
- package/types/models.d.ts +2 -1
- package/types/pipelinestage.d.ts +1 -1
- package/types/query.d.ts +6 -1
package/lib/types/map.js
CHANGED
|
@@ -42,6 +42,14 @@ class MongooseMap extends Map {
|
|
|
42
42
|
super.set(key, value);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Overwrites native Map's `get()` function to support Mongoose getters.
|
|
47
|
+
*
|
|
48
|
+
* @api public
|
|
49
|
+
* @method get
|
|
50
|
+
* @memberOf Map
|
|
51
|
+
*/
|
|
52
|
+
|
|
45
53
|
get(key, options) {
|
|
46
54
|
if (isBsonType(key, 'ObjectID')) {
|
|
47
55
|
key = key.toString();
|
|
@@ -54,6 +62,20 @@ class MongooseMap extends Map {
|
|
|
54
62
|
return this.$__schemaType.applyGetters(super.get(key), this.$__parent);
|
|
55
63
|
}
|
|
56
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Overwrites native Map's `set()` function to support setters, `populate()`,
|
|
67
|
+
* and change tracking. Note that Mongoose maps _only_ support strings and
|
|
68
|
+
* ObjectIds as keys.
|
|
69
|
+
*
|
|
70
|
+
* #### Example:
|
|
71
|
+
* doc.myMap.set('test', 42); // works
|
|
72
|
+
* doc.myMap.set({ obj: 42 }, 42); // Throws "Mongoose maps only support string keys"
|
|
73
|
+
*
|
|
74
|
+
* @api public
|
|
75
|
+
* @method set
|
|
76
|
+
* @memberOf Map
|
|
77
|
+
*/
|
|
78
|
+
|
|
57
79
|
set(key, value) {
|
|
58
80
|
if (isBsonType(key, 'ObjectID')) {
|
|
59
81
|
key = key.toString();
|
|
@@ -108,6 +130,14 @@ class MongooseMap extends Map {
|
|
|
108
130
|
}
|
|
109
131
|
}
|
|
110
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Overwrites native Map's `clear()` function to support change tracking.
|
|
135
|
+
*
|
|
136
|
+
* @api public
|
|
137
|
+
* @method clear
|
|
138
|
+
* @memberOf Map
|
|
139
|
+
*/
|
|
140
|
+
|
|
111
141
|
clear() {
|
|
112
142
|
super.clear();
|
|
113
143
|
const parent = this.$__parent;
|
|
@@ -116,6 +146,14 @@ class MongooseMap extends Map {
|
|
|
116
146
|
}
|
|
117
147
|
}
|
|
118
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Overwrites native Map's `delete()` function to support change tracking.
|
|
151
|
+
*
|
|
152
|
+
* @api public
|
|
153
|
+
* @method delete
|
|
154
|
+
* @memberOf Map
|
|
155
|
+
*/
|
|
156
|
+
|
|
119
157
|
delete(key) {
|
|
120
158
|
if (isBsonType(key, 'ObjectID')) {
|
|
121
159
|
key = key.toString();
|
|
@@ -125,6 +163,14 @@ class MongooseMap extends Map {
|
|
|
125
163
|
super.delete(key);
|
|
126
164
|
}
|
|
127
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Converts this map to a native JavaScript Map so the MongoDB driver can serialize it.
|
|
168
|
+
*
|
|
169
|
+
* @api public
|
|
170
|
+
* @method toBSON
|
|
171
|
+
* @memberOf Map
|
|
172
|
+
*/
|
|
173
|
+
|
|
128
174
|
toBSON() {
|
|
129
175
|
return new Map(this);
|
|
130
176
|
}
|
|
@@ -146,6 +192,21 @@ class MongooseMap extends Map {
|
|
|
146
192
|
return this.constructor.prototype.toObject.apply(this, arguments);
|
|
147
193
|
}
|
|
148
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Converts this map to a native JavaScript Map for `JSON.stringify()`. Set
|
|
197
|
+
* the `flattenMaps` option to convert this map to a POJO instead.
|
|
198
|
+
*
|
|
199
|
+
* #### Example:
|
|
200
|
+
* doc.myMap.toJSON() instanceof Map; // true
|
|
201
|
+
* doc.myMap.toJSON({ flattenMaps: true }) instanceof Map; // false
|
|
202
|
+
*
|
|
203
|
+
* @api public
|
|
204
|
+
* @method toJSON
|
|
205
|
+
* @param {Object} [options]
|
|
206
|
+
* @param {Boolean} [options.flattenMaps=false] set to `true` to convert the map to a POJO rather than a native JavaScript map
|
|
207
|
+
* @memberOf Map
|
|
208
|
+
*/
|
|
209
|
+
|
|
149
210
|
toJSON(options) {
|
|
150
211
|
if (typeof (options && options.flattenMaps) === 'boolean' ? options.flattenMaps : true) {
|
|
151
212
|
const ret = {};
|
|
@@ -209,6 +270,15 @@ Object.defineProperty(MongooseMap.prototype, '$__schemaType', {
|
|
|
209
270
|
configurable: false
|
|
210
271
|
});
|
|
211
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Set to `true` for all Mongoose map instances
|
|
275
|
+
*
|
|
276
|
+
* @api public
|
|
277
|
+
* @property $isMongooseMap
|
|
278
|
+
* @memberOf MongooseMap
|
|
279
|
+
* @instance
|
|
280
|
+
*/
|
|
281
|
+
|
|
212
282
|
Object.defineProperty(MongooseMap.prototype, '$isMongooseMap', {
|
|
213
283
|
enumerable: false,
|
|
214
284
|
writable: false,
|
package/lib/types/objectid.js
CHANGED
package/lib/types/subdocument.js
CHANGED
|
@@ -188,7 +188,7 @@ Subdocument.prototype.isModified = function(paths, modifiedPaths) {
|
|
|
188
188
|
* @param {String} path the field to mark as valid
|
|
189
189
|
* @api private
|
|
190
190
|
* @method $markValid
|
|
191
|
-
* @
|
|
191
|
+
* @memberOf Subdocument
|
|
192
192
|
*/
|
|
193
193
|
|
|
194
194
|
Subdocument.prototype.$markValid = function(path) {
|
package/lib/virtualtype.js
CHANGED
|
@@ -75,7 +75,7 @@ VirtualType.prototype.clone = function() {
|
|
|
75
75
|
* Mongoose calls the getter function with the below 3 parameters.
|
|
76
76
|
*
|
|
77
77
|
* - `value`: the value returned by the previous getter. If there is only one getter, `value` will be `undefined`.
|
|
78
|
-
* - `virtual`: the virtual object you called `.get()` on
|
|
78
|
+
* - `virtual`: the virtual object you called `.get()` on.
|
|
79
79
|
* - `doc`: the document this virtual is attached to. Equivalent to `this`.
|
|
80
80
|
*
|
|
81
81
|
* #### Example:
|
|
@@ -85,7 +85,7 @@ VirtualType.prototype.clone = function() {
|
|
|
85
85
|
* return this.name.first + ' ' + this.name.last;
|
|
86
86
|
* });
|
|
87
87
|
*
|
|
88
|
-
* @param {
|
|
88
|
+
* @param {function} fn
|
|
89
89
|
* @return {VirtualType} this
|
|
90
90
|
* @api public
|
|
91
91
|
*/
|
|
@@ -100,8 +100,8 @@ VirtualType.prototype.get = function(fn) {
|
|
|
100
100
|
*
|
|
101
101
|
* Mongoose calls the setter function with the below 3 parameters.
|
|
102
102
|
*
|
|
103
|
-
* - `value`: the value being set
|
|
104
|
-
* - `virtual`: the virtual object you're calling `.set()` on
|
|
103
|
+
* - `value`: the value being set.
|
|
104
|
+
* - `virtual`: the virtual object you're calling `.set()` on.
|
|
105
105
|
* - `doc`: the document this virtual is attached to. Equivalent to `this`.
|
|
106
106
|
*
|
|
107
107
|
* #### Example:
|
|
@@ -120,7 +120,7 @@ VirtualType.prototype.get = function(fn) {
|
|
|
120
120
|
* doc.name.first; // 'Jean-Luc'
|
|
121
121
|
* doc.name.last; // 'Picard'
|
|
122
122
|
*
|
|
123
|
-
* @param {
|
|
123
|
+
* @param {function} fn
|
|
124
124
|
* @return {VirtualType} this
|
|
125
125
|
* @api public
|
|
126
126
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.4.
|
|
4
|
+
"version": "6.4.5",
|
|
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.18.
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
33
|
-
"@typescript-eslint/parser": "5.
|
|
31
|
+
"@babel/core": "7.18.6",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "5.30.3",
|
|
33
|
+
"@typescript-eslint/parser": "5.30.3",
|
|
34
34
|
"acquit": "1.2.1",
|
|
35
35
|
"acquit-ignore": "0.2.0",
|
|
36
36
|
"acquit-require": "0.1.1",
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
"benchmark": "2.1.4",
|
|
41
41
|
"bluebird": "3.7.2",
|
|
42
42
|
"buffer": "^5.6.0",
|
|
43
|
-
"cheerio": "1.0.0-rc.
|
|
43
|
+
"cheerio": "1.0.0-rc.12",
|
|
44
44
|
"crypto-browserify": "3.12.0",
|
|
45
|
-
"dox": "0.
|
|
46
|
-
"eslint": "8.
|
|
45
|
+
"dox": "0.9.1",
|
|
46
|
+
"eslint": "8.19.0",
|
|
47
47
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
48
48
|
"highlight.js": "11.5.1",
|
|
49
49
|
"lodash.isequal": "4.5.0",
|
|
50
50
|
"lodash.isequalwith": "4.4.0",
|
|
51
|
-
"marked": "4.0.
|
|
51
|
+
"marked": "4.0.17",
|
|
52
52
|
"mkdirp": "^1.0.4",
|
|
53
53
|
"mocha": "10.0.0",
|
|
54
54
|
"moment": "2.x",
|
|
55
|
-
"mongodb-memory-server": "8.
|
|
55
|
+
"mongodb-memory-server": "8.7.2",
|
|
56
56
|
"ncp": "^2.0.0",
|
|
57
57
|
"nyc": "15.1.0",
|
|
58
58
|
"pug": "3.0.2",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"serve-handler": "6.1.3",
|
|
61
61
|
"sinon": "14.0.0",
|
|
62
62
|
"stream-browserify": "3.0.0",
|
|
63
|
-
"ts-benchmark": "^1.
|
|
63
|
+
"ts-benchmark": "^1.1.5",
|
|
64
64
|
"tsd": "0.20.0",
|
|
65
|
-
"typescript": "4.7.
|
|
65
|
+
"typescript": "4.7.4",
|
|
66
66
|
"uuid": "8.3.2",
|
|
67
|
-
"webpack": "5.
|
|
67
|
+
"webpack": "5.73.0"
|
|
68
68
|
},
|
|
69
69
|
"directories": {
|
|
70
70
|
"lib": "./lib/mongoose"
|
|
@@ -98,8 +98,8 @@
|
|
|
98
98
|
"test-tsd": "node ./test/types/check-types-filename && tsd",
|
|
99
99
|
"tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
|
|
100
100
|
"test-coverage": "nyc --reporter=html --reporter=text npm test",
|
|
101
|
-
"ts-benchmark": "ts-benchmark -p ./benchmarks/typescript/simple -f 17 18 29 32",
|
|
102
|
-
"ts-benchmark-watch": "ts-benchmark -p ./benchmarks/typescript/simple -w ./types -i -s -f 17 18 29 32 -b master"
|
|
101
|
+
"ts-benchmark": "ts-benchmark -p ./benchmarks/typescript/simple -f 17/100000 18 29 32",
|
|
102
|
+
"ts-benchmark-watch": "ts-benchmark -p ./benchmarks/typescript/simple -w ./types -i -s -f 17/100000 18 29 32 -b master"
|
|
103
103
|
},
|
|
104
104
|
"main": "./index.js",
|
|
105
105
|
"types": "./types/index.d.ts",
|
|
@@ -145,4 +145,4 @@
|
|
|
145
145
|
"target": "ES2017"
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
}
|
|
148
|
+
}
|
package/types/expressions.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ declare module 'mongoose' {
|
|
|
32
32
|
*
|
|
33
33
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add
|
|
34
34
|
*/
|
|
35
|
-
$add:
|
|
35
|
+
$add: Expression[];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface Ceil {
|
|
@@ -1043,7 +1043,7 @@ declare module 'mongoose' {
|
|
|
1043
1043
|
*
|
|
1044
1044
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/cond/#mongodb-expression-exp.-cond
|
|
1045
1045
|
*/
|
|
1046
|
-
$cond: { if:
|
|
1046
|
+
$cond: { if: Expression, then: AnyExpression, else: AnyExpression } | [BooleanExpression, AnyExpression, AnyExpression];
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
1049
|
export interface IfNull {
|
|
@@ -1067,13 +1067,13 @@ declare module 'mongoose' {
|
|
|
1067
1067
|
* - $case
|
|
1068
1068
|
* - $then
|
|
1069
1069
|
*/
|
|
1070
|
-
|
|
1070
|
+
branches: { case: Expression, then: Expression }[];
|
|
1071
1071
|
/**
|
|
1072
1072
|
* The path to take if no branch case expression evaluates to true.
|
|
1073
1073
|
*
|
|
1074
1074
|
* Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error.
|
|
1075
1075
|
*/
|
|
1076
|
-
|
|
1076
|
+
default: Expression;
|
|
1077
1077
|
};
|
|
1078
1078
|
}
|
|
1079
1079
|
|
|
@@ -1104,7 +1104,7 @@ declare module 'mongoose' {
|
|
|
1104
1104
|
* @version 3.2
|
|
1105
1105
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/concatArrays/#mongodb-expression-exp.-concatArrays
|
|
1106
1106
|
*/
|
|
1107
|
-
$concatArrays:
|
|
1107
|
+
$concatArrays: Expression[];
|
|
1108
1108
|
}
|
|
1109
1109
|
|
|
1110
1110
|
export interface Filter {
|
|
@@ -1957,7 +1957,7 @@ declare module 'mongoose' {
|
|
|
1957
1957
|
* @version 5.0
|
|
1958
1958
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/addToSet/#mongodb-expression-exp.-addToSet
|
|
1959
1959
|
*/
|
|
1960
|
-
$addToSet:
|
|
1960
|
+
$addToSet: Expression | Record<string, Expression>;
|
|
1961
1961
|
}
|
|
1962
1962
|
|
|
1963
1963
|
export interface Avg {
|
|
@@ -1967,7 +1967,7 @@ declare module 'mongoose' {
|
|
|
1967
1967
|
* @version 5.0
|
|
1968
1968
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/avg/#mongodb-expression-exp.-avg
|
|
1969
1969
|
*/
|
|
1970
|
-
$avg:
|
|
1970
|
+
$avg: Expression;
|
|
1971
1971
|
}
|
|
1972
1972
|
|
|
1973
1973
|
export interface Count {
|
|
@@ -2316,6 +2316,21 @@ declare module 'mongoose' {
|
|
|
2316
2316
|
$toObjectId: Expression;
|
|
2317
2317
|
}
|
|
2318
2318
|
|
|
2319
|
+
export interface Top {
|
|
2320
|
+
$top: {
|
|
2321
|
+
sortBy: AnyObject,
|
|
2322
|
+
output: Expression
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
export interface TopN {
|
|
2327
|
+
$topN: {
|
|
2328
|
+
n: Expression,
|
|
2329
|
+
sortBy: AnyObject,
|
|
2330
|
+
output: Expression
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2319
2334
|
export interface ToString {
|
|
2320
2335
|
/**
|
|
2321
2336
|
* Converts a value to a string. If the value cannot be converted to a string, $toString errors. If the value is
|
|
@@ -2406,7 +2421,10 @@ declare module 'mongoose' {
|
|
|
2406
2421
|
TypeExpressionOperator |
|
|
2407
2422
|
AccumulatorOperator |
|
|
2408
2423
|
VariableExpressionOperator |
|
|
2409
|
-
WindowOperator
|
|
2424
|
+
WindowOperator |
|
|
2425
|
+
Expression.Top |
|
|
2426
|
+
Expression.TopN |
|
|
2427
|
+
any;
|
|
2410
2428
|
|
|
2411
2429
|
export type NullExpression = null;
|
|
2412
2430
|
|
|
@@ -2430,7 +2448,8 @@ declare module 'mongoose' {
|
|
|
2430
2448
|
BinaryExpression |
|
|
2431
2449
|
FunctionExpression |
|
|
2432
2450
|
ObjectIdExpression |
|
|
2433
|
-
ConditionalExpressionOperator
|
|
2451
|
+
ConditionalExpressionOperator |
|
|
2452
|
+
any;
|
|
2434
2453
|
|
|
2435
2454
|
export type ObjectIdExpression =
|
|
2436
2455
|
TypeExpressionOperatorReturningObjectId;
|
|
@@ -2478,7 +2497,8 @@ declare module 'mongoose' {
|
|
|
2478
2497
|
DataSizeOperatorReturningNumber |
|
|
2479
2498
|
CustomAggregationExpressionOperatorReturningAny |
|
|
2480
2499
|
TypeExpressionOperatorReturningNumber |
|
|
2481
|
-
DateExpression
|
|
2500
|
+
DateExpression |
|
|
2501
|
+
DateExpressionOperatorReturningNumber;
|
|
2482
2502
|
|
|
2483
2503
|
export type ObjectExpression =
|
|
2484
2504
|
Path |
|
package/types/index.d.ts
CHANGED
|
@@ -109,9 +109,7 @@ declare module 'mongoose' {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export type Require_id<T> = T extends { _id?: infer U }
|
|
112
|
-
? U
|
|
113
|
-
? (T & { _id: Types.ObjectId })
|
|
114
|
-
: T & Required<{ _id: U }>
|
|
112
|
+
? IfAny<U, T & { _id: Types.ObjectId }, T & Required<{ _id: U }>>
|
|
115
113
|
: T & { _id: Types.ObjectId };
|
|
116
114
|
|
|
117
115
|
export type RequireOnlyTypedId<T> = T extends { _id?: infer U; }
|
|
@@ -227,6 +225,7 @@ declare module 'mongoose' {
|
|
|
227
225
|
obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>>;
|
|
228
226
|
|
|
229
227
|
/** Gets/sets schema paths. */
|
|
228
|
+
path<pathGeneric extends keyof EnforcedDocType>(path: pathGeneric): SchemaType<EnforcedDocType[pathGeneric]>;
|
|
230
229
|
path<ResultType extends SchemaType = SchemaType>(path: string): ResultType;
|
|
231
230
|
path(path: string, constructor: any): this;
|
|
232
231
|
|
|
@@ -438,6 +437,10 @@ declare module 'mongoose' {
|
|
|
438
437
|
|
|
439
438
|
export type SortOrder = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';
|
|
440
439
|
|
|
440
|
+
type Mutable<T> = {
|
|
441
|
+
-readonly [K in keyof T]: T[K];
|
|
442
|
+
};
|
|
443
|
+
|
|
441
444
|
type _UpdateQuery<TSchema> = {
|
|
442
445
|
/** @see https://docs.mongodb.com/manual/reference/operator/update-field/ */
|
|
443
446
|
$currentDate?: AnyKeys<TSchema> & AnyObject;
|
|
@@ -451,10 +454,10 @@ declare module 'mongoose' {
|
|
|
451
454
|
$unset?: AnyKeys<TSchema> & AnyObject;
|
|
452
455
|
|
|
453
456
|
/** @see https://docs.mongodb.com/manual/reference/operator/update-array/ */
|
|
454
|
-
$addToSet?: mongodb.SetFields<TSchema
|
|
457
|
+
$addToSet?: Mutable<mongodb.SetFields<TSchema>>;
|
|
455
458
|
$pop?: AnyKeys<TSchema> & AnyObject;
|
|
456
|
-
$pull?: mongodb.PullOperator<TSchema
|
|
457
|
-
$push?: mongodb.PushOperator<TSchema
|
|
459
|
+
$pull?: Mutable<mongodb.PullOperator<TSchema>>;
|
|
460
|
+
$push?: Mutable<mongodb.PushOperator<TSchema>>;
|
|
458
461
|
$pullAll?: mongodb.PullAllOperator<TSchema>;
|
|
459
462
|
|
|
460
463
|
/** @see https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */
|
|
@@ -538,7 +541,7 @@ declare module 'mongoose' {
|
|
|
538
541
|
export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
|
|
539
542
|
|
|
540
543
|
// Helpers to simplify checks
|
|
541
|
-
type IfAny<IFTYPE, THENTYPE> = 0 extends (1 & IFTYPE) ? THENTYPE :
|
|
544
|
+
type IfAny<IFTYPE, THENTYPE, ELSETYPE = IFTYPE> = 0 extends (1 & IFTYPE) ? THENTYPE : ELSETYPE;
|
|
542
545
|
type IfUnknown<IFTYPE, THENTYPE> = unknown extends IFTYPE ? THENTYPE : IFTYPE;
|
|
543
546
|
|
|
544
547
|
// tests for these two types are located in test/types/lean.test.ts
|
package/types/indexes.d.ts
CHANGED
|
@@ -51,8 +51,8 @@ declare module 'mongoose' {
|
|
|
51
51
|
* the model's schema except the `_id` index, and build any indexes that
|
|
52
52
|
* are in your schema but not in MongoDB.
|
|
53
53
|
*/
|
|
54
|
-
syncIndexes(options:
|
|
55
|
-
syncIndexes(options?:
|
|
54
|
+
syncIndexes(options: SyncIndexesOptions | null, callback: Callback<Array<string>>): void;
|
|
55
|
+
syncIndexes(options?: SyncIndexesOptions): Promise<Array<string>>;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
interface IndexesDiff {
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Schema,
|
|
3
|
+
InferSchemaType,
|
|
4
|
+
SchemaType,
|
|
5
|
+
SchemaTypeOptions,
|
|
6
|
+
TypeKeyBaseType,
|
|
7
|
+
Types,
|
|
8
|
+
NumberSchemaDefinition,
|
|
9
|
+
StringSchemaDefinition,
|
|
10
|
+
BooleanSchemaDefinition,
|
|
11
|
+
DateSchemaDefinition,
|
|
12
|
+
ObtainDocumentType,
|
|
13
|
+
DefaultTypeKey,
|
|
14
|
+
ObjectIdSchemaDefinition
|
|
15
|
+
} from 'mongoose';
|
|
2
16
|
|
|
3
17
|
declare module 'mongoose' {
|
|
4
18
|
/**
|
|
@@ -75,9 +89,9 @@ type IsPathRequired<P, TypeKey extends TypeKeyBaseType> =
|
|
|
75
89
|
? P extends { default: undefined }
|
|
76
90
|
? false
|
|
77
91
|
: true
|
|
78
|
-
: P extends (Record<TypeKey,
|
|
79
|
-
? P extends { default:
|
|
80
|
-
? true
|
|
92
|
+
: P extends (Record<TypeKey, any>)
|
|
93
|
+
? P extends { default: any }
|
|
94
|
+
? IfEquals<P['default'], undefined, false, true>
|
|
81
95
|
: false
|
|
82
96
|
: false;
|
|
83
97
|
|
|
@@ -138,7 +152,8 @@ type ObtainDocumentPathType<PathValueType, TypeKey extends TypeKeyBaseType> = Pa
|
|
|
138
152
|
? InferSchemaType<PathValueType>
|
|
139
153
|
: ResolvePathType<
|
|
140
154
|
PathValueType extends PathWithTypePropertyBaseType<TypeKey> ? PathValueType[TypeKey] : PathValueType,
|
|
141
|
-
PathValueType extends PathWithTypePropertyBaseType<TypeKey> ? Omit<PathValueType, TypeKey> : {}
|
|
155
|
+
PathValueType extends PathWithTypePropertyBaseType<TypeKey> ? Omit<PathValueType, TypeKey> : {},
|
|
156
|
+
TypeKey
|
|
142
157
|
>;
|
|
143
158
|
|
|
144
159
|
/**
|
|
@@ -151,17 +166,18 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends (
|
|
|
151
166
|
* @summary Resolve path type by returning the corresponding type.
|
|
152
167
|
* @param {PathValueType} PathValueType Document definition path type.
|
|
153
168
|
* @param {Options} Options Document definition path options except path type.
|
|
154
|
-
* @
|
|
169
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
170
|
+
* @returns Number, "Number" or "number" will be resolved to number type.
|
|
155
171
|
*/
|
|
156
|
-
type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}> =
|
|
172
|
+
type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}, TypeKey extends TypeKeyBaseType = DefaultTypeKey> =
|
|
157
173
|
PathValueType extends Schema ? InferSchemaType<PathValueType> :
|
|
158
|
-
PathValueType extends (infer Item)[] ? IfEquals<Item, never, any, ResolvePathType<Item>>[] :
|
|
174
|
+
PathValueType extends (infer Item)[] ? IfEquals<Item, never, any[], Item extends Schema ? Types.DocumentArray<ResolvePathType<Item>> : ResolvePathType<Item>[]> :
|
|
159
175
|
PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :
|
|
160
176
|
PathValueType extends NumberSchemaDefinition ? number :
|
|
161
177
|
PathValueType extends DateSchemaDefinition ? Date :
|
|
162
178
|
PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
|
|
163
179
|
PathValueType extends BooleanSchemaDefinition ? boolean :
|
|
164
|
-
PathValueType extends
|
|
180
|
+
PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId :
|
|
165
181
|
PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
|
|
166
182
|
PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
|
|
167
183
|
PathValueType extends ArrayConstructor ? any[] :
|
|
@@ -169,5 +185,5 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
|
|
|
169
185
|
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
|
|
170
186
|
IfEquals<PathValueType, {}> extends true ? any:
|
|
171
187
|
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
|
|
172
|
-
PathValueType extends
|
|
188
|
+
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, TypeKey> :
|
|
173
189
|
unknown;
|
package/types/models.d.ts
CHANGED
|
@@ -106,7 +106,7 @@ declare module 'mongoose' {
|
|
|
106
106
|
checkKeys?: boolean;
|
|
107
107
|
j?: boolean;
|
|
108
108
|
safe?: boolean | WriteConcern;
|
|
109
|
-
timestamps?: boolean;
|
|
109
|
+
timestamps?: boolean | QueryTimestampsConfig;
|
|
110
110
|
validateBeforeSave?: boolean;
|
|
111
111
|
validateModifiedOnly?: boolean;
|
|
112
112
|
w?: number | string;
|
|
@@ -351,6 +351,7 @@ declare module 'mongoose' {
|
|
|
351
351
|
findOneAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
352
352
|
|
|
353
353
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
354
|
+
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions<T> & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
354
355
|
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
355
356
|
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
356
357
|
|
package/types/pipelinestage.d.ts
CHANGED
|
@@ -212,7 +212,7 @@ declare module 'mongoose' {
|
|
|
212
212
|
|
|
213
213
|
export interface Set {
|
|
214
214
|
/** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
|
|
215
|
-
$set: Record<string, AnyExpression>
|
|
215
|
+
$set: Record<string, AnyExpression | any>
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
export interface SetWindowFields {
|
package/types/query.d.ts
CHANGED
|
@@ -90,6 +90,11 @@ declare module 'mongoose' {
|
|
|
90
90
|
[key: string]: any;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
interface QueryTimestampsConfig {
|
|
94
|
+
createdAt?: boolean;
|
|
95
|
+
updatedAt?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
93
98
|
interface QueryOptions<DocType = unknown> extends
|
|
94
99
|
PopulateOption,
|
|
95
100
|
SessionOption {
|
|
@@ -157,7 +162,7 @@ declare module 'mongoose' {
|
|
|
157
162
|
* skip timestamps for this update. Note that this allows you to overwrite
|
|
158
163
|
* timestamps. Does nothing if schema-level timestamps are not set.
|
|
159
164
|
*/
|
|
160
|
-
timestamps?: boolean;
|
|
165
|
+
timestamps?: boolean | QueryTimestampsConfig;
|
|
161
166
|
upsert?: boolean;
|
|
162
167
|
writeConcern?: mongodb.WriteConcern;
|
|
163
168
|
|