mongoose 7.0.0 → 7.0.2
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.js +232 -0
- package/README.md +16 -16
- package/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +2 -2
- package/lib/cast.js +1 -8
- package/lib/connection.js +10 -0
- package/lib/cursor/AggregationCursor.js +1 -1
- package/lib/cursor/QueryCursor.js +1 -1
- package/lib/document.js +24 -25
- package/lib/helpers/document/applyDefaults.js +1 -1
- package/lib/model.js +9 -11
- package/lib/query.js +3 -2
- package/lib/schema/documentarray.js +5 -3
- package/lib/schema/uuid.js +4 -1
- package/lib/schema.js +10 -3
- package/lib/schematype.js +1 -1
- package/package.json +15 -12
- package/scripts/generateSearch.js +32 -27
- package/types/cursor.d.ts +2 -2
- package/types/index.d.ts +8 -6
- package/types/models.d.ts +17 -2
- package/types/query.d.ts +2 -5
- package/types/types.d.ts +1 -1
- package/.eslintrc.json +0 -194
package/lib/aggregate.js
CHANGED
|
@@ -1049,7 +1049,7 @@ Aggregate.prototype.exec = async function exec() {
|
|
|
1049
1049
|
const options = clone(this.options || {});
|
|
1050
1050
|
let result;
|
|
1051
1051
|
try {
|
|
1052
|
-
const cursor = collection.aggregate(this._pipeline, options);
|
|
1052
|
+
const cursor = await collection.aggregate(this._pipeline, options);
|
|
1053
1053
|
result = await cursor.toArray();
|
|
1054
1054
|
} catch (error) {
|
|
1055
1055
|
await new Promise((resolve, reject) => {
|
|
@@ -1127,7 +1127,7 @@ Aggregate.prototype.catch = function(reject) {
|
|
|
1127
1127
|
* `Symbol.asyncIterator` is undefined, that means your Node.js version does not
|
|
1128
1128
|
* support async iterators.
|
|
1129
1129
|
*
|
|
1130
|
-
* @method Symbol.asyncIterator
|
|
1130
|
+
* @method [Symbol.asyncIterator]
|
|
1131
1131
|
* @memberOf Aggregate
|
|
1132
1132
|
* @instance
|
|
1133
1133
|
* @api public
|
package/lib/cast.js
CHANGED
|
@@ -64,18 +64,11 @@ module.exports = function cast(schema, obj, options, context) {
|
|
|
64
64
|
if (!Array.isArray(val)) {
|
|
65
65
|
throw new CastError('Array', val, path);
|
|
66
66
|
}
|
|
67
|
-
for (let k =
|
|
67
|
+
for (let k = 0; k < val.length; ++k) {
|
|
68
68
|
if (val[k] == null || typeof val[k] !== 'object') {
|
|
69
69
|
throw new CastError('Object', val[k], path + '.' + k);
|
|
70
70
|
}
|
|
71
71
|
val[k] = cast(schema, val[k], options, context);
|
|
72
|
-
if (Object.keys(val[k]).length === 0) {
|
|
73
|
-
val.splice(k, 1);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (val.length === 0) {
|
|
78
|
-
delete obj[path];
|
|
79
72
|
}
|
|
80
73
|
} else if (path === '$where') {
|
|
81
74
|
type = typeof val;
|
package/lib/connection.js
CHANGED
|
@@ -1057,6 +1057,16 @@ Connection.prototype._close = async function _close(force, destroy) {
|
|
|
1057
1057
|
return this;
|
|
1058
1058
|
};
|
|
1059
1059
|
|
|
1060
|
+
/**
|
|
1061
|
+
* Abstract method that drivers must implement.
|
|
1062
|
+
*
|
|
1063
|
+
* @api private
|
|
1064
|
+
*/
|
|
1065
|
+
|
|
1066
|
+
Connection.prototype.doClose = function() {
|
|
1067
|
+
throw new Error('Connection#doClose unimplemented by driver');
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1060
1070
|
/**
|
|
1061
1071
|
* Called when the connection closes
|
|
1062
1072
|
*
|
|
@@ -263,7 +263,7 @@ AggregationCursor.prototype.eachAsync = function(fn, opts, callback) {
|
|
|
263
263
|
* `Symbol.asyncIterator` is undefined, that means your Node.js version does not
|
|
264
264
|
* support async iterators.
|
|
265
265
|
*
|
|
266
|
-
* @method Symbol.asyncIterator
|
|
266
|
+
* @method [Symbol.asyncIterator]
|
|
267
267
|
* @memberOf AggregationCursor
|
|
268
268
|
* @instance
|
|
269
269
|
* @api public
|
|
@@ -347,7 +347,7 @@ QueryCursor.prototype._transformForAsyncIterator = function() {
|
|
|
347
347
|
* `Symbol.asyncIterator` is undefined, that means your Node.js version does not
|
|
348
348
|
* support async iterators.
|
|
349
349
|
*
|
|
350
|
-
* @method Symbol.asyncIterator
|
|
350
|
+
* @method [Symbol.asyncIterator]
|
|
351
351
|
* @memberOf QueryCursor
|
|
352
352
|
* @instance
|
|
353
353
|
* @api public
|
package/lib/document.js
CHANGED
|
@@ -2557,7 +2557,7 @@ function _evaluateRequiredFunctions(doc) {
|
|
|
2557
2557
|
* ignore
|
|
2558
2558
|
*/
|
|
2559
2559
|
|
|
2560
|
-
function _getPathsToValidate(doc) {
|
|
2560
|
+
function _getPathsToValidate(doc, pathsToValidate, pathsToSkip) {
|
|
2561
2561
|
const skipSchemaValidators = {};
|
|
2562
2562
|
|
|
2563
2563
|
_evaluateRequiredFunctions(doc);
|
|
@@ -2628,6 +2628,22 @@ function _getPathsToValidate(doc) {
|
|
|
2628
2628
|
}
|
|
2629
2629
|
}
|
|
2630
2630
|
|
|
2631
|
+
for (const path of paths) {
|
|
2632
|
+
// Single nested paths (paths embedded under single nested subdocs) will
|
|
2633
|
+
// be validated on their own when we call `validate()` on the subdoc itself.
|
|
2634
|
+
// Re: gh-8468
|
|
2635
|
+
if (doc.$__schema.singleNestedPaths.hasOwnProperty(path)) {
|
|
2636
|
+
paths.delete(path);
|
|
2637
|
+
continue;
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
if (Array.isArray(pathsToValidate)) {
|
|
2642
|
+
paths = _handlePathsToValidate(paths, pathsToValidate);
|
|
2643
|
+
} else if (Array.isArray(pathsToSkip)) {
|
|
2644
|
+
paths = _handlePathsToSkip(paths, pathsToSkip);
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2631
2647
|
// from here on we're not removing items from paths
|
|
2632
2648
|
|
|
2633
2649
|
// gh-661: if a whole array is modified, make sure to run validation on all
|
|
@@ -2687,13 +2703,6 @@ function _getPathsToValidate(doc) {
|
|
|
2687
2703
|
}
|
|
2688
2704
|
|
|
2689
2705
|
for (const path of paths) {
|
|
2690
|
-
// Single nested paths (paths embedded under single nested subdocs) will
|
|
2691
|
-
// be validated on their own when we call `validate()` on the subdoc itself.
|
|
2692
|
-
// Re: gh-8468
|
|
2693
|
-
if (doc.$__schema.singleNestedPaths.hasOwnProperty(path)) {
|
|
2694
|
-
paths.delete(path);
|
|
2695
|
-
continue;
|
|
2696
|
-
}
|
|
2697
2706
|
const _pathType = doc.$__schema.path(path);
|
|
2698
2707
|
if (!_pathType || !_pathType.$isSchemaMap) {
|
|
2699
2708
|
continue;
|
|
@@ -2776,7 +2785,7 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
|
|
|
2776
2785
|
};
|
|
2777
2786
|
|
|
2778
2787
|
// only validate required fields when necessary
|
|
2779
|
-
const pathDetails = _getPathsToValidate(this);
|
|
2788
|
+
const pathDetails = _getPathsToValidate(this, pathsToValidate, pathsToSkip);
|
|
2780
2789
|
let paths = shouldValidateModifiedOnly ?
|
|
2781
2790
|
pathDetails[0].filter((path) => this.$isModified(path)) :
|
|
2782
2791
|
pathDetails[0];
|
|
@@ -2784,11 +2793,6 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
|
|
|
2784
2793
|
if (typeof pathsToValidate === 'string') {
|
|
2785
2794
|
pathsToValidate = pathsToValidate.split(' ');
|
|
2786
2795
|
}
|
|
2787
|
-
if (Array.isArray(pathsToValidate)) {
|
|
2788
|
-
paths = _handlePathsToValidate(paths, pathsToValidate);
|
|
2789
|
-
} else if (pathsToSkip) {
|
|
2790
|
-
paths = _handlePathsToSkip(paths, pathsToSkip);
|
|
2791
|
-
}
|
|
2792
2796
|
|
|
2793
2797
|
if (paths.length === 0) {
|
|
2794
2798
|
return immediate(function() {
|
|
@@ -2907,12 +2911,12 @@ function _handlePathsToValidate(paths, pathsToValidate) {
|
|
|
2907
2911
|
}
|
|
2908
2912
|
}
|
|
2909
2913
|
|
|
2910
|
-
const ret =
|
|
2914
|
+
const ret = new Set();
|
|
2911
2915
|
for (const path of paths) {
|
|
2912
2916
|
if (_pathsToValidate.has(path)) {
|
|
2913
|
-
ret.
|
|
2917
|
+
ret.add(path);
|
|
2914
2918
|
} else if (parentPaths.has(path)) {
|
|
2915
|
-
ret.
|
|
2919
|
+
ret.add(parentPaths.get(path));
|
|
2916
2920
|
}
|
|
2917
2921
|
}
|
|
2918
2922
|
return ret;
|
|
@@ -2924,8 +2928,8 @@ function _handlePathsToValidate(paths, pathsToValidate) {
|
|
|
2924
2928
|
|
|
2925
2929
|
function _handlePathsToSkip(paths, pathsToSkip) {
|
|
2926
2930
|
pathsToSkip = new Set(pathsToSkip);
|
|
2927
|
-
paths = paths.filter(p => !pathsToSkip.has(p));
|
|
2928
|
-
return paths;
|
|
2931
|
+
paths = Array.from(paths).filter(p => !pathsToSkip.has(p));
|
|
2932
|
+
return new Set(paths);
|
|
2929
2933
|
}
|
|
2930
2934
|
|
|
2931
2935
|
/**
|
|
@@ -2981,17 +2985,12 @@ Document.prototype.validateSync = function(pathsToValidate, options) {
|
|
|
2981
2985
|
}
|
|
2982
2986
|
|
|
2983
2987
|
// only validate required fields when necessary
|
|
2984
|
-
const pathDetails = _getPathsToValidate(this);
|
|
2988
|
+
const pathDetails = _getPathsToValidate(this, pathsToValidate, pathsToSkip);
|
|
2985
2989
|
let paths = shouldValidateModifiedOnly ?
|
|
2986
2990
|
pathDetails[0].filter((path) => this.$isModified(path)) :
|
|
2987
2991
|
pathDetails[0];
|
|
2988
2992
|
const skipSchemaValidators = pathDetails[1];
|
|
2989
2993
|
|
|
2990
|
-
if (Array.isArray(pathsToValidate)) {
|
|
2991
|
-
paths = _handlePathsToValidate(paths, pathsToValidate);
|
|
2992
|
-
} else if (Array.isArray(pathsToSkip)) {
|
|
2993
|
-
paths = _handlePathsToSkip(paths, pathsToSkip);
|
|
2994
|
-
}
|
|
2995
2994
|
const validating = {};
|
|
2996
2995
|
|
|
2997
2996
|
for (let i = 0, len = paths.length; i < len; ++i) {
|
|
@@ -32,7 +32,7 @@ module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildre
|
|
|
32
32
|
}
|
|
33
33
|
} else if (exclude === false && fields && !included) {
|
|
34
34
|
const hasSubpaths = type.$isSingleNested || type.$isMongooseDocumentArray;
|
|
35
|
-
if (curPath in fields || (hasSubpaths && hasIncludedChildren != null && hasIncludedChildren[curPath])) {
|
|
35
|
+
if (curPath in fields || (j === len - 1 && hasSubpaths && hasIncludedChildren != null && hasIncludedChildren[curPath])) {
|
|
36
36
|
included = true;
|
|
37
37
|
} else if (hasIncludedChildren != null && !hasIncludedChildren[curPath]) {
|
|
38
38
|
break;
|
package/lib/model.js
CHANGED
|
@@ -1252,9 +1252,11 @@ for (const i in EventEmitter.prototype) {
|
|
|
1252
1252
|
* Mongoose calls this function automatically when a model is created using
|
|
1253
1253
|
* [`mongoose.model()`](/docs/api/mongoose.html#mongoose_Mongoose-model) or
|
|
1254
1254
|
* [`connection.model()`](/docs/api/connection.html#connection_Connection-model), so you
|
|
1255
|
-
* don't need to call
|
|
1256
|
-
*
|
|
1257
|
-
*
|
|
1255
|
+
* don't need to call `init()` to trigger index builds.
|
|
1256
|
+
*
|
|
1257
|
+
* However, you _may_ need to call `init()` to get back a promise that will resolve when your indexes are finished.
|
|
1258
|
+
* Calling `await Model.init()` is helpful if you need to wait for indexes to build before continuing.
|
|
1259
|
+
* For example, if you want to wait for unique indexes to build before continuing with a test case.
|
|
1258
1260
|
*
|
|
1259
1261
|
* #### Example:
|
|
1260
1262
|
*
|
|
@@ -1263,11 +1265,8 @@ for (const i in EventEmitter.prototype) {
|
|
|
1263
1265
|
* // `Event.init()` on your own.
|
|
1264
1266
|
* const Event = mongoose.model('Event', eventSchema);
|
|
1265
1267
|
*
|
|
1266
|
-
* Event.init()
|
|
1267
|
-
*
|
|
1268
|
-
* // over promises.
|
|
1269
|
-
* console.log('Indexes are done building!');
|
|
1270
|
-
* });
|
|
1268
|
+
* await Event.init();
|
|
1269
|
+
* console.log('Indexes are done building!');
|
|
1271
1270
|
*
|
|
1272
1271
|
* @api public
|
|
1273
1272
|
* @returns {Promise}
|
|
@@ -2110,10 +2109,9 @@ Model.findById = function findById(id, projection, options) {
|
|
|
2110
2109
|
* // Find one adventure whose `country` is 'Croatia', otherwise `null`
|
|
2111
2110
|
* await Adventure.findOne({ country: 'Croatia' }).exec();
|
|
2112
2111
|
*
|
|
2113
|
-
* //
|
|
2114
|
-
* Adventure.findOne({ country: 'Croatia' }, function (err, adventure) {});
|
|
2112
|
+
* // Model.findOne() no longer accepts a callback
|
|
2115
2113
|
*
|
|
2116
|
-
* //
|
|
2114
|
+
* // Select only the adventures name and length
|
|
2117
2115
|
* await Adventure.findOne({ country: 'Croatia' }, 'name length').exec();
|
|
2118
2116
|
*
|
|
2119
2117
|
* @param {Object} [conditions]
|
package/lib/query.js
CHANGED
|
@@ -4482,7 +4482,8 @@ Query.prototype.finally = function(onFinally) {
|
|
|
4482
4482
|
*
|
|
4483
4483
|
* @return {String}
|
|
4484
4484
|
* @api public
|
|
4485
|
-
* @method toStringTag
|
|
4485
|
+
* @method [Symbol.toStringTag]
|
|
4486
|
+
* @memberOf Query
|
|
4486
4487
|
*/
|
|
4487
4488
|
|
|
4488
4489
|
Query.prototype[Symbol.toStringTag] = function toString() {
|
|
@@ -5192,7 +5193,7 @@ Query.prototype.nearSphere = function() {
|
|
|
5192
5193
|
* `Symbol.asyncIterator` is undefined, that means your Node.js version does not
|
|
5193
5194
|
* support async iterators.
|
|
5194
5195
|
*
|
|
5195
|
-
* @method Symbol.asyncIterator
|
|
5196
|
+
* @method [Symbol.asyncIterator]
|
|
5196
5197
|
* @memberOf Query
|
|
5197
5198
|
* @instance
|
|
5198
5199
|
* @api public
|
|
@@ -416,6 +416,8 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
416
416
|
|
|
417
417
|
options = options || {};
|
|
418
418
|
|
|
419
|
+
const path = options.path || this.path;
|
|
420
|
+
|
|
419
421
|
if (!Array.isArray(value)) {
|
|
420
422
|
if (!init && !DocumentArrayPath.options.castNonArrays) {
|
|
421
423
|
throw new CastError('DocumentArray', value, this.path, null, this);
|
|
@@ -423,7 +425,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
423
425
|
// gh-2442 mark whole array as modified if we're initializing a doc from
|
|
424
426
|
// the db and the path isn't an array in the document
|
|
425
427
|
if (!!doc && init) {
|
|
426
|
-
doc.markModified(
|
|
428
|
+
doc.markModified(path);
|
|
427
429
|
}
|
|
428
430
|
return this.cast([value], doc, init, prev, options);
|
|
429
431
|
}
|
|
@@ -431,7 +433,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
431
433
|
// We need to create a new array, otherwise change tracking will
|
|
432
434
|
// update the old doc (gh-4449)
|
|
433
435
|
if (!options.skipDocumentArrayCast || utils.isMongooseDocumentArray(value)) {
|
|
434
|
-
value = new MongooseDocumentArray(value,
|
|
436
|
+
value = new MongooseDocumentArray(value, path, doc);
|
|
435
437
|
}
|
|
436
438
|
|
|
437
439
|
if (prev != null) {
|
|
@@ -439,7 +441,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
439
441
|
}
|
|
440
442
|
|
|
441
443
|
if (options.arrayPathIndex != null) {
|
|
442
|
-
value[arrayPathSymbol] =
|
|
444
|
+
value[arrayPathSymbol] = path + '.' + options.arrayPathIndex;
|
|
443
445
|
}
|
|
444
446
|
|
|
445
447
|
const rawArray = utils.isMongooseDocumentArray(value) ? value.__array : value;
|
package/lib/schema/uuid.js
CHANGED
|
@@ -231,7 +231,10 @@ SchemaUUID.checkRequired = SchemaType.checkRequired;
|
|
|
231
231
|
*/
|
|
232
232
|
|
|
233
233
|
SchemaUUID.prototype.checkRequired = function checkRequired(value) {
|
|
234
|
-
|
|
234
|
+
if (Buffer.isBuffer(value)) {
|
|
235
|
+
value = binaryToString(value);
|
|
236
|
+
}
|
|
237
|
+
return value != null && UUID_FORMAT.test(value);
|
|
235
238
|
};
|
|
236
239
|
|
|
237
240
|
/**
|
package/lib/schema.js
CHANGED
|
@@ -734,8 +734,15 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
734
734
|
if (prefix) {
|
|
735
735
|
this.nested[prefix.substring(0, prefix.length - 1)] = true;
|
|
736
736
|
}
|
|
737
|
-
|
|
738
|
-
const
|
|
737
|
+
|
|
738
|
+
const childSchemaOptions = {};
|
|
739
|
+
if (this._userProvidedOptions.typeKey) {
|
|
740
|
+
childSchemaOptions.typeKey = this._userProvidedOptions.typeKey;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const _schema = new Schema(_typeDef, childSchemaOptions);
|
|
744
|
+
_schema.$implicitlyCreated = true;
|
|
745
|
+
const schemaWrappedPath = Object.assign({}, val, { [typeKey]: _schema });
|
|
739
746
|
this.path(prefix + key, schemaWrappedPath);
|
|
740
747
|
} else {
|
|
741
748
|
// Either the type is non-POJO or we interpret it as Mixed anyway
|
|
@@ -1322,6 +1329,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1322
1329
|
} else if (Schema.Types.DocumentArray.defaultOptions._id != null) {
|
|
1323
1330
|
childSchemaOptions._id = Schema.Types.DocumentArray.defaultOptions._id;
|
|
1324
1331
|
}
|
|
1332
|
+
|
|
1325
1333
|
const childSchema = new Schema(castFromTypeKey, childSchemaOptions);
|
|
1326
1334
|
childSchema.$implicitlyCreated = true;
|
|
1327
1335
|
return new MongooseTypes.DocumentArray(path, childSchema, obj);
|
|
@@ -1365,7 +1373,6 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1365
1373
|
}
|
|
1366
1374
|
|
|
1367
1375
|
if (type && type.instanceOfSchema) {
|
|
1368
|
-
|
|
1369
1376
|
return new MongooseTypes.Subdocument(type, path, obj);
|
|
1370
1377
|
}
|
|
1371
1378
|
|
package/lib/schematype.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.2",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"sift": "16.0.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "7.
|
|
31
|
+
"@babel/core": "7.21.0",
|
|
32
32
|
"@babel/preset-env": "7.20.2",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
34
|
-
"@typescript-eslint/parser": "5.
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "5.54.0",
|
|
34
|
+
"@typescript-eslint/parser": "5.54.0",
|
|
35
35
|
"acquit": "1.3.0",
|
|
36
36
|
"acquit-ignore": "0.2.1",
|
|
37
37
|
"acquit-require": "0.1.1",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"crypto-browserify": "3.12.0",
|
|
46
46
|
"dotenv": "16.0.3",
|
|
47
47
|
"dox": "1.0.0",
|
|
48
|
-
"eslint": "8.
|
|
48
|
+
"eslint": "8.35.0",
|
|
49
|
+
"eslint-plugin-markdown": "^3.0.0",
|
|
49
50
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
50
51
|
"express": "^4.18.1",
|
|
51
52
|
"highlight.js": "11.7.0",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"mkdirp": "^2.1.3",
|
|
56
57
|
"mocha": "10.2.0",
|
|
57
58
|
"moment": "2.x",
|
|
58
|
-
"mongodb-memory-server": "8.11.
|
|
59
|
+
"mongodb-memory-server": "8.11.5",
|
|
59
60
|
"ncp": "^2.0.0",
|
|
60
61
|
"nyc": "15.1.0",
|
|
61
62
|
"pug": "3.0.2",
|
|
@@ -75,12 +76,12 @@
|
|
|
75
76
|
"docs:clean:stable": "rimraf index.html && rimraf -rf ./docs/*.html && rimraf -rf ./docs/api && rimraf -rf ./docs/tutorials/*.html && rimraf -rf ./docs/typescript/*.html && rimraf -rf ./docs/*.html && rimraf -rf ./docs/source/_docs && rimraf -rf ./tmp",
|
|
76
77
|
"docs:clean:5x": "rimraf index.html && rimraf -rf ./docs/5.x && rimraf -rf ./docs/source/_docs && rimraf -rf ./tmp",
|
|
77
78
|
"docs:clean:6x": "rimraf index.html && rimraf -rf ./docs/6.x && rimraf -rf ./docs/source/_docs && rimraf -rf ./tmp",
|
|
78
|
-
"docs:copy:tmp": "mkdirp ./tmp/docs/css && mkdirp ./tmp/docs/js && mkdirp ./tmp/docs/images && mkdirp ./tmp/docs/tutorials && mkdirp ./tmp/docs/typescript && ncp ./docs/css ./tmp/docs/css --filter=.css$ && ncp ./docs/js ./tmp/docs/js --filter=.js$ && ncp ./docs/images ./tmp/docs/images && ncp ./docs/tutorials ./tmp/docs/tutorials && ncp ./docs/typescript ./tmp/docs/typescript && cp index.html ./tmp",
|
|
79
|
+
"docs:copy:tmp": "mkdirp ./tmp/docs/css && mkdirp ./tmp/docs/js && mkdirp ./tmp/docs/images && mkdirp ./tmp/docs/tutorials && mkdirp ./tmp/docs/typescript && ncp ./docs/css ./tmp/docs/css --filter=.css$ && ncp ./docs/js ./tmp/docs/js --filter=.js$ && ncp ./docs/images ./tmp/docs/images && ncp ./docs/tutorials ./tmp/docs/tutorials && ncp ./docs/typescript ./tmp/docs/typescript && cp index.html ./tmp && cp docs/*.html ./tmp/docs/",
|
|
79
80
|
"docs:copy:tmp:5x": "rimraf ./docs/5.x && ncp ./tmp ./docs/5.x",
|
|
80
|
-
"docs:copy:tmp:6x": "rimraf ./docs/
|
|
81
|
+
"docs:copy:tmp:6x": "rimraf ./docs/6.x && ncp ./tmp ./docs/6.x",
|
|
81
82
|
"docs:checkout:gh-pages": "git checkout gh-pages",
|
|
82
83
|
"docs:checkout:5x": "git checkout 5.x",
|
|
83
|
-
"docs:checkout:6x": "git checkout
|
|
84
|
+
"docs:checkout:6x": "git checkout 6.x",
|
|
84
85
|
"docs:generate": "node ./scripts/website.js",
|
|
85
86
|
"docs:generate:search": "node ./scripts/generateSearch.js",
|
|
86
87
|
"docs:merge:stable": "git merge master",
|
|
@@ -89,16 +90,18 @@
|
|
|
89
90
|
"docs:test": "npm run docs:generate && npm run docs:generate:search",
|
|
90
91
|
"docs:view": "node ./scripts/static.js",
|
|
91
92
|
"docs:prepare:publish:stable": "npm run docs:checkout:gh-pages && npm run docs:merge:stable && npm run docs:clean:stable && npm run docs:generate && npm run docs:generate:search",
|
|
92
|
-
"docs:prepare:publish:5x": "npm run docs:checkout:5x && npm run docs:merge:5x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && docs:checkout:gh-pages && docs:copy:tmp:5x",
|
|
93
|
-
"docs:prepare:publish:6x": "npm run docs:checkout:6x && npm run docs:merge:6x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && docs:checkout:gh-pages && docs:copy:tmp:6x",
|
|
93
|
+
"docs:prepare:publish:5x": "npm run docs:checkout:5x && npm run docs:merge:5x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:5x",
|
|
94
|
+
"docs:prepare:publish:6x": "npm run docs:checkout:6x && npm run docs:merge:6x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:6x",
|
|
94
95
|
"docs:check-links": "blc http://127.0.0.1:8089 -ro",
|
|
95
96
|
"lint": "eslint .",
|
|
96
97
|
"lint-js": "eslint . --ext .js",
|
|
97
98
|
"lint-ts": "eslint . --ext .ts",
|
|
99
|
+
"lint-md": "eslint . --ext .md",
|
|
98
100
|
"build-browser": "(rm ./dist/* || true) && node ./scripts/build-browser.js",
|
|
99
101
|
"prepublishOnly": "npm run build-browser",
|
|
100
102
|
"release": "git pull && git push origin master --tags && npm publish",
|
|
101
|
-
"release-5x": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag 5x",
|
|
103
|
+
"release-5x": "git pull origin 5.x && git push origin 5.x && git push origin 5.x --tags && npm publish --tag 5x",
|
|
104
|
+
"release-6x": "git pull origin 6.x && git push origin 6.x && git push origin 6.x --tags && npm publish --tag legacy",
|
|
102
105
|
"mongo": "node ./tools/repl.js",
|
|
103
106
|
"test": "mocha --exit ./test/*.test.js",
|
|
104
107
|
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js",
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let config;
|
|
4
|
+
try {
|
|
5
|
+
config = require('../.config.js');
|
|
6
|
+
} finally {
|
|
7
|
+
if (!config || !config.uri) {
|
|
8
|
+
console.error('No Config or config.URI given, please create a .config.js file with those values in the root of the repository');
|
|
9
|
+
process.exit(-1);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
4
12
|
const cheerio = require('cheerio');
|
|
5
13
|
const filemap = require('../docs/source');
|
|
6
14
|
const fs = require('fs');
|
|
@@ -16,8 +24,6 @@ markdown.setOptions({
|
|
|
16
24
|
}
|
|
17
25
|
});
|
|
18
26
|
|
|
19
|
-
mongoose.set('strictQuery', false);
|
|
20
|
-
|
|
21
27
|
// 5.13.5 -> 5.x, 6.8.2 -> 6.x, etc.
|
|
22
28
|
version = version.slice(0, version.indexOf('.')) + '.x';
|
|
23
29
|
|
|
@@ -32,25 +38,27 @@ const Content = mongoose.model('Content', contentSchema, 'Content');
|
|
|
32
38
|
|
|
33
39
|
const contents = [];
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
contents.push(content);
|
|
51
|
-
}
|
|
41
|
+
const api = require('../docs/source/api');
|
|
42
|
+
|
|
43
|
+
// API docs are special, because they are not added to the file-map individually currently and use different properties
|
|
44
|
+
for (const _class of api.docs) {
|
|
45
|
+
for (const prop of _class.props) {
|
|
46
|
+
const content = new Content({
|
|
47
|
+
title: `API: ${prop.name}`,
|
|
48
|
+
body: prop.description,
|
|
49
|
+
url: `api/${_class.fileName}.html#${prop.anchorId}`
|
|
50
|
+
});
|
|
51
|
+
const err = content.validateSync();
|
|
52
|
+
if (err != null) {
|
|
53
|
+
console.error(content);
|
|
54
|
+
throw err;
|
|
52
55
|
}
|
|
53
|
-
|
|
56
|
+
contents.push(content);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const [filename, file] of Object.entries(filemap)) {
|
|
61
|
+
if (file.markdown) {
|
|
54
62
|
let text = fs.readFileSync(filename, 'utf8');
|
|
55
63
|
text = markdown.parse(text);
|
|
56
64
|
|
|
@@ -122,12 +130,7 @@ run().catch(async error => {
|
|
|
122
130
|
});
|
|
123
131
|
|
|
124
132
|
async function run() {
|
|
125
|
-
|
|
126
|
-
console.error('No Config or config.URI given, please create a .config.js file with those values');
|
|
127
|
-
process.exit(-1);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
await mongoose.connect(config.uri, { dbName: 'mongoose' });
|
|
133
|
+
await mongoose.connect(config.uri, { dbName: 'mongoose', serverSelectionTimeoutMS: 5000 });
|
|
131
134
|
|
|
132
135
|
// wait for the index to be created
|
|
133
136
|
await Content.init();
|
|
@@ -154,5 +157,7 @@ async function run() {
|
|
|
154
157
|
|
|
155
158
|
console.log(results.map(res => res.url));
|
|
156
159
|
|
|
160
|
+
console.log(`Added ${contents.length} Content`);
|
|
161
|
+
|
|
157
162
|
process.exit(0);
|
|
158
163
|
}
|
package/types/cursor.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ declare module 'mongoose' {
|
|
|
38
38
|
* will wait for the promise to resolve before iterating on to the next one.
|
|
39
39
|
* Returns a promise that resolves when done.
|
|
40
40
|
*/
|
|
41
|
-
eachAsync(fn: (doc: DocType[]) => any, options: EachAsyncOptions & { batchSize: number }): Promise<void>;
|
|
42
|
-
eachAsync(fn: (doc: DocType) => any, options?: EachAsyncOptions): Promise<void>;
|
|
41
|
+
eachAsync(fn: (doc: DocType[], i: number) => any, options: EachAsyncOptions & { batchSize: number }): Promise<void>;
|
|
42
|
+
eachAsync(fn: (doc: DocType, i: number) => any, options?: EachAsyncOptions): Promise<void>;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Registers a transform function which subsequently maps documents retrieved
|
package/types/index.d.ts
CHANGED
|
@@ -139,12 +139,14 @@ declare module 'mongoose' {
|
|
|
139
139
|
TOverrides = {},
|
|
140
140
|
TQueryHelpers = {}
|
|
141
141
|
> = IfAny<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
DocType,
|
|
143
|
+
any,
|
|
144
|
+
Document<unknown, TQueryHelpers, DocType> & MergeType<
|
|
145
|
+
Require_id<DocType>,
|
|
146
|
+
TOverrides extends Record<string, never> ?
|
|
147
|
+
{} :
|
|
148
|
+
IfAny<TOverrides, {}>
|
|
149
|
+
>
|
|
148
150
|
>;
|
|
149
151
|
export type HydratedSingleSubdocument<DocType, TOverrides = {}> = Types.Subdocument<unknown> & Require_id<DocType> & TOverrides;
|
|
150
152
|
export type HydratedArraySubdocument<DocType, TOverrides = {}> = Types.ArraySubdocument<unknown> & Require_id<DocType> & TOverrides;
|
package/types/models.d.ts
CHANGED
|
@@ -11,8 +11,16 @@ declare module 'mongoose' {
|
|
|
11
11
|
|
|
12
12
|
export interface AcceptsDiscriminator {
|
|
13
13
|
/** Adds a discriminator type. */
|
|
14
|
-
discriminator<D>(
|
|
15
|
-
|
|
14
|
+
discriminator<D>(
|
|
15
|
+
name: string | number,
|
|
16
|
+
schema: Schema,
|
|
17
|
+
value?: string | number | ObjectId | DiscriminatorOptions
|
|
18
|
+
): Model<D>;
|
|
19
|
+
discriminator<T, U>(
|
|
20
|
+
name: string | number,
|
|
21
|
+
schema: Schema<T, U>,
|
|
22
|
+
value?: string | number | ObjectId | DiscriminatorOptions
|
|
23
|
+
): U;
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
interface MongooseBulkWriteOptions {
|
|
@@ -342,6 +350,13 @@ declare module 'mongoose' {
|
|
|
342
350
|
populate(
|
|
343
351
|
doc: any, options: PopulateOptions | Array<PopulateOptions> | string
|
|
344
352
|
): Promise<THydratedDocumentType>;
|
|
353
|
+
populate<Paths>(
|
|
354
|
+
docs: Array<any>,
|
|
355
|
+
options: PopulateOptions | Array<PopulateOptions> | string
|
|
356
|
+
): Promise<Array<MergeType<THydratedDocumentType, Paths>>>;
|
|
357
|
+
populate<Paths>(
|
|
358
|
+
doc: any, options: PopulateOptions | Array<PopulateOptions> | string
|
|
359
|
+
): Promise<MergeType<THydratedDocumentType, Paths>>;
|
|
345
360
|
|
|
346
361
|
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
|
|
347
362
|
validate(): Promise<void>;
|
package/types/query.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ declare module 'mongoose' {
|
|
|
109
109
|
/**
|
|
110
110
|
* If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
|
|
111
111
|
*/
|
|
112
|
-
lean?: boolean | any
|
|
112
|
+
lean?: boolean | Record<string, any>;
|
|
113
113
|
limit?: number;
|
|
114
114
|
maxTimeMS?: number;
|
|
115
115
|
multi?: boolean;
|
|
@@ -532,7 +532,7 @@ declare module 'mongoose' {
|
|
|
532
532
|
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocType | AnyObject, options?: QueryOptions<DocType> | null): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
533
533
|
|
|
534
534
|
/** Specifies which document fields to include or exclude (also known as the query "projection") */
|
|
535
|
-
select(arg: string |
|
|
535
|
+
select(arg: string | string[] | Record<string, number | boolean | object>): this;
|
|
536
536
|
|
|
537
537
|
/** Determines if field selection has been made. */
|
|
538
538
|
selected(): boolean;
|
|
@@ -594,9 +594,6 @@ declare module 'mongoose' {
|
|
|
594
594
|
/** Converts this query to a customized, reusable query constructor with all arguments and options retained. */
|
|
595
595
|
toConstructor<RetType = typeof Query>(): RetType;
|
|
596
596
|
|
|
597
|
-
/** Declare and/or execute this query as an update() operation. */
|
|
598
|
-
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
599
|
-
|
|
600
597
|
/**
|
|
601
598
|
* Declare and/or execute this query as an updateMany() operation. Same as
|
|
602
599
|
* `update()`, except MongoDB will update _all_ documents that match
|
package/types/types.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ declare module 'mongoose' {
|
|
|
61
61
|
|
|
62
62
|
class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
|
|
63
63
|
/** DocumentArray constructor */
|
|
64
|
-
constructor(values:
|
|
64
|
+
constructor(values: (AnyKeys<T> & AnyObject)[]);
|
|
65
65
|
|
|
66
66
|
isMongooseDocumentArray: true;
|
|
67
67
|
|