mongoose 8.13.2 → 8.14.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/types/index.d.ts CHANGED
@@ -90,7 +90,8 @@ declare module 'mongoose' {
90
90
  HydratedDocument<
91
91
  InferSchemaType<TSchema>,
92
92
  ObtainSchemaGeneric<TSchema, 'TVirtuals'> & ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
93
- ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>
93
+ ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
94
+ ObtainSchemaGeneric<TSchema, 'TVirtuals'>
94
95
  >,
95
96
  TSchema
96
97
  > & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
@@ -146,16 +147,17 @@ declare module 'mongoose' {
146
147
  export type HydratedDocument<
147
148
  DocType,
148
149
  TOverrides = {},
149
- TQueryHelpers = {}
150
+ TQueryHelpers = {},
151
+ TVirtuals = {}
150
152
  > = IfAny<
151
153
  DocType,
152
154
  any,
153
155
  TOverrides extends Record<string, never> ?
154
- Document<unknown, TQueryHelpers, DocType> & Default__v<Require_id<DocType>> :
156
+ Document<unknown, TQueryHelpers, DocType, TVirtuals> & Default__v<Require_id<DocType>> :
155
157
  IfAny<
156
158
  TOverrides,
157
- Document<unknown, TQueryHelpers, DocType> & Default__v<Require_id<DocType>>,
158
- Document<unknown, TQueryHelpers, DocType> & MergeType<
159
+ Document<unknown, TQueryHelpers, DocType, TVirtuals> & Default__v<Require_id<DocType>>,
160
+ Document<unknown, TQueryHelpers, DocType, TVirtuals> & MergeType<
159
161
  Default__v<Require_id<DocType>>,
160
162
  TOverrides
161
163
  >
@@ -195,8 +197,9 @@ declare module 'mongoose' {
195
197
 
196
198
  export type HydratedDocumentFromSchema<TSchema extends Schema> = HydratedDocument<
197
199
  InferSchemaType<TSchema>,
198
- ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
199
- ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>
200
+ ObtainSchemaGeneric<TSchema, 'TInstanceMethods'> & ObtainSchemaGeneric<TSchema, 'TVirtuals'>,
201
+ ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
202
+ ObtainSchemaGeneric<TSchema, 'TVirtuals'>
200
203
  >;
201
204
 
202
205
  export interface TagSet {
@@ -269,7 +272,7 @@ declare module 'mongoose' {
269
272
  ObtainDocumentType<any, RawDocType, ResolveSchemaOptions<TSchemaOptions>>,
270
273
  ResolveSchemaOptions<TSchemaOptions>
271
274
  >,
272
- THydratedDocumentType = HydratedDocument<FlatRecord<DocType>, TVirtuals & TInstanceMethods>
275
+ THydratedDocumentType = HydratedDocument<FlatRecord<DocType>, TVirtuals & TInstanceMethods, {}, TVirtuals>
273
276
  >
274
277
  extends events.EventEmitter {
275
278
  /**
@@ -436,6 +439,7 @@ declare module 'mongoose' {
436
439
  ): this;
437
440
  // this = Document
438
441
  pre<T = THydratedDocumentType>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this;
442
+ pre<T = THydratedDocumentType, U = RawDocType>(method: 'init', fn: (this: T, doc: U) => void): this;
439
443
  pre<T = THydratedDocumentType>(method: MongooseDistinctDocumentMiddleware|MongooseDistinctDocumentMiddleware[], fn: PreMiddlewareFunction<T>): this;
440
444
  pre<T = THydratedDocumentType>(method: MongooseDistinctDocumentMiddleware|MongooseDistinctDocumentMiddleware[], options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
441
445
  pre<T = THydratedDocumentType>(
@@ -22,7 +22,7 @@ declare module 'mongoose' {
22
22
 
23
23
  /**
24
24
  * @summary Obtains schema Path type.
25
- * @description Obtains Path type by separating path type from other options and calling {@link ResolvePathType}
25
+ * @description Obtains Path type by separating path type from other options and calling {@link ResolveRawPathType}
26
26
  * @param {PathValueType} PathValueType Document definition path type.
27
27
  * @param {TypeKey} TypeKey A generic refers to document definition.
28
28
  */
@@ -61,14 +61,14 @@ declare module 'mongoose' {
61
61
  // so we can directly obtain its path type.
62
62
  ObtainRawDocumentPathType<Item, TypeKey>[] :
63
63
  // If the type key isn't callable, then this is an array of objects, in which case
64
- // we need to call ObtainDocumentType to correctly infer its type.
65
- Array<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
64
+ // we need to call InferRawDocType to correctly infer its type.
65
+ Array<InferRawDocType<Item>> :
66
66
  IsSchemaTypeFromBuiltinClass<Item> extends true ?
67
67
  ObtainRawDocumentPathType<Item, TypeKey>[] :
68
68
  IsItRecordAndNotAny<Item> extends true ?
69
69
  Item extends Record<string, never> ?
70
70
  ObtainRawDocumentPathType<Item, TypeKey>[] :
71
- Array<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
71
+ Array<InferRawDocType<Item>> :
72
72
  ObtainRawDocumentPathType<Item, TypeKey>[]
73
73
  >:
74
74
  PathValueType extends ReadonlyArray<infer Item> ?
@@ -77,13 +77,13 @@ declare module 'mongoose' {
77
77
  Item extends Record<TypeKey, any> ?
78
78
  Item[TypeKey] extends Function | String ?
79
79
  ObtainRawDocumentPathType<Item, TypeKey>[] :
80
- ObtainDocumentType<Item, any, { typeKey: TypeKey }>[]:
80
+ InferRawDocType<Item>[]:
81
81
  IsSchemaTypeFromBuiltinClass<Item> extends true ?
82
82
  ObtainRawDocumentPathType<Item, TypeKey>[] :
83
83
  IsItRecordAndNotAny<Item> extends true ?
84
84
  Item extends Record<string, never> ?
85
85
  ObtainRawDocumentPathType<Item, TypeKey>[] :
86
- Array<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
86
+ Array<InferRawDocType<Item>> :
87
87
  ObtainRawDocumentPathType<Item, TypeKey>[]
88
88
  >:
89
89
  PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :
@@ -114,6 +114,6 @@ declare module 'mongoose' {
114
114
  IfEquals<PathValueType, ObjectConstructor> extends true ? any:
115
115
  IfEquals<PathValueType, {}> extends true ? any:
116
116
  PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
117
- PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
117
+ PathValueType extends Record<string, any> ? InferRawDocType<PathValueType> :
118
118
  unknown;
119
119
  }
@@ -3,7 +3,7 @@ declare module 'mongoose' {
3
3
 
4
4
  type MongooseQueryAndDocumentMiddleware = 'updateOne' | 'deleteOne';
5
5
 
6
- type MongooseDistinctDocumentMiddleware = 'save' | 'init' | 'validate';
6
+ type MongooseDistinctDocumentMiddleware = 'save' | 'validate';
7
7
  type MongooseDocumentMiddleware = MongooseDistinctDocumentMiddleware | MongooseQueryAndDocumentMiddleware;
8
8
 
9
9
  type MongooseRawResultQueryMiddleware = 'findOneAndUpdate' | 'findOneAndReplace' | 'findOneAndDelete';
package/types/models.d.ts CHANGED
@@ -263,7 +263,7 @@ declare module 'mongoose' {
263
263
  TQueryHelpers = {},
264
264
  TInstanceMethods = {},
265
265
  TVirtuals = {},
266
- THydratedDocumentType = HydratedDocument<TRawDocType, TVirtuals & TInstanceMethods, TQueryHelpers>,
266
+ THydratedDocumentType = HydratedDocument<TRawDocType, TVirtuals & TInstanceMethods, TQueryHelpers, TVirtuals>,
267
267
  TSchema = any> extends
268
268
  NodeJS.EventEmitter,
269
269
  AcceptsDiscriminator,
@@ -215,5 +215,13 @@ declare module 'mongoose' {
215
215
  * to their database property names. Defaults to false.
216
216
  */
217
217
  translateAliases?: boolean;
218
+
219
+ /**
220
+ * Mongoose queries currently store an `_executionStack` property that stores the stack trace
221
+ * of where the query was originally executed for debugging `Query was already executed` errors.
222
+ * This behavior can cause performance issues with bundlers and source maps. Set this option to
223
+ * `true` to disable Mongoose query stack trace collection.
224
+ */
225
+ skipOriginalStackTraces?: boolean;
218
226
  }
219
227
  }
package/types/query.d.ts CHANGED
@@ -466,10 +466,14 @@ declare module 'mongoose' {
466
466
  options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
467
467
  ): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
468
468
  findOneAndUpdate(
469
- filter?: RootFilterQuery<RawDocType>,
470
- update?: UpdateQuery<RawDocType>,
469
+ filter: RootFilterQuery<RawDocType>,
470
+ update: UpdateQuery<RawDocType>,
471
471
  options?: QueryOptions<DocType> | null
472
472
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
473
+ findOneAndUpdate(
474
+ update: UpdateQuery<RawDocType>
475
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
476
+ findOneAndUpdate(): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
473
477
 
474
478
  /** Declares the query a findById operation. When executed, returns the document with the given `_id`. */
475
479
  findById(
@@ -173,6 +173,9 @@ declare module 'mongoose' {
173
173
  /** The maximum value allowed for this path. Only allowed for numbers and dates. */
174
174
  max?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
175
175
 
176
+ /** Set to false to disable minimizing empty single nested subdocuments by default */
177
+ minimize?: boolean;
178
+
176
179
  /** Defines a TTL index on this path. Only allowed for dates. */
177
180
  expires?: string | number;
178
181