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