mongoose 8.19.2 → 8.19.4
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/helpers/schema/getIndexes.js +1 -1
- package/lib/model.js +19 -3
- package/lib/plugins/sharding.js +1 -1
- package/lib/schema.js +4 -0
- package/package.json +9 -9
- package/types/error.d.ts +3 -0
- package/types/inferrawdoctype.d.ts +1 -1
- package/types/models.d.ts +1 -1
- package/types/schematypes.d.ts +1 -1
|
@@ -72,7 +72,7 @@ module.exports = function getIndexes(schema) {
|
|
|
72
72
|
if (index !== false && index !== null && index !== undefined) {
|
|
73
73
|
const field = {};
|
|
74
74
|
const isObject = helperIsObject(index);
|
|
75
|
-
const options = isObject ? index : {};
|
|
75
|
+
const options = isObject ? { ...index } : {};
|
|
76
76
|
const type = typeof index === 'string' ? index :
|
|
77
77
|
isObject ? index.type :
|
|
78
78
|
false;
|
package/lib/model.js
CHANGED
|
@@ -802,8 +802,18 @@ Model.prototype.deleteOne = function deleteOne(options) {
|
|
|
802
802
|
}
|
|
803
803
|
}
|
|
804
804
|
|
|
805
|
-
query.pre(function queryPreDeleteOne(
|
|
806
|
-
|
|
805
|
+
query.pre(async function queryPreDeleteOne() {
|
|
806
|
+
await new Promise((resolve, reject) => {
|
|
807
|
+
self.constructor._middleware.execPre('deleteOne', self, [self], err => {
|
|
808
|
+
if (err) reject(err);
|
|
809
|
+
else resolve();
|
|
810
|
+
});
|
|
811
|
+
});
|
|
812
|
+
// Apply custom where conditions _after_ document deleteOne middleware for
|
|
813
|
+
// consistency with save() - sharding plugin needs to set $where
|
|
814
|
+
if (self.$where != null) {
|
|
815
|
+
this.where(self.$where);
|
|
816
|
+
}
|
|
807
817
|
});
|
|
808
818
|
query.pre(function callSubdocPreHooks(cb) {
|
|
809
819
|
each(self.$getAllSubdocs(), (subdoc, cb) => {
|
|
@@ -1308,7 +1318,11 @@ Model.syncIndexes = async function syncIndexes(options) {
|
|
|
1308
1318
|
throw new MongooseError('Model.syncIndexes() no longer accepts a callback');
|
|
1309
1319
|
}
|
|
1310
1320
|
|
|
1311
|
-
const autoCreate = options?.autoCreate ??
|
|
1321
|
+
const autoCreate = options?.autoCreate ??
|
|
1322
|
+
this.schema.options?.autoCreate ??
|
|
1323
|
+
this.db.config.autoCreate ??
|
|
1324
|
+
this.db.base?.options?.autoCreate ??
|
|
1325
|
+
true;
|
|
1312
1326
|
|
|
1313
1327
|
if (autoCreate) {
|
|
1314
1328
|
try {
|
|
@@ -3066,6 +3080,8 @@ Model.$__insertMany = function(arr, options, callback) {
|
|
|
3066
3080
|
() => { callback(null, doc); },
|
|
3067
3081
|
error => {
|
|
3068
3082
|
if (ordered === false) {
|
|
3083
|
+
// Add index to validation error so users can identify which document failed
|
|
3084
|
+
error.index = index;
|
|
3069
3085
|
validationErrors.push(error);
|
|
3070
3086
|
validationErrorsToOriginalOrder.set(error, index);
|
|
3071
3087
|
results[index] = error;
|
package/lib/plugins/sharding.js
CHANGED
|
@@ -16,7 +16,7 @@ module.exports = function shardingPlugin(schema) {
|
|
|
16
16
|
applyWhere.call(this);
|
|
17
17
|
next();
|
|
18
18
|
});
|
|
19
|
-
schema.pre('
|
|
19
|
+
schema.pre('deleteOne', { document: true, query: false }, function shardingPluginPreRemove(next) {
|
|
20
20
|
applyWhere.call(this);
|
|
21
21
|
next();
|
|
22
22
|
});
|
package/lib/schema.js
CHANGED
|
@@ -1694,6 +1694,10 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
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.');
|
|
1696
1696
|
}
|
|
1697
|
+
|
|
1698
|
+
if (name === 'Union' && typeof cast === 'object') {
|
|
1699
|
+
cast.parentSchema = this;
|
|
1700
|
+
}
|
|
1697
1701
|
}
|
|
1698
1702
|
|
|
1699
1703
|
return new MongooseTypes.Array(path, cast || MongooseTypes.Mixed, obj, options);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "8.19.
|
|
4
|
+
"version": "8.19.4",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"sift": "17.1.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@ark/attest": "0.
|
|
33
|
-
"@babel/core": "7.28.
|
|
34
|
-
"@babel/preset-env": "7.28.
|
|
35
|
-
"@mongodb-js/mongodb-downloader": "^0.
|
|
32
|
+
"@ark/attest": "0.53.0",
|
|
33
|
+
"@babel/core": "7.28.5",
|
|
34
|
+
"@babel/preset-env": "7.28.5",
|
|
35
|
+
"@mongodb-js/mongodb-downloader": "^1.0.0",
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
37
37
|
"@typescript-eslint/parser": "^8.19.1",
|
|
38
38
|
"acquit": "1.4.0",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"lodash.isequal": "4.5.0",
|
|
56
56
|
"lodash.isequalwith": "4.4.0",
|
|
57
57
|
"markdownlint-cli2": "^0.18.1",
|
|
58
|
-
"marked": "
|
|
58
|
+
"marked": "16.4.1",
|
|
59
59
|
"mkdirp": "^3.0.1",
|
|
60
60
|
"mocha": "11.7.4",
|
|
61
61
|
"moment": "2.30.1",
|
|
62
|
-
"mongodb-memory-server": "10.
|
|
63
|
-
"mongodb-runner": "^
|
|
62
|
+
"mongodb-memory-server": "10.3.0",
|
|
63
|
+
"mongodb-runner": "^6.0.0",
|
|
64
64
|
"ncp": "^2.0.0",
|
|
65
65
|
"nyc": "15.1.0",
|
|
66
66
|
"pug": "3.0.3",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"tsd": "0.33.0",
|
|
71
71
|
"typescript": "5.9.3",
|
|
72
72
|
"uuid": "11.1.0",
|
|
73
|
-
"webpack": "5.102.
|
|
73
|
+
"webpack": "5.102.1"
|
|
74
74
|
},
|
|
75
75
|
"directories": {
|
|
76
76
|
"lib": "./lib/mongoose"
|
package/types/error.d.ts
CHANGED
|
@@ -91,6 +91,9 @@ declare module 'mongoose' {
|
|
|
91
91
|
errors: { [path: string]: ValidatorError | CastError };
|
|
92
92
|
addError: (path: string, error: ValidatorError | CastError) => void;
|
|
93
93
|
|
|
94
|
+
/** Index of the document in insertMany() that failed validation (only set for unordered insertMany) */
|
|
95
|
+
index?: number;
|
|
96
|
+
|
|
94
97
|
constructor(instance?: MongooseError);
|
|
95
98
|
}
|
|
96
99
|
|
|
@@ -60,7 +60,7 @@ declare module 'mongoose' {
|
|
|
60
60
|
[PathValueType] extends [neverOrAny] ? PathValueType
|
|
61
61
|
: PathValueType extends Schema ? InferSchemaType<PathValueType>
|
|
62
62
|
: PathValueType extends ReadonlyArray<infer Item> ?
|
|
63
|
-
Item extends never ? any[]
|
|
63
|
+
[Item] extends [never] ? any[]
|
|
64
64
|
: Item extends Schema ?
|
|
65
65
|
// If Item is a schema, infer its type.
|
|
66
66
|
Array<InferSchemaType<Item>>
|
package/types/models.d.ts
CHANGED
package/types/schematypes.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ declare module 'mongoose' {
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* If true, attach a required validator to this path, which ensures this path
|
|
100
|
-
*
|
|
100
|
+
* cannot be set to a nullish value. If a function, Mongoose calls the
|
|
101
101
|
* function and only checks for nullish values if the function returns a truthy value.
|
|
102
102
|
*/
|
|
103
103
|
required?:
|