@drawbridge/mongodb 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -423,22 +423,17 @@ module.exports = ({
423
423
 
424
424
  transaction : async ( callback ) => {
425
425
 
426
+ const session = client.startSession();
427
+
426
428
  try {
427
429
 
428
- const result = await new Promise(
429
- ( resolve, reject ) => client.withSession(
430
- async ( session ) => session.withTransaction(
431
- async ( session ) => resolve( await callback( session ) ),
432
- null
433
- ).catch( reject )
434
- ).catch( reject )
435
- );
430
+ const result = await session.withTransaction( async () => callback( session ) );
436
431
 
437
432
  return result;
438
433
 
439
- } catch ( error ) {
434
+ } finally {
440
435
 
441
- throw error
436
+ await session.endSession();
442
437
 
443
438
  }
444
439
 
package/dist/index.d.ts CHANGED
@@ -423,22 +423,17 @@ module.exports = ({
423
423
 
424
424
  transaction : async ( callback ) => {
425
425
 
426
+ const session = client.startSession();
427
+
426
428
  try {
427
429
 
428
- const result = await new Promise(
429
- ( resolve, reject ) => client.withSession(
430
- async ( session ) => session.withTransaction(
431
- async ( session ) => resolve( await callback( session ) ),
432
- null
433
- ).catch( reject )
434
- ).catch( reject )
435
- );
430
+ const result = await session.withTransaction( async () => callback( session ) );
436
431
 
437
432
  return result;
438
433
 
439
- } catch ( error ) {
434
+ } finally {
440
435
 
441
- throw error
436
+ await session.endSession();
442
437
 
443
438
  }
444
439
 
package/dist/index.js CHANGED
@@ -306,18 +306,12 @@ module.exports = ({
306
306
  }
307
307
  },
308
308
  transaction: async (callback) => {
309
+ const session = client.startSession();
309
310
  try {
310
- const result = await new Promise(
311
- (resolve, reject) => client.withSession(
312
- async (session) => session.withTransaction(
313
- async (session2) => resolve(await callback(session2)),
314
- null
315
- ).catch(reject)
316
- ).catch(reject)
317
- );
311
+ const result = await session.withTransaction(async () => callback(session));
318
312
  return result;
319
- } catch (error) {
320
- throw error;
313
+ } finally {
314
+ await session.endSession();
321
315
  }
322
316
  },
323
317
  update: async ({
package/dist/index.mjs CHANGED
@@ -319,18 +319,12 @@ var require_index = __commonJS({
319
319
  }
320
320
  },
321
321
  transaction: async (callback) => {
322
+ const session = client.startSession();
322
323
  try {
323
- const result = await new Promise(
324
- (resolve, reject) => client.withSession(
325
- async (session) => session.withTransaction(
326
- async (session2) => resolve(await callback(session2)),
327
- null
328
- ).catch(reject)
329
- ).catch(reject)
330
- );
324
+ const result = await session.withTransaction(async () => callback(session));
331
325
  return result;
332
- } catch (error) {
333
- throw error;
326
+ } finally {
327
+ await session.endSession();
334
328
  }
335
329
  },
336
330
  update: async ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawbridge/mongodb",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {