mongoose 6.4.2 → 6.4.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/.eslintrc.json +2 -1
- package/lib/document.js +5 -1
- package/lib/schematype.js +2 -1
- package/lib/types/buffer.js +26 -28
- package/lib/types/decimal128.js +3 -3
- package/lib/types/map.js +70 -0
- package/package.json +11 -11
- package/types/expressions.d.ts +25 -6
- package/types/index.d.ts +1 -0
- package/types/pipelinestage.d.ts +1 -1
package/.eslintrc.json
CHANGED
package/lib/document.js
CHANGED
|
@@ -1409,7 +1409,11 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1409
1409
|
// later in `$__set()` because we don't take `_doc` when we iterate through
|
|
1410
1410
|
// a single nested doc. That's to make sure we get the correct context.
|
|
1411
1411
|
// Otherwise we would double-call the setter, see gh-7196.
|
|
1412
|
-
|
|
1412
|
+
if (options != null && options.overwriteImmutable) {
|
|
1413
|
+
val = schema.applySetters(val, this, false, priorVal, { overwriteImmutable: true });
|
|
1414
|
+
} else {
|
|
1415
|
+
val = schema.applySetters(val, this, false, priorVal);
|
|
1416
|
+
}
|
|
1413
1417
|
}
|
|
1414
1418
|
|
|
1415
1419
|
if (Array.isArray(val) &&
|
package/lib/schematype.js
CHANGED
|
@@ -384,6 +384,7 @@ SchemaType.prototype.default = function(val) {
|
|
|
384
384
|
* #### Example:
|
|
385
385
|
*
|
|
386
386
|
* const s = new Schema({ name: { type: String, index: true })
|
|
387
|
+
* const s = new Schema({ name: { type: String, index: -1 })
|
|
387
388
|
* const s = new Schema({ loc: { type: [Number], index: 'hashed' })
|
|
388
389
|
* const s = new Schema({ loc: { type: [Number], index: '2d', sparse: true })
|
|
389
390
|
* const s = new Schema({ loc: { type: [Number], index: { type: '2dsphere', sparse: true }})
|
|
@@ -399,7 +400,7 @@ SchemaType.prototype.default = function(val) {
|
|
|
399
400
|
* read/write operations you send until the index build.
|
|
400
401
|
* Specify `background: false` to override Mongoose's default._
|
|
401
402
|
*
|
|
402
|
-
* @param {Object|Boolean|String} options
|
|
403
|
+
* @param {Object|Boolean|String|Number} options
|
|
403
404
|
* @return {SchemaType} this
|
|
404
405
|
* @api public
|
|
405
406
|
*/
|
package/lib/types/buffer.js
CHANGED
|
@@ -70,7 +70,7 @@ MongooseBuffer.mixin = {
|
|
|
70
70
|
*
|
|
71
71
|
* @api private
|
|
72
72
|
* @property _subtype
|
|
73
|
-
* @
|
|
73
|
+
* @memberOf MongooseBuffer
|
|
74
74
|
*/
|
|
75
75
|
|
|
76
76
|
_subtype: undefined,
|
|
@@ -80,7 +80,7 @@ MongooseBuffer.mixin = {
|
|
|
80
80
|
*
|
|
81
81
|
* @api private
|
|
82
82
|
* @method _markModified
|
|
83
|
-
* @
|
|
83
|
+
* @memberOf MongooseBuffer
|
|
84
84
|
*/
|
|
85
85
|
|
|
86
86
|
_markModified: function() {
|
|
@@ -97,7 +97,7 @@ MongooseBuffer.mixin = {
|
|
|
97
97
|
*
|
|
98
98
|
* @api public
|
|
99
99
|
* @method write
|
|
100
|
-
* @
|
|
100
|
+
* @memberOf MongooseBuffer
|
|
101
101
|
*/
|
|
102
102
|
|
|
103
103
|
write: function() {
|
|
@@ -120,7 +120,7 @@ MongooseBuffer.mixin = {
|
|
|
120
120
|
* @return {Number} The number of bytes copied.
|
|
121
121
|
* @param {Buffer} target
|
|
122
122
|
* @method copy
|
|
123
|
-
* @
|
|
123
|
+
* @memberOf MongooseBuffer
|
|
124
124
|
*/
|
|
125
125
|
|
|
126
126
|
copy: function(target) {
|
|
@@ -161,24 +161,22 @@ MongooseBuffer.mixin = {
|
|
|
161
161
|
/**
|
|
162
162
|
* Converts this buffer to its Binary type representation.
|
|
163
163
|
*
|
|
164
|
-
* ####SubTypes:
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED);
|
|
164
|
+
* #### SubTypes:
|
|
165
|
+
* const bson = require('bson')
|
|
166
|
+
* bson.BSON_BINARY_SUBTYPE_DEFAULT
|
|
167
|
+
* bson.BSON_BINARY_SUBTYPE_FUNCTION
|
|
168
|
+
* bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
|
|
169
|
+
* bson.BSON_BINARY_SUBTYPE_UUID
|
|
170
|
+
* bson.BSON_BINARY_SUBTYPE_MD5
|
|
171
|
+
* bson.BSON_BINARY_SUBTYPE_USER_DEFINED
|
|
172
|
+
* doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED);
|
|
175
173
|
*
|
|
176
174
|
* @see https://bsonspec.org/#/specification
|
|
177
175
|
* @param {Hex} [subtype]
|
|
178
176
|
* @return {Binary}
|
|
179
177
|
* @api public
|
|
180
178
|
* @method toObject
|
|
181
|
-
* @
|
|
179
|
+
* @memberOf MongooseBuffer
|
|
182
180
|
*/
|
|
183
181
|
|
|
184
182
|
MongooseBuffer.mixin.toObject = function(options) {
|
|
@@ -196,7 +194,7 @@ MongooseBuffer.mixin.$toObject = MongooseBuffer.mixin.toObject;
|
|
|
196
194
|
* @return {Binary}
|
|
197
195
|
* @api public
|
|
198
196
|
* @method toBSON
|
|
199
|
-
* @
|
|
197
|
+
* @memberOf MongooseBuffer
|
|
200
198
|
*/
|
|
201
199
|
|
|
202
200
|
MongooseBuffer.mixin.toBSON = function() {
|
|
@@ -209,7 +207,7 @@ MongooseBuffer.mixin.toBSON = function() {
|
|
|
209
207
|
* @param {Buffer} other
|
|
210
208
|
* @return {Boolean}
|
|
211
209
|
* @method equals
|
|
212
|
-
* @
|
|
210
|
+
* @memberOf MongooseBuffer
|
|
213
211
|
*/
|
|
214
212
|
|
|
215
213
|
MongooseBuffer.mixin.equals = function(other) {
|
|
@@ -233,23 +231,23 @@ MongooseBuffer.mixin.equals = function(other) {
|
|
|
233
231
|
/**
|
|
234
232
|
* Sets the subtype option and marks the buffer modified.
|
|
235
233
|
*
|
|
236
|
-
* ####SubTypes:
|
|
234
|
+
* #### SubTypes:
|
|
237
235
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
236
|
+
* const bson = require('bson')
|
|
237
|
+
* bson.BSON_BINARY_SUBTYPE_DEFAULT
|
|
238
|
+
* bson.BSON_BINARY_SUBTYPE_FUNCTION
|
|
239
|
+
* bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
|
|
240
|
+
* bson.BSON_BINARY_SUBTYPE_UUID
|
|
241
|
+
* bson.BSON_BINARY_SUBTYPE_MD5
|
|
242
|
+
* bson.BSON_BINARY_SUBTYPE_USER_DEFINED
|
|
245
243
|
*
|
|
246
|
-
*
|
|
244
|
+
* doc.buffer.subtype(bson.BSON_BINARY_SUBTYPE_UUID);
|
|
247
245
|
*
|
|
248
246
|
* @see https://bsonspec.org/#/specification
|
|
249
247
|
* @param {Hex} subtype
|
|
250
248
|
* @api public
|
|
251
249
|
* @method subtype
|
|
252
|
-
* @
|
|
250
|
+
* @memberOf MongooseBuffer
|
|
253
251
|
*/
|
|
254
252
|
|
|
255
253
|
MongooseBuffer.mixin.subtype = function(subtype) {
|
package/lib/types/decimal128.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Decimal128 type constructor
|
|
3
3
|
*
|
|
4
4
|
* #### Example
|
|
5
5
|
*
|
|
6
|
-
* const id = new mongoose.Types.
|
|
6
|
+
* const id = new mongoose.Types.Decimal128('3.1415');
|
|
7
7
|
*
|
|
8
|
-
* @constructor
|
|
8
|
+
* @constructor Decimal128
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
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 Map
|
|
279
|
+
* @instance
|
|
280
|
+
*/
|
|
281
|
+
|
|
212
282
|
Object.defineProperty(MongooseMap.prototype, '$isMongooseMap', {
|
|
213
283
|
enumerable: false,
|
|
214
284
|
writable: false,
|
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.3",
|
|
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
45
|
"dox": "0.3.1",
|
|
46
|
-
"eslint": "8.
|
|
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",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"sinon": "14.0.0",
|
|
62
62
|
"stream-browserify": "3.0.0",
|
|
63
63
|
"ts-benchmark": "^1.0.2",
|
|
64
|
-
"tsd": "0.
|
|
65
|
-
"typescript": "4.7.
|
|
64
|
+
"tsd": "0.22.0",
|
|
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"
|
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 {
|
|
@@ -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
|
|
|
@@ -2478,7 +2496,8 @@ declare module 'mongoose' {
|
|
|
2478
2496
|
DataSizeOperatorReturningNumber |
|
|
2479
2497
|
CustomAggregationExpressionOperatorReturningAny |
|
|
2480
2498
|
TypeExpressionOperatorReturningNumber |
|
|
2481
|
-
DateExpression
|
|
2499
|
+
DateExpression |
|
|
2500
|
+
DateExpressionOperatorReturningNumber;
|
|
2482
2501
|
|
|
2483
2502
|
export type ObjectExpression =
|
|
2484
2503
|
Path |
|
package/types/index.d.ts
CHANGED
|
@@ -227,6 +227,7 @@ declare module 'mongoose' {
|
|
|
227
227
|
obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>>;
|
|
228
228
|
|
|
229
229
|
/** Gets/sets schema paths. */
|
|
230
|
+
path<pathGeneric extends keyof EnforcedDocType>(path: pathGeneric): SchemaType<EnforcedDocType[pathGeneric]>;
|
|
230
231
|
path<ResultType extends SchemaType = SchemaType>(path: string): ResultType;
|
|
231
232
|
path(path: string, constructor: any): this;
|
|
232
233
|
|
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 {
|