@depup/mongoose 9.8.0-depup.0 → 9.8.1-depup.0

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/README.md CHANGED
@@ -13,8 +13,8 @@ npm install @depup/mongoose
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [mongoose](https://www.npmjs.com/package/mongoose) @ 9.8.0 |
17
- | Processed | 2026-07-21 |
16
+ | Original | [mongoose](https://www.npmjs.com/package/mongoose) @ 9.8.1 |
17
+ | Processed | 2026-07-28 |
18
18
  | Smoke test | passed |
19
19
  | Deps updated | 0 |
20
20
 
package/changes.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "bumped": {},
3
- "timestamp": "2026-07-21T16:17:39.127Z",
3
+ "timestamp": "2026-07-28T00:38:49.300Z",
4
4
  "totalUpdated": 0
5
5
  }
package/lib/document.js CHANGED
@@ -143,7 +143,7 @@ function Document(obj, fields, options) {
143
143
  this.$__.strictMode = schema.options.strict;
144
144
  }
145
145
 
146
- const requiredPaths = schema.requiredPaths(true);
146
+ const requiredPaths = schema.requiredPaths();
147
147
  for (const path of requiredPaths) {
148
148
  this.$__.activePaths.require(path);
149
149
  }
@@ -2975,9 +2975,13 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
2975
2975
  const doValidateOptions = {};
2976
2976
 
2977
2977
  _evaluateRequiredFunctions(doc);
2978
+ // gh-16379: compute the modified-path set at most once and reuse it below, so
2979
+ // checking many required paths doesn't rebuild it per-path (O(required x modified)).
2980
+ let _modifiedPaths;
2981
+ const getModifiedPaths = () => (_modifiedPaths ??= doc.modifiedPaths());
2978
2982
  // only validate required fields when necessary
2979
2983
  let paths = new Set(Object.keys(doc.$__.activePaths.getStatePaths('require')).filter(function(path) {
2980
- if (!doc.$__isSelected(path) && !doc.$isModified(path)) {
2984
+ if (!doc.$__isSelected(path) && !doc.$isModified(path, null, getModifiedPaths())) {
2981
2985
  return false;
2982
2986
  }
2983
2987
  if (path.endsWith('.$*')) {
@@ -3056,7 +3060,7 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
3056
3060
  }
3057
3061
  }
3058
3062
  }
3059
- const modifiedPaths = doc.modifiedPaths();
3063
+ const modifiedPaths = getModifiedPaths();
3060
3064
  for (const subdoc of topLevelSubdocs) {
3061
3065
  if (subdoc.$basePath) {
3062
3066
  const fullPathToSubdoc = subdoc.$__pathRelativeToParent();
@@ -11,6 +11,7 @@ const getConstructorName = require('../getConstructorName');
11
11
  const getDiscriminatorByValue = require('../discriminator/getDiscriminatorByValue');
12
12
  const getEmbeddedDiscriminatorPath = require('./getEmbeddedDiscriminatorPath');
13
13
  const handleImmutable = require('./handleImmutable');
14
+ const isOperator = require('./isOperator');
14
15
  const moveImmutableProperties = require('../update/moveImmutableProperties');
15
16
  const schemaMixedSymbol = require('../../schema/symbols').schemaMixedSymbol;
16
17
  const setDottedPath = require('../path/setDottedPath');
@@ -235,10 +236,25 @@ function walkUpdatePath(schema, obj, op, options, context, filter, prefix) {
235
236
  key = keys[i];
236
237
  val = obj[key];
237
238
 
239
+ const fullPath = prefix + key;
240
+ const isTopLevelOperator = !prefix && isOperator(key);
241
+ let fullPathSchema = isTopLevelOperator ? schema._getSchema(fullPath) : null;
242
+ const isTopLevelNestedDollarPath = isTopLevelOperator && Object.hasOwn(schema.nested, key);
243
+ if (isTopLevelOperator &&
244
+ fullPathSchema == null &&
245
+ !isTopLevelNestedDollarPath) {
246
+ throw new MongooseError('Invalid update: Unexpected modifier "' + key + '" as a key in operator "' + op + '". '
247
+ + 'Did you mean something like { ' + op + ': { fieldName: { ' + key + ': [...] } } }? '
248
+ + 'Modifiers must appear under a valid field path.');
249
+ }
250
+
238
251
  // `$pull` is special because we need to cast the RHS as a query, not as
239
252
  // an update.
240
253
  if (op === '$pull') {
241
- schematype = schema._getSchema(prefix + key);
254
+ if (!isTopLevelOperator) {
255
+ fullPathSchema = schema._getSchema(fullPath);
256
+ }
257
+ schematype = fullPathSchema;
242
258
  if (schematype == null) {
243
259
  const _res = getEmbeddedDiscriminatorPath(schema, obj, filter, prefix + key, options);
244
260
  if (_res.schematype != null) {
@@ -269,10 +285,13 @@ function walkUpdatePath(schema, obj, op, options, context, filter, prefix) {
269
285
  }
270
286
  }
271
287
 
288
+ if (!isTopLevelOperator && op !== '$pull') {
289
+ fullPathSchema = schema._getSchema(fullPath);
290
+ }
291
+ schematype = fullPathSchema;
292
+
272
293
  if (getConstructorName(val) === 'Object') {
273
294
  // watch for embedded doc schemas
274
- schematype = schema._getSchema(prefix + key);
275
-
276
295
  if (schematype == null) {
277
296
  const _res = getEmbeddedDiscriminatorPath(schema, obj, filter, prefix + key, options);
278
297
  if (_res.schematype != null) {
@@ -383,14 +402,12 @@ function walkUpdatePath(schema, obj, op, options, context, filter, prefix) {
383
402
  (utils.isObject(val) && utils.hasOwnKeys(val) === false);
384
403
  }
385
404
  } else {
386
- const isModifier = (key === '$each' || key === '$or' || key === '$and' || key === '$in');
387
- if (isModifier && !prefix) {
388
- throw new MongooseError('Invalid update: Unexpected modifier "' + key + '" as a key in operator. '
389
- + 'Did you mean something like { $addToSet: { fieldName: { $each: [...] } } }? '
390
- + 'Modifiers such as "$each", "$or", "$and", "$in" must appear under a valid field path.');
405
+ const isModifier = !isTopLevelNestedDollarPath && schematype == null &&
406
+ (key === '$each' || key === '$or' || key === '$and' || key === '$in');
407
+ const checkPath = isModifier ? prefix : fullPath;
408
+ if (isModifier) {
409
+ schematype = schema._getSchema(checkPath);
391
410
  }
392
- const checkPath = isModifier ? prefix : prefix + key;
393
- schematype = schema._getSchema(checkPath);
394
411
 
395
412
  // You can use `$setOnInsert` with immutable keys
396
413
  if (op !== '$setOnInsert' &&
package/lib/utils.js CHANGED
@@ -858,11 +858,12 @@ exports.array.unique = function(arr) {
858
858
  ret.push(item);
859
859
  primitives.add(item);
860
860
  } else if (isBsonType(item, 'ObjectId')) {
861
- if (ids.has(item.toString())) {
861
+ const idStr = item.toString();
862
+ if (ids.has(idStr)) {
862
863
  continue;
863
864
  }
864
865
  ret.push(item);
865
- ids.add(item.toString());
866
+ ids.add(idStr);
866
867
  } else {
867
868
  ret.push(item);
868
869
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depup/mongoose",
3
3
  "description": "Mongoose MongoDB ODM (with updated dependencies)",
4
- "version": "9.8.0-depup.0",
4
+ "version": "9.8.1-depup.0",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongoose",
@@ -148,8 +148,8 @@
148
148
  "changes": {},
149
149
  "depsUpdated": 0,
150
150
  "originalPackage": "mongoose",
151
- "originalVersion": "9.8.0",
152
- "processedAt": "2026-07-21T16:17:47.534Z",
151
+ "originalVersion": "9.8.1",
152
+ "processedAt": "2026-07-28T00:39:03.555Z",
153
153
  "smokeTest": "passed"
154
154
  }
155
155
  }
package/types/index.d.ts CHANGED
@@ -150,6 +150,8 @@ declare module 'mongoose' {
150
150
  ? IfAny<U, T & { _id: Types.ObjectId }, T & Required<{ _id: U }>>
151
151
  : T & { _id: Types.ObjectId };
152
152
 
153
+ export type Default_id<T, TSchemaOptions = {}> = TSchemaOptions extends { _id: false } ? T : Require_id<T>;
154
+
153
155
  export type Default__v<T, TSchemaOptions = {}> = TSchemaOptions extends { versionKey: false }
154
156
  ? T
155
157
  : TSchemaOptions extends { versionKey: infer VK }
package/types/models.d.ts CHANGED
@@ -241,7 +241,12 @@ declare module 'mongoose' {
241
241
  base: Mongoose;
242
242
 
243
243
  /** Standard Schema adapter for validating input with this model's schema. */
244
- readonly '~standard': StandardSchemaV1.Props<Default__v<Require_id<TRawDocType>, ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>>>;
244
+ readonly '~standard': StandardSchemaV1.Props<
245
+ Default__v<
246
+ Default_id<TRawDocType, ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>>,
247
+ ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>
248
+ >
249
+ >;
245
250
 
246
251
  /**
247
252
  * If this is a discriminator model, `baseModelName` is the name of
@@ -1225,7 +1230,11 @@ declare module 'mongoose' {
1225
1230
  recompileSchema(): void;
1226
1231
 
1227
1232
  /** Schema the model uses. */
1228
- schema: TSchema;
1233
+ schema: IfAny<
1234
+ TSchema,
1235
+ Schema<TRawDocType, Model<TRawDocType, TQueryHelpers, TInstanceMethods, TVirtuals>, TInstanceMethods, TQueryHelpers, TVirtuals>,
1236
+ TSchema
1237
+ >;
1229
1238
 
1230
1239
  /** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
1231
1240
  updateMany(