1
- import { BSONRegExp , Decimal128 , ObjectId } from 'bson' ;
1
+ import { BSONRegExp , Decimal128 , Long , ObjectId } from 'bson' ;
2
2
import { expectAssignable , expectNotType , expectType } from 'tsd' ;
3
3
4
4
import { Filter , MongoClient , WithId } from '../../../../src' ;
@@ -31,6 +31,7 @@ interface PetModel {
31
31
isCute : boolean ; // boolean field
32
32
bestFriend ?: HumanModel ; // object field (Embedded/Nested Documents)
33
33
createdAt : Date ; // date field
34
+ numOfPats : Long ; // long field
34
35
treats : string [ ] ; // array of string
35
36
playTimePercent : Decimal128 ; // bson Decimal128 type
36
37
readonly friends ?: ReadonlyArray < HumanModel > ; // readonly array of objects
@@ -39,6 +40,7 @@ interface PetModel {
39
40
meta ?: {
40
41
updatedAt ?: Date ;
41
42
deep ?: {
43
+ nestedArray : number [ ] ;
42
44
nested ?: {
43
45
level ?: number ;
44
46
} ;
@@ -59,6 +61,7 @@ const spot = {
59
61
type : 'dog' as const ,
60
62
isCute : true ,
61
63
createdAt : new Date ( ) ,
64
+ numOfPats : Long . fromBigInt ( 100000000n ) ,
62
65
treats : [ 'kibble' , 'bone' ] ,
63
66
playTimePercent : new Decimal128 ( '0.999999' )
64
67
} ;
@@ -114,8 +117,20 @@ expectNotType<Filter<PetModel>>({ bestFriend: [{ name: 'Andersons' }] });
114
117
/// it should query __nested document__ fields using dot-notation
115
118
collectionT . find ( { 'meta.updatedAt' : new Date ( ) } ) ;
116
119
collectionT . find ( { 'meta.deep.nested.level' : 123 } ) ;
120
+ collectionT . find ( { meta : { deep : { nested : { level : 123 } } } } ) ; // no impact on actual nesting
117
121
collectionT . find ( { 'friends.0.name' : 'John' } ) ;
118
122
collectionT . find ( { 'playmates.0.name' : 'John' } ) ;
123
+
124
+ // There's an issue with the special BSON types
125
+ collectionT . find ( { 'numOfPats.__isLong__' : true } ) ;
126
+ collectionT . find ( { numOfPats : Long . fromBigInt ( 2n ) } ) ;
127
+ collectionT . find ( { 'playTimePercent.bytes.BYTES_PER_ELEMENT' : 1 } ) ;
128
+ collectionT . find ( { playTimePercent : new Decimal128 ( '123.2' ) } ) ;
129
+
130
+ // works with some extreme indexes
131
+ collectionT . find ( { 'friends.4294967295.name' : 'John' } ) ;
132
+ collectionT . find ( { 'friends.999999999999999999999999999999999999.name' : 'John' } ) ;
133
+
119
134
/// it should not accept wrong types for nested document fields
120
135
expectNotType < Filter < PetModel > > ( { 'meta.updatedAt' : 123 } ) ;
121
136
expectNotType < Filter < PetModel > > ( { 'meta.updatedAt' : true } ) ;
@@ -126,6 +141,10 @@ expectNotType<Filter<PetModel>>({ 'meta.deep.nested.level': new Date() });
126
141
expectNotType < Filter < PetModel > > ( { 'friends.0.name' : 123 } ) ;
127
142
expectNotType < Filter < PetModel > > ( { 'playmates.0.name' : 123 } ) ;
128
143
144
+ // Nested arrays aren't checked
145
+ expectType < Filter < PetModel > > ( { 'meta.deep.nestedArray.0' : 'not a number' } ) ;
146
+ expectNotType < Filter < PetModel > > ( { 'meta.deep.nestedArray.23' : 'not a number' } ) ;
147
+
129
148
/// it should query __array__ fields by exact match
130
149
await collectionT . find ( { treats : [ 'kibble' , 'bone' ] } ) . toArray ( ) ;
131
150
/// it should query __array__ fields by element type
0 commit comments