mongoose 7.4.2 → 7.4.4

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/query.d.ts CHANGED
@@ -179,6 +179,10 @@ declare module 'mongoose' {
179
179
 
180
180
  type QueryOpThatReturnsDocument = 'find' | 'findOne' | 'findOneAndUpdate' | 'findOneAndReplace' | 'findOneAndDelete';
181
181
 
182
+ type GetLeanResultType<RawDocType, ResultType, QueryOp> = QueryOp extends QueryOpThatReturnsDocument
183
+ ? (ResultType extends any[] ? Require_id<FlattenMaps<RawDocType>>[] : Require_id<FlattenMaps<RawDocType>>)
184
+ : ResultType;
185
+
182
186
  class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType, QueryOp = 'find'> implements SessionOperation {
183
187
  _mongooseOptions: MongooseQueryOptions<DocType>;
184
188
 
@@ -499,9 +503,19 @@ declare module 'mongoose' {
499
503
  j(val: boolean | null): this;
500
504
 
501
505
  /** Sets the lean option. */
502
- lean<LeanResultType = QueryOp extends QueryOpThatReturnsDocument ? (ResultType extends any[] ? Require_id<FlattenMaps<RawDocType>>[] : Require_id<FlattenMaps<RawDocType>>) : ResultType>(
506
+ lean<
507
+ LeanResultType = GetLeanResultType<RawDocType, ResultType, QueryOp>
508
+ >(
503
509
  val?: boolean | any
504
- ): QueryWithHelpers<ResultType extends null ? LeanResultType | null : LeanResultType, DocType, THelpers, RawDocType, QueryOp>;
510
+ ): QueryWithHelpers<
511
+ ResultType extends null
512
+ ? LeanResultType | null
513
+ : LeanResultType,
514
+ DocType,
515
+ THelpers,
516
+ RawDocType,
517
+ QueryOp
518
+ >;
505
519
 
506
520
  /** Specifies the maximum number of documents the query will return. */
507
521
  limit(val: number): this;