@depup/mongoose 9.8.0-depup.0 → 9.9.0-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/lib/schemaType.js CHANGED
@@ -1158,7 +1158,7 @@ SchemaType.prototype.required = function(required, message) {
1158
1158
  return true;
1159
1159
  }
1160
1160
 
1161
- // `$cachedRequired` gets set in `_evaluateRequiredFunctions()` so we
1161
+ // `$cachedRequired` gets set in `_getPathsToValidate()` so we
1162
1162
  // don't call required functions multiple times in one validate call
1163
1163
  // See gh-6801
1164
1164
  if (cachedRequired != null && _this.path in cachedRequired) {
@@ -1292,7 +1292,8 @@ SchemaType.prototype.getDefault = function getDefault(parentDoc, init, options)
1292
1292
  if (
1293
1293
  this.defaultValue === Date.now ||
1294
1294
  this.defaultValue === Array ||
1295
- this.defaultValue.name.toLowerCase() === 'objectid'
1295
+ this.defaultValue.name === 'ObjectId' ||
1296
+ this.defaultValue.name === 'ObjectID'
1296
1297
  ) {
1297
1298
  ret = this.defaultValue.call(context);
1298
1299
  } else {
@@ -1303,7 +1304,7 @@ SchemaType.prototype.getDefault = function getDefault(parentDoc, init, options)
1303
1304
  }
1304
1305
 
1305
1306
  if (ret != null) {
1306
- if (typeof ret === 'object' && !this.options?.shared) {
1307
+ if (typeof ret === 'object' && ret != null && ret._bsontype !== 'ObjectId' && !this.options?.shared) {
1307
1308
  ret = clone(ret);
1308
1309
  }
1309
1310
 
@@ -34,7 +34,6 @@ StateMachine.ctor = function() {
34
34
  const states = [...arguments];
35
35
 
36
36
  const ctor = function() {
37
- StateMachine.apply(this, arguments);
38
37
  this.paths = {};
39
38
  this.states = {};
40
39
  };
@@ -79,6 +78,28 @@ StateMachine.prototype._changeState = function _changeState(path, nextState) {
79
78
  this.states[nextState][path] = true;
80
79
  };
81
80
 
81
+ /*!
82
+ * ignore
83
+ */
84
+
85
+ StateMachine.prototype.clearAllExcept = function clearAllExcept(state) {
86
+ // State buckets are created lazily, so `states[state]` may not exist yet.
87
+ const bucket = this.states[state];
88
+ const keys = bucket == null ? [] : Object.keys(bucket);
89
+ if (keys.length === 0) {
90
+ this.paths = {};
91
+ this.states = {};
92
+ return;
93
+ }
94
+ this.paths = {};
95
+ for (const path of keys) {
96
+ this.paths[path] = state;
97
+ }
98
+ this.states = {
99
+ [state]: this.states[state]
100
+ };
101
+ };
102
+
82
103
  /*!
83
104
  * ignore
84
105
  */
@@ -91,8 +112,6 @@ StateMachine.prototype.clear = function clear(state) {
91
112
  if (keys.length === 0) {
92
113
  return;
93
114
  }
94
- // Replace the bucket rather than deleting each key: repeated `delete` puts
95
- // the object in dictionary mode, which is significantly slower.
96
115
  this.states[state] = {};
97
116
  let i = keys.length;
98
117
 
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.9.0-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.9.0",
152
+ "processedAt": "2026-07-30T16:34:02.048Z",
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 }
@@ -56,12 +56,28 @@ declare module 'mongoose' {
56
56
  type HydratedDocTypeHint<T> = T extends { __hydratedDocTypeHint: infer U } ? U
57
57
  : never;
58
58
 
59
+ type DiscriminatorHydratedKey<TBaseSchema extends Schema> =
60
+ ObtainSchemaGeneric<TBaseSchema, 'TSchemaOptions'> extends infer TSchemaOptions ?
61
+ 'discriminatorKey' extends keyof TSchemaOptions ?
62
+ TSchemaOptions['discriminatorKey'] extends string ? TSchemaOptions['discriminatorKey'] : '__t'
63
+ : '__t'
64
+ : '__t';
65
+
66
+ type DiscriminatorHydratedBaseType<TBaseSchema extends Schema> =
67
+ InferHydratedDocTypeFromSchema<TBaseSchema> extends Record<DiscriminatorHydratedKey<TBaseSchema>, any> ?
68
+ InferHydratedDocTypeFromSchema<TBaseSchema>
69
+ : MergeType<InferHydratedDocTypeFromSchema<TBaseSchema>, { [K in DiscriminatorHydratedKey<TBaseSchema>]?: null }>;
70
+
59
71
  type ResolveDiscriminatorHydratedPathType<TBaseSchema extends Schema, TDiscriminators> =
60
72
  IsAny<TDiscriminators> extends true ? never
61
73
  : TDiscriminators extends Record<string, any> ?
62
- TDiscriminators[keyof TDiscriminators] extends Schema ?
63
- MergeType<InferHydratedDocTypeFromSchema<TBaseSchema>, InferHydratedDocTypeFromSchema<TDiscriminators[keyof TDiscriminators]>>
64
- : never
74
+ DiscriminatorHydratedBaseType<TBaseSchema> |
75
+ {
76
+ [K in keyof TDiscriminators]: TDiscriminators[K] extends Schema ?
77
+ MergeType<InferHydratedDocTypeFromSchema<TBaseSchema>, InferHydratedDocTypeFromSchema<TDiscriminators[K]>> &
78
+ { [KDiscriminatorKey in DiscriminatorHydratedKey<TBaseSchema>]: K }
79
+ : never
80
+ }[keyof TDiscriminators]
65
81
  : never;
66
82
 
67
83
  type HydratedDiscriminatorEnumType<T> = string extends keyof T ? never
@@ -45,12 +45,28 @@ declare module 'mongoose' {
45
45
  type RawDocTypeHint<T> = IsAny<T> extends true ? never
46
46
  : T extends { __rawDocTypeHint: infer U } ? U: never;
47
47
 
48
+ type DiscriminatorRawKey<TBaseSchema extends Schema> =
49
+ ObtainSchemaGeneric<TBaseSchema, 'TSchemaOptions'> extends infer TSchemaOptions ?
50
+ 'discriminatorKey' extends keyof TSchemaOptions ?
51
+ TSchemaOptions['discriminatorKey'] extends string ? TSchemaOptions['discriminatorKey'] : '__t'
52
+ : '__t'
53
+ : '__t';
54
+
55
+ type DiscriminatorRawBaseType<TBaseSchema extends Schema> =
56
+ InferRawDocTypeFromSchema<TBaseSchema> extends Record<DiscriminatorRawKey<TBaseSchema>, any> ?
57
+ InferRawDocTypeFromSchema<TBaseSchema>
58
+ : MergeType<InferRawDocTypeFromSchema<TBaseSchema>, { [K in DiscriminatorRawKey<TBaseSchema>]?: null }>;
59
+
48
60
  type ResolveDiscriminatorRawPathType<TBaseSchema extends Schema, TDiscriminators> =
49
61
  IsAny<TDiscriminators> extends true ? never
50
62
  : TDiscriminators extends Record<string, any> ?
51
- TDiscriminators[keyof TDiscriminators] extends Schema ?
52
- MergeType<InferRawDocTypeFromSchema<TBaseSchema>, InferRawDocTypeFromSchema<TDiscriminators[keyof TDiscriminators]>>
53
- : never
63
+ DiscriminatorRawBaseType<TBaseSchema> |
64
+ {
65
+ [K in keyof TDiscriminators]: TDiscriminators[K] extends Schema ?
66
+ MergeType<InferRawDocTypeFromSchema<TBaseSchema>, InferRawDocTypeFromSchema<TDiscriminators[K]>> &
67
+ { [KDiscriminatorKey in DiscriminatorRawKey<TBaseSchema>]: K }
68
+ : never
69
+ }[keyof TDiscriminators]
54
70
  : never;
55
71
 
56
72
  type RawDiscriminatorEnumType<T> = string extends keyof T ? never
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(
@@ -283,6 +283,7 @@ declare module 'mongoose' {
283
283
  typeKey: 'type';
284
284
  id: true;
285
285
  _id: true;
286
+ discriminatorKey: '__t';
286
287
  timestamps: false;
287
288
  versionKey: '__v'
288
289
  }
@@ -115,7 +115,7 @@ declare module 'mongoose' {
115
115
  * The default value for this path. If a function, Mongoose executes the function
116
116
  * and uses the return value as the default.
117
117
  */
118
- default?: DefaultType<T> | ((this: THydratedDocumentType, doc: THydratedDocumentType) => DefaultType<T> | null | undefined) | null;
118
+ default?: DefaultType<T> | ((this: THydratedDocumentType, doc: THydratedDocumentType) => DefaultType<T> | null | undefined) | null | undefined;
119
119
 
120
120
  /**
121
121
  * The model that `populate()` should use if populating this path.