mongoose 8.7.0 → 8.7.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/dist/browser.umd.js +1 -1
- package/lib/helpers/document/cleanModifiedSubpaths.js +13 -3
- package/lib/helpers/populate/getModelsMapForPopulate.js +19 -5
- package/lib/helpers/populate/modelNamesFromRefPath.js +0 -2
- package/lib/model.js +4 -5
- package/lib/options.js +2 -1
- package/lib/schema/buffer.js +8 -0
- package/package.json +9 -9
- package/types/index.d.ts +13 -1
- package/types/inferschematype.d.ts +10 -2
- package/types/models.d.ts +2 -0
- package/types/query.d.ts +1 -1
|
@@ -25,11 +25,21 @@ module.exports = function cleanModifiedSubpaths(doc, path, options) {
|
|
|
25
25
|
++deleted;
|
|
26
26
|
|
|
27
27
|
if (doc.$isSubdocument) {
|
|
28
|
-
|
|
29
|
-
const fullPath = doc.$__fullPath(modifiedPath);
|
|
30
|
-
owner.$__.activePaths.clearPath(fullPath);
|
|
28
|
+
cleanParent(doc, modifiedPath);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
return deleted;
|
|
35
33
|
};
|
|
34
|
+
|
|
35
|
+
function cleanParent(doc, path, seen = new Set()) {
|
|
36
|
+
if (seen.has(doc)) {
|
|
37
|
+
throw new Error('Infinite subdocument loop: subdoc with _id ' + doc._id + ' is a parent of itself');
|
|
38
|
+
}
|
|
39
|
+
const parent = doc.$parent();
|
|
40
|
+
const newPath = doc.$__pathRelativeToParent(void 0, false) + '.' + path;
|
|
41
|
+
parent.$__.activePaths.clearPath(newPath);
|
|
42
|
+
if (parent.$isSubdocument) {
|
|
43
|
+
cleanParent(parent, newPath, seen);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -478,9 +478,10 @@ function addModelNamesToMap(model, map, available, modelNames, options, data, re
|
|
|
478
478
|
return;
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
-
|
|
481
|
+
const flatModelNames = utils.array.flatten(modelNames);
|
|
482
|
+
let k = flatModelNames.length;
|
|
482
483
|
while (k--) {
|
|
483
|
-
let modelName =
|
|
484
|
+
let modelName = flatModelNames[k];
|
|
484
485
|
if (modelName == null) {
|
|
485
486
|
continue;
|
|
486
487
|
}
|
|
@@ -503,11 +504,10 @@ function addModelNamesToMap(model, map, available, modelNames, options, data, re
|
|
|
503
504
|
}
|
|
504
505
|
|
|
505
506
|
let ids = ret;
|
|
506
|
-
const flat = Array.isArray(ret) ? utils.array.flatten(ret) : [];
|
|
507
507
|
|
|
508
508
|
const modelNamesForRefPath = data.modelNamesInOrder ? data.modelNamesInOrder : modelNames;
|
|
509
|
-
if (data.isRefPath && Array.isArray(ret) &&
|
|
510
|
-
ids =
|
|
509
|
+
if (data.isRefPath && Array.isArray(ret) && ret.length === modelNamesForRefPath.length) {
|
|
510
|
+
ids = matchIdsToRefPaths(ret, modelNamesForRefPath, modelName);
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
const perDocumentLimit = options.perDocumentLimit == null ?
|
|
@@ -569,6 +569,20 @@ function _getModelFromConn(conn, modelName) {
|
|
|
569
569
|
return conn.model(modelName);
|
|
570
570
|
}
|
|
571
571
|
|
|
572
|
+
function matchIdsToRefPaths(ids, refPaths, refPathToFind) {
|
|
573
|
+
if (!Array.isArray(refPaths)) {
|
|
574
|
+
return refPaths === refPathToFind
|
|
575
|
+
? Array.isArray(ids)
|
|
576
|
+
? utils.array.flatten(ids)
|
|
577
|
+
: [ids]
|
|
578
|
+
: [];
|
|
579
|
+
}
|
|
580
|
+
if (Array.isArray(ids) && Array.isArray(refPaths)) {
|
|
581
|
+
return ids.flatMap((id, index) => matchIdsToRefPaths(id, refPaths[index], refPathToFind));
|
|
582
|
+
}
|
|
583
|
+
return [];
|
|
584
|
+
}
|
|
585
|
+
|
|
572
586
|
/*!
|
|
573
587
|
* ignore
|
|
574
588
|
*/
|
package/lib/model.js
CHANGED
|
@@ -75,8 +75,7 @@ const subclassedSymbol = Symbol('mongoose#Model#subclassed');
|
|
|
75
75
|
const { VERSION_INC, VERSION_WHERE, VERSION_ALL } = Document;
|
|
76
76
|
|
|
77
77
|
const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
|
|
78
|
-
bson: true
|
|
79
|
-
flattenObjectIds: false
|
|
78
|
+
bson: true
|
|
80
79
|
});
|
|
81
80
|
|
|
82
81
|
/**
|
|
@@ -3772,7 +3771,7 @@ Model.hydrate = function(obj, projection, options) {
|
|
|
3772
3771
|
* const res = await Person.updateMany({ name: /Stark$/ }, { isDeleted: true });
|
|
3773
3772
|
* res.matchedCount; // Number of documents matched
|
|
3774
3773
|
* res.modifiedCount; // Number of documents modified
|
|
3775
|
-
* res.acknowledged; // Boolean indicating
|
|
3774
|
+
* res.acknowledged; // Boolean indicating the MongoDB server received the operation. This may be false if Mongoose did not send an update to the server because the update was empty.
|
|
3776
3775
|
* res.upsertedId; // null or an id containing a document that had to be upserted.
|
|
3777
3776
|
* res.upsertedCount; // Number indicating how many documents had to be upserted. Will either be 0 or 1.
|
|
3778
3777
|
*
|
|
@@ -3812,7 +3811,7 @@ Model.updateMany = function updateMany(conditions, doc, options) {
|
|
|
3812
3811
|
* const res = await Person.updateOne({ name: 'Jean-Luc Picard' }, { ship: 'USS Enterprise' });
|
|
3813
3812
|
* res.matchedCount; // Number of documents matched
|
|
3814
3813
|
* res.modifiedCount; // Number of documents modified
|
|
3815
|
-
* res.acknowledged; // Boolean indicating
|
|
3814
|
+
* res.acknowledged; // Boolean indicating the MongoDB server received the operation. This may be false if Mongoose did not send an update to the server because the update was empty.
|
|
3816
3815
|
* res.upsertedId; // null or an id containing a document that had to be upserted.
|
|
3817
3816
|
* res.upsertedCount; // Number indicating how many documents had to be upserted. Will either be 0 or 1.
|
|
3818
3817
|
*
|
|
@@ -3850,7 +3849,7 @@ Model.updateOne = function updateOne(conditions, doc, options) {
|
|
|
3850
3849
|
* const res = await Person.replaceOne({ _id: 24601 }, { name: 'Jean Valjean' });
|
|
3851
3850
|
* res.matchedCount; // Number of documents matched
|
|
3852
3851
|
* res.modifiedCount; // Number of documents modified
|
|
3853
|
-
* res.acknowledged; // Boolean indicating
|
|
3852
|
+
* res.acknowledged; // Boolean indicating the MongoDB server received the operation.
|
|
3854
3853
|
* res.upsertedId; // null or an id containing a document that had to be upserted.
|
|
3855
3854
|
* res.upsertedCount; // Number indicating how many documents had to be upserted. Will either be 0 or 1.
|
|
3856
3855
|
*
|
package/lib/options.js
CHANGED
package/lib/schema/buffer.js
CHANGED
|
@@ -219,6 +219,14 @@ SchemaBuffer.prototype.cast = function(value, doc, init) {
|
|
|
219
219
|
return ret;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
if (utils.isPOJO(value) && (value.$binary instanceof Binary || typeof value.$binary === 'string')) {
|
|
223
|
+
const buf = this.cast(Buffer.from(value.$binary, 'base64'));
|
|
224
|
+
if (value.$type != null) {
|
|
225
|
+
buf._subtype = value.$type;
|
|
226
|
+
return buf;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
222
230
|
throw new CastError('Buffer', value, this.path, null, this);
|
|
223
231
|
};
|
|
224
232
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "8.7.
|
|
4
|
+
"version": "8.7.2",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -52,22 +52,22 @@
|
|
|
52
52
|
"highlight.js": "11.10.0",
|
|
53
53
|
"lodash.isequal": "4.5.0",
|
|
54
54
|
"lodash.isequalwith": "4.4.0",
|
|
55
|
-
"markdownlint-cli2": "^0.
|
|
56
|
-
"marked": "14.1.
|
|
55
|
+
"markdownlint-cli2": "^0.14.0",
|
|
56
|
+
"marked": "14.1.2",
|
|
57
57
|
"mkdirp": "^3.0.1",
|
|
58
58
|
"mocha": "10.7.3",
|
|
59
59
|
"moment": "2.30.1",
|
|
60
|
-
"mongodb-memory-server": "10.0.
|
|
60
|
+
"mongodb-memory-server": "10.0.1",
|
|
61
61
|
"ncp": "^2.0.0",
|
|
62
62
|
"nyc": "15.1.0",
|
|
63
63
|
"pug": "3.0.3",
|
|
64
64
|
"q": "1.5.1",
|
|
65
|
-
"sinon": "
|
|
65
|
+
"sinon": "19.0.2",
|
|
66
66
|
"stream-browserify": "3.0.0",
|
|
67
|
-
"tsd": "0.31.
|
|
68
|
-
"typescript": "5.
|
|
67
|
+
"tsd": "0.31.2",
|
|
68
|
+
"typescript": "5.6.2",
|
|
69
69
|
"uuid": "10.0.0",
|
|
70
|
-
"webpack": "5.
|
|
70
|
+
"webpack": "5.95.0"
|
|
71
71
|
},
|
|
72
72
|
"directories": {
|
|
73
73
|
"lib": "./lib/mongoose"
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"lint": "eslint .",
|
|
93
93
|
"lint-js": "eslint . --ext .js --ext .cjs",
|
|
94
94
|
"lint-ts": "eslint . --ext .ts",
|
|
95
|
-
"lint-md": "markdownlint-cli2 \"**/*.md\"",
|
|
95
|
+
"lint-md": "markdownlint-cli2 \"**/*.md\" \"#node_modules\" \"#benchmarks\"",
|
|
96
96
|
"build-browser": "(rm ./dist/* || true) && node ./scripts/build-browser.js",
|
|
97
97
|
"prepublishOnly": "npm run build-browser",
|
|
98
98
|
"release": "git pull && git push origin master --tags && npm publish",
|
package/types/index.d.ts
CHANGED
|
@@ -706,6 +706,18 @@ declare module 'mongoose' {
|
|
|
706
706
|
[K in keyof T]: FlattenProperty<T[K]>;
|
|
707
707
|
};
|
|
708
708
|
|
|
709
|
+
export type BufferToBinary<T> = T extends TreatAsPrimitives ? T : T extends Record<string, any> ? {
|
|
710
|
+
[K in keyof T]: T[K] extends Buffer
|
|
711
|
+
? mongodb.Binary
|
|
712
|
+
: T[K] extends (Buffer | null | undefined)
|
|
713
|
+
? mongodb.Binary | null | undefined
|
|
714
|
+
: T[K] extends Types.DocumentArray<infer ItemType>
|
|
715
|
+
? Types.DocumentArray<BufferToBinary<ItemType>>
|
|
716
|
+
: T[K] extends Types.Subdocument<unknown, unknown, infer SubdocType>
|
|
717
|
+
? HydratedSingleSubdocument<SubdocType>
|
|
718
|
+
: BufferToBinary<T[K]>;
|
|
719
|
+
} : T;
|
|
720
|
+
|
|
709
721
|
/**
|
|
710
722
|
* Separate type is needed for properties of union type (for example, Types.DocumentArray | undefined) to apply conditional check to each member of it
|
|
711
723
|
* https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
|
|
@@ -716,7 +728,7 @@ declare module 'mongoose' {
|
|
|
716
728
|
? Types.DocumentArray<FlattenMaps<ItemType>> : FlattenMaps<T>;
|
|
717
729
|
|
|
718
730
|
export type actualPrimitives = string | boolean | number | bigint | symbol | null | undefined;
|
|
719
|
-
export type TreatAsPrimitives = actualPrimitives | NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId | Buffer | Function;
|
|
731
|
+
export type TreatAsPrimitives = actualPrimitives | NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId | Buffer | Function | mongodb.Binary;
|
|
720
732
|
|
|
721
733
|
export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
|
|
722
734
|
|
|
@@ -183,8 +183,16 @@ type TypeHint<T> = T extends { __typehint: infer U } ? U: never;
|
|
|
183
183
|
* @param {TypeKey} TypeKey A generic refers to document definition.
|
|
184
184
|
*/
|
|
185
185
|
type ObtainDocumentPathType<PathValueType, TypeKey extends string = DefaultTypeKey> = ResolvePathType<
|
|
186
|
-
PathValueType extends PathWithTypePropertyBaseType<TypeKey>
|
|
187
|
-
PathValueType extends PathWithTypePropertyBaseType<TypeKey>
|
|
186
|
+
PathValueType extends PathWithTypePropertyBaseType<TypeKey>
|
|
187
|
+
? PathValueType[TypeKey] extends PathWithTypePropertyBaseType<TypeKey>
|
|
188
|
+
? PathValueType
|
|
189
|
+
: PathValueType[TypeKey]
|
|
190
|
+
: PathValueType,
|
|
191
|
+
PathValueType extends PathWithTypePropertyBaseType<TypeKey>
|
|
192
|
+
? PathValueType[TypeKey] extends PathWithTypePropertyBaseType<TypeKey>
|
|
193
|
+
? {}
|
|
194
|
+
: Omit<PathValueType, TypeKey>
|
|
195
|
+
: {},
|
|
188
196
|
TypeKey,
|
|
189
197
|
TypeHint<PathValueType>
|
|
190
198
|
>;
|
package/types/models.d.ts
CHANGED
package/types/query.d.ts
CHANGED
|
@@ -211,7 +211,7 @@ declare module 'mongoose' {
|
|
|
211
211
|
type QueryOpThatReturnsDocument = 'find' | 'findOne' | 'findOneAndUpdate' | 'findOneAndReplace' | 'findOneAndDelete';
|
|
212
212
|
|
|
213
213
|
type GetLeanResultType<RawDocType, ResultType, QueryOp> = QueryOp extends QueryOpThatReturnsDocument
|
|
214
|
-
? (ResultType extends any[] ? Require_id<FlattenMaps<RawDocType
|
|
214
|
+
? (ResultType extends any[] ? Require_id<BufferToBinary<FlattenMaps<RawDocType>>>[] : Require_id<BufferToBinary<FlattenMaps<RawDocType>>>)
|
|
215
215
|
: ResultType;
|
|
216
216
|
|
|
217
217
|
type MergePopulatePaths<RawDocType, ResultType, QueryOp, Paths, TQueryHelpers, TInstanceMethods = Record<string, never>> = QueryOp extends QueryOpThatReturnsDocument
|