@@ -36,8 +36,8 @@ declare module 'mongoose' {
36
36
TypeKey
37
37
> ;
38
38
39
- type InferRawDocTypeFromSchema < TSchema extends Schema > = TSchema extends AutoInferredSchema
40
- ? InferRawDocType < TSchema [ '_schemaDefinition' ] >
39
+ type InferRawDocTypeFromSchema < TSchema extends Schema > = TSchema extends AutoInferredSchema < infer SchemaDef >
40
+ ? InferRawDocType < SchemaDef >
41
41
: InferSchemaType < TSchema > ;
42
42
43
43
/**
@@ -54,35 +54,22 @@ declare module 'mongoose' {
54
54
* @returns Number, "Number" or "number" will be resolved to number type.
55
55
*/
56
56
type ResolveRawPathType < PathValueType , Options extends SchemaTypeOptions < PathValueType > = { } , TypeKey extends string = DefaultSchemaOptions [ 'typeKey' ] > =
57
- PathValueType extends Schema ?
58
- InferRawDocTypeFromSchema < PathValueType > :
59
- PathValueType extends ( infer Item ) [ ] ?
60
- IfEquals < Item , never , any [ ] , Item extends Schema ?
61
- // If Item is a schema, infer its type.
62
- Array < InferRawDocTypeFromSchema < Item > > :
63
- Item extends Record < TypeKey , any > ?
64
- Item [ TypeKey ] extends Function | String ?
65
- // If Item has a type key that's a string or a callable, it must be a scalar,
66
- // so we can directly obtain its path type.
67
- ObtainRawDocumentPathType < Item , TypeKey > [ ] :
68
- // If the type key isn't callable, then this is an array of objects, in which case
69
- // we need to call InferRawDocType to correctly infer its type.
70
- Array < InferRawDocType < Item > > :
71
- IsSchemaTypeFromBuiltinClass < Item > extends true ?
72
- ObtainRawDocumentPathType < Item , TypeKey > [ ] :
73
- IsItRecordAndNotAny < Item > extends true ?
74
- Item extends Record < string , never > ?
75
- ObtainRawDocumentPathType < Item , TypeKey > [ ] :
76
- Array < InferRawDocType < Item > > :
77
- ObtainRawDocumentPathType < Item , TypeKey > [ ]
78
- > :
79
- PathValueType extends ReadonlyArray < infer Item > ?
57
+ PathValueType extends AutoInferredSchema < infer SchemaDef > ?
58
+ InferRawDocType < SchemaDef > :
59
+ PathValueType extends Schema ?
60
+ InferSchemaType < PathValueType > :
61
+ PathValueType extends ( infer Item ) [ ] ?
80
62
IfEquals < Item , never , any [ ] , Item extends Schema ?
63
+ // If Item is a schema, infer its type.
81
64
Array < InferRawDocTypeFromSchema < Item > > :
82
65
Item extends Record < TypeKey , any > ?
83
66
Item [ TypeKey ] extends Function | String ?
67
+ // If Item has a type key that's a string or a callable, it must be a scalar,
68
+ // so we can directly obtain its path type.
84
69
ObtainRawDocumentPathType < Item , TypeKey > [ ] :
85
- InferRawDocType < Item > [ ] :
70
+ // If the type key isn't callable, then this is an array of objects, in which case
71
+ // we need to call InferRawDocType to correctly infer its type.
72
+ Array < InferRawDocType < Item > > :
86
73
IsSchemaTypeFromBuiltinClass < Item > extends true ?
87
74
ObtainRawDocumentPathType < Item , TypeKey > [ ] :
88
75
IsItRecordAndNotAny < Item > extends true ?
@@ -91,34 +78,49 @@ declare module 'mongoose' {
91
78
Array < InferRawDocType < Item > > :
92
79
ObtainRawDocumentPathType < Item , TypeKey > [ ]
93
80
> :
94
- PathValueType extends StringSchemaDefinition ? PathEnumOrString < Options [ 'enum' ] > :
95
- IfEquals < PathValueType , Schema . Types . String > extends true ? PathEnumOrString < Options [ 'enum' ] > :
96
- IfEquals < PathValueType , String > extends true ? PathEnumOrString < Options [ 'enum' ] > :
97
- PathValueType extends NumberSchemaDefinition ? Options [ 'enum' ] extends ReadonlyArray < any > ? Options [ 'enum' ] [ number ] : number :
98
- IfEquals < PathValueType , Schema . Types . Number > extends true ? number :
99
- PathValueType extends DateSchemaDefinition ? NativeDate :
100
- IfEquals < PathValueType , Schema . Types . Date > extends true ? NativeDate :
101
- PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema . Types . Buffer ? Buffer :
102
- PathValueType extends BooleanSchemaDefinition ? boolean :
103
- IfEquals < PathValueType , Schema . Types . Boolean > extends true ? boolean :
104
- PathValueType extends ObjectIdSchemaDefinition ? Types . ObjectId :
105
- IfEquals < PathValueType , Types . ObjectId > extends true ? Types . ObjectId :
106
- IfEquals < PathValueType , Schema . Types . ObjectId > extends true ? Types . ObjectId :
107
- PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema . Types . Decimal128 ? Types . Decimal128 :
108
- IfEquals < PathValueType , Schema . Types . Decimal128 > extends true ? Types . Decimal128 :
109
- IfEquals < PathValueType , Types . Decimal128 > extends true ? Types . Decimal128 :
110
- IfEquals < PathValueType , Schema . Types . BigInt > extends true ? bigint :
111
- IfEquals < PathValueType , BigInt > extends true ? bigint :
112
- PathValueType extends 'bigint' | 'BigInt' | typeof Schema . Types . BigInt | typeof BigInt ? bigint :
113
- PathValueType extends 'uuid' | 'UUID' | typeof Schema . Types . UUID ? Buffer :
114
- IfEquals < PathValueType , Schema . Types . UUID > extends true ? Buffer :
115
- PathValueType extends MapConstructor | 'Map' ? Map < string , ResolveRawPathType < Options [ 'of' ] > > :
116
- IfEquals < PathValueType , typeof Schema . Types . Map > extends true ? Map < string , ResolveRawPathType < Options [ 'of' ] > > :
117
- PathValueType extends ArrayConstructor ? any [ ] :
118
- PathValueType extends typeof Schema . Types . Mixed ? any :
119
- IfEquals < PathValueType , ObjectConstructor > extends true ? any :
120
- IfEquals < PathValueType , { } > extends true ? any :
121
- PathValueType extends typeof SchemaType ? PathValueType [ 'prototype' ] :
122
- PathValueType extends Record < string , any > ? InferRawDocType < PathValueType > :
123
- unknown ;
81
+ PathValueType extends ReadonlyArray < infer Item > ?
82
+ IfEquals < Item , never , any [ ] , Item extends Schema ?
83
+ Array < InferRawDocTypeFromSchema < Item > > :
84
+ Item extends Record < TypeKey , any > ?
85
+ Item [ TypeKey ] extends Function | String ?
86
+ ObtainRawDocumentPathType < Item , TypeKey > [ ] :
87
+ InferRawDocType < Item > [ ] :
88
+ IsSchemaTypeFromBuiltinClass < Item > extends true ?
89
+ ObtainRawDocumentPathType < Item , TypeKey > [ ] :
90
+ IsItRecordAndNotAny < Item > extends true ?
91
+ Item extends Record < string , never > ?
92
+ ObtainRawDocumentPathType < Item , TypeKey > [ ] :
93
+ Array < InferRawDocType < Item > > :
94
+ ObtainRawDocumentPathType < Item , TypeKey > [ ]
95
+ > :
96
+ PathValueType extends StringSchemaDefinition ? PathEnumOrString < Options [ 'enum' ] > :
97
+ IfEquals < PathValueType , Schema . Types . String > extends true ? PathEnumOrString < Options [ 'enum' ] > :
98
+ IfEquals < PathValueType , String > extends true ? PathEnumOrString < Options [ 'enum' ] > :
99
+ PathValueType extends NumberSchemaDefinition ? Options [ 'enum' ] extends ReadonlyArray < any > ? Options [ 'enum' ] [ number ] : number :
100
+ IfEquals < PathValueType , Schema . Types . Number > extends true ? number :
101
+ PathValueType extends DateSchemaDefinition ? NativeDate :
102
+ IfEquals < PathValueType , Schema . Types . Date > extends true ? NativeDate :
103
+ PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema . Types . Buffer ? Buffer :
104
+ PathValueType extends BooleanSchemaDefinition ? boolean :
105
+ IfEquals < PathValueType , Schema . Types . Boolean > extends true ? boolean :
106
+ PathValueType extends ObjectIdSchemaDefinition ? Types . ObjectId :
107
+ IfEquals < PathValueType , Types . ObjectId > extends true ? Types . ObjectId :
108
+ IfEquals < PathValueType , Schema . Types . ObjectId > extends true ? Types . ObjectId :
109
+ PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema . Types . Decimal128 ? Types . Decimal128 :
110
+ IfEquals < PathValueType , Schema . Types . Decimal128 > extends true ? Types . Decimal128 :
111
+ IfEquals < PathValueType , Types . Decimal128 > extends true ? Types . Decimal128 :
112
+ IfEquals < PathValueType , Schema . Types . BigInt > extends true ? bigint :
113
+ IfEquals < PathValueType , BigInt > extends true ? bigint :
114
+ PathValueType extends 'bigint' | 'BigInt' | typeof Schema . Types . BigInt | typeof BigInt ? bigint :
115
+ PathValueType extends 'uuid' | 'UUID' | typeof Schema . Types . UUID ? Buffer :
116
+ IfEquals < PathValueType , Schema . Types . UUID > extends true ? Buffer :
117
+ PathValueType extends MapConstructor | 'Map' ? Map < string , ResolveRawPathType < Options [ 'of' ] > > :
118
+ IfEquals < PathValueType , typeof Schema . Types . Map > extends true ? Map < string , ResolveRawPathType < Options [ 'of' ] > > :
119
+ PathValueType extends ArrayConstructor ? any [ ] :
120
+ PathValueType extends typeof Schema . Types . Mixed ? any :
121
+ IfEquals < PathValueType , ObjectConstructor > extends true ? any :
122
+ IfEquals < PathValueType , { } > extends true ? any :
123
+ PathValueType extends typeof SchemaType ? PathValueType [ 'prototype' ] :
124
+ PathValueType extends Record < string , any > ? InferRawDocType < PathValueType > :
125
+ unknown ;
124
126
}
0 commit comments