[@types/mongodb] Added withTransaction definition and another necessary type. (#37085)

* [@types/mongodb] added withTransaction definition

* Added missing semicolon.
This commit is contained in:
Luis Pais
2019-07-23 12:54:18 -07:00
committed by Wesley Wigham
parent ab9994e1e7
commit 08fde90f0f
+16
View File
@@ -23,6 +23,7 @@
// Erik Christensen <https://github.com/erikc5000>
// Nick Zahn <https://github.com/Manc>
// Jarom Loveridge <https://github.com/jloveridge>
// Luis Pais <https://github.com/ranguna>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -126,6 +127,19 @@ export interface ClientSession extends EventEmitter {
* Starts a new transaction with the given options.
*/
startTransaction(options?: TransactionOptions): void;
/**
* Runs a provided lambda within a transaction, retrying either the commit operation
* or entire transaction as needed (and when the error permits) to better ensure that
* the transaction can complete successfully.
*
* IMPORTANT: This method requires the user to return a Promise, all lambdas that do not
* return a Promise will result in undefined behavior.
*
* @param fn Function to execute with the new session.
* @param options Optional settings for the transaction
*/
withTransaction<T>(fn: WithTransactionCallback<T>, options?: TransactionOptions): Promise<T>;
}
@@ -202,6 +216,8 @@ export interface MongoCallback<T> {
(error: MongoError, result: T): void;
}
export type WithTransactionCallback<T> = (session: ClientSession) => Promise<T>;
/** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoError.html */
export class MongoError extends Error {
constructor(message: string);