mongoose 8.13.0 → 8.13.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/lib/document.js CHANGED
@@ -2721,12 +2721,33 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
2721
2721
  function addToPaths(p) { paths.add(p); }
2722
2722
 
2723
2723
  if (!isNestedValidate) {
2724
- // If we're validating a subdocument, all this logic will run anyway on the top-level document, so skip for subdocuments
2725
- const subdocs = doc.$getAllSubdocs({ useCache: true });
2724
+ // If we're validating a subdocument, all this logic will run anyway on the top-level document, so skip for subdocuments.
2725
+ // But only run for top-level subdocuments, because we're looking for subdocuments that are not modified at top-level but
2726
+ // have a modified path. If that is the case, we will run validation on the top-level subdocument, and via that run validation
2727
+ // on any subdocuments down to the modified path.
2728
+ const topLevelSubdocs = [];
2729
+ for (const path of Object.keys(doc.$__schema.paths)) {
2730
+ const schemaType = doc.$__schema.path(path);
2731
+ if (schemaType.$isSingleNested) {
2732
+ const subdoc = doc.$get(path);
2733
+ if (subdoc) {
2734
+ topLevelSubdocs.push(subdoc);
2735
+ }
2736
+ } else if (schemaType.$isMongooseDocumentArray) {
2737
+ const arr = doc.$get(path);
2738
+ if (arr && arr.length) {
2739
+ for (const subdoc of arr) {
2740
+ if (subdoc) {
2741
+ topLevelSubdocs.push(subdoc);
2742
+ }
2743
+ }
2744
+ }
2745
+ }
2746
+ }
2726
2747
  const modifiedPaths = doc.modifiedPaths();
2727
- for (const subdoc of subdocs) {
2748
+ for (const subdoc of topLevelSubdocs) {
2728
2749
  if (subdoc.$basePath) {
2729
- const fullPathToSubdoc = subdoc.$isSingleNested ? subdoc.$__pathRelativeToParent() : subdoc.$__fullPathWithIndexes();
2750
+ const fullPathToSubdoc = subdoc.$__pathRelativeToParent();
2730
2751
 
2731
2752
  // Remove child paths for now, because we'll be validating the whole
2732
2753
  // subdoc.
@@ -2736,11 +2757,12 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
2736
2757
  paths.delete(fullPathToSubdoc + '.' + modifiedPath);
2737
2758
  }
2738
2759
 
2760
+ const subdocParent = subdoc.$parent();
2739
2761
  if (doc.$isModified(fullPathToSubdoc, null, modifiedPaths) &&
2740
2762
  // Avoid using isDirectModified() here because that does additional checks on whether the parent path
2741
2763
  // is direct modified, which can cause performance issues re: gh-14897
2742
- !doc.$__.activePaths.getStatePaths('modify').hasOwnProperty(fullPathToSubdoc) &&
2743
- !doc.$isDefault(fullPathToSubdoc)) {
2764
+ !subdocParent.$__.activePaths.getStatePaths('modify').hasOwnProperty(fullPathToSubdoc) &&
2765
+ !subdocParent.$isDefault(fullPathToSubdoc)) {
2744
2766
  paths.add(fullPathToSubdoc);
2745
2767
 
2746
2768
  if (doc.$__.pathsToScopes == null) {
@@ -78,7 +78,12 @@ function assignRawDocsToIdStructure(rawIds, resultDocs, resultOrder, options, re
78
78
  continue;
79
79
  }
80
80
 
81
- sid = String(id);
81
+ if (id?.constructor?.name === 'Binary' && id.sub_type === 4 && typeof id.toUUID === 'function') {
82
+ // Workaround for gh-15315 because Mongoose UUIDs don't use BSON UUIDs yet.
83
+ sid = String(id.toUUID());
84
+ } else {
85
+ sid = String(id);
86
+ }
82
87
  doc = resultDocs[sid];
83
88
  // If user wants separate copies of same doc, use this option
84
89
  if (options.clone && doc != null) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.13.0",
4
+ "version": "8.13.2",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -29,7 +29,7 @@
29
29
  "sift": "17.1.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@babel/core": "7.26.9",
32
+ "@babel/core": "7.26.10",
33
33
  "@babel/preset-env": "7.26.9",
34
34
  "@typescript-eslint/eslint-plugin": "^8.19.1",
35
35
  "@typescript-eslint/parser": "^8.19.1",
@@ -62,7 +62,7 @@
62
62
  "nyc": "15.1.0",
63
63
  "pug": "3.0.3",
64
64
  "q": "1.5.1",
65
- "sinon": "19.0.2",
65
+ "sinon": "20.0.0",
66
66
  "stream-browserify": "3.0.0",
67
67
  "tsd": "0.31.2",
68
68
  "typescript": "5.7.3",
@@ -97,7 +97,7 @@ declare module 'mongoose' {
97
97
  * The default value for this path. If a function, Mongoose executes the function
98
98
  * and uses the return value as the default.
99
99
  */
100
- default?: DefaultType<T> | ((this: EnforcedDocType, doc: any) => DefaultType<T>) | null;
100
+ default?: DefaultType<T> | ((this: EnforcedDocType, doc: any) => DefaultType<T> | null | undefined) | null;
101
101
 
102
102
  /**
103
103
  * The model that `populate()` should use if populating this path.