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 } 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
} ;
@@ -109,8 +112,20 @@ expectNotType<Filter<PetModel>>({ bestFriend: [{ name: 'Andersons' }] });
109
112
/// it should query __nested document__ fields using dot-notation
110
113
collectionT . find ( { 'meta.updatedAt' : new Date ( ) } ) ;
111
114
collectionT . find ( { 'meta.deep.nested.level' : 123 } ) ;
115
+ collectionT . find ( { meta : { deep : { nested : { level : 123 } } } } ) ; // no impact on actual nesting
112
116
collectionT . find ( { 'friends.0.name' : 'John' } ) ;
113
117
collectionT . 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
+
114
129
/// it should not accept wrong types for nested document fields
115
130
expectNotType < Filter < PetModel > > ( { 'meta.updatedAt' : 123 } ) ;
116
131
expectNotType < Filter < PetModel > > ( { 'meta.updatedAt' : true } ) ;
@@ -121,6 +136,10 @@ expectNotType<Filter<PetModel>>({ 'meta.deep.nested.level': new Date() });
121
136
expectNotType < Filter < PetModel > > ( { 'friends.0.name' : 123 } ) ;
122
137
expectNotType < Filter < PetModel > > ( { 'playmates.0.name' : 123 } ) ;
123
138
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
+
124
143
/// it should query __array__ fields by exact match
125
144
await collectionT . find ( { treats : [ 'kibble' , 'bone' ] } ) . toArray ( ) ;
126
145
/// it should query __array__ fields by element type
0 commit comments