1- import { BSONRegExp , Decimal128 , ObjectId } from 'bson' ;
1+ import { BSONRegExp , Decimal128 , Long , ObjectId } from 'bson' ;
22import { expectAssignable , expectNotType , expectType } from 'tsd' ;
33import { Filter , MongoClient } from '../../../../src' ;
44
@@ -30,6 +30,7 @@ interface PetModel {
3030 isCute : boolean ; // boolean field
3131 bestFriend ?: HumanModel ; // object field (Embedded/Nested Documents)
3232 createdAt : Date ; // date field
33+ numOfPats : Long ; // long field
3334 treats : string [ ] ; // array of string
3435 playTimePercent : Decimal128 ; // bson Decimal128 type
3536 readonly friends ?: ReadonlyArray < HumanModel > ; // readonly array of objects
@@ -38,6 +39,7 @@ interface PetModel {
3839 meta ?: {
3940 updatedAt ?: Date ;
4041 deep ?: {
42+ nestedArray : number [ ] ;
4143 nested ?: {
4244 level ?: number ;
4345 } ;
@@ -58,6 +60,7 @@ const spot = {
5860 type : 'dog' as const ,
5961 isCute : true ,
6062 createdAt : new Date ( ) ,
63+ numOfPats : Long . fromBigInt ( 100000000n ) ,
6164 treats : [ 'kibble' , 'bone' ] ,
6265 playTimePercent : new Decimal128 ( '0.999999' )
6366} ;
@@ -109,8 +112,20 @@ expectNotType<Filter<PetModel>>({ bestFriend: [{ name: 'Andersons' }] });
109112/// it should query __nested document__ fields using dot-notation
110113collectionT . find ( { 'meta.updatedAt' : new Date ( ) } ) ;
111114collectionT . find ( { 'meta.deep.nested.level' : 123 } ) ;
115+ collectionT . find ( { meta : { deep : { nested : { level : 123 } } } } ) ; // no impact on actual nesting
112116collectionT . find ( { 'friends.0.name' : 'John' } ) ;
113117collectionT . find ( { 'playmates.0.name' : 'John' } ) ;
118+
119+ // There's an issue with the special BSON types
120+ collectionT . find ( { 'numOfPats.__isLong__' : true } ) ;
121+ collectionT . find ( { numOfPats : Long . fromBigInt ( 2n ) } ) ;
122+ collectionT . find ( { 'playTimePercent.bytes.BYTES_PER_ELEMENT' : 1 } ) ;
123+ collectionT . find ( { playTimePercent : new Decimal128 ( '123.2' ) } ) ;
124+
125+ // works with some extreme indexes
126+ collectionT . find ( { 'friends.4294967295.name' : 'John' } ) ;
127+ collectionT . find ( { 'friends.999999999999999999999999999999999999.name' : 'John' } ) ;
128+
114129/// it should not accept wrong types for nested document fields
115130expectNotType < Filter < PetModel > > ( { 'meta.updatedAt' : 123 } ) ;
116131expectNotType < Filter < PetModel > > ( { 'meta.updatedAt' : true } ) ;
@@ -121,6 +136,10 @@ expectNotType<Filter<PetModel>>({ 'meta.deep.nested.level': new Date() });
121136expectNotType < Filter < PetModel > > ( { 'friends.0.name' : 123 } ) ;
122137expectNotType < Filter < PetModel > > ( { 'playmates.0.name' : 123 } ) ;
123138
139+ // Nested arrays aren't checked
140+ expectType < Filter < PetModel > > ( { 'meta.deep.nestedArray.0' : 'not a number' } ) ;
141+ expectNotType < Filter < PetModel > > ( { 'meta.deep.nestedArray.23' : 'not a number' } ) ;
142+
124143/// it should query __array__ fields by exact match
125144await collectionT . find ( { treats : [ 'kibble' , 'bone' ] } ) . toArray ( ) ;
126145/// it should query __array__ fields by element type
0 commit comments