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.
- package/eslint.config.mjs +1 -0
- package/lib/aggregate.js +11 -4
- package/lib/cursor/aggregationCursor.js +19 -3
- package/lib/cursor/queryCursor.js +17 -5
- package/lib/document.js +10 -0
- package/lib/helpers/buildMiddlewareFilter.js +21 -3
- package/lib/helpers/model/applyHooks.js +9 -2
- package/lib/helpers/model/applyStaticHooks.js +9 -1
- package/lib/helpers/projection/isPathSelectedInclusive.js +1 -11
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/model.js +47 -5
- package/lib/query.js +7 -1
- package/lib/schema/array.js +9 -1
- package/lib/schema/documentArray.js +2 -2
- package/lib/schema/subdocument.js +2 -2
- package/lib/schema.js +55 -0
- package/lib/schemaType.js +10 -4
- package/package.json +8 -8
- package/types/aggregate.d.ts +14 -1
- package/types/document.d.ts +2 -2
- package/types/index.d.ts +56 -8
- package/types/indexes.d.ts +73 -0
- package/types/middlewares.d.ts +11 -2
- package/types/models.d.ts +317 -1
- package/types/utility.d.ts +40 -0
package/types/utility.d.ts
CHANGED
|
@@ -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;
|