UNPKG

1.68 kBTypeScriptView Raw
1declare module 'mongoose' {
2 import mongodb = require('mongodb');
3
4 type ClientSessionOptions = mongodb.ClientSessionOptions;
5 type ClientSession = mongodb.ClientSession;
6
7 /**
8 * _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
9 * for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
10 * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
11 */
12 function startSession(options: ClientSessionOptions | undefined | null, callback: Callback<ClientSession>): void;
13 function startSession(callback: Callback<ClientSession>): void;
14 function startSession(options?: ClientSessionOptions): Promise<ClientSession>;
15
16 interface SessionOperation {
17 /** Sets the session. Useful for [transactions](/docs/transactions.html). */
18 session(session: mongodb.ClientSession | null): this;
19 }
20
21 interface SessionStarter {
22
23 /**
24 * Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
25 * for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
26 * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
27 */
28 startSession(options: ClientSessionOptions | undefined | null, callback: Callback<ClientSession>): void;
29 startSession(callback: Callback<ClientSession>): void;
30 startSession(options?: ClientSessionOptions): Promise<ClientSession>;
31 }
32
33 interface SessionOption {
34 session?: ClientSession | null;
35 }
36}