mongoose 9.9.4 → 9.9.5

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
@@ -28,6 +28,7 @@ const compile = require('./helpers/document/compile').compile;
28
28
  const defineKey = require('./helpers/document/compile').defineKey;
29
29
  const firstKey = require('./helpers/firstKey');
30
30
  const flatten = require('./helpers/common').flatten;
31
+ const getConstructorName = require('./helpers/getConstructorName');
31
32
  const getEmbeddedDiscriminatorPath = require('./helpers/document/getEmbeddedDiscriminatorPath');
32
33
  const getKeysInSchemaOrder = require('./helpers/schema/getKeysInSchemaOrder');
33
34
  const getSubdocumentStrictValue = require('./helpers/schema/getSubdocumentStrictValue');
@@ -3589,6 +3590,15 @@ Document.prototype.invalidate = function(path, err, val, kind) {
3589
3590
  return this.$__.validationError;
3590
3591
  }
3591
3592
 
3593
+ // Set the model on cast errors with a custom message so `{MODEL}` gets
3594
+ // replaced for document validation, not just query casting (gh-8300)
3595
+ if (typeof err.setModel === 'function') {
3596
+ const owner = this.ownerDocument();
3597
+ if (getConstructorName(owner) === 'model') {
3598
+ err.setModel(owner.constructor);
3599
+ }
3600
+ }
3601
+
3592
3602
  this.$__.validationError.addError(path, err);
3593
3603
  return this.$__.validationError;
3594
3604
  };
@@ -7,19 +7,9 @@
7
7
  module.exports = function isPathSelectedInclusive(fields, path) {
8
8
  const chunks = path.split('.');
9
9
  let cur = '';
10
- let j;
11
- let keys;
12
- let numKeys;
13
10
  for (let i = 0; i < chunks.length; ++i) {
14
- cur += cur.length ? '.' : '' + chunks[i];
11
+ cur += cur.length ? '.' + chunks[i] : chunks[i];
15
12
  if (fields[cur]) {
16
- keys = Object.keys(fields);
17
- numKeys = keys.length;
18
- for (j = 0; j < numKeys; ++j) {
19
- if (keys[i].indexOf(cur + '.') === 0 && keys[i].indexOf(path) !== 0) {
20
- continue;
21
- }
22
- }
23
13
  return true;
24
14
  }
25
15
  }
@@ -264,7 +264,7 @@ function castComparison(val, schema, strictQuery) {
264
264
  throw new StrictModeError(path);
265
265
  }
266
266
  } else {
267
- val[1] = _castExpression(val[1]);
267
+ val[1] = _castExpression(val[1], schema, strictQuery);
268
268
  }
269
269
 
270
270
  return val;
package/lib/model.js CHANGED
@@ -1431,7 +1431,7 @@ Model.dropSearchIndex = async function dropSearchIndex(name) {
1431
1431
  * const Customer = mongoose.model('Customer', schema);
1432
1432
  *
1433
1433
  * await Customer.createSearchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
1434
- * const res = await Customer.listSearchIndexes(); // Includes `[{ name: 'test' }]`
1434
+ * const res = await Customer.listSearchIndexes(); // Includes `[{ id: '...', name: 'test', status: 'READY', queryable: true, latestDefinition: { ... } }]`
1435
1435
  *
1436
1436
  * @param {object} [options]
1437
1437
  * @return {Promise<Array>}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "9.9.4",
4
+ "version": "9.9.5",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -40,18 +40,18 @@
40
40
  "c8": "12.0.0",
41
41
  "cheerio": "1.2.0",
42
42
  "dox": "1.0.0",
43
- "eslint": "10.8.0",
43
+ "eslint": "10.9.1",
44
44
  "eslint-plugin-mocha-no-only": "1.2.0",
45
45
  "express": "5.2.1",
46
46
  "fs-extra": "~11.4.0",
47
47
  "glob": "^13.0.6",
48
48
  "globals": "^17.4.0",
49
- "highlight.js": "11.11.1",
49
+ "highlight.js": "11.12.0",
50
50
  "linkinator": "8.x",
51
51
  "lodash.isequal": "4.5.0",
52
52
  "lodash.isequalwith": "4.4.0",
53
53
  "markdownlint-cli2": "0.23.2",
54
- "marked": "18.0.7",
54
+ "marked": "18.0.11",
55
55
  "mkdirp": "^3.0.1",
56
56
  "mocha": "12.0.0-rc.5",
57
57
  "moment": "2.30.1",
@@ -64,7 +64,7 @@
64
64
  "tstyche": "^7.0.0",
65
65
  "typescript": "5.9.3",
66
66
  "typescript-eslint": "^8.31.1",
67
- "uuid": "14.0.1",
67
+ "uuid": "14.0.2",
68
68
  "xss": "1.0.15"
69
69
  },
