@@ -152,17 +152,15 @@ type OptionalPaths<T, TypeKey extends string = DefaultTypeKey> = {
152
152
153
153
/**
154
154
* @summary Obtains schema Path type.
155
- * @description Obtains Path type by calling { @link ResolvePathType} OR by calling {@link InferSchemaType} if path of schema type.
155
+ * @description Obtains Path type by separating path type from other options and calling {@link ResolvePathType}
156
156
* @param {PathValueType } PathValueType Document definition path type.
157
157
* @param {TypeKey } TypeKey A generic refers to document definition.
158
158
*/
159
- type ObtainDocumentPathType < PathValueType , TypeKey extends string = DefaultTypeKey > = PathValueType extends Schema < any >
160
- ? InferSchemaType < PathValueType >
161
- : ResolvePathType <
162
- PathValueType extends PathWithTypePropertyBaseType < TypeKey > ? PathValueType [ TypeKey ] : PathValueType ,
163
- PathValueType extends PathWithTypePropertyBaseType < TypeKey > ? Omit < PathValueType , TypeKey > : { } ,
164
- TypeKey
165
- > ;
159
+ type ObtainDocumentPathType < PathValueType , TypeKey extends string = DefaultTypeKey > = ResolvePathType <
160
+ PathValueType extends PathWithTypePropertyBaseType < TypeKey > ? PathValueType [ TypeKey ] : PathValueType ,
161
+ PathValueType extends PathWithTypePropertyBaseType < TypeKey > ? Omit < PathValueType , TypeKey > : { } ,
162
+ TypeKey
163
+ > ;
166
164
167
165
/**
168
166
* @param {T } T A generic refers to string path enums.
@@ -179,8 +177,29 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends R
179
177
*/
180
178
type ResolvePathType < PathValueType , Options extends SchemaTypeOptions < PathValueType > = { } , TypeKey extends string = DefaultSchemaOptions [ 'typeKey' ] > =
181
179
PathValueType extends Schema ? InferSchemaType < PathValueType > :
182
- PathValueType extends ( infer Item ) [ ] ? IfEquals < Item , never , any [ ] , Item extends Schema ? Types . DocumentArray < ObtainDocumentPathType < Item , TypeKey > > : ObtainDocumentPathType < Item , TypeKey > [ ] > :
183
- PathValueType extends ReadonlyArray < infer Item > ? IfEquals < Item , never , any [ ] , Item extends Schema ? Types . DocumentArray < ObtainDocumentPathType < Item , TypeKey > > : ObtainDocumentPathType < Item , TypeKey > [ ] > :
180
+ PathValueType extends ( infer Item ) [ ] ?
181
+ IfEquals < Item , never , any [ ] , Item extends Schema ?
182
+ // If Item is a schema, infer its type.
183
+ Types . DocumentArray < InferSchemaType < Item > > :
184
+ Item extends Record < TypeKey , any > ?
185
+ Item [ TypeKey ] extends Function | String ?
186
+ // If Item has a type key that's a string or a callable, it must be a scalar,
187
+ // so we can directly obtain its path type.
188
+ ObtainDocumentPathType < Item , TypeKey > [ ] :
189
+ // If the type key isn't callable, then this is an array of objects, in which case
190
+ // we need to call ObtainDocumentType to correctly infer its type.
191
+ ObtainDocumentType < Item , any , { typeKey : TypeKey } > [ ] :
192
+ ObtainDocumentPathType < Item , TypeKey > [ ]
193
+ > :
194
+ PathValueType extends ReadonlyArray < infer Item > ?
195
+ IfEquals < Item , never , any [ ] , Item extends Schema ?
196
+ Types . DocumentArray < InferSchemaType < Item > > :
197
+ Item extends Record < TypeKey , any > ?
198
+ Item [ TypeKey ] extends Function | String ?
199
+ ObtainDocumentPathType < Item , TypeKey > [ ] :
200
+ ObtainDocumentType < Item , any , { typeKey : TypeKey } > [ ] :
201
+ ObtainDocumentPathType < Item , TypeKey > [ ]
202
+ > :
184
203
PathValueType extends StringSchemaDefinition ? PathEnumOrString < Options [ 'enum' ] > :
185
204
IfEquals < PathValueType , Schema . Types . String > extends true ? PathEnumOrString < Options [ 'enum' ] > :
186
205
IfEquals < PathValueType , String > extends true ? PathEnumOrString < Options [ 'enum' ] > :
0 commit comments