-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo-transactions.d.ts
30 lines (29 loc) · 1.25 KB
/
mongo-transactions.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
declare module 'meteor/mongo' {
namespace Mongo {
/**
* Executes a function within a MongoDB Transaction, providing error handling and optional retry functionality.
*
* @async
* @function
* @template T
* @param {() => Promise<T>} fn - The function to be executed within the Transaction.
* @param {boolean} [options.autoRetry=true] - If true, uses the Mongo Transactions Callback API for automatic retry on certain errors (refer to Mongo Docs); otherwise, uses the Core API.
* @param {...any} [options] - Options specific to MongoDB Transactions (writeConcern, readConcern, etc). See the Mongo Docs for more details.
* @returns {Promise<T>} - A promise resolving to the result of the provided function.
* @throws {Error} - Throws an error if the Transaction encounters an issue and cannot be committed.
*/
export const withTransaction: <T>(
fn: () => Promise<T>,
options?: {
autoRetry?: boolean;
[key: string]: any;
}
) => Promise<T>;
/**
* Checks whether the current session is in a Transaction.
*
* @returns {boolean} Returns `true` if the current session is in a Transaction, `false` otherwise.
*/
export const inTransaction: () => boolean;
}
}