@@ -68,7 +68,7 @@ export type WithoutId<TSchema> = Omit<TSchema, '_id'>;
68
68
export type Filter < TSchema > =
69
69
| Partial < TSchema >
70
70
| ( {
71
- [ Property in Join < NestedPaths < WithId < TSchema > > , '.' > ] ?: Condition <
71
+ [ Property in Join < NestedPaths < WithId < TSchema > , [ ] > , '.' > ] ?: Condition <
72
72
PropertyType < WithId < TSchema > , Property >
73
73
> ;
74
74
} & RootFilterOperators < WithId < TSchema > > ) ;
@@ -263,7 +263,7 @@ export type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType = FieldTyp
263
263
/** @public */
264
264
export type MatchKeysAndValues < TSchema > = Readonly <
265
265
{
266
- [ Property in Join < NestedPaths < TSchema > , '.' > ] ?: PropertyType < TSchema , Property > ;
266
+ [ Property in Join < NestedPaths < TSchema , [ ] > , '.' > ] ?: PropertyType < TSchema , Property > ;
267
267
} & {
268
268
[ Property in `${NestedPathsOfType < TSchema , any [ ] > } .$${`[${string } ]` | '' } `] ?: ArrayElement <
269
269
PropertyType < TSchema , Property extends `${infer Key } .$${string } ` ? Key : never >
@@ -272,7 +272,7 @@ export type MatchKeysAndValues<TSchema> = Readonly<
272
272
[ Property in `${NestedPathsOfType < TSchema , Record < string , any > [ ] > } .$${
273
273
| `[${string } ]`
274
274
| '' } .${string } `] ?: any ; // Could be further narrowed
275
- }
275
+ } & Document
276
276
> ;
277
277
278
278
/** @public */
@@ -498,20 +498,29 @@ export type PropertyType<Type, Property extends string> = string extends Propert
498
498
* @public
499
499
* returns tuple of strings (keys to be joined on '.') that represent every path into a schema
500
500
* https://docs.mongodb.com/manual/tutorial/query-embedded-documents/
501
+ *
502
+ * @remarks
503
+ * Through testing we determined that a depth of 8 is safe for the typescript compiler
504
+ * and provides reasonable compilation times. This number is otherwise not special and
505
+ * should be changed if issues are found with this level of checking. Beyond this
506
+ * depth any helpers that make use of NestedPaths should devolve to not asserting any
507
+ * type safety on the input.
501
508
*/
502
- export type NestedPaths < Type > = Type extends
503
- | string
504
- | number
505
- | boolean
506
- | Date
507
- | RegExp
508
- | Buffer
509
- | Uint8Array
510
- | ( ( ...args : any [ ] ) => any )
511
- | { _bsontype : string }
509
+ export type NestedPaths < Type , Depth extends number [ ] > = Depth [ 'length' ] extends 8
510
+ ? [ ]
511
+ : Type extends
512
+ | string
513
+ | number
514
+ | boolean
515
+ | Date
516
+ | RegExp
517
+ | Buffer
518
+ | Uint8Array
519
+ | ( ( ...args : any [ ] ) => any )
520
+ | { _bsontype : string }
512
521
? [ ]
513
522
: Type extends ReadonlyArray < infer ArrayType >
514
- ? [ ] | [ number , ...NestedPaths < ArrayType > ]
523
+ ? [ ] | [ number , ...NestedPaths < ArrayType , [ ... Depth , 1 ] > ]
515
524
: Type extends Map < string , any >
516
525
? [ string ]
517
526
: Type extends object
@@ -529,9 +538,9 @@ export type NestedPaths<Type> = Type extends
529
538
ArrayType extends Type
530
539
? [ Key ] // we have a recursive array union
531
540
: // child is an array, but it's not a recursive array
532
- [ Key , ...NestedPaths < Type [ Key ] > ]
541
+ [ Key , ...NestedPaths < Type [ Key ] , [ ... Depth , 1 ] > ]
533
542
: // child is not structured the same as the parent
534
- [ Key , ...NestedPaths < Type [ Key ] > ] | [ Key ] ;
543
+ [ Key , ...NestedPaths < Type [ Key ] , [ ... Depth , 1 ] > ] | [ Key ] ;
535
544
} [ Extract < keyof Type , string > ]
536
545
: [ ] ;
537
546
@@ -542,7 +551,7 @@ export type NestedPaths<Type> = Type extends
542
551
*/
543
552
export type NestedPathsOfType < TSchema , Type > = KeysOfAType <
544
553
{
545
- [ Property in Join < NestedPaths < TSchema > , '.' > ] : PropertyType < TSchema , Property > ;
554
+ [ Property in Join < NestedPaths < TSchema , [ ] > , '.' > ] : PropertyType < TSchema , Property > ;
546
555
} ,
547
556
Type
548
557
> ;
0 commit comments