-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NODE-3727): add overloads for BulkOperationBase's execute function (
#3018) Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
- Loading branch information
1 parent
c3149e1
commit 216d194
Showing
2 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { expectType } from 'tsd'; | ||
|
||
import { | ||
BulkWriteResult, | ||
MongoClient, | ||
BatchType, | ||
UpdateStatement, | ||
DeleteStatement, | ||
AnyError, | ||
BulkWriteOptions, | ||
Callback, | ||
Document | ||
} from '../../../../src/index'; | ||
import { BulkOperationBase, Batch } from '../../../../src/bulk/common'; | ||
|
||
const client = new MongoClient(''); | ||
const db = client.db('test'); | ||
const collection = db.collection('test'); | ||
|
||
class TestBulkOperation extends BulkOperationBase { | ||
constructor() { | ||
super(collection, {}, true); | ||
} | ||
|
||
addToOperationsList( | ||
batchType: BatchType, | ||
document: Document | UpdateStatement | DeleteStatement | ||
): this { | ||
this.s.currentBatch = new Batch<Document>(batchType, 0); | ||
this.s.currentBatch.operations.push(document); | ||
return this; | ||
} | ||
} | ||
|
||
const bulkOperation = new TestBulkOperation(); | ||
|
||
// execute | ||
|
||
const options: BulkWriteOptions = {}; | ||
|
||
expectType<Promise<BulkWriteResult>>(bulkOperation.execute()); | ||
|
||
expectType<Promise<BulkWriteResult>>(bulkOperation.execute(options)); | ||
|
||
// ensure we can use the bulk operation execute in a callback based wrapper function | ||
function extendedPromiseBasedBulkExecute( | ||
optionalOptions?: BulkWriteOptions | ||
): Promise<BulkWriteResult> { | ||
return bulkOperation.execute(optionalOptions); | ||
} | ||
|
||
expectType<Promise<BulkWriteResult>>(extendedPromiseBasedBulkExecute()); | ||
|
||
expectType<void>( | ||
bulkOperation.execute((error, bulkWriteResult) => { | ||
expectType<AnyError | undefined>(error); | ||
expectType<BulkWriteResult | undefined>(bulkWriteResult); | ||
}) | ||
); | ||
|
||
expectType<void>( | ||
bulkOperation.execute(options, (error, bulkWriteResult) => { | ||
expectType<AnyError | undefined>(error); | ||
expectType<BulkWriteResult | undefined>(bulkWriteResult); | ||
}) | ||
); | ||
|
||
// ensure we can use the bulk operation execute in a callback based wrapper function | ||
function extendedCallbackBasedBulkExecute( | ||
callback: Callback<BulkWriteResult>, | ||
optionalOptions?: BulkWriteOptions | ||
): void { | ||
bulkOperation.execute(optionalOptions, callback); | ||
} | ||
|
||
expectType<void>( | ||
extendedCallbackBasedBulkExecute((error, bulkWriteResult) => { | ||
expectType<AnyError | undefined>(error); | ||
expectType<BulkWriteResult | undefined>(bulkWriteResult); | ||
}) | ||
); |