@@ -15,8 +15,6 @@ import {
15
15
import { ADMIN_DB , asPrintable , namespaceInfo , ServerVersions , Topologies } from './enums' ;
16
16
import {
17
17
adaptAggregateOptions ,
18
- assertArgsDefined ,
19
- assertArgsType ,
20
18
assertKeysDefined ,
21
19
dataFormat ,
22
20
validateExplainableVerbosity ,
@@ -29,7 +27,8 @@ import {
29
27
processMapReduceOptions ,
30
28
setHideIndex ,
31
29
maybeMarkAsExplainOutput ,
32
- markAsExplainOutput
30
+ markAsExplainOutput ,
31
+ assertArgsDefinedType
33
32
} from './helpers' ;
34
33
import {
35
34
AnyBulkWriteOperation ,
@@ -287,7 +286,7 @@ export default class Collection extends ShellApiClass {
287
286
*/
288
287
@returnsPromise
289
288
async deleteMany ( filter : Document , options : DeleteOptions = { } ) : Promise < DeleteResult | Document > {
290
- assertArgsDefined ( filter ) ;
289
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.deleteMany' ) ;
291
290
this . _emitCollectionApiCall ( 'deleteMany' , { filter, options } ) ;
292
291
293
292
const result = await this . _mongo . _serviceProvider . deleteMany (
@@ -320,7 +319,7 @@ export default class Collection extends ShellApiClass {
320
319
*/
321
320
@returnsPromise
322
321
async deleteOne ( filter : Document , options : DeleteOptions = { } ) : Promise < DeleteResult | Document > {
323
- assertArgsDefined ( filter ) ;
322
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.deleteOne' ) ;
324
323
this . _emitCollectionApiCall ( 'deleteOne' , { filter, options } ) ;
325
324
326
325
const result = await this . _mongo . _serviceProvider . deleteOne (
@@ -409,7 +408,7 @@ export default class Collection extends ShellApiClass {
409
408
410
409
@returnsPromise
411
410
async findAndModify ( options : FindAndModifyMethodShellOptions ) : Promise < Document > {
412
- assertArgsDefined ( options ) ;
411
+ assertArgsDefinedType ( [ options ] , [ true ] , 'Collection.findAndModify' ) ;
413
412
assertKeysDefined ( options , [ 'query' ] ) ;
414
413
this . _emitCollectionApiCall (
415
414
'findAndModify' ,
@@ -463,8 +462,7 @@ export default class Collection extends ShellApiClass {
463
462
newName : string ,
464
463
dropTarget ?: boolean
465
464
) : Promise < Document > {
466
- assertArgsDefined ( newName ) ;
467
- assertArgsType ( [ newName ] , [ 'string' ] ) ;
465
+ assertArgsDefinedType ( [ newName ] , [ 'string' ] , 'Collection.renameCollection' ) ;
468
466
this . _emitCollectionApiCall ( 'renameCollection' , { newName, dropTarget } ) ;
469
467
470
468
try {
@@ -505,7 +503,7 @@ export default class Collection extends ShellApiClass {
505
503
@returnType ( 'Document' )
506
504
@serverVersions ( [ '3.2.0' , ServerVersions . latest ] )
507
505
async findOneAndDelete ( filter : Document , options : FindAndModifyOptions = { } ) : Promise < Document > {
508
- assertArgsDefined ( filter ) ;
506
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.findOneAndDelete' ) ;
509
507
this . _emitCollectionApiCall ( 'findOneAndDelete' , { filter, options } ) ;
510
508
const result = await this . _mongo . _serviceProvider . findOneAndDelete (
511
509
this . _database . _name ,
@@ -538,7 +536,7 @@ export default class Collection extends ShellApiClass {
538
536
@returnType ( 'Document' )
539
537
@serverVersions ( [ '3.2.0' , ServerVersions . latest ] )
540
538
async findOneAndReplace ( filter : Document , replacement : Document , options : FindAndModifyShellOptions = { } ) : Promise < Document > {
541
- assertArgsDefined ( filter ) ;
539
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.findOneAndReplace' ) ;
542
540
const findOneAndReplaceOptions = processFindAndModifyOptions ( {
543
541
...this . _database . _baseOptions ,
544
542
...options
@@ -576,7 +574,7 @@ export default class Collection extends ShellApiClass {
576
574
@returnType ( 'Document' )
577
575
@serverVersions ( [ '3.2.0' , ServerVersions . latest ] )
578
576
async findOneAndUpdate ( filter : Document , update : Document | Document [ ] , options : FindAndModifyShellOptions = { } ) : Promise < Document > {
579
- assertArgsDefined ( filter ) ;
577
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.findOneAndUpdate' ) ;
580
578
const findOneAndUpdateOptions = processFindAndModifyOptions ( {
581
579
...this . _database . _baseOptions ,
582
580
...options
@@ -616,7 +614,7 @@ export default class Collection extends ShellApiClass {
616
614
'Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.' ,
617
615
this . _mongo . _internalState . context . print
618
616
) ;
619
- assertArgsDefined ( docs ) ;
617
+ assertArgsDefinedType ( [ docs ] , [ true ] , 'Collection.insert' ) ;
620
618
// When inserting documents into MongoDB that do not contain the _id field,
621
619
// one will be added to each of the documents missing it by the Node driver,
622
620
// mutating the document. To prevent this behaviour we pass not the original document,
@@ -654,7 +652,7 @@ export default class Collection extends ShellApiClass {
654
652
@returnsPromise
655
653
@serverVersions ( [ '3.2.0' , ServerVersions . latest ] )
656
654
async insertMany ( docs : Document [ ] , options : BulkWriteOptions = { } ) : Promise < InsertManyResult > {
657
- assertArgsDefined ( docs ) ;
655
+ assertArgsDefinedType ( [ docs ] , [ true ] , 'Collection.insertMany' ) ;
658
656
const docsToInsert : Document [ ] = Array . isArray ( docs ) ? docs . map ( ( doc ) => ( { ...doc } ) ) : docs ;
659
657
660
658
this . _emitCollectionApiCall ( 'insertMany' , { options } ) ;
@@ -687,7 +685,7 @@ export default class Collection extends ShellApiClass {
687
685
@returnsPromise
688
686
@serverVersions ( [ '3.2.0' , ServerVersions . latest ] )
689
687
async insertOne ( doc : Document , options : InsertOneOptions = { } ) : Promise < InsertOneResult > {
690
- assertArgsDefined ( doc ) ;
688
+ assertArgsDefinedType ( [ doc ] , [ true ] , 'Collection.insertOne' ) ;
691
689
692
690
this . _emitCollectionApiCall ( 'insertOne' , { options } ) ;
693
691
const result = await this . _mongo . _serviceProvider . insertOne (
@@ -734,7 +732,7 @@ export default class Collection extends ShellApiClass {
734
732
'Collection.remove() is deprecated. Use deleteOne, deleteMany, findOneAndDelete, or bulkWrite.' ,
735
733
this . _mongo . _internalState . context . print
736
734
) ;
737
- assertArgsDefined ( query ) ;
735
+ assertArgsDefinedType ( [ query ] , [ true ] , 'Collection.remove' ) ;
738
736
const removeOptions = processRemoveOptions ( options ) ;
739
737
const method = removeOptions . justOne ? 'deleteOne' : 'deleteMany' ;
740
738
delete removeOptions . justOne ;
@@ -781,7 +779,7 @@ export default class Collection extends ShellApiClass {
781
779
@returnsPromise
782
780
@serverVersions ( [ '3.2.0' , ServerVersions . latest ] )
783
781
async replaceOne ( filter : Document , replacement : Document , options : ReplaceOptions = { } ) : Promise < UpdateResult > {
784
- assertArgsDefined ( filter ) ;
782
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.replaceOne' ) ;
785
783
786
784
this . _emitCollectionApiCall ( 'replaceOne' , { filter, options } ) ;
787
785
const result = await this . _mongo . _serviceProvider . replaceOne (
@@ -808,7 +806,7 @@ export default class Collection extends ShellApiClass {
808
806
'Collection.update() is deprecated. Use updateOne, updateMany, or bulkWrite.' ,
809
807
this . _mongo . _internalState . context . print
810
808
) ;
811
- assertArgsDefined ( update ) ;
809
+ assertArgsDefinedType ( [ filter , update ] , [ true , true ] , 'Collection.update' ) ;
812
810
this . _emitCollectionApiCall ( 'update' , { filter, options } ) ;
813
811
let result ;
814
812
@@ -857,7 +855,7 @@ export default class Collection extends ShellApiClass {
857
855
@returnsPromise
858
856
@serverVersions ( [ '3.2.0' , ServerVersions . latest ] )
859
857
async updateMany ( filter : Document , update : Document , options : UpdateOptions = { } ) : Promise < UpdateResult | Document > {
860
- assertArgsDefined ( filter ) ;
858
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.updateMany' ) ;
861
859
this . _emitCollectionApiCall ( 'updateMany' , { filter, options } ) ;
862
860
const result = await this . _mongo . _serviceProvider . updateMany (
863
861
this . _database . _name ,
@@ -899,7 +897,7 @@ export default class Collection extends ShellApiClass {
899
897
update : Document ,
900
898
options : UpdateOptions = { }
901
899
) : Promise < UpdateResult | Document > {
902
- assertArgsDefined ( filter ) ;
900
+ assertArgsDefinedType ( [ filter ] , [ true ] , 'Collection.updateOne' ) ;
903
901
this . _emitCollectionApiCall ( 'updateOne' , { filter, options } ) ;
904
902
const result = await this . _mongo . _serviceProvider . updateOne (
905
903
this . _database . _name ,
@@ -956,7 +954,7 @@ export default class Collection extends ShellApiClass {
956
954
keyPatterns : Document [ ] ,
957
955
options : CreateIndexesOptions = { }
958
956
) : Promise < string [ ] > {
959
- assertArgsDefined ( keyPatterns ) ;
957
+ assertArgsDefinedType ( [ keyPatterns ] , [ true ] , 'Collection.createIndexes' ) ;
960
958
if ( typeof options !== 'object' || Array . isArray ( options ) ) {
961
959
throw new MongoshInvalidInputError (
962
960
'The "options" argument must be an object.' ,
@@ -990,7 +988,7 @@ export default class Collection extends ShellApiClass {
990
988
keys : Document ,
991
989
options : CreateIndexesOptions = { }
992
990
) : Promise < string > {
993
- assertArgsDefined ( keys ) ;
991
+ assertArgsDefinedType ( [ keys ] , [ true ] , 'Collection.createIndex' ) ;
994
992
if ( typeof options !== 'object' || Array . isArray ( options ) ) {
995
993
throw new MongoshInvalidInputError (
996
994
'The "options" argument must be an object.' ,
@@ -1025,7 +1023,7 @@ export default class Collection extends ShellApiClass {
1025
1023
keys : Document ,
1026
1024
options : CreateIndexesOptions = { }
1027
1025
) : Promise < Document > {
1028
- assertArgsDefined ( keys ) ;
1026
+ assertArgsDefinedType ( [ keys ] , [ true ] , 'Collection.ensureIndex' ) ;
1029
1027
if ( typeof options !== 'object' || Array . isArray ( options ) ) {
1030
1028
throw new MongoshInvalidInputError (
1031
1029
'The "options" argument must be an object.' ,
@@ -1145,7 +1143,7 @@ export default class Collection extends ShellApiClass {
1145
1143
*/
1146
1144
@returnsPromise
1147
1145
async dropIndex ( index : string | Document ) : Promise < Document > {
1148
- assertArgsDefined ( index ) ;
1146
+ assertArgsDefinedType ( [ index ] , [ true ] , 'Collection.dropIndex' ) ;
1149
1147
this . _emitCollectionApiCall ( 'dropIndex' , { index } ) ;
1150
1148
if ( index === '*' ) {
1151
1149
throw new MongoshInvalidInputError (
@@ -1315,7 +1313,7 @@ export default class Collection extends ShellApiClass {
1315
1313
1316
1314
@returnsPromise
1317
1315
async runCommand ( commandName : string , options ?: RunCommandOptions ) : Promise < Document > {
1318
- assertArgsType ( [ commandName ] , [ 'string' ] ) ;
1316
+ assertArgsDefinedType ( [ commandName ] , [ 'string' ] , 'Collection.runCommand' ) ;
1319
1317
1320
1318
if ( options && commandName in options ) {
1321
1319
throw new MongoshInvalidInputError (
@@ -1475,7 +1473,7 @@ export default class Collection extends ShellApiClass {
1475
1473
1476
1474
@returnsPromise
1477
1475
async mapReduce ( map : Function | string , reduce : Function | string , optionsOrOutString : MapReduceShellOptions ) : Promise < Document > {
1478
- assertArgsDefined ( map , reduce , optionsOrOutString ) ;
1476
+ assertArgsDefinedType ( [ map , reduce , optionsOrOutString ] , [ true , true , true ] , 'Collection.mapReduce' ) ;
1479
1477
this . _emitCollectionApiCall ( 'mapReduce' , { map, reduce, out : optionsOrOutString } ) ;
1480
1478
1481
1479
let cmd = {
0 commit comments