70
70
  "directories": {
@@ -94,4 +94,77 @@ declare module 'mongoose' {
94
94
  };
95
95
 
96
96
  type SearchIndexDescription = mongodb.SearchIndexDescription;
97
+
98
+ type SearchIndexStatus = 'BUILDING' | 'DELETING' | 'DOES_NOT_EXIST' | 'FAILED' | 'PENDING' | 'READY' | 'STALE';
99
+
100
+ type SearchIndexSynonymMappingStatus = 'BUILDING' | 'FAILED' | 'READY';
101
+
102
+ /** The status of one synonym mapping on one search node. */
103
+ interface SearchIndexSynonymMappingDetail {
104
+ /** The build state of the synonym mapping. */
105
+ status: SearchIndexSynonymMappingStatus;
106
+ /** Whether the synonym mapping can serve queries. */
107
+ queryable: boolean;
108
+ /** The error that made the synonym mapping fail, only returned when its status is `FAILED`. */
109
+ message?: string;
110
+ }
111
+
112
+ /** The status of one index generation, active or staged, on one search node. */
113
+ interface SearchIndexGenerationDetail {
114
+ /** The build state of this index generation. */
115
+ status: SearchIndexStatus;
116
+ /** Whether this index generation is ready to serve queries. */
117
+ queryable: boolean;
118
+ /** When the definition this generation builds with was created, and its version number. */
119
+ definitionVersion: { version: number, createdAt: NativeDate };
120
+ /** The definition this generation builds with. */
121
+ definition: AnyObject;
122
+ /** The status of this generation's synonym mappings, only returned when the index defines any. */
123
+ synonymMappingStatus?: SearchIndexSynonymMappingStatus;
124
+ /** The status of each of this generation's synonym mappings, keyed by mapping name. */
125
+ synonymMappingStatusDetail?: Array<Record<string, SearchIndexSynonymMappingDetail>>;
126
+ }
127
+
128
+ /** The status of the index on one search node (`mongot`). */
129
+ interface SearchIndexStatusDetail {
130
+ /** The hostname of the search node, in the form `<replSetName>.<server.name>.<server.id>`. */
131
+ hostname: string;
132
+ /** The build state of the index on this search node. */
133
+ status: SearchIndexStatus;
134
+ /** Whether the index is ready to serve queries on this search node. */
135
+ queryable: boolean;
136
+ /** The active index on this search node. */
137
+ mainIndex: SearchIndexGenerationDetail;
138
+ /** The index being built in the background, only returned while an existing index is being updated. */
139
+ stagedIndex?: SearchIndexGenerationDetail;
140
+ }
141
+
142
+ /**
143
+ * A single entry of the [`$listSearchIndexes`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/)
144
+ * output, as returned by `Model.listSearchIndexes()`.
145
+ */
146
+ interface SearchIndexInfo {
147
+ /** The index's unique identifier, a hex string rather than an ObjectId. */
148
+ id: string;
149
+ /** The name of the index. */
150
+ name: string;
151
+ /** The type of the index. Only returned for Atlas deployments. */
152
+ type?: 'search' | 'vectorSearch';
153
+ /** The build state of the index. */
154
+ status: SearchIndexStatus;
155
+ /** Whether the index is ready to serve queries. */
156
+ queryable: boolean;
157
+ /** The version number of the most recent definition. */
158
+ latestVersion?: number;
159
+ /** When the most recent definition was created, and its version number. */
160
+ latestDefinitionVersion?: { version: number, createdAt: NativeDate };
161
+ /** The most recent definition of the index. */
162
+ latestDefinition: AnyObject;
163
+ /** The status of the index on each individual search node. */
164
+ statusDetail?: SearchIndexStatusDetail[];
165
+ /** The status of the index's synonym mappings, only returned when the index defines any. */
166
+ synonymMappingStatus?: SearchIndexSynonymMappingStatus;
167
+ /** The status of each synonym mapping on each search node, keyed by mapping name. */
168
+ synonymMappingStatusDetail?: Array<Record<string, SearchIndexSynonymMappingDetail>>;
169
+ }
97
170
  }
package/types/models.d.ts CHANGED
@@ -658,7 +658,7 @@ declare module 'mongoose' {
658
658
  * List all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) on this model's collection.
659
659
  * This function only works when connected to MongoDB Atlas.
660
660
  */
661
- listSearchIndexes(options?: mongodb.ListSearchIndexesOptions): Promise<Array<{ name: string }>>;
661
+ listSearchIndexes(options?: mongodb.ListSearchIndexesOptions): Promise<Array<SearchIndexInfo>>;
662
662
 
663
663
  /** The name of the model */
664
664
  modelName: string;