mongoose 9.9.4 → 9.10.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.
@@ -1,4 +1,44 @@
1
1
  declare module 'mongoose' {
2
+ type IsNonDefiningProjection<Value, Key, Projection> = Value extends { $slice: any } | { $meta: any }
3
+ ? true
4
+ : Key extends '_id'
5
+ ? Value extends 0 | false
6
+ ? false
7
+ // Including `_id` only defines inclusion when it is the sole projected field.
8
+ : Exclude<keyof Projection, '_id'> extends never ? false : true
9
+ : false;
10
+ type ProjectionPath<Key> = Key extends `${infer Parent}.$` ? Parent : Key;
11
+ type DefiningProjectionKeys<Projection> = {
12
+ [Key in keyof Projection]-?: Key extends string
13
+ ? IsNonDefiningProjection<Projection[Key], Key, Projection> extends true ? never : ProjectionPath<Key>
14
+ : never
15
+ }[keyof Projection];
16
+ type DefiningProjectionValues<Projection> = {
17
+ [Key in keyof Projection]-?: IsNonDefiningProjection<Projection[Key], Key, Projection> extends true ? never : Projection[Key]
18
+ }[keyof Projection];
19
+
20
+ export type ApplyProjection<T, Projection> = Projection extends string
21
+ ? T
22
+ : Projection extends AnyObject
23
+ ? [DefiningProjectionKeys<Projection>] extends [never]
24
+ ? T
25
+ : Exclude<DefiningProjectionValues<Projection>, 0 | false | undefined> extends never
26
+ ? Omit<T, Extract<DefiningProjectionKeys<Projection>, keyof T>>
27
+ : Pick<T, Extract<DefiningProjectionKeys<Projection>, keyof T>> &
28
+ (Projection extends { _id?: infer Id }
29
+ ? Id extends 0 | false
30
+ ? unknown
31
+ : Pick<T, Extract<'_id', keyof T>>
32
+ : Pick<T, Extract<'_id', keyof T>>)
33
+ : T;
34
+
35
+ export type ProjectedHydratedDocument<RawDocType, Projection, TInstanceMethods = {}, TQueryHelpers = {}, TVirtuals = {}> =
36
+ Projection extends { _id?: infer Id }
37
+ ? Id extends 0 | false
38
+ ? Omit<HydratedDocument<ApplyProjection<RawDocType, Projection>, TInstanceMethods, TQueryHelpers, TVirtuals>, '_id'>
39
+ : HydratedDocument<ApplyProjection<RawDocType, Projection>, TInstanceMethods, TQueryHelpers, TVirtuals>
40
+ : HydratedDocument<ApplyProjection<RawDocType, Projection>, TInstanceMethods, TQueryHelpers, TVirtuals>;
41
+
2
42
  type IfAny<IFTYPE, THENTYPE, ELSETYPE = IFTYPE> = 0 extends 1 & IFTYPE
3
43
  ? THENTYPE
4
44
  : ELSETYPE;